I'm a noob and using Flanker to parse emails.
I'm getting a Not Iterable error that I just can't seem to figure out. I've read tons of pages about lists, but I just can't get it to work. I'm hopeful I can get some help.
To run the following code, you will need to install Flanker, and save this file as 'email'.
I'm trying to read the 'attachmenttype' and do something depending on the response. Can't get it to work though. Here is the test code:
from flanker import mime
with open ("email", mode="rb") as myfile:
msg = mime.from_string(message_string)
#read attachment type
attachmenttype = msg.parts
#This errors for me: TypeError: argument of type 'MimePart' is not iterable
if '(text/html)' in attachmenttype:
attachmenttype may be printed a string but it is not a string. However, since you can print it, you're halfway there. Just convert it to a string using
str and compare that.
Fix your code like this. I couldn't test it but I don't see how it wouldn't work:
if attachmenttype: if '(text/html)' in str(attachmenttype): print("woohoo")