By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,383 Members | 2,070 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,383 IT Pros & Developers. It's quick & easy.

msg.walk()

P: n/a
Hi Guys

Using Python 2.3 here, trying to parse a MBOX email file using the code below:

------------------------

mailboxfile = 'emails.txt'

import email
import email.Errors, email.Parser, email.Message
import mailbox

def msgfactory(fp):
try:
return email.message_from_file(fp)
except email.Errors.MessageParseError:
# Don't return None since that will
# stop the mailbox iterator
return ''
def main():
fp = open(mailboxfile, 'r')
mbox = mailbox.UnixMailbox(fp, msgfactory)
for msg in mbox:
print msg
for part in msg.walk():
print part

if __name__=="__main__":
main()
---------------------

not much there that isn't in the examples. Anyway, says I can't use
walk() on a string (msg)! Suggestions?

Jul 18 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
On Sat, 26 Jun 2004 15:30:04 +0100
Samuel Wright <ly*******@gmail.com> wrote:
Hi Guys

Using Python 2.3 here, trying to parse a MBOX email file using the
code below:

[...]
def msgfactory(fp):
try:
return email.message_from_file(fp)
except email.Errors.MessageParseError:
# Don't return None since that will
# stop the mailbox iterator
return ''

Notice the return ''

def main():
fp = open(mailboxfile, 'r')
mbox = mailbox.UnixMailbox(fp, msgfactory)
for msg in mbox:
print msg
for part in msg.walk():
print part
[...]


You have to do a test for an empty string in your main method (like the docs say).
Jul 18 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.