【问题标题】:Searching email body without downloading - IMAP在不下载的情况下搜索电子邮件正文 - IMAP
【发布时间】:2014-12-09 09:24:47
【问题描述】:

我可以通过 IMAP 搜索所有电子邮件下载邮件吗?

RFC 3501 IMAP 版本 4 修订版 1 (IMAP4rev1) 的 6.4.4 中所述:

SEARCH 命令在邮箱中搜索匹配的邮件 给定的搜索条件。搜索条件包括一个 或更多搜索键。来自服务器的未标记搜索响应 包含对应于的消息序列号列表 那些符合搜索条件的消息。

定义的搜索关键字如下。参考正式 语法部分的精确句法定义 论据

身体 在正文中包含指定字符串的消息 消息。

...所以我想知道我是否可以在不先下载的情况下在电子邮件正文中搜索?

【问题讨论】:

    标签: php email imap horde


    【解决方案1】:

    imap_search() 函数可以帮助您,但请记住,它需要得到 IMAP 服务器的支持才能工作。

    更新:

    这是小程序:

    error_reporting(E_ALL);
    ini_set('display_errors', '1');
    
    $user = '';         // put your Gmail email address here (including '@gmail.com');
    $pass = '';         // put your Gmail password here
    $host = 'imap.gmail.com:993';      // Put your IMAP server here with portGmail
    $keyword = '';      // put the word you want to find
    
    
    $mailbox = sprintf('{%s/imap/ssl/user=%s}INBOX', $host, $user);
    $query = sprintf('BODY "%s"', $keyword);
    
    $mbox  = imap_open($mailbox, $user, $pass, OP_READONLY);
    if ($mbox) {
        $list = imap_search($mbox, $query, SE_UID);
        var_dump($list);
        imap_close($mbox);
    }
    

    它可能适用于您的设置,也可能不适用。它在我们公司的邮件服务器上使用一个帐户对我有用。它无法连接到与我的常规电子邮件客户端正常工作的另一台服务器上。

    它在使用 Gmail 的同时 (!!) 工作和失败。不要问!

    【讨论】:

    • 我现在只关注 GMAIL,它支持 SEARCH 吗?
    • 我不知道 :-) 尝试编写一个调用imap_open()imap_search() 的小程序,你会发现。文档页面中有一个示例,只需输入您的凭据和搜索条件即可。
    猜你喜欢
    • 2016-12-03
    • 1970-01-01
    • 2013-10-29
    • 1970-01-01
    • 2019-02-16
    • 2014-07-08
    • 2011-04-09
    • 1970-01-01
    • 2011-12-21
    相关资源
    最近更新 更多