[PATCH] Use email addresses of recipients as fallback to lookup the patch's project

Guilherme Salgado guilherme.salgado at linaro.org
Tue Apr 19 21:43:31 EST 2011


Hi Jeremy,

On Tue, 2011-04-19 at 14:21 +0800, Jeremy Kerr wrote:
> Hi Guilherme,
> 
> > This is used only when the List-ID lookup doesn't return any projects *and*
> > the PATCHWORK_FALLBACK_TO_LISTEMAIL setting is set to True.
> 
> Just one more thing I noticed when applying this:
> 
> > +def extract_email_addresses(str):
> > +    email_re = re.compile(
> > +        r"([_\.0-9a-zA-Z-+=]+@(([0-9a-zA-Z-]{1,}\.)*)[a-zA-Z]{2,})")
> 
> Is there not an existing RE we can use here? Would be good not to have
> to reinvent the wheel.

The only one I could find is in django.core.validators but it doesn't
seem to be part of the public API, so it's probably not a good idea to
use it.

email_re = re.compile(
    r"(^[-!#$%&'*+/=?^_`{}|~0-9A-Z]+(\.[-!#$%&'*+/=?^_`{}|~0-9A-Z]+)*"  # dot-atom
    r'|^"([\001-\010\013\014\016-\037!#-\[\]-\177]|\\[\001-011\013\014\016-\177])*"' # quoted-string
    r')@(?:[A-Z0-9](?:[A-Z0-9-]{0,61}[A-Z0-9])?\.)+[A-Z]{2,6}\.?$', re.IGNORECASE)  # domain

> 
> If not:
> 
> > +    # re.findall() will return a list of tuples because we have multiple
> > +    # groups on the regex above, but we're only interested on the outermost
> > +    # group (which should contain the whole email address), so we drop the
> > +    # second and third groups.
> 
> In that case, use the non-grouping format: (?:...).

Oh, good catch; I didn't know about that. :)

> 
> Also, using \w allows you to reduce the size of the regex.

Indeed, I can use \w on the user part, but not on the hostname part as
\w matches the underscore as well, which doesn't seem to be allowed in
hostnames.

Thanks for the review and suggestions, I'll submit a second version of
this patch in a minute.

-- 
Guilherme Salgado <https://launchpad.net/~salgado>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 198 bytes
Desc: This is a digitally signed message part
URL: <http://lists.ozlabs.org/pipermail/patchwork/attachments/20110419/16e7b440/attachment.pgp>


More information about the Patchwork mailing list