2017-12-06 06:35:03 +01:00
|
|
|
|
# -*- coding: utf-8 -*-
|
2023-02-09 09:54:55 +01:00
|
|
|
|
# BSD 3-Clause License
|
2017-12-06 06:35:03 +01:00
|
|
|
|
#
|
2023-02-09 09:54:55 +01:00
|
|
|
|
# Apprise - Push Notification Library.
|
|
|
|
|
# Copyright (c) 2023, Chris Caron <lead2gold@gmail.com>
|
2017-12-06 06:35:03 +01:00
|
|
|
|
#
|
2023-02-09 09:54:55 +01:00
|
|
|
|
# Redistribution and use in source and binary forms, with or without
|
|
|
|
|
# modification, are permitted provided that the following conditions are met:
|
2017-12-06 06:35:03 +01:00
|
|
|
|
#
|
2023-02-09 09:54:55 +01:00
|
|
|
|
# 1. Redistributions of source code must retain the above copyright notice,
|
|
|
|
|
# this list of conditions and the following disclaimer.
|
2017-12-06 06:35:03 +01:00
|
|
|
|
#
|
2023-02-09 09:54:55 +01:00
|
|
|
|
# 2. Redistributions in binary form must reproduce the above copyright notice,
|
|
|
|
|
# this list of conditions and the following disclaimer in the documentation
|
|
|
|
|
# and/or other materials provided with the distribution.
|
2017-12-06 06:35:03 +01:00
|
|
|
|
#
|
2023-02-09 09:54:55 +01:00
|
|
|
|
# 3. Neither the name of the copyright holder nor the names of its
|
|
|
|
|
# contributors may be used to endorse or promote products derived from
|
|
|
|
|
# this software without specific prior written permission.
|
|
|
|
|
#
|
|
|
|
|
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
|
|
|
|
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
|
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
|
# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
|
|
|
|
|
# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
|
|
|
|
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
|
|
|
|
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
|
|
|
|
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
|
|
|
|
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
|
|
|
|
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
|
|
|
|
# POSSIBILITY OF SUCH DAMAGE.
|
2017-12-06 06:35:03 +01:00
|
|
|
|
|
2022-11-21 03:01:26 +01:00
|
|
|
|
import logging
|
2019-11-11 17:34:25 +01:00
|
|
|
|
import os
|
2019-02-25 07:02:29 +01:00
|
|
|
|
import re
|
2022-10-08 02:28:36 +02:00
|
|
|
|
from unittest import mock
|
2022-09-01 02:05:40 +02:00
|
|
|
|
|
2019-02-25 07:02:29 +01:00
|
|
|
|
import smtplib
|
2020-08-09 03:05:30 +02:00
|
|
|
|
from email.header import decode_header
|
2019-02-25 07:02:29 +01:00
|
|
|
|
|
2022-10-09 11:28:18 +02:00
|
|
|
|
from apprise import NotifyType, NotifyBase
|
2017-12-06 06:35:03 +01:00
|
|
|
|
from apprise import Apprise
|
2019-11-11 17:34:25 +01:00
|
|
|
|
from apprise import AttachBase
|
|
|
|
|
from apprise import AppriseAttachment
|
2022-10-09 11:28:18 +02:00
|
|
|
|
from apprise.plugins.NotifyEmail import NotifyEmail
|
2022-11-21 03:01:26 +01:00
|
|
|
|
from apprise.plugins import NotifyEmail as NotifyEmailModule
|
2022-10-09 11:28:18 +02:00
|
|
|
|
|
2022-11-21 03:01:26 +01:00
|
|
|
|
# Disable logging for a cleaner testing output
|
2019-02-25 07:02:29 +01:00
|
|
|
|
logging.disable(logging.CRITICAL)
|
2017-12-06 06:35:03 +01:00
|
|
|
|
|
2022-11-21 03:01:26 +01:00
|
|
|
|
|
2019-11-11 17:34:25 +01:00
|
|
|
|
# Attachment Directory
|
|
|
|
|
TEST_VAR_DIR = os.path.join(os.path.dirname(__file__), 'var')
|
|
|
|
|
|
2017-12-14 03:35:59 +01:00
|
|
|
|
TEST_URLS = (
|
2017-12-06 06:35:03 +01:00
|
|
|
|
##################################
|
|
|
|
|
# NotifyEmail
|
|
|
|
|
##################################
|
|
|
|
|
('mailto://', {
|
|
|
|
|
'instance': None,
|
|
|
|
|
}),
|
|
|
|
|
('mailtos://', {
|
|
|
|
|
'instance': None,
|
|
|
|
|
}),
|
|
|
|
|
('mailto://:@/', {
|
|
|
|
|
'instance': None
|
|
|
|
|
}),
|
|
|
|
|
# No Username
|
|
|
|
|
('mailtos://:pass@nuxref.com:567', {
|
|
|
|
|
# Can't prepare a To address using this expression
|
2019-02-13 23:48:09 +01:00
|
|
|
|
'instance': TypeError,
|
2017-12-06 06:35:03 +01:00
|
|
|
|
}),
|
|
|
|
|
|
|
|
|
|
# Pre-Configured Email Services
|
|
|
|
|
('mailto://user:pass@gmail.com', {
|
2022-10-09 11:28:18 +02:00
|
|
|
|
'instance': NotifyEmail,
|
2017-12-06 06:35:03 +01:00
|
|
|
|
}),
|
|
|
|
|
('mailto://user:pass@hotmail.com', {
|
2022-10-09 11:28:18 +02:00
|
|
|
|
'instance': NotifyEmail,
|
2017-12-06 06:35:03 +01:00
|
|
|
|
}),
|
|
|
|
|
('mailto://user:pass@live.com', {
|
2022-10-09 11:28:18 +02:00
|
|
|
|
'instance': NotifyEmail,
|
2017-12-06 06:35:03 +01:00
|
|
|
|
}),
|
|
|
|
|
('mailto://user:pass@prontomail.com', {
|
2022-10-09 11:28:18 +02:00
|
|
|
|
'instance': NotifyEmail,
|
2017-12-06 06:35:03 +01:00
|
|
|
|
}),
|
|
|
|
|
('mailto://user:pass@yahoo.com', {
|
2022-10-09 11:28:18 +02:00
|
|
|
|
'instance': NotifyEmail,
|
2017-12-06 06:35:03 +01:00
|
|
|
|
}),
|
|
|
|
|
('mailto://user:pass@yahoo.ca', {
|
2022-10-09 11:28:18 +02:00
|
|
|
|
'instance': NotifyEmail,
|
2017-12-06 06:35:03 +01:00
|
|
|
|
}),
|
2018-12-06 18:00:55 +01:00
|
|
|
|
('mailto://user:pass@fastmail.com', {
|
2022-10-09 11:28:18 +02:00
|
|
|
|
'instance': NotifyEmail,
|
2018-12-06 18:00:55 +01:00
|
|
|
|
}),
|
2019-08-21 03:34:13 +02:00
|
|
|
|
('mailto://user:pass@sendgrid.com', {
|
2022-10-09 11:28:18 +02:00
|
|
|
|
'instance': NotifyEmail,
|
2019-08-21 03:34:13 +02:00
|
|
|
|
}),
|
2017-12-06 06:35:03 +01:00
|
|
|
|
|
2020-09-29 21:16:02 +02:00
|
|
|
|
# Yandex
|
|
|
|
|
('mailto://user:pass@yandex.com', {
|
2022-10-09 11:28:18 +02:00
|
|
|
|
'instance': NotifyEmail,
|
2020-09-29 21:16:02 +02:00
|
|
|
|
}),
|
|
|
|
|
('mailto://user:pass@yandex.ru', {
|
2022-10-09 11:28:18 +02:00
|
|
|
|
'instance': NotifyEmail,
|
2020-09-29 21:16:02 +02:00
|
|
|
|
}),
|
|
|
|
|
('mailto://user:pass@yandex.fr', {
|
2022-10-09 11:28:18 +02:00
|
|
|
|
'instance': NotifyEmail,
|
2020-09-29 21:16:02 +02:00
|
|
|
|
}),
|
|
|
|
|
|
2017-12-06 06:35:03 +01:00
|
|
|
|
# Custom Emails
|
|
|
|
|
('mailtos://user:pass@nuxref.com:567', {
|
2022-10-09 11:28:18 +02:00
|
|
|
|
'instance': NotifyEmail,
|
2017-12-06 06:35:03 +01:00
|
|
|
|
}),
|
2022-11-23 13:13:38 +01:00
|
|
|
|
('mailto://user:pass@nuxref.com?mode=ssl', {
|
|
|
|
|
# mailto:// with mode=ssl causes us to convert to ssl
|
|
|
|
|
'instance': NotifyEmail,
|
|
|
|
|
# Our expected url(privacy=True) startswith() response:
|
|
|
|
|
'privacy_url': 'mailtos://user:****@nuxref.com',
|
|
|
|
|
}),
|
2017-12-06 06:35:03 +01:00
|
|
|
|
('mailto://user:pass@nuxref.com:567?format=html', {
|
2022-10-09 11:28:18 +02:00
|
|
|
|
'instance': NotifyEmail,
|
2017-12-06 06:35:03 +01:00
|
|
|
|
}),
|
|
|
|
|
('mailtos://user:pass@nuxref.com:567?to=l2g@nuxref.com', {
|
2022-10-09 11:28:18 +02:00
|
|
|
|
'instance': NotifyEmail,
|
2017-12-06 06:35:03 +01:00
|
|
|
|
}),
|
2019-05-30 02:07:05 +02:00
|
|
|
|
('mailtos://user:pass@nuxref.com:567/l2g@nuxref.com', {
|
2022-10-09 11:28:18 +02:00
|
|
|
|
'instance': NotifyEmail,
|
2019-05-30 02:07:05 +02:00
|
|
|
|
}),
|
2017-12-06 06:35:03 +01:00
|
|
|
|
(
|
|
|
|
|
'mailto://user:pass@example.com:2525?user=l2g@example.com'
|
|
|
|
|
'&pass=l2g@apprise!is!Awesome', {
|
2022-10-09 11:28:18 +02:00
|
|
|
|
'instance': NotifyEmail,
|
2017-12-06 06:35:03 +01:00
|
|
|
|
},
|
|
|
|
|
),
|
|
|
|
|
(
|
|
|
|
|
'mailto://user:pass@example.com:2525?user=l2g@example.com'
|
|
|
|
|
'&pass=l2g@apprise!is!Awesome&format=text', {
|
2022-10-09 11:28:18 +02:00
|
|
|
|
'instance': NotifyEmail,
|
2017-12-06 06:35:03 +01:00
|
|
|
|
},
|
|
|
|
|
),
|
2019-08-21 03:34:13 +02:00
|
|
|
|
(
|
|
|
|
|
# Test Carbon Copy
|
|
|
|
|
'mailtos://user:pass@example.com?smtp=smtp.example.com'
|
|
|
|
|
'&name=l2g&cc=noreply@example.com,test@example.com', {
|
2022-10-09 11:28:18 +02:00
|
|
|
|
'instance': NotifyEmail,
|
2019-08-21 03:34:13 +02:00
|
|
|
|
},
|
|
|
|
|
),
|
|
|
|
|
(
|
|
|
|
|
# Test Blind Carbon Copy
|
|
|
|
|
'mailtos://user:pass@example.com?smtp=smtp.example.com'
|
|
|
|
|
'&name=l2g&bcc=noreply@example.com,test@example.com', {
|
2022-10-09 11:28:18 +02:00
|
|
|
|
'instance': NotifyEmail,
|
2019-08-21 03:34:13 +02:00
|
|
|
|
},
|
|
|
|
|
),
|
|
|
|
|
(
|
|
|
|
|
# Test Carbon Copy with bad email
|
|
|
|
|
'mailtos://user:pass@example.com?smtp=smtp.example.com'
|
|
|
|
|
'&name=l2g&cc=noreply@example.com,@', {
|
2022-10-09 11:28:18 +02:00
|
|
|
|
'instance': NotifyEmail,
|
2019-08-21 03:34:13 +02:00
|
|
|
|
},
|
|
|
|
|
),
|
|
|
|
|
(
|
|
|
|
|
# Test Blind Carbon Copy with bad email
|
|
|
|
|
'mailtos://user:pass@example.com?smtp=smtp.example.com'
|
|
|
|
|
'&name=l2g&bcc=noreply@example.com,@', {
|
2022-10-09 11:28:18 +02:00
|
|
|
|
'instance': NotifyEmail,
|
2019-08-21 03:34:13 +02:00
|
|
|
|
},
|
|
|
|
|
),
|
2022-09-06 00:59:43 +02:00
|
|
|
|
(
|
|
|
|
|
# Test Reply To
|
|
|
|
|
'mailtos://user:pass@example.com?smtp=smtp.example.com'
|
|
|
|
|
'&name=l2g&reply=test@example.com,test2@example.com', {
|
2022-10-09 11:28:18 +02:00
|
|
|
|
'instance': NotifyEmail,
|
2022-09-06 00:59:43 +02:00
|
|
|
|
},
|
|
|
|
|
),
|
|
|
|
|
(
|
|
|
|
|
# Test Reply To with bad email
|
|
|
|
|
'mailtos://user:pass@example.com?smtp=smtp.example.com'
|
|
|
|
|
'&name=l2g&reply=test@example.com,@', {
|
2022-10-09 11:28:18 +02:00
|
|
|
|
'instance': NotifyEmail,
|
2022-09-06 00:59:43 +02:00
|
|
|
|
},
|
|
|
|
|
),
|
2020-10-06 22:32:00 +02:00
|
|
|
|
# headers
|
|
|
|
|
('mailto://user:pass@localhost.localdomain'
|
|
|
|
|
'?+X-Customer-Campaign-ID=Apprise', {
|
2022-10-09 11:28:18 +02:00
|
|
|
|
'instance': NotifyEmail,
|
2020-10-06 22:32:00 +02:00
|
|
|
|
}),
|
2017-12-06 06:35:03 +01:00
|
|
|
|
# No Password
|
|
|
|
|
('mailtos://user:@nuxref.com', {
|
2022-10-09 11:28:18 +02:00
|
|
|
|
'instance': NotifyEmail,
|
2017-12-06 06:35:03 +01:00
|
|
|
|
}),
|
2022-11-05 21:37:57 +01:00
|
|
|
|
# Invalid From Address; but just gets put as the from name instead
|
|
|
|
|
# Hence the below generats From: "@ <user@nuxref.com>"
|
2017-12-06 06:35:03 +01:00
|
|
|
|
('mailtos://user:pass@nuxref.com?from=@', {
|
2022-11-05 21:37:57 +01:00
|
|
|
|
'instance': NotifyEmail,
|
2017-12-06 06:35:03 +01:00
|
|
|
|
}),
|
2018-05-31 02:14:41 +02:00
|
|
|
|
# Invalid From Address
|
2017-12-06 06:35:03 +01:00
|
|
|
|
('mailtos://nuxref.com?user=&pass=.', {
|
2019-02-13 23:48:09 +01:00
|
|
|
|
'instance': TypeError,
|
2017-12-06 06:35:03 +01:00
|
|
|
|
}),
|
2019-05-30 02:07:05 +02:00
|
|
|
|
# Invalid To Address is accepted, but we won't be able to properly email
|
|
|
|
|
# using the notify() call
|
2018-05-31 02:14:41 +02:00
|
|
|
|
('mailtos://user:pass@nuxref.com?to=@', {
|
2022-10-09 11:28:18 +02:00
|
|
|
|
'instance': NotifyEmail,
|
2019-05-30 02:07:05 +02:00
|
|
|
|
'response': False,
|
2018-05-31 02:14:41 +02:00
|
|
|
|
}),
|
2017-12-06 06:35:03 +01:00
|
|
|
|
# Valid URL, but can't structure a proper email
|
2022-10-14 01:53:32 +02:00
|
|
|
|
('mailtos://nuxref.com?user=%20"&pass=.', {
|
2019-02-13 23:48:09 +01:00
|
|
|
|
'instance': TypeError,
|
2017-12-06 06:35:03 +01:00
|
|
|
|
}),
|
2018-05-31 02:14:41 +02:00
|
|
|
|
# Invalid From (and To) Address
|
2017-12-06 06:35:03 +01:00
|
|
|
|
('mailtos://nuxref.com?to=test', {
|
2019-02-13 23:48:09 +01:00
|
|
|
|
'instance': TypeError,
|
2017-12-06 06:35:03 +01:00
|
|
|
|
}),
|
2018-12-06 18:00:55 +01:00
|
|
|
|
# Invalid Secure Mode
|
|
|
|
|
('mailtos://user:pass@example.com?mode=notamode', {
|
2019-02-13 23:48:09 +01:00
|
|
|
|
'instance': TypeError,
|
2018-12-06 18:00:55 +01:00
|
|
|
|
}),
|
|
|
|
|
# STARTTLS flag checking
|
|
|
|
|
('mailtos://user:pass@gmail.com?mode=starttls', {
|
2022-10-09 11:28:18 +02:00
|
|
|
|
'instance': NotifyEmail,
|
2019-09-29 23:17:25 +02:00
|
|
|
|
# Our expected url(privacy=True) startswith() response:
|
|
|
|
|
'privacy_url': 'mailtos://user:****@gmail.com',
|
2018-12-06 18:00:55 +01:00
|
|
|
|
}),
|
|
|
|
|
# SSL flag checking
|
|
|
|
|
('mailtos://user:pass@gmail.com?mode=ssl', {
|
2022-10-09 11:28:18 +02:00
|
|
|
|
'instance': NotifyEmail,
|
2018-12-06 18:00:55 +01:00
|
|
|
|
}),
|
2017-12-06 06:35:03 +01:00
|
|
|
|
# Can make a To address using what we have (l2g@nuxref.com)
|
|
|
|
|
('mailtos://nuxref.com?user=l2g&pass=.', {
|
2022-10-09 11:28:18 +02:00
|
|
|
|
'instance': NotifyEmail,
|
2019-09-29 23:17:25 +02:00
|
|
|
|
# Our expected url(privacy=True) startswith() response:
|
|
|
|
|
'privacy_url': 'mailtos://l2g:****@nuxref.com',
|
2017-12-06 06:35:03 +01:00
|
|
|
|
}),
|
|
|
|
|
('mailto://user:pass@localhost:2525', {
|
2022-10-09 11:28:18 +02:00
|
|
|
|
'instance': NotifyEmail,
|
2017-12-06 06:35:03 +01:00
|
|
|
|
# Throws a series of connection and transfer exceptions when this flag
|
|
|
|
|
# is set and tests that we gracfully handle them
|
|
|
|
|
'test_smtplib_exceptions': True,
|
|
|
|
|
}),
|
2022-11-05 21:37:57 +01:00
|
|
|
|
# Use of both 'name' and 'from' together; these are synonymous
|
|
|
|
|
('mailtos://user:pass@nuxref.com?'
|
|
|
|
|
'from=jack@gmail.com&name=Jason<jason@gmail.com>', {
|
|
|
|
|
'instance': NotifyEmail}),
|
2020-03-18 18:57:24 +01:00
|
|
|
|
# Test no auth at all
|
|
|
|
|
('mailto://localhost?from=test@example.com&to=test@example.com', {
|
2022-10-09 11:28:18 +02:00
|
|
|
|
'instance': NotifyEmail,
|
2020-03-18 18:57:24 +01:00
|
|
|
|
'privacy_url': 'mailto://localhost',
|
|
|
|
|
}),
|
2020-08-18 20:05:29 +02:00
|
|
|
|
# Test multi-emails where some are bad
|
|
|
|
|
('mailto://user:pass@localhost/test@example.com/test2@/$@!/', {
|
2022-10-09 11:28:18 +02:00
|
|
|
|
'instance': NotifyEmail,
|
2020-08-18 20:05:29 +02:00
|
|
|
|
'privacy_url': 'mailto://user:****@localhost/'
|
|
|
|
|
}),
|
|
|
|
|
('mailto://user:pass@localhost/?bcc=test2@,$@!/', {
|
2022-10-09 11:28:18 +02:00
|
|
|
|
'instance': NotifyEmail,
|
2020-08-18 20:05:29 +02:00
|
|
|
|
}),
|
|
|
|
|
('mailto://user:pass@localhost/?cc=test2@,$@!/', {
|
2022-10-09 11:28:18 +02:00
|
|
|
|
'instance': NotifyEmail,
|
2020-08-18 20:05:29 +02:00
|
|
|
|
}),
|
2022-09-06 00:59:43 +02:00
|
|
|
|
('mailto://user:pass@localhost/?reply=test2@,$@!/', {
|
2022-10-09 11:28:18 +02:00
|
|
|
|
'instance': NotifyEmail,
|
2022-09-06 00:59:43 +02:00
|
|
|
|
}),
|
2017-12-06 06:35:03 +01:00
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@mock.patch('smtplib.SMTP')
|
2018-12-06 18:00:55 +01:00
|
|
|
|
@mock.patch('smtplib.SMTP_SSL')
|
2022-10-16 16:48:44 +02:00
|
|
|
|
def test_plugin_email(mock_smtp, mock_smtpssl):
|
2017-12-06 06:35:03 +01:00
|
|
|
|
"""
|
2021-11-25 21:20:22 +01:00
|
|
|
|
NotifyEmail() General Checks
|
2017-12-06 06:35:03 +01:00
|
|
|
|
|
|
|
|
|
"""
|
|
|
|
|
|
|
|
|
|
# iterate over our dictionary and test it out
|
2017-12-14 03:35:59 +01:00
|
|
|
|
for (url, meta) in TEST_URLS:
|
2017-12-06 06:35:03 +01:00
|
|
|
|
|
|
|
|
|
# Our expected instance
|
|
|
|
|
instance = meta.get('instance', None)
|
|
|
|
|
|
|
|
|
|
# Our expected server objects
|
|
|
|
|
self = meta.get('self', None)
|
|
|
|
|
|
|
|
|
|
# Our expected Query response (True, False, or exception type)
|
|
|
|
|
response = meta.get('response', True)
|
|
|
|
|
|
2019-09-29 23:17:25 +02:00
|
|
|
|
# Our expected privacy url
|
|
|
|
|
# Don't set this if don't need to check it's value
|
|
|
|
|
privacy_url = meta.get('privacy_url')
|
|
|
|
|
|
2017-12-06 06:35:03 +01:00
|
|
|
|
test_smtplib_exceptions = meta.get(
|
|
|
|
|
'test_smtplib_exceptions', False)
|
|
|
|
|
|
|
|
|
|
# Our mock of our socket action
|
|
|
|
|
mock_socket = mock.Mock()
|
|
|
|
|
mock_socket.starttls.return_value = True
|
|
|
|
|
mock_socket.login.return_value = True
|
|
|
|
|
|
|
|
|
|
# Create a mock SMTP Object
|
|
|
|
|
mock_smtp.return_value = mock_socket
|
2018-12-06 18:00:55 +01:00
|
|
|
|
mock_smtpssl.return_value = mock_socket
|
2017-12-06 06:35:03 +01:00
|
|
|
|
|
2017-12-14 03:35:59 +01:00
|
|
|
|
if test_smtplib_exceptions:
|
2017-12-06 06:35:03 +01:00
|
|
|
|
# Handle exception testing; first we turn the boolean flag ito
|
|
|
|
|
# a list of exceptions
|
|
|
|
|
test_smtplib_exceptions = (
|
|
|
|
|
smtplib.SMTPHeloError(
|
|
|
|
|
0, 'smtplib.SMTPHeloError() not handled'),
|
|
|
|
|
smtplib.SMTPException(
|
|
|
|
|
0, 'smtplib.SMTPException() not handled'),
|
|
|
|
|
RuntimeError(
|
|
|
|
|
0, 'smtplib.HTTPError() not handled'),
|
|
|
|
|
smtplib.SMTPRecipientsRefused(
|
|
|
|
|
'smtplib.SMTPRecipientsRefused() not handled'),
|
|
|
|
|
smtplib.SMTPSenderRefused(
|
|
|
|
|
0, 'smtplib.SMTPSenderRefused() not handled',
|
|
|
|
|
'addr@example.com'),
|
|
|
|
|
smtplib.SMTPDataError(
|
|
|
|
|
0, 'smtplib.SMTPDataError() not handled'),
|
|
|
|
|
smtplib.SMTPServerDisconnected(
|
|
|
|
|
'smtplib.SMTPServerDisconnected() not handled'),
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
try:
|
|
|
|
|
obj = Apprise.instantiate(url, suppress_exceptions=False)
|
|
|
|
|
|
|
|
|
|
if obj is None:
|
2019-02-13 23:48:09 +01:00
|
|
|
|
# We're done (assuming this is what we were expecting)
|
|
|
|
|
assert instance is None
|
2017-12-06 06:35:03 +01:00
|
|
|
|
continue
|
|
|
|
|
|
|
|
|
|
if instance is None:
|
|
|
|
|
# Expected None but didn't get it
|
2019-02-13 23:48:09 +01:00
|
|
|
|
print('%s instantiated %s (but expected None)' % (
|
|
|
|
|
url, str(obj)))
|
2019-10-09 18:39:31 +02:00
|
|
|
|
assert False
|
2017-12-06 06:35:03 +01:00
|
|
|
|
|
2019-10-09 18:39:31 +02:00
|
|
|
|
assert isinstance(obj, instance)
|
2017-12-06 06:35:03 +01:00
|
|
|
|
|
2022-10-09 11:28:18 +02:00
|
|
|
|
if isinstance(obj, NotifyBase):
|
2019-02-13 23:48:09 +01:00
|
|
|
|
# We loaded okay; now lets make sure we can reverse this url
|
2022-10-08 02:28:36 +02:00
|
|
|
|
assert isinstance(obj.url(), str) is True
|
2019-02-13 23:48:09 +01:00
|
|
|
|
|
2023-05-13 04:05:46 +02:00
|
|
|
|
# Verify we can acquire a target count as an integer
|
|
|
|
|
assert isinstance(len(obj), int)
|
|
|
|
|
|
2019-09-29 23:17:25 +02:00
|
|
|
|
# Test url() with privacy=True
|
2019-10-09 18:39:31 +02:00
|
|
|
|
assert isinstance(
|
2022-10-08 02:28:36 +02:00
|
|
|
|
obj.url(privacy=True), str) is True
|
2019-09-29 23:17:25 +02:00
|
|
|
|
|
|
|
|
|
# Some Simple Invalid Instance Testing
|
|
|
|
|
assert instance.parse_url(None) is None
|
|
|
|
|
assert instance.parse_url(object) is None
|
|
|
|
|
assert instance.parse_url(42) is None
|
|
|
|
|
|
|
|
|
|
if privacy_url:
|
|
|
|
|
# Assess that our privacy url is as expected
|
|
|
|
|
assert obj.url(privacy=True).startswith(privacy_url)
|
|
|
|
|
|
2019-02-13 23:48:09 +01:00
|
|
|
|
# Instantiate the exact same object again using the URL from
|
|
|
|
|
# the one that was already created properly
|
|
|
|
|
obj_cmp = Apprise.instantiate(obj.url())
|
|
|
|
|
|
|
|
|
|
# Our object should be the same instance as what we had
|
|
|
|
|
# originally expected above.
|
2022-10-09 11:28:18 +02:00
|
|
|
|
if not isinstance(obj_cmp, NotifyBase):
|
2019-02-13 23:48:09 +01:00
|
|
|
|
# Assert messages are hard to trace back with the way
|
|
|
|
|
# these tests work. Just printing before throwing our
|
|
|
|
|
# assertion failure makes things easier to debug later on
|
|
|
|
|
print('TEST FAIL: {} regenerated as {}'.format(
|
|
|
|
|
url, obj.url()))
|
2019-10-09 18:39:31 +02:00
|
|
|
|
assert False
|
2019-02-13 23:48:09 +01:00
|
|
|
|
|
2023-05-13 04:05:46 +02:00
|
|
|
|
# Verify there is no change from the old and the new
|
|
|
|
|
if len(obj) != len(obj_cmp):
|
|
|
|
|
print('%d targets found in %s' % (
|
|
|
|
|
len(obj), obj.url(privacy=True)))
|
|
|
|
|
print('But %d targets found in %s' % (
|
|
|
|
|
len(obj_cmp), obj_cmp.url(privacy=True)))
|
|
|
|
|
raise AssertionError("Target miscount %d != %d")
|
|
|
|
|
|
2017-12-06 06:35:03 +01:00
|
|
|
|
if self:
|
|
|
|
|
# Iterate over our expected entries inside of our object
|
|
|
|
|
for key, val in self.items():
|
|
|
|
|
# Test that our object has the desired key
|
2019-10-09 18:39:31 +02:00
|
|
|
|
assert hasattr(key, obj)
|
|
|
|
|
assert getattr(key, obj) == val
|
2017-12-06 06:35:03 +01:00
|
|
|
|
|
|
|
|
|
try:
|
|
|
|
|
if test_smtplib_exceptions is False:
|
2023-05-13 04:05:46 +02:00
|
|
|
|
# Verify we can acquire a target count as an integer
|
|
|
|
|
targets = len(obj)
|
|
|
|
|
|
2017-12-06 06:35:03 +01:00
|
|
|
|
# check that we're as expected
|
|
|
|
|
assert obj.notify(
|
|
|
|
|
title='test', body='body',
|
|
|
|
|
notify_type=NotifyType.INFO) == response
|
|
|
|
|
|
2023-05-13 04:05:46 +02:00
|
|
|
|
if response:
|
|
|
|
|
# If we successfully got a response, there must have
|
|
|
|
|
# been at least 1 target present
|
|
|
|
|
assert targets > 0
|
|
|
|
|
|
2017-12-06 06:35:03 +01:00
|
|
|
|
else:
|
|
|
|
|
for exception in test_smtplib_exceptions:
|
|
|
|
|
mock_socket.sendmail.side_effect = exception
|
|
|
|
|
try:
|
|
|
|
|
assert obj.notify(
|
|
|
|
|
title='test', body='body',
|
|
|
|
|
notify_type=NotifyType.INFO) is False
|
|
|
|
|
|
|
|
|
|
except AssertionError:
|
|
|
|
|
# Don't mess with these entries
|
|
|
|
|
raise
|
|
|
|
|
|
2019-02-18 05:28:37 +01:00
|
|
|
|
except Exception:
|
2017-12-06 06:35:03 +01:00
|
|
|
|
# We can't handle this exception type
|
2019-02-13 23:48:09 +01:00
|
|
|
|
raise
|
2017-12-06 06:35:03 +01:00
|
|
|
|
|
|
|
|
|
except AssertionError:
|
|
|
|
|
# Don't mess with these entries
|
2019-02-13 23:48:09 +01:00
|
|
|
|
print('%s AssertionError' % url)
|
2017-12-06 06:35:03 +01:00
|
|
|
|
raise
|
|
|
|
|
|
|
|
|
|
except Exception as e:
|
|
|
|
|
# Check that we were expecting this exception to happen
|
2019-02-13 23:48:09 +01:00
|
|
|
|
if not isinstance(e, response):
|
|
|
|
|
raise
|
2017-12-06 06:35:03 +01:00
|
|
|
|
|
|
|
|
|
except AssertionError:
|
|
|
|
|
# Don't mess with these entries
|
|
|
|
|
print('%s AssertionError' % url)
|
|
|
|
|
raise
|
|
|
|
|
|
|
|
|
|
except Exception as e:
|
|
|
|
|
# Handle our exception
|
2022-08-06 18:56:19 +02:00
|
|
|
|
if instance is None:
|
2019-02-13 23:48:09 +01:00
|
|
|
|
raise
|
|
|
|
|
|
|
|
|
|
if not isinstance(e, instance):
|
|
|
|
|
raise
|
2017-12-06 06:35:03 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@mock.patch('smtplib.SMTP')
|
2018-12-06 18:00:55 +01:00
|
|
|
|
@mock.patch('smtplib.SMTP_SSL')
|
2021-11-25 21:20:22 +01:00
|
|
|
|
def test_plugin_email_webbase_lookup(mock_smtp, mock_smtpssl):
|
2017-12-06 06:35:03 +01:00
|
|
|
|
"""
|
2021-11-25 21:20:22 +01:00
|
|
|
|
NotifyEmail() Web Based Lookup Tests
|
2017-12-06 06:35:03 +01:00
|
|
|
|
|
|
|
|
|
"""
|
|
|
|
|
|
|
|
|
|
# Insert a test email at the head of our table
|
2022-11-21 03:01:26 +01:00
|
|
|
|
NotifyEmailModule.EMAIL_TEMPLATES = (
|
2017-12-06 06:35:03 +01:00
|
|
|
|
(
|
|
|
|
|
# Testing URL
|
|
|
|
|
'Testing Lookup',
|
|
|
|
|
re.compile(r'^(?P<id>[^@]+)@(?P<domain>l2g\.com)$', re.I),
|
|
|
|
|
{
|
|
|
|
|
'port': 123,
|
|
|
|
|
'smtp_host': 'smtp.l2g.com',
|
|
|
|
|
'secure': True,
|
2022-11-21 03:01:26 +01:00
|
|
|
|
'login_type': (NotifyEmailModule.WebBaseLogin.USERID, )
|
2017-12-06 06:35:03 +01:00
|
|
|
|
},
|
|
|
|
|
),
|
2022-11-21 03:01:26 +01:00
|
|
|
|
) + NotifyEmailModule.EMAIL_TEMPLATES
|
2017-12-06 06:35:03 +01:00
|
|
|
|
|
|
|
|
|
obj = Apprise.instantiate(
|
|
|
|
|
'mailto://user:pass@l2g.com', suppress_exceptions=True)
|
|
|
|
|
|
2022-10-09 11:28:18 +02:00
|
|
|
|
assert isinstance(obj, NotifyEmail)
|
2019-05-30 02:07:05 +02:00
|
|
|
|
assert len(obj.targets) == 1
|
2020-08-18 20:05:29 +02:00
|
|
|
|
assert (False, 'user@l2g.com') in obj.targets
|
2022-11-05 21:37:57 +01:00
|
|
|
|
assert obj.from_addr[0] == obj.app_id
|
|
|
|
|
assert obj.from_addr[1] == 'user@l2g.com'
|
2017-12-06 06:35:03 +01:00
|
|
|
|
assert obj.password == 'pass'
|
|
|
|
|
assert obj.user == 'user'
|
|
|
|
|
assert obj.secure is True
|
|
|
|
|
assert obj.port == 123
|
|
|
|
|
assert obj.smtp_host == 'smtp.l2g.com'
|
2018-09-06 02:45:24 +02:00
|
|
|
|
|
2019-04-26 03:28:38 +02:00
|
|
|
|
# We get the same results if an email is identified as the username
|
|
|
|
|
# because the USERID variable forces that we can't use an email
|
|
|
|
|
obj = Apprise.instantiate(
|
|
|
|
|
'mailto://_:pass@l2g.com?user=user@test.com', suppress_exceptions=True)
|
|
|
|
|
assert obj.user == 'user'
|
|
|
|
|
|
2018-09-06 03:27:52 +02:00
|
|
|
|
|
2018-09-06 02:45:24 +02:00
|
|
|
|
@mock.patch('smtplib.SMTP')
|
2022-10-16 16:48:44 +02:00
|
|
|
|
def test_plugin_email_smtplib_init_fail(mock_smtplib):
|
2018-09-06 02:45:24 +02:00
|
|
|
|
"""
|
2021-11-25 21:20:22 +01:00
|
|
|
|
NotifyEmail() Test exception handling when calling smtplib.SMTP()
|
2018-09-06 02:45:24 +02:00
|
|
|
|
|
|
|
|
|
"""
|
|
|
|
|
|
|
|
|
|
obj = Apprise.instantiate(
|
|
|
|
|
'mailto://user:pass@gmail.com', suppress_exceptions=False)
|
2022-10-09 11:28:18 +02:00
|
|
|
|
assert isinstance(obj, NotifyEmail)
|
2018-09-06 02:45:24 +02:00
|
|
|
|
|
|
|
|
|
# Support Exception handling of smtplib.SMTP
|
2019-02-18 04:21:59 +01:00
|
|
|
|
mock_smtplib.side_effect = RuntimeError('Test')
|
2018-09-06 02:45:24 +02:00
|
|
|
|
|
2019-02-18 04:21:59 +01:00
|
|
|
|
assert obj.notify(
|
|
|
|
|
body='body', title='test', notify_type=NotifyType.INFO) is False
|
2018-09-06 02:45:24 +02:00
|
|
|
|
|
2018-09-06 03:27:52 +02:00
|
|
|
|
# A handled and expected exception
|
|
|
|
|
mock_smtplib.side_effect = smtplib.SMTPException('Test')
|
2019-02-18 04:21:59 +01:00
|
|
|
|
assert obj.notify(
|
|
|
|
|
body='body', title='test', notify_type=NotifyType.INFO) is False
|
2018-09-06 03:27:52 +02:00
|
|
|
|
|
2018-09-06 02:45:24 +02:00
|
|
|
|
|
|
|
|
|
@mock.patch('smtplib.SMTP')
|
2022-10-16 16:48:44 +02:00
|
|
|
|
def test_plugin_email_smtplib_send_okay(mock_smtplib):
|
2018-09-06 02:45:24 +02:00
|
|
|
|
"""
|
2021-11-25 21:20:22 +01:00
|
|
|
|
NotifyEmail() Test a successfully sent email
|
2018-09-06 02:45:24 +02:00
|
|
|
|
|
|
|
|
|
"""
|
|
|
|
|
|
2019-02-06 04:02:42 +01:00
|
|
|
|
# Defaults to HTML
|
2018-09-06 02:45:24 +02:00
|
|
|
|
obj = Apprise.instantiate(
|
|
|
|
|
'mailto://user:pass@gmail.com', suppress_exceptions=False)
|
2022-10-09 11:28:18 +02:00
|
|
|
|
assert isinstance(obj, NotifyEmail)
|
2018-09-06 02:45:24 +02:00
|
|
|
|
|
|
|
|
|
# Support an email simulation where we can correctly quit
|
|
|
|
|
mock_smtplib.starttls.return_value = True
|
|
|
|
|
mock_smtplib.login.return_value = True
|
|
|
|
|
mock_smtplib.sendmail.return_value = True
|
|
|
|
|
mock_smtplib.quit.return_value = True
|
|
|
|
|
|
2019-10-09 18:39:31 +02:00
|
|
|
|
assert obj.notify(
|
|
|
|
|
body='body', title='test', notify_type=NotifyType.INFO) is True
|
2019-02-06 04:02:42 +01:00
|
|
|
|
|
|
|
|
|
# Set Text
|
|
|
|
|
obj = Apprise.instantiate(
|
|
|
|
|
'mailto://user:pass@gmail.com?format=text', suppress_exceptions=False)
|
2022-10-09 11:28:18 +02:00
|
|
|
|
assert isinstance(obj, NotifyEmail)
|
2019-02-06 04:02:42 +01:00
|
|
|
|
|
2019-10-09 18:39:31 +02:00
|
|
|
|
assert obj.notify(
|
|
|
|
|
body='body', title='test', notify_type=NotifyType.INFO) is True
|
2019-04-04 02:27:59 +02:00
|
|
|
|
|
2019-11-11 17:34:25 +01:00
|
|
|
|
# Create an apprise object to work with as well
|
|
|
|
|
a = Apprise()
|
|
|
|
|
assert a.add('mailto://user:pass@gmail.com?format=text')
|
|
|
|
|
|
|
|
|
|
# Send Attachment with success
|
|
|
|
|
attach = os.path.join(TEST_VAR_DIR, 'apprise-test.gif')
|
|
|
|
|
assert obj.notify(
|
|
|
|
|
body='body', title='test', notify_type=NotifyType.INFO,
|
|
|
|
|
attach=attach) is True
|
|
|
|
|
|
|
|
|
|
# same results happen from our Apprise object
|
|
|
|
|
assert a.notify(body='body', title='test', attach=attach) is True
|
|
|
|
|
|
|
|
|
|
# test using an Apprise Attachment object
|
|
|
|
|
assert obj.notify(
|
|
|
|
|
body='body', title='test', notify_type=NotifyType.INFO,
|
|
|
|
|
attach=AppriseAttachment(attach)) is True
|
|
|
|
|
|
|
|
|
|
# same results happen from our Apprise object
|
|
|
|
|
assert a.notify(
|
|
|
|
|
body='body', title='test', attach=AppriseAttachment(attach)) is True
|
|
|
|
|
|
|
|
|
|
max_file_size = AttachBase.max_file_size
|
|
|
|
|
# Now do a case where the file can't be sent
|
|
|
|
|
|
|
|
|
|
AttachBase.max_file_size = 1
|
|
|
|
|
assert obj.notify(
|
|
|
|
|
body='body', title='test', notify_type=NotifyType.INFO,
|
|
|
|
|
attach=attach) is False
|
|
|
|
|
|
|
|
|
|
# same results happen from our Apprise object
|
|
|
|
|
assert a.notify(body='body', title='test', attach=attach) is False
|
|
|
|
|
|
|
|
|
|
# Restore value
|
|
|
|
|
AttachBase.max_file_size = max_file_size
|
|
|
|
|
|
2019-04-04 02:27:59 +02:00
|
|
|
|
|
2022-11-03 19:26:46 +01:00
|
|
|
|
@mock.patch('smtplib.SMTP')
|
|
|
|
|
def test_plugin_email_smtplib_send_multiple_recipients(mock_smtplib):
|
|
|
|
|
"""
|
|
|
|
|
Verify that NotifyEmail() will use a single SMTP session for submitting
|
|
|
|
|
multiple emails.
|
|
|
|
|
"""
|
|
|
|
|
|
|
|
|
|
# Defaults to HTML
|
|
|
|
|
obj = Apprise.instantiate(
|
|
|
|
|
'mailto://user:pass@mail.example.org?'
|
|
|
|
|
'to=foo@example.net,bar@example.com&'
|
|
|
|
|
'cc=baz@example.org&bcc=qux@example.org', suppress_exceptions=False)
|
|
|
|
|
assert isinstance(obj, NotifyEmail)
|
|
|
|
|
|
|
|
|
|
assert obj.notify(
|
|
|
|
|
body='body', title='test', notify_type=NotifyType.INFO) is True
|
|
|
|
|
|
|
|
|
|
assert mock_smtplib.mock_calls == [
|
|
|
|
|
mock.call('mail.example.org', 25, None, timeout=15),
|
|
|
|
|
mock.call().login('user', 'pass'),
|
|
|
|
|
mock.call().sendmail(
|
|
|
|
|
'user@mail.example.org',
|
|
|
|
|
['foo@example.net', 'baz@example.org', 'qux@example.org'],
|
|
|
|
|
mock.ANY),
|
|
|
|
|
mock.call().sendmail(
|
|
|
|
|
'user@mail.example.org',
|
|
|
|
|
['bar@example.com', 'baz@example.org', 'qux@example.org'],
|
|
|
|
|
mock.ANY),
|
|
|
|
|
mock.call().quit(),
|
|
|
|
|
]
|
|
|
|
|
|
2022-11-05 21:37:57 +01:00
|
|
|
|
# No from= used in the above
|
|
|
|
|
assert re.match(r'.*from=.*', obj.url()) is None
|
|
|
|
|
# No mode= as this isn't a secure connection
|
|
|
|
|
assert re.match(r'.*mode=.*', obj.url()) is None
|
|
|
|
|
# No smtp= as the SMTP server is the same as the hostname in this case
|
|
|
|
|
assert re.match(r'.*smtp=.*', obj.url()) is None
|
|
|
|
|
# URL is assembled based on provided user
|
|
|
|
|
assert re.match(
|
|
|
|
|
r'^mailto://user:pass\@mail.example.org/.*', obj.url()) is not None
|
|
|
|
|
|
|
|
|
|
# Verify our added emails are still part of the URL
|
|
|
|
|
assert re.match(r'.*/foo%40example.net[/?].*', obj.url()) is not None
|
|
|
|
|
assert re.match(r'.*/bar%40example.com[/?].*', obj.url()) is not None
|
|
|
|
|
|
|
|
|
|
assert re.match(r'.*bcc=qux%40example.org.*', obj.url()) is not None
|
|
|
|
|
assert re.match(r'.*cc=baz%40example.org.*', obj.url()) is not None
|
|
|
|
|
|
2022-11-03 19:26:46 +01:00
|
|
|
|
|
2020-08-09 03:05:30 +02:00
|
|
|
|
@mock.patch('smtplib.SMTP')
|
2022-10-16 16:48:44 +02:00
|
|
|
|
def test_plugin_email_smtplib_internationalization(mock_smtp):
|
2020-08-09 03:05:30 +02:00
|
|
|
|
"""
|
2021-11-25 21:20:22 +01:00
|
|
|
|
NotifyEmail() Internationalization Handling
|
2020-08-09 03:05:30 +02:00
|
|
|
|
|
|
|
|
|
"""
|
|
|
|
|
|
|
|
|
|
# Defaults to HTML
|
|
|
|
|
obj = Apprise.instantiate(
|
|
|
|
|
'mailto://user:pass@gmail.com?name=Например%20так',
|
|
|
|
|
suppress_exceptions=False)
|
2022-10-09 11:28:18 +02:00
|
|
|
|
assert isinstance(obj, NotifyEmail)
|
2020-08-09 03:05:30 +02:00
|
|
|
|
|
2022-10-08 02:28:36 +02:00
|
|
|
|
class SMTPMock:
|
2020-08-09 03:05:30 +02:00
|
|
|
|
def sendmail(self, *args, **kwargs):
|
|
|
|
|
"""
|
|
|
|
|
over-ride sendmail calls so we can check our our
|
|
|
|
|
internationalization formatting went
|
|
|
|
|
"""
|
|
|
|
|
|
|
|
|
|
match_subject = re.search(
|
|
|
|
|
r'\n?(?P<line>Subject: (?P<subject>(.+?)))\n(?:[a-z0-9-]+:)',
|
|
|
|
|
args[2], re.I | re.M | re.S)
|
|
|
|
|
assert match_subject is not None
|
|
|
|
|
|
|
|
|
|
match_from = re.search(
|
|
|
|
|
r'^(?P<line>From: (?P<name>.+) <(?P<email>[^>]+)>)$',
|
|
|
|
|
args[2], re.I | re.M)
|
|
|
|
|
assert match_from is not None
|
|
|
|
|
|
|
|
|
|
# Verify our output was correctly stored
|
|
|
|
|
assert match_from.group('email') == 'user@gmail.com'
|
|
|
|
|
|
2022-10-08 02:28:36 +02:00
|
|
|
|
assert decode_header(match_from.group('name'))[0][0]\
|
|
|
|
|
.decode('utf-8') == 'Например так'
|
2020-08-09 03:05:30 +02:00
|
|
|
|
|
2022-10-08 02:28:36 +02:00
|
|
|
|
assert decode_header(match_subject.group('subject'))[0][0]\
|
|
|
|
|
.decode('utf-8') == 'دعونا نجعل العالم مكانا أفضل.'
|
2020-08-09 03:05:30 +02:00
|
|
|
|
|
|
|
|
|
# Dummy Function
|
|
|
|
|
def quit(self, *args, **kwargs):
|
|
|
|
|
return True
|
|
|
|
|
|
|
|
|
|
# Dummy Function
|
|
|
|
|
def starttls(self, *args, **kwargs):
|
|
|
|
|
return True
|
|
|
|
|
|
|
|
|
|
# Dummy Function
|
|
|
|
|
def login(self, *args, **kwargs):
|
|
|
|
|
return True
|
|
|
|
|
|
|
|
|
|
# Prepare our object we will test our generated email against
|
|
|
|
|
mock_smtp.return_value = SMTPMock()
|
|
|
|
|
|
|
|
|
|
# Further test encoding through the message content as well
|
|
|
|
|
assert obj.notify(
|
|
|
|
|
# Google Translated to Arabic: "Let's make the world a better place."
|
|
|
|
|
title='دعونا نجعل العالم مكانا أفضل.',
|
|
|
|
|
# Google Translated to Hungarian: "One line of code at a time.'
|
|
|
|
|
body='Egy sor kódot egyszerre.',
|
|
|
|
|
notify_type=NotifyType.INFO) is True
|
|
|
|
|
|
|
|
|
|
|
2021-11-25 21:20:22 +01:00
|
|
|
|
def test_plugin_email_url_escaping():
|
2019-04-04 02:27:59 +02:00
|
|
|
|
"""
|
2021-11-25 21:20:22 +01:00
|
|
|
|
NotifyEmail() Test that user/passwords are properly escaped from URL
|
2019-04-04 02:27:59 +02:00
|
|
|
|
|
|
|
|
|
"""
|
|
|
|
|
# quote(' %20')
|
|
|
|
|
passwd = '%20%2520'
|
|
|
|
|
|
|
|
|
|
# Basically we want to check that ' ' equates to %20 and % equates to %25
|
|
|
|
|
# So the above translates to ' %20' (a space in front of %20). We want
|
|
|
|
|
# to verify the handling of the password escaping and when it happens.
|
|
|
|
|
# a very bad response would be ' ' (double space)
|
2022-10-09 11:28:18 +02:00
|
|
|
|
obj = NotifyEmail.parse_url(
|
2019-04-04 02:27:59 +02:00
|
|
|
|
'mailto://user:{}@gmail.com?format=text'.format(passwd))
|
|
|
|
|
|
|
|
|
|
assert isinstance(obj, dict) is True
|
|
|
|
|
assert 'password' in obj
|
|
|
|
|
|
|
|
|
|
# Escaping doesn't happen at this stage because we want to leave this to
|
|
|
|
|
# the plugins discretion
|
|
|
|
|
assert obj.get('password') == '%20%2520'
|
|
|
|
|
|
|
|
|
|
obj = Apprise.instantiate(
|
|
|
|
|
'mailto://user:{}@gmail.com?format=text'.format(passwd),
|
|
|
|
|
suppress_exceptions=False)
|
2022-10-09 11:28:18 +02:00
|
|
|
|
assert isinstance(obj, NotifyEmail) is True
|
2019-04-04 02:27:59 +02:00
|
|
|
|
|
2020-08-09 03:05:30 +02:00
|
|
|
|
# The password is escaped only 'once'
|
2019-04-27 03:09:37 +02:00
|
|
|
|
assert obj.password == ' %20'
|
|
|
|
|
|
2019-04-26 03:28:38 +02:00
|
|
|
|
|
2021-11-25 21:20:22 +01:00
|
|
|
|
def test_plugin_email_url_variations():
|
2019-04-26 03:28:38 +02:00
|
|
|
|
"""
|
2021-11-25 21:20:22 +01:00
|
|
|
|
NotifyEmail() Test URL variations to ensure parsing is correct
|
2019-04-26 03:28:38 +02:00
|
|
|
|
|
|
|
|
|
"""
|
|
|
|
|
# Test variations of username required to be an email address
|
|
|
|
|
# user@example.com
|
|
|
|
|
obj = Apprise.instantiate(
|
2022-11-05 21:37:57 +01:00
|
|
|
|
'mailto://{user}:{passwd}@example.com?smtp=example.com'.format(
|
2019-04-26 03:28:38 +02:00
|
|
|
|
user='apprise%40example21.ca',
|
|
|
|
|
passwd='abcd123'),
|
|
|
|
|
suppress_exceptions=False)
|
2022-10-09 11:28:18 +02:00
|
|
|
|
assert isinstance(obj, NotifyEmail) is True
|
2019-04-26 03:28:38 +02:00
|
|
|
|
|
|
|
|
|
assert obj.password == 'abcd123'
|
|
|
|
|
assert obj.user == 'apprise@example21.ca'
|
|
|
|
|
|
2022-11-05 21:37:57 +01:00
|
|
|
|
# No from= used in the above
|
|
|
|
|
assert re.match(r'.*from=.*', obj.url()) is None
|
|
|
|
|
# No mode= as this isn't a secure connection
|
|
|
|
|
assert re.match(r'.*mode=.*', obj.url()) is None
|
|
|
|
|
# No smtp= as the SMTP server is the same as the hostname in this case
|
|
|
|
|
# even though it was explicitly specified
|
|
|
|
|
assert re.match(r'.*smtp=.*', obj.url()) is None
|
|
|
|
|
# URL is assembled based on provided user
|
|
|
|
|
assert re.match(
|
|
|
|
|
r'^mailto://apprise:abcd123\@example.com/.*', obj.url()) is not None
|
|
|
|
|
|
2019-04-26 03:28:38 +02:00
|
|
|
|
# test username specified in the url body (as an argument)
|
|
|
|
|
# this always over-rides the entry at the front of the url
|
|
|
|
|
obj = Apprise.instantiate(
|
|
|
|
|
'mailto://_:{passwd}@example.com?user={user}'.format(
|
|
|
|
|
user='apprise%40example21.ca',
|
|
|
|
|
passwd='abcd123'),
|
|
|
|
|
suppress_exceptions=False)
|
2022-10-09 11:28:18 +02:00
|
|
|
|
assert isinstance(obj, NotifyEmail) is True
|
2019-04-26 03:28:38 +02:00
|
|
|
|
|
|
|
|
|
assert obj.password == 'abcd123'
|
|
|
|
|
assert obj.user == 'apprise@example21.ca'
|
|
|
|
|
|
2022-11-05 21:37:57 +01:00
|
|
|
|
# No from= used in the above
|
|
|
|
|
assert re.match(r'.*from=.*', obj.url()) is None
|
|
|
|
|
# No mode= as this isn't a secure connection
|
|
|
|
|
assert re.match(r'.*mode=.*', obj.url()) is None
|
|
|
|
|
# No smtp= as the SMTP server is the same as the hostname in this case
|
|
|
|
|
assert re.match(r'.*smtp=.*', obj.url()) is None
|
|
|
|
|
# URL is assembled based on provided user
|
|
|
|
|
assert re.match(
|
|
|
|
|
r'^mailto://apprise:abcd123\@example.com/.*', obj.url()) is not None
|
|
|
|
|
|
2019-04-26 03:28:38 +02:00
|
|
|
|
# test user and password specified in the url body (as an argument)
|
|
|
|
|
# this always over-rides the entries at the front of the url
|
|
|
|
|
obj = Apprise.instantiate(
|
2022-11-05 21:37:57 +01:00
|
|
|
|
'mailtos://_:_@example.com?user={user}&pass={passwd}'.format(
|
2019-04-26 03:28:38 +02:00
|
|
|
|
user='apprise%40example21.ca',
|
|
|
|
|
passwd='abcd123'),
|
|
|
|
|
suppress_exceptions=False)
|
2022-10-09 11:28:18 +02:00
|
|
|
|
assert isinstance(obj, NotifyEmail) is True
|
2019-04-26 03:28:38 +02:00
|
|
|
|
|
|
|
|
|
assert obj.password == 'abcd123'
|
|
|
|
|
assert obj.user == 'apprise@example21.ca'
|
2019-05-30 02:07:05 +02:00
|
|
|
|
assert len(obj.targets) == 1
|
2020-08-18 20:05:29 +02:00
|
|
|
|
assert (False, 'apprise@example.com') in obj.targets
|
2022-11-05 21:37:57 +01:00
|
|
|
|
assert obj.from_addr[0] == obj.app_id
|
|
|
|
|
assert obj.from_addr[1] == 'apprise@example.com'
|
|
|
|
|
assert obj.targets[0][0] is False
|
|
|
|
|
assert obj.targets[0][1] == obj.from_addr[1]
|
|
|
|
|
|
|
|
|
|
# No from= used in the above
|
|
|
|
|
assert re.match(r'.*from=.*', obj.url()) is None
|
|
|
|
|
# Default mode is starttls
|
|
|
|
|
assert re.match(r'.*mode=starttls.*', obj.url()) is not None
|
|
|
|
|
# No smtp= as the SMTP server is the same as the hostname in this case
|
|
|
|
|
assert re.match(r'.*smtp=.*', obj.url()) is None
|
|
|
|
|
# URL is assembled based on provided user
|
|
|
|
|
assert re.match(
|
|
|
|
|
r'^mailtos://apprise:abcd123\@example.com/.*', obj.url()) is not None
|
2019-04-26 03:28:38 +02:00
|
|
|
|
|
|
|
|
|
# test user and password specified in the url body (as an argument)
|
|
|
|
|
# this always over-rides the entries at the front of the url
|
|
|
|
|
# this is similar to the previous test except we're only specifying
|
|
|
|
|
# this information in the kwargs
|
|
|
|
|
obj = Apprise.instantiate(
|
|
|
|
|
'mailto://example.com?user={user}&pass={passwd}'.format(
|
|
|
|
|
user='apprise%40example21.ca',
|
|
|
|
|
passwd='abcd123'),
|
|
|
|
|
suppress_exceptions=False)
|
2022-10-09 11:28:18 +02:00
|
|
|
|
assert isinstance(obj, NotifyEmail) is True
|
2019-04-26 03:28:38 +02:00
|
|
|
|
|
|
|
|
|
assert obj.password == 'abcd123'
|
|
|
|
|
assert obj.user == 'apprise@example21.ca'
|
2019-05-30 02:07:05 +02:00
|
|
|
|
assert len(obj.targets) == 1
|
2020-08-18 20:05:29 +02:00
|
|
|
|
assert (False, 'apprise@example.com') in obj.targets
|
2022-11-05 21:37:57 +01:00
|
|
|
|
assert obj.from_addr[0] == obj.app_id
|
|
|
|
|
assert obj.from_addr[1] == 'apprise@example.com'
|
|
|
|
|
assert obj.targets[0][0] is False
|
|
|
|
|
assert obj.targets[0][1] == obj.from_addr[1]
|
2019-04-26 03:28:38 +02:00
|
|
|
|
assert obj.smtp_host == 'example.com'
|
|
|
|
|
|
2022-11-05 21:37:57 +01:00
|
|
|
|
# No from= used in the above
|
|
|
|
|
assert re.match(r'.*from=.*', obj.url()) is None
|
|
|
|
|
# No mode= as this isn't a secure connection
|
|
|
|
|
assert re.match(r'.*mode=.*', obj.url()) is None
|
|
|
|
|
# No smtp= as the SMTP server is the same as the hostname in this case
|
|
|
|
|
assert re.match(r'.*smtp=.*', obj.url()) is None
|
|
|
|
|
# URL is assembled based on provided user
|
|
|
|
|
assert re.match(
|
|
|
|
|
r'^mailto://apprise:abcd123\@example.com/.*', obj.url()) is not None
|
|
|
|
|
|
2019-04-26 03:28:38 +02:00
|
|
|
|
# test a complicated example
|
|
|
|
|
obj = Apprise.instantiate(
|
|
|
|
|
'mailtos://{user}:{passwd}@{host}:{port}'
|
2022-11-05 21:37:57 +01:00
|
|
|
|
'?smtp={smtp_host}&format=text&from=Charles<{this}>&to={that}'.format(
|
2019-04-26 03:28:38 +02:00
|
|
|
|
user='apprise%40example21.ca',
|
|
|
|
|
passwd='abcd123',
|
|
|
|
|
host='example.com',
|
|
|
|
|
port=1234,
|
|
|
|
|
this='from@example.jp',
|
|
|
|
|
that='to@example.jp',
|
|
|
|
|
smtp_host='smtp.example.edu'),
|
|
|
|
|
suppress_exceptions=False)
|
2022-10-09 11:28:18 +02:00
|
|
|
|
assert isinstance(obj, NotifyEmail) is True
|
2019-04-26 03:28:38 +02:00
|
|
|
|
|
|
|
|
|
assert obj.password == 'abcd123'
|
|
|
|
|
assert obj.user == 'apprise@example21.ca'
|
|
|
|
|
assert obj.host == 'example.com'
|
|
|
|
|
assert obj.port == 1234
|
|
|
|
|
assert obj.smtp_host == 'smtp.example.edu'
|
2019-05-30 02:07:05 +02:00
|
|
|
|
assert len(obj.targets) == 1
|
2020-08-18 20:05:29 +02:00
|
|
|
|
assert (False, 'to@example.jp') in obj.targets
|
2022-11-05 21:37:57 +01:00
|
|
|
|
assert obj.from_addr[0] == 'Charles'
|
|
|
|
|
assert obj.from_addr[1] == 'from@example.jp'
|
|
|
|
|
assert re.match(
|
|
|
|
|
r'.*from=Charles\+%3Cfrom%40example.jp%3E.*', obj.url()) is not None
|
|
|
|
|
|
|
|
|
|
# Test Tagging under various urll encodings
|
|
|
|
|
for toaddr in ('/john.smith+mytag@domain.com',
|
|
|
|
|
'?to=john.smith+mytag@domain.com',
|
|
|
|
|
'/john.smith%2Bmytag@domain.com',
|
|
|
|
|
'?to=john.smith%2Bmytag@domain.com'):
|
|
|
|
|
|
|
|
|
|
obj = Apprise.instantiate(
|
|
|
|
|
'mailto://user:pass@domain.com{}'.format(toaddr))
|
|
|
|
|
assert isinstance(obj, NotifyEmail) is True
|
|
|
|
|
assert obj.password == 'pass'
|
|
|
|
|
assert obj.user == 'user'
|
|
|
|
|
assert obj.host == 'domain.com'
|
|
|
|
|
assert obj.from_addr[0] == obj.app_id
|
|
|
|
|
assert obj.from_addr[1] == 'user@domain.com'
|
|
|
|
|
assert len(obj.targets) == 1
|
|
|
|
|
assert obj.targets[0][0] is False
|
|
|
|
|
assert obj.targets[0][1] == 'john.smith+mytag@domain.com'
|
2019-05-30 02:07:05 +02:00
|
|
|
|
|
|
|
|
|
|
2021-11-25 21:20:22 +01:00
|
|
|
|
def test_plugin_email_dict_variations():
|
2019-05-30 02:07:05 +02:00
|
|
|
|
"""
|
2021-11-25 21:20:22 +01:00
|
|
|
|
NotifyEmail() Test email dictionary variations to ensure parsing is correct
|
2019-05-30 02:07:05 +02:00
|
|
|
|
|
|
|
|
|
"""
|
|
|
|
|
# Test variations of username required to be an email address
|
|
|
|
|
# user@example.com
|
|
|
|
|
obj = Apprise.instantiate({
|
|
|
|
|
'schema': 'mailto',
|
|
|
|
|
'user': 'apprise@example.com',
|
|
|
|
|
'password': 'abd123',
|
|
|
|
|
'host': 'example.com'}, suppress_exceptions=False)
|
2022-10-09 11:28:18 +02:00
|
|
|
|
assert isinstance(obj, NotifyEmail) is True
|
2022-07-06 14:01:35 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@mock.patch('smtplib.SMTP_SSL')
|
|
|
|
|
@mock.patch('smtplib.SMTP')
|
2022-10-16 16:48:44 +02:00
|
|
|
|
def test_plugin_email_url_parsing(mock_smtp, mock_smtp_ssl):
|
2022-07-06 14:01:35 +02:00
|
|
|
|
"""
|
|
|
|
|
NotifyEmail() Test email url parsing
|
|
|
|
|
|
|
|
|
|
"""
|
|
|
|
|
|
|
|
|
|
response = mock.Mock()
|
|
|
|
|
mock_smtp_ssl.return_value = response
|
|
|
|
|
mock_smtp.return_value = response
|
|
|
|
|
|
|
|
|
|
# Test variations of username required to be an email address
|
|
|
|
|
# user@example.com; we also test an over-ride port on a template driven
|
|
|
|
|
# mailto:// entry
|
2022-10-09 11:28:18 +02:00
|
|
|
|
results = NotifyEmail.parse_url(
|
2022-07-06 14:01:35 +02:00
|
|
|
|
'mailtos://user:pass123@hotmail.com:444'
|
|
|
|
|
'?to=user2@yahoo.com&name=test%20name')
|
|
|
|
|
assert isinstance(results, dict)
|
2022-11-05 21:37:57 +01:00
|
|
|
|
assert 'test name' == results['from_addr']
|
2022-07-06 14:01:35 +02:00
|
|
|
|
assert 'user' == results['user']
|
|
|
|
|
assert 444 == results['port']
|
|
|
|
|
assert 'hotmail.com' == results['host']
|
|
|
|
|
assert 'pass123' == results['password']
|
|
|
|
|
assert 'user2@yahoo.com' in results['targets']
|
|
|
|
|
|
|
|
|
|
obj = Apprise.instantiate(results, suppress_exceptions=False)
|
2022-10-09 11:28:18 +02:00
|
|
|
|
assert isinstance(obj, NotifyEmail) is True
|
2022-07-06 14:01:35 +02:00
|
|
|
|
|
|
|
|
|
assert mock_smtp.call_count == 0
|
|
|
|
|
assert mock_smtp_ssl.call_count == 0
|
|
|
|
|
assert obj.notify("test") is True
|
|
|
|
|
assert mock_smtp.call_count == 1
|
|
|
|
|
assert mock_smtp_ssl.call_count == 0
|
|
|
|
|
assert response.starttls.call_count == 1
|
|
|
|
|
assert response.login.call_count == 1
|
|
|
|
|
assert response.sendmail.call_count == 1
|
|
|
|
|
# Store our Sent Arguments
|
|
|
|
|
# Syntax is:
|
|
|
|
|
# sendmail(from_addr, to_addrs, msg, mail_options=(), rcpt_options=())
|
|
|
|
|
# [0] [1] [2]
|
|
|
|
|
_from = response.sendmail.call_args[0][0]
|
|
|
|
|
_to = response.sendmail.call_args[0][1]
|
|
|
|
|
_msg = response.sendmail.call_args[0][2]
|
|
|
|
|
assert _from == 'user@hotmail.com'
|
|
|
|
|
assert isinstance(_to, list)
|
|
|
|
|
assert len(_to) == 1
|
|
|
|
|
assert _to[0] == 'user2@yahoo.com'
|
2022-09-06 00:59:43 +02:00
|
|
|
|
assert _msg.split('\n')[-3] == 'test'
|
2022-07-06 14:01:35 +02:00
|
|
|
|
|
|
|
|
|
# Our URL port was over-ridden (on template) to use 444
|
|
|
|
|
# We can verify that this was correctly saved
|
|
|
|
|
assert obj.url().startswith(
|
|
|
|
|
'mailtos://user:pass123@hotmail.com:444/user2%40yahoo.com')
|
|
|
|
|
assert 'mode=starttls' in obj.url()
|
|
|
|
|
assert 'smtp=smtp-mail.outlook.com' in obj.url()
|
|
|
|
|
|
|
|
|
|
mock_smtp.reset_mock()
|
2022-11-23 13:13:38 +01:00
|
|
|
|
mock_smtp_ssl.reset_mock()
|
2022-07-06 14:01:35 +02:00
|
|
|
|
response.reset_mock()
|
|
|
|
|
|
|
|
|
|
# The below switches the `name` with the `to` to verify the results
|
|
|
|
|
# are the same; it also verfies that the mode gets changed to SSL
|
|
|
|
|
# instead of STARTTLS
|
2022-10-09 11:28:18 +02:00
|
|
|
|
results = NotifyEmail.parse_url(
|
2022-07-06 14:01:35 +02:00
|
|
|
|
'mailtos://user:pass123@hotmail.com?smtp=override.com'
|
|
|
|
|
'&name=test%20name&to=user2@yahoo.com&mode=ssl')
|
|
|
|
|
assert isinstance(results, dict)
|
2022-11-05 21:37:57 +01:00
|
|
|
|
assert 'test name' == results['from_addr']
|
2022-07-06 14:01:35 +02:00
|
|
|
|
assert 'user' == results['user']
|
|
|
|
|
assert 'hotmail.com' == results['host']
|
|
|
|
|
assert 'pass123' == results['password']
|
|
|
|
|
assert 'user2@yahoo.com' in results['targets']
|
|
|
|
|
assert 'ssl' == results['secure_mode']
|
|
|
|
|
obj = Apprise.instantiate(results, suppress_exceptions=False)
|
2022-10-09 11:28:18 +02:00
|
|
|
|
assert isinstance(obj, NotifyEmail) is True
|
2022-07-06 14:01:35 +02:00
|
|
|
|
|
|
|
|
|
assert mock_smtp.call_count == 0
|
|
|
|
|
assert mock_smtp_ssl.call_count == 0
|
|
|
|
|
assert obj.notify("test") is True
|
|
|
|
|
assert mock_smtp.call_count == 0
|
|
|
|
|
assert mock_smtp_ssl.call_count == 1
|
|
|
|
|
assert response.starttls.call_count == 0
|
|
|
|
|
assert response.login.call_count == 1
|
|
|
|
|
assert response.sendmail.call_count == 1
|
|
|
|
|
# Store our Sent Arguments
|
|
|
|
|
# Syntax is:
|
|
|
|
|
# sendmail(from_addr, to_addrs, msg, mail_options=(), rcpt_options=())
|
|
|
|
|
# [0] [1] [2]
|
|
|
|
|
_from = response.sendmail.call_args[0][0]
|
|
|
|
|
_to = response.sendmail.call_args[0][1]
|
|
|
|
|
_msg = response.sendmail.call_args[0][2]
|
|
|
|
|
assert _from == 'user@hotmail.com'
|
|
|
|
|
assert isinstance(_to, list)
|
|
|
|
|
assert len(_to) == 1
|
|
|
|
|
assert _to[0] == 'user2@yahoo.com'
|
2022-09-06 00:59:43 +02:00
|
|
|
|
assert _msg.split('\n')[-3] == 'test'
|
2022-07-06 14:01:35 +02:00
|
|
|
|
|
2022-11-23 13:13:38 +01:00
|
|
|
|
user, pw = response.login.call_args[0]
|
|
|
|
|
# the SMTP Server was ovr
|
|
|
|
|
assert pw == 'pass123'
|
|
|
|
|
assert user == 'user'
|
|
|
|
|
|
2022-07-06 14:01:35 +02:00
|
|
|
|
assert obj.url().startswith(
|
|
|
|
|
'mailtos://user:pass123@hotmail.com/user2%40yahoo.com')
|
|
|
|
|
# Test that our template over-ride worked
|
|
|
|
|
assert 'mode=ssl' in obj.url()
|
|
|
|
|
assert 'smtp=override.com' in obj.url()
|
2022-09-16 18:14:38 +02:00
|
|
|
|
# No reply address specified
|
|
|
|
|
assert 'reply=' not in obj.url()
|
2022-08-06 18:56:19 +02:00
|
|
|
|
|
|
|
|
|
mock_smtp.reset_mock()
|
2022-11-23 13:13:38 +01:00
|
|
|
|
mock_smtp_ssl.reset_mock()
|
2022-08-06 18:56:19 +02:00
|
|
|
|
response.reset_mock()
|
|
|
|
|
|
|
|
|
|
#
|
|
|
|
|
# Test outlook/hotmail lookups
|
|
|
|
|
#
|
2022-11-23 13:13:38 +01:00
|
|
|
|
results = NotifyEmail.parse_url(
|
|
|
|
|
'mailtos://user:pass123@hotmail.com')
|
|
|
|
|
obj = Apprise.instantiate(results, suppress_exceptions=False)
|
|
|
|
|
assert isinstance(obj, NotifyEmail) is True
|
|
|
|
|
assert obj.smtp_host == 'smtp-mail.outlook.com'
|
|
|
|
|
# No entries in the reply_to
|
|
|
|
|
assert not obj.reply_to
|
|
|
|
|
|
|
|
|
|
assert mock_smtp.call_count == 0
|
|
|
|
|
assert mock_smtp_ssl.call_count == 0
|
|
|
|
|
assert response.starttls.call_count == 0
|
|
|
|
|
assert obj.notify("test") is True
|
|
|
|
|
assert mock_smtp.call_count == 1
|
|
|
|
|
assert mock_smtp_ssl.call_count == 0
|
|
|
|
|
assert response.starttls.call_count == 1
|
|
|
|
|
assert response.login.call_count == 1
|
|
|
|
|
assert response.sendmail.call_count == 1
|
|
|
|
|
|
|
|
|
|
user, pw = response.login.call_args[0]
|
|
|
|
|
assert pw == 'pass123'
|
|
|
|
|
assert user == 'user@hotmail.com'
|
|
|
|
|
|
|
|
|
|
mock_smtp.reset_mock()
|
|
|
|
|
mock_smtp_ssl.reset_mock()
|
|
|
|
|
response.reset_mock()
|
|
|
|
|
|
2022-10-09 11:28:18 +02:00
|
|
|
|
results = NotifyEmail.parse_url(
|
2022-08-06 18:56:19 +02:00
|
|
|
|
'mailtos://user:pass123@outlook.com')
|
|
|
|
|
obj = Apprise.instantiate(results, suppress_exceptions=False)
|
2022-10-09 11:28:18 +02:00
|
|
|
|
assert isinstance(obj, NotifyEmail) is True
|
2022-11-12 20:44:59 +01:00
|
|
|
|
assert obj.smtp_host == 'smtp.outlook.com'
|
2022-09-16 18:14:38 +02:00
|
|
|
|
# No entries in the reply_to
|
|
|
|
|
assert not obj.reply_to
|
2022-08-06 18:56:19 +02:00
|
|
|
|
|
2022-11-23 13:13:38 +01:00
|
|
|
|
assert mock_smtp.call_count == 0
|
|
|
|
|
assert mock_smtp_ssl.call_count == 0
|
|
|
|
|
assert response.starttls.call_count == 0
|
|
|
|
|
assert obj.notify("test") is True
|
|
|
|
|
assert mock_smtp.call_count == 1
|
|
|
|
|
assert mock_smtp_ssl.call_count == 0
|
|
|
|
|
assert response.starttls.call_count == 1
|
|
|
|
|
assert response.login.call_count == 1
|
|
|
|
|
assert response.sendmail.call_count == 1
|
|
|
|
|
|
|
|
|
|
user, pw = response.login.call_args[0]
|
|
|
|
|
assert pw == 'pass123'
|
|
|
|
|
assert user == 'user@outlook.com'
|
|
|
|
|
|
|
|
|
|
mock_smtp.reset_mock()
|
|
|
|
|
mock_smtp_ssl.reset_mock()
|
|
|
|
|
response.reset_mock()
|
|
|
|
|
|
2022-10-09 11:28:18 +02:00
|
|
|
|
results = NotifyEmail.parse_url(
|
2022-08-06 18:56:19 +02:00
|
|
|
|
'mailtos://user:pass123@outlook.com.au')
|
|
|
|
|
obj = Apprise.instantiate(results, suppress_exceptions=False)
|
2022-10-09 11:28:18 +02:00
|
|
|
|
assert isinstance(obj, NotifyEmail) is True
|
2022-11-12 20:44:59 +01:00
|
|
|
|
assert obj.smtp_host == 'smtp.outlook.com'
|
2022-09-16 18:14:38 +02:00
|
|
|
|
# No entries in the reply_to
|
|
|
|
|
assert not obj.reply_to
|
2022-08-06 18:56:19 +02:00
|
|
|
|
|
2022-11-23 13:13:38 +01:00
|
|
|
|
assert mock_smtp.call_count == 0
|
|
|
|
|
assert mock_smtp_ssl.call_count == 0
|
|
|
|
|
assert response.starttls.call_count == 0
|
|
|
|
|
assert obj.notify("test") is True
|
|
|
|
|
assert mock_smtp.call_count == 1
|
|
|
|
|
assert mock_smtp_ssl.call_count == 0
|
|
|
|
|
assert response.starttls.call_count == 1
|
|
|
|
|
assert response.login.call_count == 1
|
|
|
|
|
assert response.sendmail.call_count == 1
|
|
|
|
|
|
|
|
|
|
user, pw = response.login.call_args[0]
|
|
|
|
|
assert pw == 'pass123'
|
|
|
|
|
assert user == 'user@outlook.com.au'
|
|
|
|
|
|
|
|
|
|
mock_smtp.reset_mock()
|
|
|
|
|
mock_smtp_ssl.reset_mock()
|
|
|
|
|
response.reset_mock()
|
|
|
|
|
|
2022-11-12 20:44:59 +01:00
|
|
|
|
# Consisitency Checks
|
|
|
|
|
results = NotifyEmail.parse_url(
|
|
|
|
|
'mailtos://outlook.com?smtp=smtp.outlook.com'
|
|
|
|
|
'&user=user@outlook.com&pass=app.pw')
|
|
|
|
|
obj1 = Apprise.instantiate(results, suppress_exceptions=False)
|
|
|
|
|
assert isinstance(obj1, NotifyEmail) is True
|
|
|
|
|
assert obj1.smtp_host == 'smtp.outlook.com'
|
|
|
|
|
assert obj1.user == 'user@outlook.com'
|
|
|
|
|
assert obj1.password == 'app.pw'
|
|
|
|
|
assert obj1.secure_mode == 'starttls'
|
|
|
|
|
assert obj1.port == 587
|
|
|
|
|
|
2022-11-23 13:13:38 +01:00
|
|
|
|
assert mock_smtp.call_count == 0
|
|
|
|
|
assert mock_smtp_ssl.call_count == 0
|
|
|
|
|
assert response.starttls.call_count == 0
|
|
|
|
|
assert obj1.notify("test") is True
|
|
|
|
|
assert mock_smtp.call_count == 1
|
|
|
|
|
assert mock_smtp_ssl.call_count == 0
|
|
|
|
|
assert response.starttls.call_count == 1
|
|
|
|
|
assert response.login.call_count == 1
|
|
|
|
|
assert response.sendmail.call_count == 1
|
|
|
|
|
|
|
|
|
|
user, pw = response.login.call_args[0]
|
|
|
|
|
assert pw == 'app.pw'
|
|
|
|
|
assert user == 'user@outlook.com'
|
|
|
|
|
|
|
|
|
|
mock_smtp.reset_mock()
|
|
|
|
|
mock_smtp_ssl.reset_mock()
|
|
|
|
|
response.reset_mock()
|
|
|
|
|
|
2022-11-12 20:44:59 +01:00
|
|
|
|
results = NotifyEmail.parse_url(
|
|
|
|
|
'mailtos://user:app.pw@outlook.com')
|
|
|
|
|
obj2 = Apprise.instantiate(results, suppress_exceptions=False)
|
|
|
|
|
assert isinstance(obj2, NotifyEmail) is True
|
|
|
|
|
assert obj2.smtp_host == obj1.smtp_host
|
|
|
|
|
assert obj2.user == obj1.user
|
|
|
|
|
assert obj2.password == obj1.password
|
|
|
|
|
assert obj2.secure_mode == obj1.secure_mode
|
|
|
|
|
assert obj2.port == obj1.port
|
|
|
|
|
|
2022-11-23 13:13:38 +01:00
|
|
|
|
assert mock_smtp.call_count == 0
|
|
|
|
|
assert mock_smtp_ssl.call_count == 0
|
|
|
|
|
assert response.starttls.call_count == 0
|
|
|
|
|
assert obj2.notify("test") is True
|
|
|
|
|
assert mock_smtp.call_count == 1
|
|
|
|
|
assert mock_smtp_ssl.call_count == 0
|
|
|
|
|
assert response.starttls.call_count == 1
|
|
|
|
|
assert response.login.call_count == 1
|
|
|
|
|
assert response.sendmail.call_count == 1
|
|
|
|
|
|
|
|
|
|
user, pw = response.login.call_args[0]
|
|
|
|
|
assert pw == 'app.pw'
|
|
|
|
|
assert user == 'user@outlook.com'
|
|
|
|
|
|
|
|
|
|
mock_smtp.reset_mock()
|
|
|
|
|
mock_smtp_ssl.reset_mock()
|
|
|
|
|
response.reset_mock()
|
|
|
|
|
|
2022-10-09 11:28:18 +02:00
|
|
|
|
results = NotifyEmail.parse_url(
|
2022-08-06 18:56:19 +02:00
|
|
|
|
'mailtos://user:pass123@live.com')
|
|
|
|
|
obj = Apprise.instantiate(results, suppress_exceptions=False)
|
2022-10-09 11:28:18 +02:00
|
|
|
|
assert isinstance(obj, NotifyEmail) is True
|
2022-09-16 18:14:38 +02:00
|
|
|
|
# No entries in the reply_to
|
|
|
|
|
assert not obj.reply_to
|
2022-08-06 18:56:19 +02:00
|
|
|
|
|
2022-11-23 13:13:38 +01:00
|
|
|
|
assert mock_smtp.call_count == 0
|
|
|
|
|
assert mock_smtp_ssl.call_count == 0
|
|
|
|
|
assert response.starttls.call_count == 0
|
|
|
|
|
assert obj.notify("test") is True
|
|
|
|
|
assert mock_smtp.call_count == 1
|
|
|
|
|
assert mock_smtp_ssl.call_count == 0
|
|
|
|
|
assert response.starttls.call_count == 1
|
|
|
|
|
assert response.login.call_count == 1
|
|
|
|
|
assert response.sendmail.call_count == 1
|
|
|
|
|
|
|
|
|
|
user, pw = response.login.call_args[0]
|
|
|
|
|
assert pw == 'pass123'
|
|
|
|
|
assert user == 'user@live.com'
|
|
|
|
|
|
|
|
|
|
mock_smtp.reset_mock()
|
|
|
|
|
mock_smtp_ssl.reset_mock()
|
|
|
|
|
response.reset_mock()
|
|
|
|
|
|
2022-10-09 11:28:18 +02:00
|
|
|
|
results = NotifyEmail.parse_url(
|
2022-08-06 18:56:19 +02:00
|
|
|
|
'mailtos://user:pass123@hotmail.com')
|
|
|
|
|
obj = Apprise.instantiate(results, suppress_exceptions=False)
|
2022-10-09 11:28:18 +02:00
|
|
|
|
assert isinstance(obj, NotifyEmail) is True
|
2022-09-16 18:14:38 +02:00
|
|
|
|
# No entries in the reply_to
|
|
|
|
|
assert not obj.reply_to
|
2022-08-06 19:09:35 +02:00
|
|
|
|
|
2022-11-23 13:13:38 +01:00
|
|
|
|
assert mock_smtp.call_count == 0
|
|
|
|
|
assert mock_smtp_ssl.call_count == 0
|
|
|
|
|
assert response.starttls.call_count == 0
|
|
|
|
|
assert obj.notify("test") is True
|
|
|
|
|
assert mock_smtp.call_count == 1
|
|
|
|
|
assert mock_smtp_ssl.call_count == 0
|
|
|
|
|
assert response.starttls.call_count == 1
|
|
|
|
|
assert response.login.call_count == 1
|
|
|
|
|
assert response.sendmail.call_count == 1
|
|
|
|
|
|
|
|
|
|
user, pw = response.login.call_args[0]
|
|
|
|
|
assert pw == 'pass123'
|
|
|
|
|
assert user == 'user@hotmail.com'
|
|
|
|
|
|
|
|
|
|
mock_smtp.reset_mock()
|
|
|
|
|
mock_smtp_ssl.reset_mock()
|
|
|
|
|
response.reset_mock()
|
|
|
|
|
|
2022-08-06 19:09:35 +02:00
|
|
|
|
#
|
|
|
|
|
# Test Port Over-Riding
|
|
|
|
|
#
|
2022-10-09 11:28:18 +02:00
|
|
|
|
results = NotifyEmail.parse_url(
|
2022-08-06 19:09:35 +02:00
|
|
|
|
"mailtos://abc:password@xyz.cn:465?"
|
|
|
|
|
"smtp=smtp.exmail.qq.com&mode=ssl")
|
|
|
|
|
obj = Apprise.instantiate(results, suppress_exceptions=False)
|
2022-10-09 11:28:18 +02:00
|
|
|
|
assert isinstance(obj, NotifyEmail) is True
|
2022-08-06 19:09:35 +02:00
|
|
|
|
|
|
|
|
|
# Verify our over-rides are in place
|
|
|
|
|
assert obj.smtp_host == 'smtp.exmail.qq.com'
|
|
|
|
|
assert obj.port == 465
|
2022-11-05 21:37:57 +01:00
|
|
|
|
assert obj.from_addr[0] == obj.app_id
|
|
|
|
|
assert obj.from_addr[1] == 'abc@xyz.cn'
|
2022-08-06 19:09:35 +02:00
|
|
|
|
assert obj.secure_mode == 'ssl'
|
2022-09-16 18:14:38 +02:00
|
|
|
|
# No entries in the reply_to
|
|
|
|
|
assert not obj.reply_to
|
2022-08-06 19:09:35 +02:00
|
|
|
|
|
2022-11-05 21:37:57 +01:00
|
|
|
|
# No from= used in the above
|
|
|
|
|
assert re.match(r'.*from=.*', obj.url()) is None
|
|
|
|
|
# No Our secure connection is SSL
|
|
|
|
|
assert re.match(r'.*mode=ssl.*', obj.url()) is not None
|
|
|
|
|
# No smtp= as the SMTP server is the same as the hostname in this case
|
|
|
|
|
assert re.match(r'.*smtp=smtp.exmail.qq.com.*', obj.url()) is not None
|
2022-11-23 13:13:38 +01:00
|
|
|
|
# URL is assembled based on provided user (:465 is dropped because it
|
|
|
|
|
# is a default port when using xyz.cn)
|
2022-11-05 21:37:57 +01:00
|
|
|
|
assert re.match(
|
2022-11-23 13:13:38 +01:00
|
|
|
|
r'^mailtos://abc:password@xyz.cn/.*', obj.url()) is not None
|
|
|
|
|
|
|
|
|
|
assert mock_smtp.call_count == 0
|
|
|
|
|
assert mock_smtp_ssl.call_count == 0
|
|
|
|
|
assert response.starttls.call_count == 0
|
|
|
|
|
assert obj.notify("test") is True
|
|
|
|
|
assert mock_smtp.call_count == 0
|
|
|
|
|
assert mock_smtp_ssl.call_count == 1
|
|
|
|
|
assert response.starttls.call_count == 0
|
|
|
|
|
assert response.login.call_count == 1
|
|
|
|
|
assert response.sendmail.call_count == 1
|
|
|
|
|
|
|
|
|
|
user, pw = response.login.call_args[0]
|
|
|
|
|
assert pw == 'password'
|
|
|
|
|
assert user == 'abc'
|
|
|
|
|
|
|
|
|
|
mock_smtp.reset_mock()
|
|
|
|
|
mock_smtp_ssl.reset_mock()
|
|
|
|
|
response.reset_mock()
|
2022-11-05 21:37:57 +01:00
|
|
|
|
|
2022-10-09 11:28:18 +02:00
|
|
|
|
results = NotifyEmail.parse_url(
|
2022-08-06 19:09:35 +02:00
|
|
|
|
"mailtos://abc:password@xyz.cn?"
|
|
|
|
|
"smtp=smtp.exmail.qq.com&mode=ssl&port=465")
|
|
|
|
|
obj = Apprise.instantiate(results, suppress_exceptions=False)
|
2022-10-09 11:28:18 +02:00
|
|
|
|
assert isinstance(obj, NotifyEmail) is True
|
2022-08-06 19:09:35 +02:00
|
|
|
|
|
|
|
|
|
# Verify our over-rides are in place
|
|
|
|
|
assert obj.smtp_host == 'smtp.exmail.qq.com'
|
|
|
|
|
assert obj.port == 465
|
2022-11-05 21:37:57 +01:00
|
|
|
|
assert obj.from_addr[0] == obj.app_id
|
|
|
|
|
assert obj.from_addr[1] == 'abc@xyz.cn'
|
2022-08-06 19:09:35 +02:00
|
|
|
|
assert obj.secure_mode == 'ssl'
|
2022-09-16 18:14:38 +02:00
|
|
|
|
# No entries in the reply_to
|
|
|
|
|
assert not obj.reply_to
|
|
|
|
|
|
2022-11-23 13:13:38 +01:00
|
|
|
|
assert mock_smtp.call_count == 0
|
|
|
|
|
assert mock_smtp_ssl.call_count == 0
|
|
|
|
|
assert response.starttls.call_count == 0
|
|
|
|
|
assert obj.notify("test") is True
|
|
|
|
|
assert mock_smtp.call_count == 0
|
|
|
|
|
assert mock_smtp_ssl.call_count == 1
|
|
|
|
|
assert response.starttls.call_count == 0
|
|
|
|
|
assert response.login.call_count == 1
|
|
|
|
|
assert response.sendmail.call_count == 1
|
|
|
|
|
|
|
|
|
|
user, pw = response.login.call_args[0]
|
|
|
|
|
assert pw == 'password'
|
|
|
|
|
assert user == 'abc'
|
|
|
|
|
|
|
|
|
|
mock_smtp.reset_mock()
|
|
|
|
|
mock_smtp_ssl.reset_mock()
|
|
|
|
|
response.reset_mock()
|
|
|
|
|
|
2022-09-16 18:14:38 +02:00
|
|
|
|
#
|
|
|
|
|
# Test Reply-To Email
|
|
|
|
|
#
|
2022-10-09 11:28:18 +02:00
|
|
|
|
results = NotifyEmail.parse_url(
|
2022-09-16 18:14:38 +02:00
|
|
|
|
"mailtos://user:pass@example.com?reply=noreply@example.com")
|
|
|
|
|
obj = Apprise.instantiate(results, suppress_exceptions=False)
|
2022-10-09 11:28:18 +02:00
|
|
|
|
assert isinstance(obj, NotifyEmail) is True
|
2022-09-16 18:14:38 +02:00
|
|
|
|
# Verify our over-rides are in place
|
|
|
|
|
assert obj.smtp_host == 'example.com'
|
2022-11-05 21:37:57 +01:00
|
|
|
|
assert obj.from_addr[0] == obj.app_id
|
|
|
|
|
assert obj.from_addr[1] == 'user@example.com'
|
2022-09-16 18:14:38 +02:00
|
|
|
|
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()
|
2022-11-05 21:37:57 +01:00
|
|
|
|
|
2022-11-23 13:13:38 +01:00
|
|
|
|
assert mock_smtp.call_count == 0
|
|
|
|
|
assert mock_smtp_ssl.call_count == 0
|
|
|
|
|
assert response.starttls.call_count == 0
|
|
|
|
|
assert obj.notify("test") is True
|
|
|
|
|
assert mock_smtp.call_count == 1
|
|
|
|
|
assert mock_smtp_ssl.call_count == 0
|
|
|
|
|
assert response.starttls.call_count == 1
|
|
|
|
|
assert response.login.call_count == 1
|
|
|
|
|
assert response.sendmail.call_count == 1
|
|
|
|
|
|
|
|
|
|
user, pw = response.login.call_args[0]
|
|
|
|
|
assert pw == 'pass'
|
|
|
|
|
assert user == 'user'
|
|
|
|
|
|
|
|
|
|
mock_smtp.reset_mock()
|
|
|
|
|
mock_smtp_ssl.reset_mock()
|
|
|
|
|
response.reset_mock()
|
|
|
|
|
|
2022-11-05 21:37:57 +01:00
|
|
|
|
#
|
|
|
|
|
# Test Reply-To Email with Name Inline
|
|
|
|
|
#
|
|
|
|
|
results = NotifyEmail.parse_url(
|
|
|
|
|
"mailtos://user:pass@example.com?reply=Chris<noreply@example.ca>")
|
|
|
|
|
obj = Apprise.instantiate(results, suppress_exceptions=False)
|
|
|
|
|
assert isinstance(obj, NotifyEmail) is True
|
|
|
|
|
# Verify our over-rides are in place
|
|
|
|
|
assert obj.smtp_host == 'example.com'
|
|
|
|
|
assert obj.from_addr[0] == obj.app_id
|
|
|
|
|
assert obj.from_addr[1] == '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=Chris+%3Cnoreply%40example.ca%3E' in obj.url()
|
2022-11-23 13:13:38 +01:00
|
|
|
|
|
|
|
|
|
assert mock_smtp.call_count == 0
|
|
|
|
|
assert mock_smtp_ssl.call_count == 0
|
|
|
|
|
assert response.starttls.call_count == 0
|
|
|
|
|
assert obj.notify("test") is True
|
|
|
|
|
assert mock_smtp.call_count == 1
|
|
|
|
|
assert mock_smtp_ssl.call_count == 0
|
|
|
|
|
assert response.starttls.call_count == 1
|
|
|
|
|
assert response.login.call_count == 1
|
|
|
|
|
assert response.sendmail.call_count == 1
|
|
|
|
|
|
|
|
|
|
user, pw = response.login.call_args[0]
|
|
|
|
|
assert pw == 'pass'
|
|
|
|
|
assert user == 'user'
|
|
|
|
|
|
|
|
|
|
mock_smtp.reset_mock()
|
|
|
|
|
mock_smtp_ssl.reset_mock()
|
|
|
|
|
response.reset_mock()
|
|
|
|
|
|
|
|
|
|
# Fast Mail Handling
|
|
|
|
|
|
|
|
|
|
# Test variations of username required to be an email address
|
|
|
|
|
# user@example.com; we also test an over-ride port on a template driven
|
|
|
|
|
# mailto:// entry
|
|
|
|
|
results = NotifyEmail.parse_url(
|
|
|
|
|
'mailto://fastmail.com/?to=hello@concordium-explorer.nl'
|
|
|
|
|
'&user=joe@mydomain.nl&pass=abc123'
|
|
|
|
|
'&from=Concordium Explorer Bot<bot@concordium-explorer.nl>')
|
|
|
|
|
assert isinstance(results, dict)
|
|
|
|
|
assert 'Concordium Explorer Bot<bot@concordium-explorer.nl>' == \
|
|
|
|
|
results['from_addr']
|
|
|
|
|
assert 'joe@mydomain.nl' == results['user']
|
|
|
|
|
assert results['port'] is None
|
|
|
|
|
assert 'fastmail.com' == results['host']
|
|
|
|
|
assert 'abc123' == results['password']
|
|
|
|
|
assert 'hello@concordium-explorer.nl' in results['targets']
|
|
|
|
|
|
|
|
|
|
obj = Apprise.instantiate(results, suppress_exceptions=False)
|
|
|
|
|
assert isinstance(obj, NotifyEmail) is True
|
|
|
|
|
|
|
|
|
|
assert mock_smtp.call_count == 0
|
|
|
|
|
assert mock_smtp_ssl.call_count == 0
|
|
|
|
|
assert obj.notify("test") is True
|
|
|
|
|
assert mock_smtp.call_count == 0
|
|
|
|
|
assert mock_smtp_ssl.call_count == 1
|
|
|
|
|
assert response.starttls.call_count == 0
|
|
|
|
|
assert response.login.call_count == 1
|
|
|
|
|
assert response.sendmail.call_count == 1
|
|
|
|
|
# Store our Sent Arguments
|
|
|
|
|
# Syntax is:
|
|
|
|
|
# sendmail(from_addr, to_addrs, msg, mail_options=(), rcpt_options=())
|
|
|
|
|
# [0] [1] [2]
|
|
|
|
|
_from = response.sendmail.call_args[0][0]
|
|
|
|
|
_to = response.sendmail.call_args[0][1]
|
|
|
|
|
_msg = response.sendmail.call_args[0][2]
|
|
|
|
|
assert _from == 'bot@concordium-explorer.nl'
|
|
|
|
|
assert isinstance(_to, list)
|
|
|
|
|
assert len(_to) == 1
|
|
|
|
|
assert _to[0] == 'hello@concordium-explorer.nl'
|
|
|
|
|
assert _msg.split('\n')[-3] == 'test'
|
|
|
|
|
|
|
|
|
|
user, pw = response.login.call_args[0]
|
|
|
|
|
assert pw == 'abc123'
|
|
|
|
|
assert user == 'joe@mydomain.nl'
|
2022-12-10 18:48:45 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@mock.patch('smtplib.SMTP_SSL')
|
|
|
|
|
@mock.patch('smtplib.SMTP')
|
|
|
|
|
def test_plugin_email_plus_in_toemail(mock_smtp, mock_smtp_ssl):
|
|
|
|
|
"""
|
|
|
|
|
NotifyEmail() support + in To Email address
|
|
|
|
|
|
|
|
|
|
"""
|
|
|
|
|
|
|
|
|
|
response = mock.Mock()
|
|
|
|
|
mock_smtp_ssl.return_value = response
|
|
|
|
|
mock_smtp.return_value = response
|
|
|
|
|
|
|
|
|
|
# We want to test the case where a + is found in the To address; we want to
|
|
|
|
|
# ensure that it is supported
|
|
|
|
|
results = NotifyEmail.parse_url(
|
|
|
|
|
'mailtos://user:pass123@gmail.com'
|
|
|
|
|
'?to=Plus Support<test+notification@gmail.com>')
|
|
|
|
|
assert isinstance(results, dict)
|
|
|
|
|
assert 'user' == results['user']
|
|
|
|
|
assert 'gmail.com' == results['host']
|
|
|
|
|
assert 'pass123' == results['password']
|
|
|
|
|
assert results['port'] is None
|
|
|
|
|
assert 'Plus Support<test+notification@gmail.com>' in results['targets']
|
|
|
|
|
|
|
|
|
|
obj = Apprise.instantiate(results, suppress_exceptions=False)
|
|
|
|
|
assert isinstance(obj, NotifyEmail) is True
|
|
|
|
|
|
|
|
|
|
assert len(obj.targets) == 1
|
|
|
|
|
assert ('Plus Support', 'test+notification@gmail.com') in obj.targets
|
|
|
|
|
|
|
|
|
|
assert mock_smtp.call_count == 0
|
|
|
|
|
assert mock_smtp_ssl.call_count == 0
|
|
|
|
|
assert obj.notify("test") is True
|
|
|
|
|
assert mock_smtp.call_count == 1
|
|
|
|
|
assert mock_smtp_ssl.call_count == 0
|
|
|
|
|
assert response.starttls.call_count == 1
|
|
|
|
|
assert response.login.call_count == 1
|
|
|
|
|
assert response.sendmail.call_count == 1
|
|
|
|
|
# Store our Sent Arguments
|
|
|
|
|
# Syntax is:
|
|
|
|
|
# sendmail(from_addr, to_addrs, msg, mail_options=(), rcpt_options=())
|
|
|
|
|
# [0] [1] [2]
|
|
|
|
|
_from = response.sendmail.call_args[0][0]
|
|
|
|
|
_to = response.sendmail.call_args[0][1]
|
|
|
|
|
_msg = response.sendmail.call_args[0][2]
|
|
|
|
|
assert _from == 'user@gmail.com'
|
|
|
|
|
assert isinstance(_to, list)
|
|
|
|
|
assert len(_to) == 1
|
|
|
|
|
assert _to[0] == 'test+notification@gmail.com'
|
|
|
|
|
assert _msg.split('\n')[-3] == 'test'
|
|
|
|
|
|
|
|
|
|
mock_smtp.reset_mock()
|
|
|
|
|
mock_smtp_ssl.reset_mock()
|
|
|
|
|
response.reset_mock()
|
|
|
|
|
|
|
|
|
|
#
|
|
|
|
|
# Perform the same test where the To field jsut contains the + in the
|
|
|
|
|
# address
|
|
|
|
|
#
|
|
|
|
|
results = NotifyEmail.parse_url(
|
|
|
|
|
'mailtos://user:pass123@gmail.com'
|
|
|
|
|
'?to=test+notification@gmail.com')
|
|
|
|
|
assert isinstance(results, dict)
|
|
|
|
|
assert 'user' == results['user']
|
|
|
|
|
assert 'gmail.com' == results['host']
|
|
|
|
|
assert 'pass123' == results['password']
|
|
|
|
|
assert results['port'] is None
|
|
|
|
|
assert 'test+notification@gmail.com' in results['targets']
|
|
|
|
|
|
|
|
|
|
obj = Apprise.instantiate(results, suppress_exceptions=False)
|
|
|
|
|
assert isinstance(obj, NotifyEmail) is True
|
|
|
|
|
|
|
|
|
|
assert len(obj.targets) == 1
|
|
|
|
|
assert (False, 'test+notification@gmail.com') in obj.targets
|
|
|
|
|
|
|
|
|
|
assert mock_smtp.call_count == 0
|
|
|
|
|
assert mock_smtp_ssl.call_count == 0
|
|
|
|
|
assert obj.notify("test") is True
|
|
|
|
|
assert mock_smtp.call_count == 1
|
|
|
|
|
assert mock_smtp_ssl.call_count == 0
|
|
|
|
|
assert response.starttls.call_count == 1
|
|
|
|
|
assert response.login.call_count == 1
|
|
|
|
|
assert response.sendmail.call_count == 1
|
|
|
|
|
# Store our Sent Arguments
|
|
|
|
|
# Syntax is:
|
|
|
|
|
# sendmail(from_addr, to_addrs, msg, mail_options=(), rcpt_options=())
|
|
|
|
|
# [0] [1] [2]
|
|
|
|
|
_from = response.sendmail.call_args[0][0]
|
|
|
|
|
_to = response.sendmail.call_args[0][1]
|
|
|
|
|
_msg = response.sendmail.call_args[0][2]
|
|
|
|
|
assert _from == 'user@gmail.com'
|
|
|
|
|
assert isinstance(_to, list)
|
|
|
|
|
assert len(_to) == 1
|
|
|
|
|
assert _to[0] == 'test+notification@gmail.com'
|
|
|
|
|
assert _msg.split('\n')[-3] == 'test'
|
|
|
|
|
|
|
|
|
|
mock_smtp.reset_mock()
|
|
|
|
|
mock_smtp_ssl.reset_mock()
|
|
|
|
|
response.reset_mock()
|
|
|
|
|
|
|
|
|
|
#
|
|
|
|
|
# Perform the same test where the To field is in the URL itself
|
|
|
|
|
#
|
|
|
|
|
results = NotifyEmail.parse_url(
|
|
|
|
|
'mailtos://user:pass123@gmail.com'
|
|
|
|
|
'/test+notification@gmail.com')
|
|
|
|
|
assert isinstance(results, dict)
|
|
|
|
|
assert 'user' == results['user']
|
|
|
|
|
assert 'gmail.com' == results['host']
|
|
|
|
|
assert 'pass123' == results['password']
|
|
|
|
|
assert results['port'] is None
|
|
|
|
|
assert 'test+notification@gmail.com' in results['targets']
|
|
|
|
|
|
|
|
|
|
obj = Apprise.instantiate(results, suppress_exceptions=False)
|
|
|
|
|
assert isinstance(obj, NotifyEmail) is True
|
|
|
|
|
|
|
|
|
|
assert len(obj.targets) == 1
|
|
|
|
|
assert (False, 'test+notification@gmail.com') in obj.targets
|
|
|
|
|
|
|
|
|
|
assert mock_smtp.call_count == 0
|
|
|
|
|
assert mock_smtp_ssl.call_count == 0
|
|
|
|
|
assert obj.notify("test") is True
|
|
|
|
|
assert mock_smtp.call_count == 1
|
|
|
|
|
assert mock_smtp_ssl.call_count == 0
|
|
|
|
|
assert response.starttls.call_count == 1
|
|
|
|
|
assert response.login.call_count == 1
|
|
|
|
|
assert response.sendmail.call_count == 1
|
|
|
|
|
# Store our Sent Arguments
|
|
|
|
|
# Syntax is:
|
|
|
|
|
# sendmail(from_addr, to_addrs, msg, mail_options=(), rcpt_options=())
|
|
|
|
|
# [0] [1] [2]
|
|
|
|
|
_from = response.sendmail.call_args[0][0]
|
|
|
|
|
_to = response.sendmail.call_args[0][1]
|
|
|
|
|
_msg = response.sendmail.call_args[0][2]
|
|
|
|
|
assert _from == 'user@gmail.com'
|
|
|
|
|
assert isinstance(_to, list)
|
|
|
|
|
assert len(_to) == 1
|
|
|
|
|
assert _to[0] == 'test+notification@gmail.com'
|
|
|
|
|
assert _msg.split('\n')[-3] == 'test'
|