[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.


python EmailParserNew.py -d /Users/tweek/Documents/ /Users/tweek/ 
Counter: 2

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')

-------------- 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