Reply-To not put in header if not specified (#664)

This commit is contained in:
Chris Caron 2022-09-16 12:14:38 -04:00 committed by GitHub
parent d1c653fc04
commit 3efb2c6f3e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 49 additions and 17 deletions

View File

@ -544,10 +544,6 @@ class NotifyEmail(NotifyBase):
'({}) specified.'.format(recipient),
)
if not reply_to:
# Add ourselves to the Reply-To directive
self.reply_to.add(self.from_addr)
# Validate recipients (reply-to:) and drop bad ones:
for recipient in parse_emails(reply_to):
email = is_email(recipient)
@ -699,10 +695,11 @@ class NotifyEmail(NotifyBase):
(self.names.get(addr, False), addr), charset='utf-8')
for addr in bcc]
# Format our reply-to addresses to support the Name field
reply_to = [formataddr(
(self.names.get(addr, False), addr), charset='utf-8')
for addr in reply_to]
if reply_to:
# Format our reply-to addresses to support the Name field
reply_to = [formataddr(
(self.names.get(addr, False), addr), charset='utf-8')
for addr in reply_to]
except TypeError:
# Python v2.x Support (no charset keyword)
@ -714,9 +711,11 @@ class NotifyEmail(NotifyBase):
bcc = [formataddr( # pragma: no branch
(self.names.get(addr, False), addr)) for addr in bcc]
# Format our reply-to addresses to support the Name field
reply_to = [formataddr( # pragma: no branch
(self.names.get(addr, False), addr)) for addr in reply_to]
if reply_to:
# Format our reply-to addresses to support the Name field
reply_to = [formataddr( # pragma: no branch
(self.names.get(addr, False), addr))
for addr in reply_to]
self.logger.debug(
'Email From: {} <{}>'.format(from_name, self.from_addr))
@ -808,7 +807,8 @@ class NotifyEmail(NotifyBase):
if cc:
base['Cc'] = ','.join(cc)
base['Reply-To'] = ','.join(reply_to)
if reply_to:
base['Reply-To'] = ','.join(reply_to)
# bind the socket variable to the current namespace
socket = None
@ -901,11 +901,13 @@ class NotifyEmail(NotifyBase):
'' if not e not in self.names
else '{}:'.format(self.names[e]), e) for e in self.bcc])
# Handle our Reply-To Addresses
params['reply'] = ','.join(
['{}{}'.format(
'' if not e not in self.names
else '{}:'.format(self.names[e]), e) for e in self.reply_to])
if self.reply_to:
# Handle our Reply-To Addresses
params['reply'] = ','.join(
['{}{}'.format(
'' if not e not in self.names
else '{}:'.format(self.names[e]), e)
for e in self.reply_to])
# pull email suffix from username (if present)
user = None if not self.user else self.user.split('@')[0]

View File

@ -859,6 +859,8 @@ def test_plugin_email_url_parsing(mock_smtp, mock_smtp_ssl):
# Test that our template over-ride worked
assert 'mode=ssl' in obj.url()
assert 'smtp=override.com' in obj.url()
# No reply address specified
assert 'reply=' not in obj.url()
mock_smtp.reset_mock()
response.reset_mock()
@ -871,22 +873,30 @@ def test_plugin_email_url_parsing(mock_smtp, mock_smtp_ssl):
obj = Apprise.instantiate(results, suppress_exceptions=False)
assert isinstance(obj, plugins.NotifyEmail) is True
assert obj.smtp_host == 'smtp-mail.outlook.com'
# No entries in the reply_to
assert not obj.reply_to
results = plugins.NotifyEmail.parse_url(
'mailtos://user:pass123@outlook.com.au')
obj = Apprise.instantiate(results, suppress_exceptions=False)
assert isinstance(obj, plugins.NotifyEmail) is True
assert obj.smtp_host == 'smtp-mail.outlook.com'
# No entries in the reply_to
assert not obj.reply_to
results = plugins.NotifyEmail.parse_url(
'mailtos://user:pass123@live.com')
obj = Apprise.instantiate(results, suppress_exceptions=False)
assert isinstance(obj, plugins.NotifyEmail) is True
# No entries in the reply_to
assert not obj.reply_to
results = plugins.NotifyEmail.parse_url(
'mailtos://user:pass123@hotmail.com')
obj = Apprise.instantiate(results, suppress_exceptions=False)
assert isinstance(obj, plugins.NotifyEmail) is True
# No entries in the reply_to
assert not obj.reply_to
#
# Test Port Over-Riding
@ -902,6 +912,8 @@ def test_plugin_email_url_parsing(mock_smtp, mock_smtp_ssl):
assert obj.port == 465
assert obj.from_addr == 'abc@xyz.cn'
assert obj.secure_mode == 'ssl'
# No entries in the reply_to
assert not obj.reply_to
results = plugins.NotifyEmail.parse_url(
"mailtos://abc:password@xyz.cn?"
@ -914,3 +926,21 @@ def test_plugin_email_url_parsing(mock_smtp, mock_smtp_ssl):
assert obj.port == 465
assert obj.from_addr == 'abc@xyz.cn'
assert obj.secure_mode == 'ssl'
# No entries in the reply_to
assert not obj.reply_to
#
# Test Reply-To Email
#
results = plugins.NotifyEmail.parse_url(
"mailtos://user:pass@example.com?reply=noreply@example.com")
obj = Apprise.instantiate(results, suppress_exceptions=False)
assert isinstance(obj, plugins.NotifyEmail) is True
# Verify our over-rides are in place
assert obj.smtp_host == 'example.com'
assert obj.from_addr == 'user@example.com'
assert obj.secure_mode == 'starttls'
assert obj.url().startswith(
'mailtos://user:pass@example.com')
# Test that our template over-ride worked
assert 'reply=noreply%40example.com' in obj.url()