Do not set empty To, Cc nor Bcc in email message

Since gh-102988, email.utils.getaddresses() return [('', '')] for invalid email
addresses which includes empty string if the header is set with an empty list.

Closes #13649
This commit is contained in:
Cédric Krier
2024-11-18 08:44:57 +01:00
parent ffeeb1cdfe
commit 27e589ccd7
4 changed files with 20 additions and 11 deletions
+6 -3
View File
@@ -149,9 +149,12 @@ class Dunning(metaclass=PoolMeta):
if dunning.level.email_from:
from_ = dunning.level.email_from
set_from_header(msg, sender, from_)
msg['To'] = to
msg['Cc'] = cc
msg['Bcc'] = bcc
if to:
msg['To'] = to
if cc:
msg['Cc'] = cc
if bcc:
msg['Bcc'] = bcc
msg['Subject'] = title
msg['Auto-Submitted'] = 'auto-generated'
return msg
+6 -3
View File
@@ -200,9 +200,12 @@ class Email(ModelSQL, ModelView):
filename=('utf-8', '', name))
set_from_header(msg, sender, from_)
msg['To'] = to
msg['Cc'] = cc
msg['Bcc'] = bcc
if to:
msg['To'] = to
if cc:
msg['Cc'] = cc
if bcc:
msg['Bcc'] = bcc
msg['Subject'] = title
msg['Auto-Submitted'] = 'auto-generated'
return msg
@@ -120,8 +120,8 @@ class NotificationEmailTestCase(CompanyTestMixin, ModuleTestCase):
email, = Email.search([])
self.assertEqual(email.recipients, 'Administrator <user@example.com>')
self.assertEqual(email.recipients_secondary, '')
self.assertEqual(email.recipients_hidden, '')
self.assertEqual(email.recipients_secondary, None)
self.assertEqual(email.recipients_hidden, None)
self.assertEqual(email.subject, 'Notification Email')
self.assertEqual(email.resource, user)
self.assertEqual(email.notification_email, notification_email)
+6 -3
View File
@@ -153,9 +153,12 @@ class Email(ResourceAccessMixin, ModelSQL, ModelView):
filename=('utf-8', '', name))
from_ = config.get('email', 'from')
set_from_header(msg, from_, user.email or from_)
msg['To'] = [format_address(a, n) for n, a in getaddresses([to])]
msg['Cc'] = [format_address(a, n) for n, a in getaddresses([cc])]
msg['Bcc'] = [format_address(a, n) for n, a in getaddresses([bcc])]
if to:
msg['To'] = [format_address(a, n) for n, a in getaddresses([to])]
if cc:
msg['Cc'] = [format_address(a, n) for n, a in getaddresses([cc])]
if bcc:
msg['Bcc'] = [format_address(a, n) for n, a in getaddresses([bcc])]
msg['Subject'] = subject
send_message_transactional(msg, strict=True)