1

I am using a php script to retrieve emails like this:

$inbox  = imap_open($hostname,$username,$password);
$emails = imap_search($inbox,'ALL');

Since I have many emails, I want only to process new emails so I'm trying to figure out how to search emails having id greater than id x.

Problem is that I cannot find a single UID search criteria for imap.

Is there any way to achieve this without having to loop all mails?

Amani Ben Azzouz
  • 2,477
  • 3
  • 15
  • 26
  • http://stackoverflow.com/questions/9147424/imap-search-for-messages-with-uid-greater-than-x-or-generally-after-my-last-s – Funk Forty Niner Mar 27 '17 at 11:56
  • Thx I have already tested it before asking the question `$emails = imap_search($inbox, 'SEARCH UID 5:*',SE_UID);` and it returns `Unknown search criterion` – Amani Ben Azzouz Mar 27 '17 at 11:59
  • the search is already implied: try imap_search($inbox, 'UID 5:*', SE_UID). You're sending the equivalent of `UID SEARCH SEARCH UID 5:*` – Max Mar 27 '17 at 12:15
  • I tried many combinations `imap_search($inbox, 'SEARCH UID 5:*',SE_UID);` ... `imap_search($inbox, 'UID 5:*', SE_UID)` ... `imap_search($inbox, 'UID 5:*')` .... `imap_search($inbox, 'UID 5:*',FT_UID)` and I get always the same warning --> `Unknown search criterion` – Amani Ben Azzouz Mar 27 '17 at 12:21
  • What is the server software? – Max Mar 27 '17 at 14:17
  • I use macOS Server. – Amani Ben Azzouz Mar 27 '17 at 14:27
  • I mean, the IMAP Server software. Can you @tag me when you respond, otherwise I have no way of telling when you do so. – Max Mar 27 '17 at 14:55
  • Can you provide the exact and entire error message you get for `imap_search($inbox, 'UID 5:*', SE_UID)`? It looks like the PHP library may not support this search term. – Max Mar 27 '17 at 15:17
  • @Max This gives me `PHP Notice: Unknown: Unknown search criterion: UID (errflg=2) in Unknown on line 0`; ... for my emails Iam using macOs Server app. – Amani Ben Azzouz Mar 27 '17 at 15:58
  • @Max I forgot to mention in my question that this search criteria only worked for `map_fetch_overview` function : `$emails = imap_fetch_overview($inbox, "5:*", SE_UID);` but I need also the body of mails... – Amani Ben Azzouz Mar 27 '17 at 16:05
  • That's not a search criteria, but UID SEARCH UID 5:* is a little bit redundant, since you could just get the messages directly, like you did. This is a problem with the library PHP uses for IMAP support not supporting that search criteria. You could rebuild it yourself if you wished. – Max Mar 27 '17 at 18:24

0 Answers0