[PATCH] patchbomb: fix address parsing, allow multiple addrs in --to/cc/bcc

Maxim Dounin mdounin at mdounin.ru
Wed Nov 4 13:40:12 CST 2009


Hello!

On Wed, Nov 04, 2009 at 02:49:17AM +0200, Marti Raudsepp wrote:

> Here is version 2 of my patch to allow multiple addresses in --to/cc/bcc
> arguments.
> 
> On Mon, 2009-11-02 at 09:45 +0200, timeless wrote: 
> > >  addrs = ','.join(opts.get(opt)).split(',')
> > 
> > from a purity perspective, this is wrong :)
> > 
> > at work, an email address might be of the form:
> > "Smith, David" <david.smith at example.com>
> > 
> > proper parsing of email addresses is non trivial
> 
> You are right. The current code already breaks your example because it
> splits configuration variables/interactive input by ','. In fact, MIME
> doesn't even require a comma between multiple addresses. So instead of

It does.  Well, MIME has nothing to do with address list syntax, 
it's all about RFC 5322, but comma is mandatory even in obsolete 
syntax:

address-list    =   (address *("," address)) / obs-addr-list
obs-addr-list   =   *([CFWS] ",") address *("," [address / CFWS])

> trying to extend this broken behavior, I will fix it.
> 
> I change mecurial/mail.py to add a new function addrlistencode(). This
> gets rid of the ugly list comprehension etc, because Python's
> email.utils.getaddresses() already does stripping, splitting and
> everything else for us and it knows more about proper MIME syntax than
> we do.
> 
> For reference, here are the outputs of the new testcase: 
> hg email --date '1980-1-1 0:1' -m tmp.mbox -f quux -t 'spam<spam><eggs>' \
>  -t toast -c 'foo,bar at example.com' -c '"A, B <>" <a at example.com>' -s test -r 0 \
>  --config email.bcc='"Quux, A." <quux>'
> 
> with patch:
>   To: spam <spam>, eggs, toast
>   Cc: foo, bar at example.com, "A, B <>" <a at example.com>
>   Bcc: "Quux, A." <quux>
> 
> without patch:
>   To: spam <spam>, toast
>   Cc: foo, "A, B <>" <a at example.com>
>   Bcc: Quux, A.

I belive 'spam<spam><eggs>' should be rejected as invalid, but as 
long as it's email.Utils.getaddresses() bug/feature it probably 
doesn't matter.

Anyway with patch it looks much better than without.  Thank you 
for your work.

Maxim Dounin


More information about the Mercurial-devel mailing list