I'm trying to use the php imap_search function to collect all of the emails I receive from my business's fulfillment company on a given day. The problem is that I can't seem to get the SEARCH ON to return all of the emails in a day, instead it seems to return all of the emails in a day shifted a few hours.

Howdy,

The emails are all being sent from PA, I live in OH, and my hosting is based in CA.

Eeeep, the above example should start with: date_default_timezone_set('America/New_York');posted by Jezztek at 4:01 PM on March 11, 2013

Have you tried specifying the timezone in the search criteria?posted by missmagenta at 4:05 PM on March 11, 2013

Hmmmmm, I can't seem to figure out how to enter a timezone as a part of the search that won't throw an error. I'll see if I can find a way to do so.posted by Jezztek at 4:13 PM on March 11, 2013

Hmm. Google isn't yielding much and I don't have an IMAP server handy to play with, but any chance it's using UTC?

Bit of a hack, but you could try getting a broader list of mail and filtering them on your end using, say, strtotime($this_header->Date).posted by brennen at 4:31 PM on March 11, 2013

Unfortunately, I think this is a limitation of the IMAP protocol's search function. Here's the relevant portion of the IMAP RFC:

ON <date>
Messages whose internal date (disregarding time and timezone)
is within the specified date.

And some clarifying text:

Clarify that date searches disregard the time and timezone of the
INTERNALDATE or Date: header. In other words, "ON 13-APR-2000" means
messages with an INTERNALDATE text which starts with "13-APR-2000",
even if timezone differential from the local timezone is sufficient
to move that INTERNALDATE into the previous or next day.

So you're limited to whatever timezone the server happened to store its internal dates in.posted by zsazsa at 4:36 PM on March 11, 2013

Ok, so at least I'm not crazy!

I suppose it makes sense to grab the last two days worth at a time, then filter them on my end per brennen's suggestion.

Tags

Share

About Ask MetaFilter

Ask MetaFilter is a question and answer site that covers nearly any question on earth, where members help each other solve problems. Ask MetaFilter is where thousands of life's little questions are answered.