dongnao2582 2016-05-12 01:54
浏览 363

imap_fetchbody()的正确选项;

I am making an email client, and I have a function which saves all the files attached to an email on server. Files are saving on the server, but the issue is that the size of every file becomes 0 kB, and the encoding for every file is equal to 3.

I want to know how I can select the correct option for imap_fetchbody() on the basis of the sub-type of an attachment.

This is my code:

if($attachments[$i]['is_attachment']){

    $attachments[$i]['attachment'] = imap_fetchbody($imap, $uid, $i + 1;);

    if($structure->parts[$i]->type == 1){
        // 3 = BASE64
        $attachments[$i]['attachment'] = imap_8bit($attachments[$i]['attachment']);
    }

    if($structure->parts[$i]->type == 2){
        // 3 = BASE64
        $attachments[$i]['attachment'] = imap_binary($attachments[$i]['attachment']);
    }

    if($structure->parts[$i]->type == 7){
        // 3 = BASE64
        $attachments[$i]['attachment'] = imap_base64($attachments[$i]['attachment']);
    }

    if($structure->parts[$i]->type == 4){
        // 3 = BASE64
        $attachments[$i]['attachment'] = imap_qprint($attachments[$i]['attachment']);
    }

    if($structure->parts[$i]->type == 3){
        // 3 = BASE64
        $attachments[$i]['attachment'] = base64_decode($attachments[$i]['attachment']);
    }
    elseif($structure->parts[$i]->type == 4){
        // 4 = QUOTED - PRINTABLE
        $attachments[$i]['attachment'] = quoted_printable_decode($attachments[$i]['attachment']);
    }
    //return $message;

}
  • 写回答

1条回答 默认 最新

  • drq22639 2016-05-12 14:09
    关注

    You should be looking at the transfer encoding, not the type, since it's possible to encode a certain file type (e.g. an image, type 5 or TYPEIMAGE) with different encodings (e.g. base64 or quoted-printable).

    Do something like this:

    if($structure->parts[$i]->encoding == ENC8BIT){
        $attachments[$i]['attachment'] = imap_8bit($attachments[$i]['attachment']);
    }
    
    elseif($structure->parts[$i]->encoding == ENCBINARY){
        $attachments[$i]['attachment'] = imap_binary($attachments[$i]['attachment']);
    }
    
    elseif($structure->parts[$i]->encoding == ENCBASE64){
        $attachments[$i]['attachment'] = imap_base64($attachments[$i]['attachment']);
    }
    
    elseif($structure->parts[$i]->encoding == ENCQUOTEDPRINTABLE){
        $attachments[$i]['attachment'] = imap_qprint($attachments[$i]['attachment']);
    }
    
    评论

报告相同问题?

悬赏问题

  • ¥15 用windows做服务的同志有吗
  • ¥60 求一个简单的网页(标签-安全|关键词-上传)
  • ¥35 lstm时间序列共享单车预测,loss值优化,参数优化算法
  • ¥15 基于卷积神经网络的声纹识别
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 一直显示正在等待HID—ISP