douzhan1868 2013-06-12 21:30
浏览 25
已采纳

从IMAP消息中提取链接

i need to extract an URL from an IMAP message, so far i have been able to extract the message in plain text but not the link, i could really use some help here. Here's what i got so far

$section    = empty( $attachments ) ? 1 : 1.2;  
$text       = imap_fetchbody($connection, $msgno, $section );

echo $text."<hr/>";

I tried changing the section number from 1 : 1.1 to 1: 1.2 but it didn't help.

I need to extract the mail as html so it contains the link, what do i need to change to get the link?

  • 写回答

1条回答 默认 最新

  • douya1855 2013-06-14 16:55
    关注

    Some bugs in the code above:

    • Using 1.2 as a floating point number instead of a string. It's a string and it's only sheer luck that your 1.2 is not getting converted as 1.2000000001.
    • Having a hardcoded part number in case the mail comes with multiple body parts -- read the description in RFC 3501, p. 56 for details on what these body parts are, how they work and how to find out which ones are relevant for you
    • Not performing any decoding of the Content-Transfer-Encoding or dealing with character set conversions. You are apparently interested in text parts of a message, these can arrive in multiple encodings like quoted-printable or base64 which you will have to decode. If you'd like to play it safe (you should, it's 2013 already and there are funny characters in URLs, not speaking about the IDNs), also converted from their charset into unicode and only then matched for contents.
    • You should probably check the MIME types of at least all top-level body parts so that you do not try to detect "links" within the attached images or undecoded, binary representaiton of zip files, etc.
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 抖音咸鱼付款链接转码支付宝
  • ¥15 ubuntu22.04上安装ursim-3.15.8.106339遇到的问题
  • ¥15 求螺旋焊缝的图像处理
  • ¥15 blast算法(相关搜索:数据库)
  • ¥15 请问有人会紧聚焦相关的matlab知识嘛?
  • ¥15 网络通信安全解决方案
  • ¥50 yalmip+Gurobi
  • ¥20 win10修改放大文本以及缩放与布局后蓝屏无法正常进入桌面
  • ¥15 itunes恢复数据最后一步发生错误
  • ¥15 关于#windows#的问题:2024年5月15日的win11更新后资源管理器没有地址栏了顶部的地址栏和文件搜索都消失了