[Python编程(第4版)].(Programming.Python.4th.Edition).Mark.Lutz.文字版

(yzsuai) #1

non-multipart, content-type text/HTML (rude but true!)


if type == 'text/html':
if ((not mailconfig.verifyHTMLTextOpen) or
askyesno(appname, 'Open message text in browser?')):


3.0: get post mime decode, pre unicode decode bytes


type, asbytes = self.findMainText(message, asStr=False)
try:
from tempfile import gettempdir # or a Tk HTML viewer?
tempname = os.path.join(gettempdir(), 'pymailgui.html')
tmp = open(tempname, 'wb') # already encoded
tmp.write(asbytes)
webbrowser.open_new('file://' + tempname)
except:
showerror(appname, 'Cannot open in browser')


def onWriteMail(self):
"""
compose a new email from scratch, without fetching others;
nothing to quote here, but adds sig, and prefills Bcc with the
sender's address if this optional header enabled in mailconfig;
From may be i18N encoded in mailconfig: view window will decode;
"""
starttext = '\n' # use auto signature text
if mailconfig.mysignature:
starttext += '%s\n' % mailconfig.mysignature
From = mailconfig.myaddress
WriteWindow(starttext = starttext,
headermap = dict(From=From, Bcc=From)) # 3.0: prefill bcc


def onReplyMail(self):


possibly threaded: reply to selected emails


msgnums = self.verifySelectedMsgs()
if msgnums:
self.getMessages(msgnums, after=lambda: self.contReply(msgnums))


def contReply(self, msgnums):
"""
finish Reply: drop attachments, quote with '>', add signature;
presets initial to/from values from mail or config module;
don't use original To for From: may be many or a listname;
To keeps name+ format even if ',' separator in name;
Uses original From for To, ignores reply-to header is any;
3.0: replies also copy to all original recipients by default;


3.0: now uses getaddresses/parseaddr full parsing to separate
addrs on commas, and handle any commas that appear nested in
email name parts; multiple addresses are separated by comma
in GUI, we copy comma separators when displaying headers, and
we use getaddresses to split addrs as needed; ',' is required
by servers for separator; no longer uses parseaddr to get 1st
name/addr pair of getaddresses result: use full From for To;


3.0: we decode the Subject header here because we need its text,


1072 | Chapter 14: The PyMailGUI Client

Free download pdf