emails: use new default_sender_name variable set from hobo (#44566)

This commit is contained in:
Frédéric Péters 2020-06-30 09:34:41 +02:00
parent cdb71d3628
commit db17f2f0e1
2 changed files with 17 additions and 3 deletions

View File

@ -1245,6 +1245,19 @@ def test_email(pub, emails):
assert emails.count() == 1
assert emails.get('foobar').get('from') == 'foobar@localhost'
# custom sender name defined from site-options variable
pub.load_site_options()
if not pub.site_options.has_section('variables'):
pub.site_options.add_section('variables')
pub.site_options.set('variables', 'email_sender_name', 'SENDER NAME')
emails.empty()
item.to = [role1.id]
item.custom_from = '="foobar@localhost"'
item.perform(formdata)
get_response().process_after_jobs()
assert emails.count() == 1
assert emails.get('foobar')['msg']['From'] == 'SENDER NAME <foobar@localhost>'
def test_email_django_escaping(pub, emails):
formdef = FormDef()

View File

@ -292,9 +292,10 @@ def email(subject, mail_body, email_rcpt, replyto=None, bcc=None,
if not email_from:
email_from = '%s@%s' % (pwd.getpwuid(os.getuid())[0], socket.getfqdn())
sitename = get_publisher().get_site_option('global_title', 'variables')
if sitename:
msg['From'] = formataddr((str(Header(sitename, encoding)), email_from))
sender_name = (get_publisher().get_site_option('email_sender_name', 'variables') or
get_publisher().get_site_option('global_title', 'variables'))
if sender_name:
msg['From'] = formataddr((str(Header(sender_name, encoding)), email_from))
else:
msg['From'] = email_from