<html><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><div>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.</div><div>I am not sure how exactly to do this. Can anybody help me out.</div><div><br></div><div>Thanks in advance.</div><div><br></div><div>-Grishma</div><div><br></div><div><div><span class="Apple-style-span" style="text-decoration: underline;">Command:</span></div><div>python EmailParserNew.py -d /Users/tweek/Documents/ /Users/tweek/Desktop/tmp/automated/Feedback</div><div>25</div><div>Counter: 2</div></div><div><br></div><div><span class="Apple-style-span" style="text-decoration: underline;">Code:</span></div><div>print msg.__len__()</div><div>&nbsp;&nbsp; &nbsp;counter = 1</div><div>&nbsp;&nbsp; &nbsp;for part in msg.walk():</div><div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;# multipart/* are just containers</div><div>## &nbsp; &nbsp; &nbsp; &nbsp;if part.get_content_maintype() == 'multipart':</div><div>## &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;continue</div><div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;# Applications should really sanitize the given filename so that an</div><div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;# email message can't be used to overwrite important files</div><div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;filename = part.get_filename()</div><div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;if not filename:</div><div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;ext = mimetypes.guess_extension(part.get_content_type())</div><div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;if not ext:</div><div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;# Use a generic bag-of-bits extension</div><div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;ext = '.bin'</div><div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;filename = 'part-%03d%s' % (counter, ext)</div><div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;counter += 1</div><div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;print 'Counter:',counter</div><div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;fp = open(os.path.join(opts.directory, filename), 'wb')</div><div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;fp.write(part.get_payload(decode=True))</div><div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;fp.close()</div><div><br></div><div><div><br></div><div><br></div></div></body></html>