Improve date handling in getDate method#37
Merged
Conversation
Enhance date handling in getDate method to support Horde_Imap_Client_DateTime and improve timestamp parsing.
Contributor
Author
|
@ralflang please verify whether this is a valid approach, you are deeper in the date corner. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Handle unparseable IMAP envelope dates in
getDate()Summary
Horde_Imap_Client_DateTime::getTimestamp()for valid envelope dates instead of casting the object to string.error()), fall back to the messageDateheader, then to the current time."0"as invalid (IMAP client error sentinel), not as a Unix timestamp.Problem
During ActiveSync Sync,
Horde_ActiveSync_Imap_EasMessageBuilder::_setHeaderProperties()setsdatereceivedfromHorde_ActiveSync_Imap_Message::getDate(). Ifnew Horde_Date()throws, the Sync response aborts with HTTP 500 and clients retry indefinitely.Observed log (German locale):
The German message is Horde_Date’s “Failed to parse time string (%s)” — here with
%s=0, not “format id 0”.Root cause
$this->envelope->dateis aHorde_Imap_Client_DateTime. When the IMAP layer cannot parse the envelope date, it stores an internal error value and__toString()returns"0":Previous
getDate()logic (after #15’s fix for numeric timestamp strings):For an error-state envelope date:
$dateis an object → thectype_digitbranch is skipped.(string) $date→"0".Horde_Date("0")does not accept single-digit timestamp strings →DateTime("0")fails → exception → Sync 500.This is separate from horde/ActiveSync#15, which fixed valid Unix timestamps passed as 9–11 digit strings (e.g.
"1773944669").Solution
Horde_Imap_Client_DateTimenew Horde_Date($timestamp)error())Date:header; if that fails, use nownew Horde_Date((int) $string)(#15)"0"Sync can complete even when individual messages have malformed envelope dates;
datereceivedmay be approximate only when both envelope and header dates fail.Related work
Horde_Imap_Client_DateTimeerror handling and__toString()sentinel (Ticket #14381).Horde_Dateconstructor semantics (per upstream discussion on Improve date handling in getDate method #15).Test plan
Zeitformat (0) nicht erkanntvia Outlook or another EAS client; confirm Sync completes without HTTP 500.datereceived.Date:header; confirm the header date is used.Horde_Date_ExceptionfromgetDate()duringSyncfor the above cases.