← Back to team overview

openerp-community-reviewer team mailing list archive

[Merge] lp:~hirt/ocb-addons/6.1_fix_mailaddress-parsing into lp:ocb-addons/6.1

 

Etienne Hirt has proposed merging lp:~hirt/ocb-addons/6.1_fix_mailaddress-parsing into lp:ocb-addons/6.1.

Requested reviews:
  OpenERP Community Backports Team (ocb)
Related bugs:
  Bug #1165531 in OpenERP Addons: "[6.1] Text to email parsing incomplete"
  https://bugs.launchpad.net/openobject-addons/+bug/1165531

For more details, see:
https://code.launchpad.net/~hirt/ocb-addons/6.1_fix_mailaddress-parsing/+merge/194030

While using 6.1 mail_message to_email function I found that it does not
cope with all the possible names in the emaillist.

example: 'bla@xxxx' <bla@xxxx>, (bla@xxxx) <bla@xxxx>, "'bla@xxxx'" <bla@xxxx>, etc

The regexp in the function to_email of mail/mail_message.py is enhanced that it also removes ", () and
even if the allowed '.
-- 
https://code.launchpad.net/~hirt/ocb-addons/6.1_fix_mailaddress-parsing/+merge/194030
Your team OpenERP Community Backports Team is requested to review the proposed merge of lp:~hirt/ocb-addons/6.1_fix_mailaddress-parsing into lp:ocb-addons/6.1.
=== modified file 'mail/mail_message.py'
--- mail/mail_message.py	2013-10-28 11:57:54 +0000
+++ mail/mail_message.py	2013-11-05 22:35:01 +0000
@@ -60,9 +60,28 @@
         return ''.join([tools.ustr(x[0], x[1]) for x in text])
 
 def to_email(text):
-    """Return a list of the email addresses found in ``text``"""
+    """Returns a list of the email addresses found in ``text``
+    
+     According to rfc2822 the allowed characters are letter and digits and  
+            "!" / "#" /     ;  SP, and specials.
+                        "$" / "%" /     ;  Used for atoms
+                        "&" / "'" /
+                        "*" / "+" /
+                        "-" / "/" /
+                        "=" / "?" /
+                        "^" / "_" /
+                        "`" / "{" /
+                        "|" / "}" /
+                        "~"
+    Therefore remove also " and () around the addresses
+    and additionally ' because it is sometimes added to names that are taken from email address
+    and I doubt that other clients can handle it.
+    
+    Warning: can create double entries                     
+                       
+    """
     if not text: return []
-    return re.findall(r'([^ ,<@]+@[^> ,]+)', text)
+    return re.findall(r'([^ ,(\'"<@]+@[^> ,)\'"]+)',text)
 
 class mail_message_common(osv.osv_memory):
     """Common abstract class for holding the main attributes of a 


Follow ups