Ability to handle multipart/related and other multipart trees & HTML if no text available#35
Open
foulkesj wants to merge 2 commits intoasweigart:masterfrom
Open
Ability to handle multipart/related and other multipart trees & HTML if no text available#35foulkesj wants to merge 2 commits intoasweigart:masterfrom
foulkesj wants to merge 2 commits intoasweigart:masterfrom
Conversation
Commit addresses more complex Mimetype structures. In current code there are fails to find body/original body. This results in body returning the default [], and original body not being created, causing error when calling. In particular original code fails to find body where multipart/related or multipart/mixed are present in the mimetype tree See here for various descriptions: https://techcommunity.microsoft.com/t5/exchange-team-blog/mixed-ing-it-up-multipart-mixed-messages-and-you/ba-p/585841 Commit now finds text/plain inside a multitype/alternative it more places in the tree. If no text/plain or multitype is found will return an HTML version. Additional while loop used to travel through multi-type tree until multitype/alternative is found. Due to the increase number of locations where body/original body can be found a separate function has been added to get the encoding (from the headers) and add the originalBody and Body to self.
Address Typos and location of function
|
Hi @asweigart, any updates on this? |
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.
Commit addresses more complex Mimetype structures.
When using the current code across a Gmail inbox (e.g. find all and save to file) there are cases where ezgmail fails to find body/original body (as it is not in text/plain or multitype/alternative:text/plain).
This results in body returning the default empty list, and original body not being created, causing error when calling in outside programs.
Other mimeTypes I have seen used include multipart/related or multipart/mixed, although more complex ones may be present:
See here for descriptions:
https://techcommunity.microsoft.com/t5/exchange-team-blog/mixed-ing-it-up-multipart-mixed-messages-and-you/ba-p/585841
https://stackoverflow.com/questions/3902455/mail-multipart-alternative-vs-multipart-mixed
This version largely retains the original code for finding text/plain and multitype/alternative.
However it now uses a while loop to travel through a multi-type tree until multitype/alternative is found. (If multitype is found in mimeType it goes a level deeper)
It will still not find a body if no multitype/alternative exists.
If no html/plain is found at the top level, or there is not text.plain in a multitype/alternative, it will will return an HTML version.
Due to the increased number of locations where body/original body can be found the encode and assign body code has been placed in a separate function (getEncodingAndOriginalBody).
getEncodingAndOriginalBody accesses the encoding (from the headers) and add the originalBody and Body to self, replicating the actions of the original code.
[ from for header in multipartPart["headers"]:
to
self.body = removeQuotedParts(self.originalBody)]
At a future stage could collect both html and plain text, if present, and return separately.