[Tutor] body extraction from mbox file - emails
grishma20 at gmail.com
Thu Sep 11 17:04:34 CEST 2008
The Code is take from the last example on the example page. When I run
the command i see the msg lenght is 25 but it run through it only
once, updates and counter and does not run through the rest of
messages. I want to extract the body irrespective of whether there is
an attachment or not.
I am not sure how exactly to do this. Can anybody help me out.
Thanks in advance.
python EmailParserNew.py -d /Users/tweek/Documents/ /Users/tweek/
counter = 1
for part in msg.walk():
# multipart/* are just containers
## if part.get_content_maintype() == 'multipart':
# Applications should really sanitize the given filename so
# email message can't be used to overwrite important files
filename = part.get_filename()
if not filename:
ext = mimetypes.guess_extension(part.get_content_type())
if not ext:
# Use a generic bag-of-bits extension
ext = '.bin'
filename = 'part-%03d%s' % (counter, ext)
counter += 1
fp = open(os.path.join(opts.directory, filename), 'wb')
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Tutor