[FIX] ir.mail.server: improve support for user names with emails
authorOlivier Dony <odo@openerp.com>
Wed, 18 Sep 2013 14:38:07 +0000 (16:38 +0200)
committerOlivier Dony <odo@openerp.com>
Wed, 18 Sep 2013 14:38:07 +0000 (16:38 +0200)
The previous fix in revision 5072 only allowed user names
that contained the exact same emails, but users will do
the wildest things like having `someone@domain.com` as
name but setting their email to `someone@domain2.com`.

This was blocked by our sanity check looking for a single
email in the From header. As this check is only done
in order to provide a better error message, it should
not impact valid cases.
Modifying the check to pass when at least one email
was found should be enough to catch most invalid cases,
without requiring a more advanced analysis of the
header value (the RFCs allows very strange things!)

bzr revid: odo@openerp.com-20130918143807-wqqpqomyu1ppa2ih

openerp/addons/base/ir/ir_mail_server.py

index 7e691a6..ec5b12f 100644 (file)
@@ -402,9 +402,10 @@ class ir_mail_server(osv.osv):
 
         # The email's "Envelope From" (Return-Path), and all recipient addresses must only contain ASCII characters.
         from_rfc2822 = extract_rfc2822_addresses(smtp_from)
-        assert len(set(from_rfc2822)) == 1, ("Malformed 'Return-Path' or 'From' address: %r - "
-                                             "It should contain one plain ASCII email") % smtp_from
-        smtp_from = from_rfc2822[0]
+        assert from_rfc2822, ("Malformed 'Return-Path' or 'From' address: %r - "
+                              "It should contain one valid plain ASCII email") % smtp_from
+        # use last extracted email, to support rarities like 'Support@MyComp <support@mycompany.com>'
+        smtp_from = from_rfc2822[-1]
         email_to = message['To']
         email_cc = message['Cc']
         email_bcc = message['Bcc']