diff hgext/patchbomb.py @ 9947:4600e6222efb

patchbomb: fix parsing of multiple addresses, allow multiple addrs in --to/cc/bcc Instead of using custom code to split apart addresses, we now use mail.parseaddrlist() which always does the Right Thing as it relies on Python's email.Utils.getaddresses(). Previously, 'hg email --to=foo,bar' only respected foo and discarded bar. Also, commas in names were not allowed in hgrc or the interactive prompt; specifying '"Lastname, Firstname" <foo>' would confuse patchbomb. The testcase uses '-m tmp.mbox' because -n (like in other tests) would disable address mangling.
author Marti Raudsepp <marti@juffo.org>
date Thu, 26 Nov 2009 12:23:28 +0200
parents 72d670c43f6e
children 4e3a8f3e9dc2
line wrap: on
line diff
--- a/hgext/patchbomb.py	Fri Nov 27 13:53:27 2009 +0100
+++ b/hgext/patchbomb.py	Thu Nov 26 12:23:28 2009 +0200
@@ -379,20 +379,21 @@
     else:
         msgs = getpatchmsgs(list(getpatches(revs)))
 
-    def getaddrs(opt, prpt, default = None):
-        addrs = opts.get(opt) or (ui.config('email', opt) or
-                                  ui.config('patchbomb', opt) or
-                                  prompt(ui, prpt, default)).split(',')
-        return [mail.addressencode(ui, a.strip(), _charsets, opts.get('test'))
-                for a in addrs if a.strip()]
+    def getaddrs(opt, prpt=None, default=None):
+        if opts.get(opt):
+            return mail.addrlistencode(ui, opts.get(opt), _charsets,
+                                       opts.get('test'))
+
+        addrs = (ui.config('email', opt) or
+                 ui.config('patchbomb', opt) or '')
+        if not addrs and prpt:
+            addrs = prompt(ui, prpt, default)
+
+        return mail.addrlistencode(ui, [addrs], _charsets, opts.get('test'))
 
     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 = [mail.addressencode(ui, a.strip(), _charsets, opts.get('test'))
-           for a in bcc if a.strip()]
+    bcc = getaddrs('bcc')
 
     ui.write('\n')