diff options
| author | Julien Castiaux <juc@odoo.com> | 2019-08-20 13:09:55 +0000 |
|---|---|---|
| committer | Julien Castiaux <juc@odoo.com> | 2019-09-17 11:32:54 +0000 |
| commit | dbb6cfdbf803d2ab86ba11450b5928abf5ab658b (patch) | |
| tree | 830220c1e66d96736e097219949b724b9db0744e /addons/mail | |
| parent | 1b057dd76b19db00eb5b63dc02f87cdc13cc07cf (diff) | |
[REF] mail: remove deprecated email formataddr
[PEP 594] is going to depreciate the legacy `email.message.Message` API
and its related modules. Among them the `email.utils.formataddr`
function, this function takes a `(name, email)` pair and returns a
string value suitable for From, To and Cc headers.
The stdlib function is capable of handling several character encoding
and two binary-to-ascii encoding. Odoo only uses `utf-8` which is
compatible with the base64 b2a encoding. The re-implementation of that
function has been simplified to only support base64-ed utf-8 and ascii.
[PEP 594]: https://www.python.org/dev/peps/pep-0594/\#email-lagacy-api
Diffstat (limited to 'addons/mail')
| -rw-r--r-- | addons/mail/models/mail_cc_mixin.py | 3 | ||||
| -rw-r--r-- | addons/mail/models/mail_channel.py | 3 | ||||
| -rw-r--r-- | addons/mail/models/mail_mail.py | 3 | ||||
| -rw-r--r-- | addons/mail/models/mail_message.py | 5 | ||||
| -rw-r--r-- | addons/mail/models/mail_thread.py | 3 | ||||
| -rw-r--r-- | addons/mail/wizard/mail_compose_message.py | 4 |
6 files changed, 7 insertions, 14 deletions
diff --git a/addons/mail/models/mail_cc_mixin.py b/addons/mail/models/mail_cc_mixin.py index cc1554fcff5..427eb25a2bb 100644 --- a/addons/mail/models/mail_cc_mixin.py +++ b/addons/mail/models/mail_cc_mixin.py @@ -2,7 +2,6 @@ # Part of Odoo. See LICENSE file for full copyright and licensing details. from odoo import _, api, fields, models, tools -from email.utils import formataddr class MailCCMixin(models.AbstractModel): @@ -16,7 +15,7 @@ class MailCCMixin(models.AbstractModel): '''return a dict of sanitize_email:raw_email from a string of cc''' if not cc_string: return {} - return {tools.email_normalize(email): formataddr((name, tools.email_normalize(email))) + return {tools.email_normalize(email): tools.formataddr((name, tools.email_normalize(email))) for (name, email) in tools.email_split_tuples(cc_string)} @api.model diff --git a/addons/mail/models/mail_channel.py b/addons/mail/models/mail_channel.py index 91d40bed9de..fb27b41830b 100644 --- a/addons/mail/models/mail_channel.py +++ b/addons/mail/models/mail_channel.py @@ -5,13 +5,12 @@ import base64 import logging import re -from email.utils import formataddr from uuid import uuid4 from odoo import _, api, fields, models, modules, tools from odoo.exceptions import UserError, ValidationError from odoo.osv import expression -from odoo.tools import ormcache +from odoo.tools import ormcache, formataddr MODERATION_FIELDS = ['moderation', 'moderator_ids', 'moderation_ids', 'moderation_notify', 'moderation_notify_msg', 'moderation_guidelines', 'moderation_guidelines_msg'] _logger = logging.getLogger(__name__) diff --git a/addons/mail/models/mail_mail.py b/addons/mail/models/mail_mail.py index 59a8e604fb1..c1e3a19fe54 100644 --- a/addons/mail/models/mail_mail.py +++ b/addons/mail/models/mail_mail.py @@ -10,7 +10,6 @@ import threading import re from collections import defaultdict -from email.utils import formataddr from odoo import _, api, fields, models from odoo import tools @@ -195,7 +194,7 @@ class MailMail(models.Model): body = self._send_prepare_body() body_alternative = tools.html2plaintext(body) if partner: - email_to = [formataddr((partner.name or 'False', partner.email or 'False'))] + email_to = [tools.formataddr((partner.name or 'False', partner.email or 'False'))] else: email_to = tools.email_split_and_format(self.email_to) res = { diff --git a/addons/mail/models/mail_message.py b/addons/mail/models/mail_message.py index e49a6153976..2e8b1e0441d 100644 --- a/addons/mail/models/mail_message.py +++ b/addons/mail/models/mail_message.py @@ -7,7 +7,6 @@ import re from binascii import Error as binascii_error from collections import defaultdict from operator import itemgetter -from email.utils import formataddr from openerp.http import request from odoo import _, api, fields, models, modules, tools @@ -32,7 +31,7 @@ class Message(models.Model): @api.model def _get_default_from(self): if self.env.user.email: - return formataddr((self.env.user.name, self.env.user.email)) + return tools.formataddr((self.env.user.name, self.env.user.email)) raise UserError(_("Unable to post message, please configure the sender's email address.")) @api.model @@ -1179,7 +1178,7 @@ class Message(models.Model): if not msg.email_from: continue if self.env.user.partner_id.email: - email_from = formataddr((self.env.user.partner_id.name, self.env.user.partner_id.email)) + email_from = tools.formataddr((self.env.user.partner_id.name, self.env.user.partner_id.email)) else: email_from = self.env.company.catchall diff --git a/addons/mail/models/mail_thread.py b/addons/mail/models/mail_thread.py index 15d5f882f0a..af4001fb4e3 100644 --- a/addons/mail/models/mail_thread.py +++ b/addons/mail/models/mail_thread.py @@ -22,7 +22,6 @@ except ImportError: from collections import namedtuple from email.message import EmailMessage -from email.utils import formataddr from lxml import etree from werkzeug import url_encode from werkzeug import urls @@ -2633,7 +2632,7 @@ class MailThread(models.AbstractModel): company_name = company.name if company else self.env.company.name for res_id in result_email.keys(): name = '%s%s%s' % (company_name, ' ' if doc_names.get(res_id) else '', doc_names.get(res_id, '')) - result[res_id] = formataddr((name, result_email[res_id])) + result[res_id] = tools.formataddr((name, result_email[res_id])) left_ids = set(_res_ids) - set(result_email) if left_ids: diff --git a/addons/mail/wizard/mail_compose_message.py b/addons/mail/wizard/mail_compose_message.py index aeeba8c2339..b8b516f878c 100644 --- a/addons/mail/wizard/mail_compose_message.py +++ b/addons/mail/wizard/mail_compose_message.py @@ -1,8 +1,6 @@ # -*- coding: utf-8 -*- # Part of Odoo. See LICENSE file for full copyright and licensing details. -from email.utils import formataddr - import base64 import re @@ -68,7 +66,7 @@ class MailComposer(models.TransientModel): elif 'email_from' not in result: author = self.env['res.partner'].browse(result['author_id']) if author.email: - result['email_from'] = formataddr((author.name, author.email)) + result['email_from'] = tools.formataddr((author.name, author.email)) # v6.1 compatibility mode result['composition_mode'] = result.get('composition_mode', self._context.get('mail.compose.message.mode', 'comment')) |
