parsing - Reading .eml files with Python 3.6 using emaildata 0.3.4 -


i using python 3.6.1 , want read in email files (.eml) processing. using emaildata 0.3.4 package, whenever try import text class in documentation, module errors:

import email email.text import text >>> modulenotfounderror: no module named 'cstringio' 

when tried correct using this update, next error relating mimetools

>>> modulenotfounderror: no module named 'mimetools' 

is possible use emaildata 0.3.4 python 3.6 parse .eml files? or there other packages can use parse .eml files? thanks

using email package, can read in .eml files. then, use bytesparser library parse file. finally, use plain preference (for plain text) get_body() method, , get_content() method raw text of email.

import email email import policy email.parser import bytesparser files = glob.glob('*.eml') # returns list of files open(files[2], 'rb') fp:     msg = bytesparser(policy=policy.default).parse(fp)  text = msg.get_body(preferencelist=('plain')).get_content() print(text) >>> "hi, >>> email >>> regards, >>> mister. e" 

granted, simplified example - no mention of html or attachments. gets done question asks , want do.


Comments

Popular posts from this blog

android - InAppBilling registering BroadcastReceiver in AndroidManifest -

python Tkinter Capturing keyboard events save as one single string -

sql server - Why does Linq-to-SQL add unnecessary COUNT()? -