Extracting TIFF from emails

Ryan Swift ryan at ryanswift.com
Wed Sep 3 15:00:34 EDT 2003


I have found the email module, I am using 2.2.2.

This is my code:

if __name__ == "__main__":
    server = connect(mailserver, mailuser, mailpasswd)
    try:
        (msgCount, msgBytes) = server.stat()
        print '\nThere are', msgCount, 'mail messages, total',
msgBytes, 'bytes'
        print 'Retrieving message', msgCount, '\n'
        (hdr, message, octets) = server.retr(msgCount)
        print 'Header:', hdr
        print 'Octets:', octets
        print 'Message:', message

        email_file = open('email.txt', 'w')
        email_file.writelines(message)
        email_file.close()

        for part in message.walk():
            if part.get_content_maintype() == 'multipart':
                continue
            filename = part.get_filename()
            fp = open(os.path.join(dir, filename), 'wb')
            fp.write(part.get_payload(decode=1))
            fp.close()
    finally:                
        server.quit()       
    print 'Closed connection

I can print message and see it with no problems. It also gets written
to 'email.txt' with no problems.  It is a simple multi-part MIME email
with TIF attachment.  However, I get this error when I try to walk
through it:

Traceback (most recent call last):
  File "C:\Python22\lib\site-packages\Pythonwin\pywin\framework\scriptutils.py",
line 305, in RunScript
    debugger.run(codeObject, __main__.__dict__, start_stepping=1)
  File "C:\Python22\lib\site-packages\Pythonwin\pywin\debugger\__init__.py",
line 60, in run
    _GetCurrentDebugger().run(cmd, globals,locals, start_stepping)
  File "C:\Python22\lib\site-packages\Pythonwin\pywin\debugger\debugger.py",
line 591, in run
    exec cmd in globals, locals
  File "C:\Python22\mailtest.py", line 29, in ?
    for part in message.walk():
AttributeError: 'list' object has no attribute 'walk'

Am I not properly using walk?

Thanks again.




More information about the Python-list mailing list