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.