dpsyssiv90846 2019-05-19 13:56
浏览 300

PHP IMAP_SEARCH语法UNSEEN,SINCE,RECENT会产生意外结果

I am trying to get a list of the most recent unseen messages from a particular email address.

$imapResource = GmailAdapter::imapLogin();

$imapEmails = imap_search($imapResource, 'FROM "email@lala.com" SINCE "18-Mar-2019"');

            if (is_array($imapEmails))
            {
                rsort($imapEmails);

                foreach ($imapEmails as $emailIdent)
                {
                    $overview = imap_fetch_overview($imapResource, $emailIdent, 0);
                    $header = imap_header($imapResource, $emailIdent);
                    $subject = $header->subject;
                    $message = imap_fetchbody($imapResource, $emailIdent, '1');
                    $messageExcerpt = substr($message, 0, 150);
                    $partialMessage = trim(quoted_printable_decode($messageExcerpt));
                    $date = date("d F, Y", strtotime($overview[0]->date));

                    dump($overview);
                    dump($message);
                    dump($subject);
                    dump($date);
                }
                imap_close($imapResource);
            }


I have tried SINCE, RECENT, SEARCH RECENT, SEARCH SINCE, UNSEEN and many combinations of these but they all bring up empty arrays. It seems as soon as I use any of the aforementioned keywords, gmail just says "fuck no" and gives me nothing.

I also tried many different date formats, still nothing.

If I use exclusively

'FROM "email_address"'

it works, but it gives me a subset of email id's spanning from 2012 to 2018 march 6th, so I can't even work with that as I want all the recent emails from a from address.

I've done some looking around on google and here, and it seems nobody has a good answer.

Can anyone shed some light on this, and other similar issues with php IMAP? Why is it so quirky?

UPDATE

I just tried using search term 'ALL' and curiously, it gave me the same last msgno as using my FROM query; 1,000,000, dated March 6th, 2018. Of course, this time, the messages were consecutive,(1,000,000, then 999,999, etc) Which is as it should be when asking for 'ALL' messages. But i wonder, Is this some sort of limitation with gmail?
Could I grab messages > 1,000,000 somehow?

UPDATE #2 Confirmed, gmail has a limitation, if you have more than 1 million emails in a mailbox, it will not grab more than 1,00,000, starting from oldest first, which causes problems like I'm having. Still though, those search keywords don't give me anything it should, for example RECENT, or UNSEEN. The solution seems to involve making sure you have less than a million messages, if you want to grab anything recent. I'm attempting the same on a gmail that has much less than 1,000,000 emails and see what happens.

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 C++ 头文件/宏冲突问题解决
    • ¥15 用comsol模拟大气湍流通过底部加热(温度不同)的腔体
    • ¥50 安卓adb backup备份子用户应用数据失败
    • ¥20 有人能用聚类分析帮我分析一下文本内容嘛
    • ¥15 请问Lammps做复合材料拉伸模拟,应力应变曲线问题
    • ¥30 python代码,帮调试
    • ¥15 #MATLAB仿真#车辆换道路径规划
    • ¥15 java 操作 elasticsearch 8.1 实现 索引的重建
    • ¥15 数据可视化Python
    • ¥15 要给毕业设计添加扫码登录的功能!!有偿