From 9f0160549c6ef6773cb6edca4cd5ae0cc7b92fc8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20P=C3=A9ters?= Date: Mon, 1 Jun 2020 09:23:25 +0200 Subject: [PATCH] emails: compute default from using local user/hostname (#43496) --- tests/test_misc.py | 4 +++- wcs/qommon/emails.py | 5 ++++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/tests/test_misc.py b/tests/test_misc.py index 570b6407b..758d0928d 100644 --- a/tests/test_misc.py +++ b/tests/test_misc.py @@ -4,6 +4,8 @@ import json import pytest import os import pickle +import pwd +import socket import re import time import datetime @@ -309,7 +311,7 @@ def test_email_from(emails): pub = create_temporary_pub() send_email('test', mail_body='Hello', email_rcpt='test@localhost', want_html=False) assert emails.count() == 1 - assert emails.emails['test']['from'] == 'noreply@entrouvert.com' + assert emails.emails['test']['from'] == '%s@%s' % (pwd.getpwuid(os.getuid())[0], socket.getfqdn()) pub.cfg['emails'] = {'from': 'foo@localhost'} send_email('test', mail_body='Hello', email_rcpt='test@localhost', want_html=False) diff --git a/wcs/qommon/emails.py b/wcs/qommon/emails.py index f65e12d7d..a4b6ec0af 100644 --- a/wcs/qommon/emails.py +++ b/wcs/qommon/emails.py @@ -15,6 +15,7 @@ # along with this program; if not, see . import os +import pwd import re from email import encoders @@ -287,7 +288,9 @@ def email(subject, mail_body, email_rcpt, replyto=None, bcc=None, msg['To'] = email_rcpt if not email_from: - email_from = emails_cfg.get('from', 'noreply@entrouvert.com') + email_from = emails_cfg.get('from') + 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: