https://bz.apache.org/bugzilla/show_bug.cgi?id=70365

            Bug ID: 70365
           Summary: HSMF: MessageSubmissionChunk.getAcceptedAtTime()
                    ignores the trailing 'Z' and parses the submission-ID
                    timestamp in the JVM default timezone
           Product: POI
           Version: 6.0.0-FINAL
          Hardware: All
                OS: All
            Status: NEW
          Severity: normal
          Priority: P2
         Component: HSMF
          Assignee: [email protected]
          Reporter: [email protected]
  Target Milestone: ---

MessageSubmissionChunk extracts a yymmddhhmmssZ timestamp from the submission
ID (PidTagMessageSubmissionId), e.g.

c=US;a= ;p=HostedService2;l=THHS2EXBE1X-070614094255Z-84723
The pattern matches the trailing 'Z' ((\d\d){6}Z?), but the Calendar is created
with LocaleUtil.getLocaleCalendar(), i.e. the user/JVM default timezone, so the
wall-clock fields are interpreted as local time. The resulting instant is wrong
by the machine's UTC offset everywhere except UTC.

MAPIMessage.getMessageDate() prefers this value when the submission chunk is
present, so the main message date is affected too.

Reproduction with POI 6.0.0 and POI's own test-data/hsmf/quick.msg:

MAPIMessage m = new MAPIMessage(new File("test-data/hsmf/quick.msg"));
m.getMainChunks().getSubmissionChunk().getAcceptedAtTime().toInstant();
m.getMessageDate().toInstant();

-Duser.timezone=UTC                 -> 2007-06-14T09:42:55Z
-Duser.timezone=America/New_York    -> 2007-06-14T13:42:55Z
-Duser.timezone=Australia/Adelaide  -> 2007-06-14T00:12:55Z
The same file's FILETIME properties, which are timezone-independent, agree with
the UTC reading in every timezone:

ClientSubmitTime    = 2007-06-14T09:42:53.500Z
MessageDeliveryTime = 2007-06-14T09:42:55.584Z
So the 'Z' does denote UTC here. (MS-OXOMSG treats the submission ID as an
opaque MTA-assigned identifier, so parsing a date out of it is a heuristic; but
given the 'Z' is already matched, honouring it seems right.)

The existing tests don't catch this: TestMessageSubmissionChunk and
TestMessageSubmissionChunkY2KRead assert only the year, and
TestOutlookTextExtractor pins LocaleUtil.setUserTimeZone(TIMEZONE_UTC) and
builds the expected value in that same zone.

Proposed fix: use LocaleUtil.getLocaleCalendar(LocaleUtil.TIMEZONE_UTC) in
MessageSubmissionChunk, plus a test that runs under a non-UTC user timezone and
asserts the full instant. I'm happy to submit a PR.

Found via Apache Tika, whose OutlookParserTest fails on machines at UTC+9 and
further east.

-- 
You are receiving this mail because:
You are the assignee for the bug.
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to