walking a MIME encoded multipart email [python]

David Stockwell winexpert at hotmail.com
Thu Jun 3 20:31:54 CEST 2004


snippet

       payload = {}
       try:
         message = email.message_from_string(message)
         messageHeader = dict(message._headers)

         addressFrom = messageHeader["From"]
         addressReply = messageHeader.get("Reply-To")
         messageId = messageHeader.get("Message-ID")

	 if messageId is not None:
	    if addressFrom is not None:
	       if addressReply is not None:
	          if message.is_multipart:
		    count = 0
                    for partition in message.walk():
                       if partition.get_type() == "application/vnd.ms-word":
                          payload[partition.get_filename()] = 
partition.get_payload(count,True)
		          count += 1

	 message.close()
       except:
         print "Houston we have a problem"
--- end of snippet

I've wrote the above segment but haven't tried running it yet because I'm 
unclear about the api for message.
In the get_payload api it says if you don't pass parameters it returns a 
list of messages (1 for each part)

it also states a lot of other stuff which I found to be a bit confusing.

If I use it as above, is it going to return a string? or  message object?
If its a message object, what does it mean to have an decoded message object 
vs an encoded message object?

finally I want to associate each part's original name with the part (whether 
actual data or a message object) so I was thinking of using a dictionary 
approach



David
-------
Tracfone: http://cellphone.duneram.com/index.html
Cam: http://www.duneram.com/cam/index.html
Tax: http://www.duneram.com/index.html

_________________________________________________________________
Getting married? Find great tips, tools and the latest trends at MSN Life 
Events. http://lifeevents.msn.com/category.aspx?cid=married





More information about the Python-list mailing list