【发布时间】:2016-03-09 06:15:54
【问题描述】:
我想在 php 中使用 IMAP 获取只有 .ics 文件的电子邮件
$emails = imap_search($inbox, 'ALL');
我正在使用上面的代码进行搜索,我需要一些条件而不是“全部”或某些扩展名(.ics)的 imap_search,这给了我具有 .ics 的电子邮件
【问题讨论】:
我想在 php 中使用 IMAP 获取只有 .ics 文件的电子邮件
$emails = imap_search($inbox, 'ALL');
我正在使用上面的代码进行搜索,我需要一些条件而不是“全部”或某些扩展名(.ics)的 imap_search,这给了我具有 .ics 的电子邮件
【问题讨论】:
您可以使用此功能在您的电子邮件中搜索特定的扩展名。
<?php $keyword=".ics";
$emails = imap_search($inbox,'BODY "'.$keyword.'"', SE_FREE, "UTF-8");
?>
【讨论】:
搜索关键字header content-disposition ".ics" 可能有效,也可能无效。取决于服务器。
IMAP 在这方面的定义不是很好。
HEADER <field-name> <string>
Messages that have a header with the specified field-name (as
defined in [RFC-2822]) and that contains the specified string
in the text of the header (what comes after the colon). If the
string to search is zero-length, this matches all messages that
have a header line with the specified field-name regardless of
the contents.
因此字段名称必须与 2822 中定义的一样。但是电子邮件包含三种标头(顶级消息标头、嵌入的消息/822 标头和最后的正文部分标头),并且所有三种都使用该语法。我怀疑大多数服务器要么搜索第一种标头,要么搜索所有三种标头,并且 RFC 的作者考虑了前两种。
那么你为什么不直接在目标服务器上尝试搜索键,如果它有效,它就有效。
【讨论】:
谢谢朋友,我的问题得到了确切的解决方案
我首先通过imap_open打开连接,然后搜索电子邮件
$imap_search($inbox, 'ALL')
然后通过imap_fetchstructure 获取电子邮件的结构并从该结构中我从附件中获取ics 文件,最后形成附件我得到imap body imap_base64(imap_fetchbody($mbox, $mid, 2));
它实际上会给我 .ics 日历内容
【讨论】: