diff options
| author | David Beguin <dbe@odoo.com> | 2018-10-30 10:47:28 +0000 |
|---|---|---|
| committer | David Beguin <dbe@odoo.com> | 2018-11-20 11:37:05 +0000 |
| commit | e69b89b8fa8439fea27094ef86d97ffd8972124c (patch) | |
| tree | 23aefa790fc8346fc73796b11579381bafb8d796 /odoo/tools/mail.py | |
| parent | fc2a8d63ee09053f12493683400ec424cab8ce16 (diff) | |
[IMP] tools, mail : adds email normalization method in mail tools
In order to normalize email independently from the
mail.address.mixin model.
Diffstat (limited to 'odoo/tools/mail.py')
| -rw-r--r-- | odoo/tools/mail.py | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/odoo/tools/mail.py b/odoo/tools/mail.py index 668d0678f88..3bb080094ab 100644 --- a/odoo/tools/mail.py +++ b/odoo/tools/mail.py @@ -502,6 +502,21 @@ def email_split_and_format(text): if addr[1] if '@' in addr[1]] +def email_normalize(text): + """ Sanitize and standardize email address entries. + A normalized email is considered as : + - having a left part + @ + a right part (the domain can be without '.something') + - being lower case + - having no name before the address. Typically, having no 'Name <>' + Ex: + - Possible Input Email : 'Name <NaMe@DoMaIn.CoM>' + - Normalized Output Email : 'name@domain.com' + """ + emails = email_split(text) + if not emails or len(emails) != 1: + return False + return emails[0].lower() + def email_escape_char(email_address): """ Escape problematic characters in the given email address string""" return email_address.replace('\\', '\\\\').replace('%', '\\%').replace('_', '\\_') |
