fix(outlook): read .msg string properties saved in the non-Unicode format - #2295
Open
Guillermo Dols (gdols) wants to merge 1 commit into
Open
fix(outlook): read .msg string properties saved in the non-Unicode format#2295Guillermo Dols (gdols) wants to merge 1 commit into
Guillermo Dols (gdols) wants to merge 1 commit into
Conversation
Every string property in a .msg lives under a stream whose name ends in its MAPI type: 001F for PT_UNICODE (UTF-16LE) or 001E for PT_STRING8, written in the message's code page. Outlook writes one or the other for a given message, never both, so a message saved in the legacy non-Unicode format carries no 001F streams at all. The converter addressed only the 001F names. Such a message therefore came out as bare scaffolding -- "# Email Message" followed by "## Content" -- with From, To, Subject and the body all silently dropped, and no error raised. Each property is now read from the 001F stream and, failing that, from its 001E counterpart. PT_STRING8 streams record no encoding of their own, so the charset is detected with charset_normalizer, as is already done for other 8-bit sources in the codebase. The Unicode path is unchanged.
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.
A
.msgsaved in the legacy non-Unicode format converts to nothing but scaffolding —# Email Messagefollowed by## Content, with From, To, Subject and the body all missing. No exception is raised, so the loss is silent.Why
Every string property in a
.msgis stored under a stream whose name ends in the property's MAPI type:001FPT_UNICODE001EPT_STRING8Outlook writes one or the other for a given message, never both. The converter addressed only the
001Fnames:so for a non-Unicode message every lookup misses,
_get_stream_datareturnsNonefor each, and the headers are skipped by theif value:guard while the body is skipped byif body:.Note this is not reachable by fixing the decode:
_get_stream_datanever sees any bytes, because the streams it names do not exist in the file.The change
Each property is now looked up by its tag, trying
001Ffirst and falling back to001E:PT_STRING8streams record no encoding of their own, so the charset is detected withcharset_normalizer, consistent with how other 8-bit sources are handled in the codebase. ReadingPR_INTERNET_CPIDout of__properties_version1.0would give the declared code page instead, but that means parsing the fixed-property stream by hand, and detection is what the rest of the converters already rely on. Happy to switch if you would rather have the declared value.The Unicode path is untouched — it is still tried first, and still decoded exactly as before.
Tests
packages/markitdown/tests/test_outlook_msg_ansi.py. A.msgis an OLE2 compound file and nothing in the dependency set can write that container, so the streams are served through a stand-in forolefile.OleFileIOrather than a binary fixture:test_outlook_msg.msgstill converts, read through realolefile.The two non-Unicode tests fail on
mainand all four pass with this change. The rest of the suite is unaffected andblackreports no changes.Note
This does not overlap #2245, which resolves the Exchange sender DN and the HTML-only body. That PR reads the same
001Fstream names, so a non-Unicode message stays empty there.