Mercurial > hg
comparison 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 |
comparison
equal
deleted
inserted
replaced
9946:2059be77d4f8 | 9947:4600e6222efb |
---|---|
377 elif opts.get('bundle'): | 377 elif opts.get('bundle'): |
378 msgs = getbundlemsgs(getbundle(dest)) | 378 msgs = getbundlemsgs(getbundle(dest)) |
379 else: | 379 else: |
380 msgs = getpatchmsgs(list(getpatches(revs))) | 380 msgs = getpatchmsgs(list(getpatches(revs))) |
381 | 381 |
382 def getaddrs(opt, prpt, default = None): | 382 def getaddrs(opt, prpt=None, default=None): |
383 addrs = opts.get(opt) or (ui.config('email', opt) or | 383 if opts.get(opt): |
384 ui.config('patchbomb', opt) or | 384 return mail.addrlistencode(ui, opts.get(opt), _charsets, |
385 prompt(ui, prpt, default)).split(',') | 385 opts.get('test')) |
386 return [mail.addressencode(ui, a.strip(), _charsets, opts.get('test')) | 386 |
387 for a in addrs if a.strip()] | 387 addrs = (ui.config('email', opt) or |
388 ui.config('patchbomb', opt) or '') | |
389 if not addrs and prpt: | |
390 addrs = prompt(ui, prpt, default) | |
391 | |
392 return mail.addrlistencode(ui, [addrs], _charsets, opts.get('test')) | |
388 | 393 |
389 to = getaddrs('to', 'To') | 394 to = getaddrs('to', 'To') |
390 cc = getaddrs('cc', 'Cc', '') | 395 cc = getaddrs('cc', 'Cc', '') |
391 | 396 bcc = getaddrs('bcc') |
392 bcc = opts.get('bcc') or (ui.config('email', 'bcc') or | |
393 ui.config('patchbomb', 'bcc') or '').split(',') | |
394 bcc = [mail.addressencode(ui, a.strip(), _charsets, opts.get('test')) | |
395 for a in bcc if a.strip()] | |
396 | 397 |
397 ui.write('\n') | 398 ui.write('\n') |
398 | 399 |
399 parent = opts.get('in_reply_to') or None | 400 parent = opts.get('in_reply_to') or None |
400 # angle brackets may be omitted, they're not semantically part of the msg-id | 401 # angle brackets may be omitted, they're not semantically part of the msg-id |