[IMP] mail, portal: use formataddr to format email
Somehow followup of dbb6cfdbf8 . Purpose is
to use formataddr from tools instead of manually handcrafting the full
email address format. Indeed the tools one correctly encapsulates and
format name and email.
Task ID 2068986
This commit is contained in:
@@ -1287,7 +1287,7 @@ class Lead(models.Model):
|
||||
emails = email_re.findall(partner_info['full_name'] or '')
|
||||
email = emails and emails[0] or ''
|
||||
if email and self.email_from and email.lower() == self.email_from.lower():
|
||||
partner_info['full_name'] = '%s <%s>' % (self.contact_name or self.partner_name, email)
|
||||
partner_info['full_name'] = tools.formataddr((self.contact_name or self.partner_name, email))
|
||||
break
|
||||
return result
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
# Part of Odoo. See LICENSE file for full copyright and licensing details.
|
||||
|
||||
from odoo import api, fields, models, SUPERUSER_ID
|
||||
from odoo import api, fields, models, tools, SUPERUSER_ID
|
||||
from odoo.tools.translate import _
|
||||
from odoo.exceptions import UserError
|
||||
|
||||
@@ -397,7 +397,7 @@ class Applicant(models.Model):
|
||||
elif applicant.email_from:
|
||||
email_from = applicant.email_from
|
||||
if applicant.partner_name:
|
||||
email_from = '%s<%s>' % (applicant.partner_name, email_from)
|
||||
email_from = tools.formataddr((applicant.partner_name, email_from))
|
||||
applicant._message_add_suggested_recipient(recipients, email=email_from, reason=_('Contact Email'))
|
||||
return recipients
|
||||
|
||||
|
||||
@@ -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 odoo.http import request
|
||||
|
||||
from odoo import _, api, fields, models, modules, tools
|
||||
|
||||
@@ -679,7 +679,7 @@ class MailThread(models.AbstractModel):
|
||||
}
|
||||
bounce_from = self.env['ir.mail_server']._get_default_bounce_address()
|
||||
if bounce_from:
|
||||
bounce_mail_values['email_from'] = 'MAILER-DAEMON <%s>' % bounce_from
|
||||
bounce_mail_values['email_from'] = tools.formataddr(('MAILER-DAEMON', bounce_from))
|
||||
bounce_mail_values.update(mail_values)
|
||||
self.env['mail.mail'].create(bounce_mail_values).send()
|
||||
|
||||
@@ -1483,7 +1483,7 @@ class MailThread(models.AbstractModel):
|
||||
if partner and partner.id in [val[0] for val in result[self.ids[0]]]: # already existing partner ID -> skip
|
||||
return result
|
||||
if partner and partner.email: # complete profile: id, name <email>
|
||||
result[self.ids[0]].append((partner.id, '%s<%s>' % (partner.name, partner.email), reason))
|
||||
result[self.ids[0]].append((partner.id, tools.formataddr((partner.name, partner.email)), reason))
|
||||
elif partner: # incomplete profile: id, name
|
||||
result[self.ids[0]].append((partner.id, '%s' % (partner.name), reason))
|
||||
else: # unknown partner, we are probably managing an email address
|
||||
|
||||
@@ -99,7 +99,7 @@ class PortalWizardUser(models.TransientModel):
|
||||
'\n- '.join(partners_error_emails.mapped('email'))))
|
||||
if partners_error_user:
|
||||
error_msg.append("%s\n- %s" % (_("Some contacts have the same email as an existing portal user:"),
|
||||
'\n- '.join(['%s <%s>' % (p.display_name, p.email) for p in partners_error_user])))
|
||||
'\n- '.join([p.email_formatted for p in partners_error_user])))
|
||||
if error_msg:
|
||||
error_msg.append(_("To resolve this error, you can: \n"
|
||||
"- Correct the emails of the relevant contacts\n"
|
||||
|
||||
@@ -271,7 +271,7 @@ class TestMailgateway(BaseFunctionalTest, MockEmails):
|
||||
# Test bounce email
|
||||
self.assertEqual(self._mails[0].get('subject'), 'Re: Should Bounce')
|
||||
self.assertEqual(self._mails[0].get('email_to')[0], 'whatever-2a840@postmaster.twitter.com')
|
||||
self.assertEqual(self._mails[0].get('email_from'), 'MAILER-DAEMON <bounce.test@test.com>')
|
||||
self.assertEqual(self._mails[0].get('email_from'), '"MAILER-DAEMON" <bounce.test@test.com>')
|
||||
|
||||
@mute_logger('odoo.addons.mail.models.mail_thread', 'odoo.models.unlink', 'odoo.addons.mail.models.mail_mail')
|
||||
def test_message_process_alias_followers_bounce(self):
|
||||
@@ -289,7 +289,7 @@ class TestMailgateway(BaseFunctionalTest, MockEmails):
|
||||
'message_process: incoming email on Followers alias should send a bounce email')
|
||||
self.assertEqual(self._mails[0].get('subject'), 'Re: Should Bounce')
|
||||
self.assertEqual(self._mails[0].get('email_to')[0], 'whatever-2a840@postmaster.twitter.com')
|
||||
self.assertEqual(self._mails[0].get('email_from'), 'MAILER-DAEMON <bounce.test@test.com>')
|
||||
self.assertEqual(self._mails[0].get('email_from'), '"MAILER-DAEMON" <bounce.test@test.com>')
|
||||
|
||||
# Test: partner on followers alias -> bounce
|
||||
self._init_mock_build_email()
|
||||
@@ -299,7 +299,7 @@ class TestMailgateway(BaseFunctionalTest, MockEmails):
|
||||
'message_process: incoming email on Followers alias should send a bounce email')
|
||||
self.assertEqual(self._mails[0].get('subject'), 'Re: Should Bounce')
|
||||
self.assertEqual(self._mails[0].get('email_to')[0], 'whatever-2a840@postmaster.twitter.com')
|
||||
self.assertEqual(self._mails[0].get('email_from'), 'MAILER-DAEMON <bounce.test@test.com>')
|
||||
self.assertEqual(self._mails[0].get('email_from'), '"MAILER-DAEMON" <bounce.test@test.com>')
|
||||
|
||||
@mute_logger('odoo.addons.mail.models.mail_thread', 'odoo.models')
|
||||
def test_message_process_alias_partner(self):
|
||||
@@ -423,7 +423,7 @@ class TestMailgateway(BaseFunctionalTest, MockEmails):
|
||||
# Test bounce email
|
||||
self.assertEqual(self._mails[0].get('subject'), 'Re: Should Bounce')
|
||||
self.assertEqual(self._mails[0].get('email_to')[0], 'whatever-2a840@postmaster.twitter.com')
|
||||
self.assertEqual(self._mails[0].get('email_from'), 'MAILER-DAEMON <bounce.test@test.com>')
|
||||
self.assertEqual(self._mails[0].get('email_from'), '"MAILER-DAEMON" <bounce.test@test.com>')
|
||||
|
||||
@mute_logger('odoo.addons.mail.models.mail_thread')
|
||||
def test_message_process_bounce_alias(self):
|
||||
|
||||
Reference in New Issue
Block a user