duanjian5059 2019-06-09 00:57
浏览 92

从imap电子邮件中提取链接时检测quoted_printable

I have the following:

if($emails) {
    $output = '';
    rsort($emails);
    foreach($emails as $email_number) {
        foreach ([1,2] as $option) {
            $structure = imap_fetchstructure($inbox, $email_number);
            $overview = imap_fetch_overview($inbox,$email_number,0);
            $message = quoted_printable_decode(imap_fetchbody($inbox,$email_number,$option));

            $regex = '#\bhttps?://[^,\s()<>]+(?:\([\w\d]+\)|([^,[:punct:]\s]|/))#';
            preg_match_all($regex, $message, $links);
            foreach ($links[0] AS $link) {
                $output .= $link.'<br>';
            }
    }}
    echo $output;
}

This works okay except some links contain � and some contain a small empty quare box.

If I don't use quoted_printable_decode(imap_fetchbody($inbox,$email_number,$option))

Then some links contain =3D.

I can' seem to figure out how to get this right.

I have also tried:

$structure = imap_fetchstructure($inbox, $email_number, FT_UID);
if($structure->encoding == "4"){
    $message = base64_decode(imap_fetchbody($inbox, imap_msgno($inbox, $email_number), $option));
} elseif ($structure->encoding == "3") { 
    $message = imap_qprint(map_fetchbody($inbox, imap_msgno($inbox, $email_number), $option));
} else { 
    $message = imap_fetchbody($inbox,$email_number,$option);
}

I simply cannot figure out how to do this.

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 C++ yoloV5改写遇到的问题
    • ¥20 win11修改中文用户名路径
    • ¥15 win2012磁盘空间不足,c盘正常,d盘无法写入
    • ¥15 用土力学知识进行土坡稳定性分析与挡土墙设计
    • ¥70 PlayWright在Java上连接CDP关联本地Chrome启动失败,貌似是Windows端口转发问题
    • ¥15 帮我写一个c++工程
    • ¥30 Eclipse官网打不开,官网首页进不去,显示无法访问此页面,求解决方法
    • ¥15 关于smbclient 库的使用
    • ¥15 微信小程序协议怎么写
    • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?