dslh32311 2014-12-09 09:24
浏览 49
已采纳

搜索电子邮件正文而无需下载 - IMAP

Can I search ALL emails over IMAP without downloading the message(s)?

As specified in 6.4.4 of RFC 3501 IMAP version 4 revision 1 (IMAP4rev1):

The SEARCH command searches the mailbox for messages that match the given searching criteria. Searching criteria consist of one or more search keys. The untagged SEARCH response from the server contains a listing of message sequence numbers corresponding to those messages that match the searching criteria.

The defined search keys are as follows. Refer to the Formal Syntax section for the precise syntactic definitions of the arguments

BODY Messages that contain the specified string in the body of the message.

...so I wonder if I can search inside the body of the email without downloading it first?

  • 写回答

1条回答 默认 最新

  • douren0558 2014-12-09 09:37
    关注

    The function imap_search() could help you but have in mind that it needs to be supported by the IMAP server to work.

    UPDATE:

    This is the small program:

    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);
    }
    

    It may or may not work with your setup. It worked for me with one account on our company mail server. It failed to connect on another server that works fine with my regular email client.

    It worked and failed on the same time (!!) with Gmail. Don't ask!

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥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更新后资源管理器没有地址栏了顶部的地址栏和文件搜索都消失了