bpo-33972: Fix EmailMessage.iter_attachments raising AttributeError.#14119
Conversation
When certain malformed messages have content-type set to 'mulitpart/*' but still have a single part body, iter_attachments can raise AttributeError. This patch fixes it by returning a None value instead when the body is single part.
|
It looks like Docs builds are failing on both Azure and Travis, even though I haven't changed anything in there. |
|
@maxking docs look fine now. |
|
Yep, I am not sure what was the reason for it. I moved multiipart/* (invalid rst?) text to Or it could be unrelated, I am not sure. |
| # Certain malformed messages can have content type set to `multipart/*` | ||
| # but still have single part body, in which case payload.copy() can | ||
| # fail with AttributeError. | ||
| if not isinstance(payload, list): |
There was a problem hiding this comment.
What do you think about catching the AttributeError on .copy() instead of doing a type test here? E.g.:
try:
parts = payload.copy()
except AttributeError:
return None
? (Also aside, when returning None is part of the API, it's generally better to be explicit.)
There was a problem hiding this comment.
I'll update to catch AttributeError.
It technically doesn't return None, since this is a generator. I don't know if it that makes any sense?
There was a problem hiding this comment.
It is same what other return statements in this method do.
There was a problem hiding this comment.
Cool, thanks! I didn't pick that up from the diff context.
|
A Python core developer has requested some changes be made to your pull request before we can consider merging it. If you could please address their requests along with any other requests in other reviews from core developers that would be appreciated. Once you have made the requested changes, please leave a comment on this pull request containing the phrase |
…rror. (pythonGH-14119) * bpo-33972: Fix EmailMessage.iter_attachments raising AttributeError. When certain malformed messages have content-type set to 'mulitpart/*' but still have a single part body, iter_attachments can raise AttributeError. This patch fixes it by returning a None value instead when the body is single part. (cherry picked from commit 0225701) Co-authored-by: Abhilash Raj <maxking@users.noreply.github.com>
…rror. (pythonGH-14119) * bpo-33972: Fix EmailMessage.iter_attachments raising AttributeError. When certain malformed messages have content-type set to 'mulitpart/*' but still have a single part body, iter_attachments can raise AttributeError. This patch fixes it by returning a None value instead when the body is single part. (cherry picked from commit 0225701) Co-authored-by: Abhilash Raj <maxking@users.noreply.github.com>
…rror (GH-14119) (GH-14380) When certain malformed messages have content-type set to 'mulitpart/*' but still have a single part body, iter_attachments can raise AttributeError. This patch fixes it by returning a None value instead when the body is single part. (cherry picked from commit 0225701) Co-authored-by: Abhilash Raj <maxking@users.noreply.github.com> https://bugs.python.org/issue33972
…rror. (GH-14119) (GH-14381) When certain malformed messages have content-type set to 'mulitpart/*' but still have a single part body, iter_attachments can raise AttributeError. This patch fixes it by returning a None value instead when the body is single part. (cherry picked from commit 0225701) Co-authored-by: Abhilash Raj <maxking@users.noreply.github.com> https://bugs.python.org/issue33972
…ythonGH-14119) * bpo-33972: Fix EmailMessage.iter_attachments raising AttributeError. When certain malformed messages have content-type set to 'mulitpart/*' but still have a single part body, iter_attachments can raise AttributeError. This patch fixes it by returning a None value instead when the body is single part.
…ythonGH-14119) * bpo-33972: Fix EmailMessage.iter_attachments raising AttributeError. When certain malformed messages have content-type set to 'mulitpart/*' but still have a single part body, iter_attachments can raise AttributeError. This patch fixes it by returning a None value instead when the body is single part.
When certain malformed messages have content-type set to 'mulitpart/*' but
still have a single part body, iter_attachments can raise AttributeError. This
patch fixes it by returning a None value instead when the body is single part.
https://bugs.python.org/issue33972