[Tutor] body extraction from mbox file - emails
grishma govani
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.
-Grishma
Command:
python EmailParserNew.py -d /Users/tweek/Documents/ /Users/tweek/
Desktop/tmp/automated/Feedback
25
Counter: 2
Code:
print msg.__len__()
counter = 1
for part in msg.walk():
# multipart/* are just containers
## if part.get_content_maintype() == 'multipart':
## continue
# Applications should really sanitize the given filename so
that an
# 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
print 'Counter:',counter
fp = open(os.path.join(opts.directory, filename), 'wb')
fp.write(part.get_payload(decode=True))
fp.close()
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20080911/cb2ff80c/attachment.htm>
More information about the Tutor
mailing list