def printMailboxContent(conn) : msgList = pop_helpers.listMessages(conn) numMessages = len(msgList) print "There are %i messages (via POP)." % (numMessages,) for (sid, emailObj) in pop_helpers.iterMessages(conn, msgList) : #emailObj = email.message_from_string(rawMail) for headerType, headerTrunc in mail_helpers.iterEmailHeaders(emailObj, truncateAt = 70) : if mail_helpers.IsBaseHeader(headerType) : headerDisplay = mail_helpers.RemoveLineBreaks(headerTrunc) print " %-30s %s" % (headerType, headerDisplay,) print
def printPopMailboxContent(conn) : """ Reads the latest mail via POP. """ msgList = pop_helpers.listMessages(conn) numMessages = len(msgList) if 0 : print("There are %i messages (via POP)." % (numMessages,)) newestMailObj = None for (sid, emailObj) in pop_helpers.iterMessages(conn, msgList, newestFirst = True) : if 0 : print("ID = %r" % (sid,)) for headerType, headerTrunc in mail_helpers.iterEmailHeaders(emailObj, truncateAt = 70) : if mail_helpers.IsBaseHeader(headerType) : headerDisplay = mail_helpers.RemoveLineBreaks(headerTrunc) print(" %-30s %s" % (headerType, headerDisplay,)) print() # empty line newestMailObj = emailObj break # show informations of the newest mail if newestMailObj is None : print("Could not access POP server.", file=sys.stderr) sys.exit(2) return None # print all parts of a multipart mail if 0 : for (i, msg) in enumerate(newestMailObj.get_payload()) : print("PART", i) print(" charset =", msg.get_charset()) print(" contentType =", msg.get_content_type()) print(" contentMainType =", msg.get_content_maintype()) print(" contentSubType =", msg.get_content_subtype()) print(" defaultType =", msg.get_default_type()) print(" filename =", msg.get_filename()) print(" boundary =", msg.get_boundary()) print(" contentCharset =", msg.get_content_charset()) print(" charsets =", msg.get_charsets()) print() print(" <CONTENT>") print(msg.as_string()) print(" </CONTENT>") print() pass return newestMailObj