Prev: Python 2.6 and modules dbi AND odbc
Next: Platform Requirement Checker (was Does this already exists?: A modulethat checks if the used platform is supported)
From: T on 11 Mar 2010 18:19 Thanks for your suggestions! Here's what seems to be working - it's basically the same thing I originally had, but first checks to see if the line is blank response, lines, bytes = M.retr(i+1) # For each line in message for line in lines: if not line.strip(): M.dele(i+1) break emailMessage = email.message_from_string(line) # Get fields fields = emailMessage.keys() # If email contains "From" field if emailMessage.has_key("From"): # Get contents of From field from_field = emailMessage.__getitem__("From")
From: Thomas Guettler on 12 Mar 2010 07:59
T wrote: > Thanks for your suggestions! Here's what seems to be working - it's > basically the same thing I originally had, but first checks to see if > the line is blank > > response, lines, bytes = M.retr(i+1) > # For each line in message > for line in lines: > if not line.strip(): > M.dele(i+1) > break > > emailMessage = email.message_from_string(line) > # Get fields > fields = emailMessage.keys() > # If email contains "From" field > if emailMessage.has_key("From"): > # Get contents of From field > from_field = emailMessage.__getitem__("From") Hi T, wait, this code looks strange. You delete the email if it contains an empty line? I use something like this: message='\n'.join(connection.retr(msg_num)[1]) Your code: emailMessage = email.message_from_string(line) create an email object from only *one* line! You retrieve the whole message (you don't save bandwith), but maybe that's what you want. Thomas -- Thomas Guettler, http://www.thomas-guettler.de/ E-Mail: guettli (*) thomas-guettler + de |