← Back to team overview

openerp-community team mailing list archive

[Bug 1199386] Re: Email address regular expression needs work

 

Here are various occurences of regular expressions looking very strongly
like email matching regexps I found with grep in the trunk branches:

ack --type=python 're\.(compile|search|match).*@' server/trunk addons/trunk web/trunk/
server/trunk/openerp/addons/base/ir/ir_mail_server.py
123:name_with_email_pattern = re.compile(r'("[^<@>]+")\s*<([^ ,<@]+@[^> ,]+)>')
124:address_pattern = re.compile(r'([^ ,<@]+@[^> ,]+)')

server/trunk/openerp/tools/mail.py
58:    part = re.compile(r"(<(([^a<>]|a[^<>\s])[^<>]*)@[^<>]+>)", re.IGNORECASE | re.DOTALL)
487:email_re = re.compile(r"""([a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,6})""", re.VERBOSE) 
490:single_email_re = re.compile(r"""^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,6}$""", re.VERBOSE)
498:reference_re = re.compile("<.*-open(?:object|erp)-(\\d+)(?:-([\w.]+))?.*@(.*)>", re.UNICODE)

addons/trunk/survey/wizard/survey_answer.py
704:                                    if re.match("^[a-zA-Z0-9._%-+]+@[a-zA-Z0-9._%-]+.[a-zA-Z]{2,6}$", val1) == None:
743:                                if re.match("^[a-zA-Z0-9._%-+]+@[a-zA-Z0-9._%-]+.[a-zA-Z]{2,6}$", val1) == None:
906:                                    if re.match("^[a-zA-Z0-9._%-+]+@[a-zA-Z0-9._%-]+.[a-zA-Z]{2,6}$", val) == None:
942:                                if re.match("^[a-zA-Z0-9._%-+]+@[a-zA-Z0-9._%-]+.[a-zA-Z]{2,6}$", val) == None:

addons/trunk/crm/base_partner_merge.py
741:        re_email = re.compile(r".*@")

This badly needs unification and consistency.

-- 
You received this bug notification because you are a member of OpenERP
Community, which is subscribed to the bug report.
https://bugs.launchpad.net/bugs/1199386

Title:
  Email address regular expression needs work

Status in OpenERP Addons (modules):
  New
Status in OpenERP Server:
  New

Bug description:
  During testing with my email-address 'm@xxxxxxxxxxxxxx'  I noticed a
  couple of things:

  1. The partner contact with that email-address can't be given access
  to the portal by the portal wizard, it fails on creation of the user
  in addons/mail/res_user.py:68 :

          if not data.get('login', False):
              raise osv.except_osv(_('Invalid Action!'),...)))

  2. The login field is empty, because the portal wizard uses the email
  field to create a login in addons/portal/wizard/portal_wizard.py:177
  :

              'login': extract_email(wizard_user.email),

  The extract_email function in portal_wizard.py uses 'email_re' to determine what the login field should look like.
  'email_re' is defined as in multiple places, which is the first problem. It at least in  tools/mail.py and tools/import_email.py. (The latter contains email information from the 'steel-sa.com ' (?!?) domain by the way.)

  email_re = re.compile(r"""
      ([a-zA-Z][\w\.-]*[a-zA-Z0-9]     # username part
      @                                                          # mandatory @ sign
      [a-zA-Z0-9][\w\.-]*                       # domain must start with a letter ... Ged> why do we include a 0-9 then?
       \.
       [a-z]{2,3}                      # TLD
      )
      """, re.VERBOSE)

  Problems I see:

  1. The email_re is defined in multiple places; make it one;
  2. It forces to have email-addresses with at least 2 characters for the user part, of which the first must contain a letter; addresses like m@xxxxxxxxxx won't work then; is there a reason for this?
  3. the TLD must contain 2 or 3 characters, which is unsuitable for domains like .name or .info

To manage notifications about this bug go to:
https://bugs.launchpad.net/openobject-addons/+bug/1199386/+subscriptions