From 3efb2c6f3e352065ec65840fda3e1bce94846217 Mon Sep 17 00:00:00 2001 From: Chris Caron Date: Fri, 16 Sep 2022 12:14:38 -0400 Subject: [PATCH] Reply-To not put in header if not specified (#664) --- apprise/plugins/NotifyEmail.py | 36 ++++++++++++++++++---------------- test/test_plugin_email.py | 30 ++++++++++++++++++++++++++++ 2 files changed, 49 insertions(+), 17 deletions(-) diff --git a/apprise/plugins/NotifyEmail.py b/apprise/plugins/NotifyEmail.py index 911352a7..b7f3d685 100644 --- a/apprise/plugins/NotifyEmail.py +++ b/apprise/plugins/NotifyEmail.py @@ -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] diff --git a/test/test_plugin_email.py b/test/test_plugin_email.py index ea2d4dad..8c9ada0d 100644 --- a/test/test_plugin_email.py +++ b/test/test_plugin_email.py @@ -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()