[PATCH 2 of 3] patchbomb: mime-encode headers and parts not containing patches
Christian Ebert
blacktrash at gmx.net
Thu Sep 11 01:44:38 UTC 2008
# HG changeset patch
# User Christian Ebert <blacktrash at gmx.net>
# Date 1215886330 -3600
# Node ID a2ec13cc036f525c31d8c47620291b90d7e1f108
# Parent 959f46039fcdfcd7869eb903c8122f6d2a76745e
patchbomb: mime-encode headers and parts not containing patches
Do nothing for "hg email --test" to preserve display.
diff --git a/hgext/patchbomb.py b/hgext/patchbomb.py
--- a/hgext/patchbomb.py
+++ b/hgext/patchbomb.py
@@ -176,7 +176,7 @@
if opts.get('attach') or opts.get('inline'):
msg = email.MIMEMultipart.MIMEMultipart()
if body:
- msg.attach(email.MIMEText.MIMEText(body, 'plain'))
+ msg.attach(mail.mimeencode(ui, body, opts.get('test')))
p = email.MIMEText.MIMEText('\n'.join(patch), 'x-patch')
binnode = bin(node)
# if node is mq patch, it will have patch file name as tag
@@ -204,9 +204,9 @@
else:
tlen = len(str(total))
subj = '[PATCH %0*d of %d] %s' % (tlen, idx, total, subj)
- msg['Subject'] = subj
+ msg['Subject'] = mail.headencode(ui, subj, opts.get('test'))
msg['X-Mercurial-Node'] = node
- return msg
+ return msg, subj
def outgoing(dest, revs):
'''Return the revisions present locally but not in dest'''
@@ -328,10 +328,10 @@
body = '\n' + d
body = getdescription(body, sender)
- msg = email.MIMEText.MIMEText(body)
- msg['Subject'] = subj
+ msg = mail.mimeencode(ui, body, opts.get('test'))
+ msg['Subject'] = mail.headencode(ui, subj, opts.get('test'))
- msgs.insert(0, msg)
+ msgs.insert(0, (msg, subj))
return msgs
def getbundlemsgs(bundle):
@@ -341,15 +341,15 @@
body = getdescription('', sender)
msg = email.MIMEMultipart.MIMEMultipart()
if body:
- msg.attach(email.MIMEText.MIMEText(body, 'plain'))
+ msg.attach(mail.mimeencode(ui, body, opts.get('test')))
datapart = email.MIMEBase.MIMEBase('application', 'x-mercurial-bundle')
datapart.set_payload(bundle)
datapart.add_header('Content-Disposition', 'attachment',
filename='bundle.hg')
email.Encoders.encode_base64(datapart)
msg.attach(datapart)
- msg['Subject'] = subj
- return [msg]
+ msg['Subject'] = mail.headencode(ui, subj, opts.get('test'))
+ return [(msg, subj)]
sender = (opts.get('from') or ui.config('email', 'from') or
ui.config('patchbomb', 'from') or
@@ -364,22 +364,25 @@
addrs = opts.get(opt) or (ui.config('email', opt) or
ui.config('patchbomb', opt) or
prompt(prpt, default = default)).split(',')
- return [a.strip() for a in addrs if a.strip()]
+ return [mail.addressencode(ui, a.strip(), opts.get('test'))
+ for a in addrs if a.strip()]
to = getaddrs('to', 'To')
cc = getaddrs('cc', 'Cc', '')
bcc = opts.get('bcc') or (ui.config('email', 'bcc') or
ui.config('patchbomb', 'bcc') or '').split(',')
- bcc = [a.strip() for a in bcc if a.strip()]
+ bcc = [mail.addressencode(ui, a.strip(), opts.get('test'))
+ for a in bcc if a.strip()]
ui.write('\n')
parent = None
sender_addr = email.Utils.parseaddr(sender)[1]
+ sender = mail.addressencode(ui, sender, opts.get('test'))
sendmail = None
- for m in msgs:
+ for m, subj in msgs:
try:
m['Message-Id'] = genmsgid(m['X-Mercurial-Node'])
except TypeError:
@@ -398,7 +401,7 @@
if bcc:
m['Bcc'] = ', '.join(bcc)
if opts.get('test'):
- ui.status(_('Displaying '), m['Subject'], ' ...\n')
+ ui.status(_('Displaying '), subj, ' ...\n')
ui.flush()
if 'PAGER' in os.environ:
fp = util.popen(os.environ['PAGER'], 'w')
@@ -414,7 +417,7 @@
if fp is not ui:
fp.close()
elif opts.get('mbox'):
- ui.status(_('Writing '), m['Subject'], ' ...\n')
+ ui.status(_('Writing '), subj, ' ...\n')
fp = open(opts.get('mbox'), 'In-Reply-To' in m and 'ab+' or 'wb+')
generator = email.Generator.Generator(fp, mangle_from_=True)
date = util.datestr(start_time, '%a %b %d %H:%M:%S %Y')
@@ -425,7 +428,7 @@
else:
if not sendmail:
sendmail = mail.connect(ui)
- ui.status(_('Sending '), m['Subject'], ' ...\n')
+ ui.status(_('Sending '), subj, ' ...\n')
# Exim does not remove the Bcc field
del m['Bcc']
fp = cStringIO.StringIO()
More information about the Mercurial-devel
mailing list