msgtype = msg.get_content_maintype() # no is_multipart yet
msgline = (msgtype == 'multipart' and '') or ' '
msgline += '%03d' % (ix+1)
for key in showhdrs:
mysize = maxsize[key]
if key not in addrhdrs:
keytext = self.decodeHeader(msg.get(key, ' '))
else:
keytext = self.decodeAddrHeader(msg.get(key, ' '))
msgline += ' | %-s' % (mysize, keytext[:mysize])
msgline += '| %.1fK' % (self.mailSize(ix+1) / 1024) # 3.0: .0 optional
self.listBox.insert(END, msgline)
self.listBox.see(END) # show most recent mail=last line
def replyCopyTo(self, message):
"""
3.0: replies copy all original recipients, by prefilling
Cc header with all addreses in original To and Cc after
removing duplicates and new sender; could decode i18n addrs
here, but the view window will decode to display (and send
will reencode) and the unique set filtering here will work
either way, though a sender's i18n address is assumed to be
in encoded form in mailconfig (else it is not removed here);
empty To or Cc headers are okay: split returns empty lists;
"""
if not mailconfig.repliesCopyToAll:
reply to sender only
Cc = ''
else:
copy all original recipients (3.0)
allRecipients = (self.splitAddresses(message.get('To', '')) +
self.splitAddresses(message.get('Cc', '')))
uniqueOthers = set(allRecipients) - set([mailconfig.myaddress])
Cc = ', '.join(uniqueOthers)
return Cc or '?'
def formatQuotedMainText(self, message):
"""
3.0: factor out common code shared by Reply and Forward:
fetch decoded text, extract text if html, line wrap, add > quote
"""
type, maintext = self.findMainText(message) # 3.0: decoded str
if type in ['text/html', 'text/xml']: # 3.0: get plain text
maintext = html2text.html2text(maintext)
maintext = wraplines.wrapText1(maintext, mailconfig.wrapsz-2) # 2 = '> '
maintext = self.quoteOrigText(maintext, message) # add hdrs, >
if mailconfig.mysignature:
maintext = ('\n%s\n' % mailconfig.mysignature) + maintext
return maintext
def quoteOrigText(self, maintext, message):
"""
3.0: we need to decode any i18n (internationalizd) headers here too,
or they show up in email+MIME encoded form in the quoted text block;
decodeAddrHeader works on one addr or all in a comma-separated list;
1076 | Chapter 14: The PyMailGUI Client