Skip to content

Commit

Permalink
Fix mailto://ip.addr support (#1114)
Browse files Browse the repository at this point in the history
  • Loading branch information
caronc authored Apr 20, 2024
1 parent 22c979d commit 2316a4b
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 3 deletions.
10 changes: 7 additions & 3 deletions apprise/plugins/NotifyEmail.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
from ..URLBase import PrivacyMode
from ..common import NotifyFormat, NotifyType
from ..conversion import convert_between
from ..utils import is_email, parse_emails, is_hostname
from ..utils import is_ipaddr, is_email, parse_emails, is_hostname
from ..AppriseLocale import gettext_lazy as _
from ..logger import logger

Expand Down Expand Up @@ -1053,8 +1053,12 @@ def parse_url(url):
# Prepare our target lists
results['targets'] = []

if not is_hostname(results['host'], ipv4=False, ipv6=False,
underscore=False):
if is_ipaddr(results['host']):
# Silently move on and do not disrupt any configuration
pass

elif not is_hostname(results['host'], ipv4=False, ipv6=False,
underscore=False):

if is_email(NotifyEmail.unquote(results['host'])):
# Don't lose defined email addresses
Expand Down
42 changes: 42 additions & 0 deletions test/test_plugin_email.py
Original file line number Diff line number Diff line change
Expand Up @@ -2006,3 +2006,45 @@ def test_plugin_host_detection_from_source_email(mock_smtp, mock_smtp_ssl):
assert len(_to) == 1
assert _to[0] == 'john@yahoo.ca'
assert _msg.split('\n')[-3] == 'body'


@mock.patch('smtplib.SMTP_SSL')
@mock.patch('smtplib.SMTP')
def test_plugin_email_by_ipaddr_1113(mock_smtp, mock_smtp_ssl):
"""
NotifyEmail() GitHub Issue 1113
https://github.com/caronc/apprise/issues/1113
Email with ip addresses not working
"""

response = mock.Mock()
mock_smtp_ssl.return_value = response
mock_smtp.return_value = response

results = NotifyEmail.parse_url(
'mailto://10.0.0.195:25/?to=alerts@example.com&'
'from=sender@example.com')

assert isinstance(results, dict)
assert results['user'] is None
assert results['password'] is None
assert results['host'] == '10.0.0.195'
assert results['from_addr'] == 'sender@example.com'
assert isinstance(results['targets'], list)
assert len(results['targets']) == 1
assert results['targets'][0] == 'alerts@example.com'
assert results['port'] == 25

email = Apprise.instantiate(results, suppress_exceptions=False)
assert isinstance(email, NotifyEmail) is True

assert len(email.targets) == 1
assert (False, 'alerts@example.com') in email.targets

assert email.from_addr == (False, 'sender@example.com')
assert email.user is None
assert email.password is None
assert email.smtp_host == '10.0.0.195'
assert email.port == 25
assert email.targets == [(False, 'alerts@example.com')]

0 comments on commit 2316a4b

Please sign in to comment.