From f7e9a24962b70c063137f1cd25d74a8acf20d7cd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thibault=20Delavall=C3=A9e?= Date: Fri, 24 Apr 2020 12:02:06 +0000 Subject: [PATCH] [IMP] mail: add some docstrings and helpers PURPOSE Prepare code cleaning and optimization in mail, mass_mailing and SMS by cleaning models for readability and code complexity and footprint reduction. LINKS Prepares task ID 2238597 (notification and trace models cleaning) Task ID 1906925 (mass mailing tests cleaning) PR #50169 --- addons/mail/models/mail_thread.py | 16 ++++++++++++---- addons/mass_mailing/models/mailing_trace.py | 2 +- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/addons/mail/models/mail_thread.py b/addons/mail/models/mail_thread.py index 5e19ef8d75f..61b1df78dc9 100644 --- a/addons/mail/models/mail_thread.py +++ b/addons/mail/models/mail_thread.py @@ -1346,8 +1346,16 @@ class MailThread(models.AbstractModel): processing. :param email_message: an email.message instance; - :param message_dict: dictionary holding already-parsed values and in - which bounce-related values will be added; + :param message_dict: dictionary holding already-parsed values; + + :return dict: bounce-related values will be added, containing + + * bounced_email: email that bounced (normalized); + * bounce_partner: res.partner recordset whose email_normalized = + bounced_email; + * bounced_msg_id: list of message_ID references (<...@myserver>) linked + to the email that bounced; + * bounced_message: if found, mail.message recordset matching bounced_msg_id; """ if not isinstance(email_message, EmailMessage): raise TypeError('message must be an email.message.EmailMessage at this point') @@ -1367,8 +1375,8 @@ class MailThread(models.AbstractModel): bounced_msg_id = False bounced_message = self.env['mail.message'].sudo() if email_part: - email = email_part.get_payload()[0] - bounced_msg_id = tools.mail_header_msgid_re.findall(tools.decode_message_header(email, 'Message-Id')) + email_payload = email_part.get_payload()[0] + bounced_msg_id = tools.mail_header_msgid_re.findall(tools.decode_message_header(email_payload, 'Message-Id')) if bounced_msg_id: bounced_message = self.env['mail.message'].sudo().search([('message_id', 'in', bounced_msg_id)]) diff --git a/addons/mass_mailing/models/mailing_trace.py b/addons/mass_mailing/models/mailing_trace.py index ef3c51f0141..f79bda46ea6 100644 --- a/addons/mass_mailing/models/mailing_trace.py +++ b/addons/mass_mailing/models/mailing_trace.py @@ -25,7 +25,7 @@ class MailingTrace(models.Model): 'However the ID is needed for several action and controllers.', index=True, ) - email = fields.Char(string="Email") + email = fields.Char(string="Email", help="Normalized email address") message_id = fields.Char(string='Message-ID') # document model = fields.Char(string='Document model')