mirror of
https://github.com/facebook/sapling.git
synced 2024-10-07 15:27:13 +03:00
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.
This commit is contained in:
parent
95e9713b6e
commit
7ea70f1f49
@ -379,20 +379,21 @@ def patchbomb(ui, repo, *revs, **opts):
|
||||
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')
|
||||
|
||||
|
@ -169,6 +169,12 @@ echo "% test multiple flags for multiple patches"
|
||||
hg email --date '1970-1-1 0:1' -n --flag fooFlag --flag barFlag -f quux -t foo \
|
||||
-c bar -s test -r 0:1 | fixheaders
|
||||
|
||||
echo "% test multi-address parsing"
|
||||
hg email --date '1980-1-1 0:1' -m tmp.mbox -f quux -t 'spam<spam><eggs>' \
|
||||
-t toast -c 'foo,bar@example.com' -c '"A, B <>" <a@example.com>' -s test -r 0 \
|
||||
--config email.bcc='"Quux, A." <quux>'
|
||||
cat tmp.mbox | fixheaders
|
||||
|
||||
echo "% test multi-byte domain parsing"
|
||||
UUML=`printf '\374'`
|
||||
HGENCODING=iso-8859-1
|
||||
|
@ -1469,6 +1469,39 @@ diff -r 8580ff50825a -r 97d72e5f12c7 b
|
||||
@@ -0,0 +1,1 @@
|
||||
+b
|
||||
|
||||
% test multi-address parsing
|
||||
This patch series consists of 1 patches.
|
||||
|
||||
|
||||
Writing [PATCH] test ...
|
||||
From quux Tue Jan 01 00:01:01 1980
|
||||
Content-Type: text/plain; charset="us-ascii"
|
||||
MIME-Version: 1.0
|
||||
Content-Transfer-Encoding: 7bit
|
||||
Subject: [PATCH] test
|
||||
X-Mercurial-Node: 8580ff50825a50c8f716709acdf8de0deddcd6ab
|
||||
Message-Id: <8580ff50825a50c8f716.315532860@
|
||||
User-Agent: Mercurial-patchbomb
|
||||
Date: Tue, 01 Jan 1980 00:01:00 +0000
|
||||
From: quux
|
||||
To: spam <spam>, eggs, toast
|
||||
Cc: foo, bar@example.com, "A, B <>" <a@example.com>
|
||||
Bcc: "Quux, A." <quux>
|
||||
|
||||
# HG changeset patch
|
||||
# User test
|
||||
# Date 1 0
|
||||
# Node ID 8580ff50825a50c8f716709acdf8de0deddcd6ab
|
||||
# Parent 0000000000000000000000000000000000000000
|
||||
a
|
||||
|
||||
diff -r 000000000000 -r 8580ff50825a a
|
||||
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
|
||||
+++ b/a Thu Jan 01 00:00:01 1970 +0000
|
||||
@@ -0,0 +1,1 @@
|
||||
+a
|
||||
|
||||
|
||||
% test multi-byte domain parsing
|
||||
This patch series consists of 1 patches.
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user