You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I am trying to extract the size of a message from the BODYSTRUCTURE report. I notice that it contains a multipart parameter, and this lets me evaluate the report.
However it seems that I get a third type of result, which contains an extra 'layer'.
Why does that last message have ([([(b'text, rather than ([(b'text'??
Extract of my code
for msgid, data in mail.fetch(smaller, ['BODYSTRUCTURE']).items():
bodystructure = data[b'BODYSTRUCTURE']
print("---")
print(bodystructure)
if bodystructure:
if bodystructure.is_multipart:
size = 0
for part in bodystructure[0]:
size += part[6]
print("multipart: %d" % size)
else:
size = bodystructure[6]
print("singlepart: %d" % size)
if size > maxsize:
print("Size: %d" % size)
The text was updated successfully, but these errors were encountered:
Your program is making assumptions about the possible structures for emails. Email parts can be arbitrarily nested. The message that is breaking your code is fairly complex. Reformatting the BODYSTRUCTURE for readability:
At the outer layer, the email is multipart/mixed. Within that, the first part is a multipart/alternative part which itself contains plain text and HTML versions of the main email text. That's then followed by an inline jpeg and then a jpeg attachment (seemingly for the same image based on the filename!).
In order to handle any email structure your code needs to recursively walk through the BODYSTRUCTURE responses. I hope that makes sense.
I am trying to extract the size of a message from the BODYSTRUCTURE report. I notice that it contains a
multipart
parameter, and this lets me evaluate the report.However it seems that I get a third type of result, which contains an extra 'layer'.
Why does that last message have
([([(b'text
, rather than([(b'text'
??Extract of my code
The text was updated successfully, but these errors were encountered: