This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author patrick totzke
Recipients patrick totzke
Date 2020-06-17.16:06:51
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1592410013.12.0.0160903099449.issue41010@roundup.psfhosted.org>
In-reply-to
Content
I am trying to use EmailMessage.get_body() on the attached spam email.
Although that message may be malformed, I believe that this method should fail gracefully.

To reproduce

```
with open('msg', 'rb') as f: 
    m = email.message_from_binary_file(f, _class=email.message.EmailMessage) 

 m.get_body()                                                                                               
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-21-0d3554e3ba7a> in <module>
----> 1 m.get_body()

/usr/lib/python3.8/email/message.py in get_body(self, preferencelist)
   1016         best_prio = len(preferencelist)
   1017         body = None
-> 1018         for prio, part in self._find_body(self, preferencelist):
   1019             if prio < best_prio:
   1020                 best_prio = prio

/usr/lib/python3.8/email/message.py in _find_body(self, part, preferencelist)
    987         if subtype != 'related':
    988             for subpart in part.iter_parts():
--> 989                 yield from self._find_body(subpart, preferencelist)
    990             return
    991         if 'related' in preferencelist:

/usr/lib/python3.8/email/message.py in _find_body(self, part, preferencelist)
    987         if subtype != 'related':
    988             for subpart in part.iter_parts():
--> 989                 yield from self._find_body(subpart, preferencelist)
    990             return
    991         if 'related' in preferencelist:

/usr/lib/python3.8/email/message.py in _find_body(self, part, preferencelist)
    976 
    977     def _find_body(self, part, preferencelist):
--> 978         if part.is_attachment():
    979             return
    980         maintype, subtype = part.get_content_type().split('/')

AttributeError: 'str' object has no attribute 'is_attachment'

```

I am on Python 3.8.3 on debian testing.
History
Date User Action Args
2020-06-17 16:06:53patrick totzkesetrecipients: + patrick totzke
2020-06-17 16:06:53patrick totzkesetmessageid: <1592410013.12.0.0160903099449.issue41010@roundup.psfhosted.org>
2020-06-17 16:06:53patrick totzkelinkissue41010 messages
2020-06-17 16:06:53patrick totzkecreate