Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 499ce5a

Browse files
committed
[#6838] Use the headers Reply-to value if its set in the extensions
1 parent e62d48a commit 499ce5a

2 files changed

Lines changed: 26 additions & 1 deletion

File tree

ckan/lib/mailer.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,8 @@ def _mail_recipient(recipient_name, recipient_email,
5959
msg['To'] = u"%s <%s>" % (recipient_name, recipient_email)
6060
msg['Date'] = utils.formatdate(time())
6161
msg['X-Mailer'] = "CKAN %s" % ckan.__version__
62-
if reply_to and reply_to != '':
62+
# Check if extension is setting reply-to via headers or use config option
63+
if reply_to and reply_to != '' and not msg['Reply-to']:
6364
msg['Reply-to'] = reply_to
6465

6566
# Send the email using Python's smtplib.

ckan/tests/lib/test_mailer.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -281,3 +281,27 @@ def test_reply_to(self, mail_server):
281281
)
282282

283283
assert expected_from_header in msg[3]
284+
285+
@pytest.mark.ckan_config("smtp.reply_to", "[email protected]")
286+
def test_reply_to_ext_headers_overwrite(self, mail_server):
287+
288+
msgs = mail_server.get_smtp_messages()
289+
assert msgs == []
290+
291+
# send email
292+
test_email = {
293+
"recipient_name": "Bob",
294+
"recipient_email": "[email protected]",
295+
"subject": "Meeting",
296+
"body": "The meeting is cancelled.",
297+
"headers": {"Reply-to": "[email protected]"},
298+
}
299+
mailer.mail_recipient(**test_email)
300+
301+
# check it went to the mock smtp server
302+
msgs = mail_server.get_smtp_messages()
303+
msg = msgs[0]
304+
305+
expected_from_header = 'Reply-to: [email protected]'
306+
307+
assert expected_from_header in msg[3]

0 commit comments

Comments
 (0)