[Python编程(第4版)].(Programming.Python.4th.Edition).Mark.Lutz.文字版
Example 13-22. PP4E\Internet\Email\mailtools\mailTool.py """ ################################################################### ...
could in principle also catch part file decoding errors and return an error indicator string (as we do for received mails in the ...
""" linelen = 76 # per MIME standards from email.encoders import encode_base64 encode_base64(msgobj) # what email does normally: ...
assumes that To, Cc, Bcc hdr values are lists of 1 or more already decoded addresses (possibly in full name+ format); client mus ...
if name.lower() != 'bcc': # 4E: bcc gets mail, no hdr msg[name] = ', '.join(value) # add commas between cc recip = list(set(reci ...
else: data = open(filename, 'rb') msg = MIMEText(data.read(), _subtype=subtype, _charset=fileencode) data.close() elif maintype ...
self.trace('Could not save sent message') # not a show-stopper def encodeHeader(self, headertext, unicodeencoding='utf-8'): """ ...
pass # no login required for this server/class def getPassword(self): pass # no login required for this server/class ########### ...
MailFetcher Class The class defined in Example 13-24 does the work of interfacing with a POP email server—loading, deleting, and ...
file _test-decoding.py in the examples package for a test of this logic). In practice, an 8- bit Unicode encoding such as Latin- ...
To assist clients, Example 13-24 includes tools, which match message headers on de- letions to ensure accuracy and perform gener ...
def connect(self): self.trace('Connecting...') self.getPassword() # file, GUI, or console server = poplib.POP3(self.popServer) s ...
except UnicodeError: text = ['From: (sender of unknown Unicode format headers)'] text += ['', '--Sorry: mailtools cannot decode ...
resp, hdrlines, respsz = server.top(msgnum, 0) hdrlines = self.decodeFullText(hdrlines) allhdrs.append('\n'.join(hdrlines)) fina ...
for (ix, msgnum) in enumerate(msgnums): # don't reconnect for each if progress: progress(ix+1, len(msgnums)) server.dele(msgnum) ...
list matches what is on the server, using the TOP command in POP to fetch headers text; use if inbox can change due to deletes i ...
msgid1 = [line for line in split1 if line[:11].lower() == 'message-id:'] msgid2 = [line for line in split2 if line[:11].lower() ...
MailParser Class Example 13-25 implements the last major class in the mailtools package—given the (already decoded) text of an e ...
Example 13-25. PP4E\Internet\Email\mailtools\mailParser.py """ ################################################################# ...
maintype = part.get_content_maintype() if maintype == 'multipart': # multipart/: container continue elif fulltype == 'message/rf ...
«
46
47
48
49
50
51
52
53
54
55
»
Free download pdf