From 551fa0d708a43b2e36587e39a55edb476f061b92 Mon Sep 17 00:00:00 2001 From: Chris Caron Date: Sun, 15 Dec 2024 13:02:18 -0500 Subject: [PATCH] Refactored apprise mailto:// and utils module (#1255) --- apprise/apprise.py | 7 +- apprise/apprise_attachment.py | 2 +- apprise/apprise_config.py | 5 +- apprise/asset.py | 6 + apprise/attachment/base.py | 2 +- apprise/attachment/file.py | 2 +- apprise/cli.py | 3 +- apprise/config/base.py | 7 +- apprise/config/file.py | 2 +- apprise/decorators/base.py | 6 +- apprise/exception.py | 8 + apprise/manager.py | 14 +- apprise/persistent_store.py | 2 +- apprise/plugins/__init__.py | 5 +- apprise/plugins/africas_talking.py | 6 +- apprise/plugins/apprise_api.py | 3 +- apprise/plugins/aprs.py | 3 +- apprise/plugins/bark.py | 3 +- apprise/plugins/base.py | 2 +- apprise/plugins/bulksms.py | 4 +- apprise/plugins/bulkvs.py | 4 +- apprise/plugins/burstsms.py | 6 +- apprise/plugins/chantify.py | 2 +- apprise/plugins/clicksend.py | 4 +- apprise/plugins/d7networks.py | 6 +- apprise/plugins/dapnet.py | 6 +- apprise/plugins/dbus.py | 2 +- apprise/plugins/dingtalk.py | 3 +- apprise/plugins/discord.py | 3 +- apprise/plugins/email/__init__.py | 53 + apprise/plugins/{email.py => email/base.py} | 1065 ++++++------------- apprise/plugins/email/common.py | 84 ++ apprise/plugins/email/templates.py | 272 +++++ apprise/plugins/emby.py | 2 +- apprise/plugins/fcm/__init__.py | 6 +- apprise/plugins/fcm/color.py | 2 +- apprise/plugins/feishu.py | 2 +- apprise/plugins/flock.py | 4 +- apprise/plugins/gnome.py | 2 +- apprise/plugins/google_chat.py | 2 +- apprise/plugins/gotify.py | 2 +- apprise/plugins/growl.py | 2 +- apprise/plugins/home_assistant.py | 2 +- apprise/plugins/httpsms.py | 4 +- apprise/plugins/ifttt.py | 3 +- apprise/plugins/join.py | 4 +- apprise/plugins/kavenegar.py | 4 +- apprise/plugins/kumulos.py | 2 +- apprise/plugins/lametric.py | 4 +- apprise/plugins/line.py | 4 +- apprise/plugins/lunasea.py | 6 +- apprise/plugins/macosx.py | 2 +- apprise/plugins/mailgun.py | 6 +- apprise/plugins/mastodon.py | 4 +- apprise/plugins/matrix.py | 6 +- apprise/plugins/mattermost.py | 4 +- apprise/plugins/messagebird.py | 4 +- apprise/plugins/misskey.py | 2 +- apprise/plugins/mqtt.py | 3 +- apprise/plugins/msg91.py | 5 +- apprise/plugins/msteams.py | 6 +- apprise/plugins/nextcloud.py | 2 +- apprise/plugins/nextcloudtalk.py | 2 +- apprise/plugins/notica.py | 2 +- apprise/plugins/notifiarr.py | 3 +- apprise/plugins/notifico.py | 3 +- apprise/plugins/ntfy.py | 7 +- apprise/plugins/office365.py | 4 +- apprise/plugins/one_signal.py | 8 +- apprise/plugins/opsgenie.py | 5 +- apprise/plugins/pagerduty.py | 3 +- apprise/plugins/pagertree.py | 3 +- apprise/plugins/parseplatform.py | 2 +- apprise/plugins/plivo.py | 6 +- apprise/plugins/popcorn_notify.py | 7 +- apprise/plugins/prowl.py | 2 +- apprise/plugins/pushbullet.py | 4 +- apprise/plugins/pushdeer.py | 2 +- apprise/plugins/pushed.py | 3 +- apprise/plugins/pushjet.py | 2 +- apprise/plugins/pushme.py | 3 +- apprise/plugins/pushover.py | 3 +- apprise/plugins/pushsafer.py | 3 +- apprise/plugins/pushy.py | 3 +- apprise/plugins/reddit.py | 4 +- apprise/plugins/revolt.py | 3 +- apprise/plugins/rocketchat.py | 3 +- apprise/plugins/rsyslog.py | 2 +- apprise/plugins/ryver.py | 3 +- apprise/plugins/sendgrid.py | 4 +- apprise/plugins/serverchan.py | 2 +- apprise/plugins/ses.py | 4 +- apprise/plugins/seven.py | 3 +- apprise/plugins/sfr.py | 3 +- apprise/plugins/signal_api.py | 4 +- apprise/plugins/simplepush.py | 2 +- apprise/plugins/sinch.py | 4 +- apprise/plugins/slack.py | 6 +- apprise/plugins/smseagle.py | 6 +- apprise/plugins/smsmanager.py | 6 +- apprise/plugins/smtp2go.py | 6 +- apprise/plugins/sns.py | 4 +- apprise/plugins/sparkpost.py | 6 +- apprise/plugins/splunk.py | 2 +- apprise/plugins/streamlabs.py | 2 +- apprise/plugins/syslog.py | 2 +- apprise/plugins/techuluspush.py | 2 +- apprise/plugins/telegram.py | 4 +- apprise/plugins/threema.py | 5 +- apprise/plugins/twilio.py | 4 +- apprise/plugins/twist.py | 3 +- apprise/plugins/twitter.py | 4 +- apprise/plugins/voipms.py | 4 +- apprise/plugins/vonage.py | 4 +- apprise/plugins/webexteams.py | 2 +- apprise/plugins/wecombot.py | 2 +- apprise/plugins/whatsapp.py | 4 +- apprise/plugins/windows.py | 2 +- apprise/plugins/workflows.py | 6 +- apprise/plugins/wxpusher.py | 3 +- apprise/plugins/xbmc.py | 2 +- apprise/plugins/zulip.py | 10 +- apprise/url.py | 7 +- apprise/utils/__init__.py | 27 + apprise/utils/base64.py | 88 ++ apprise/utils/cwe312.py | 197 ++++ apprise/utils/disk.py | 178 ++++ apprise/utils/logic.py | 121 +++ apprise/utils/module.py | 59 + apprise/{utils.py => utils/parse.py} | 651 +----------- apprise/utils/pgp.py | 354 ++++++ apprise/utils/singleton.py | 43 + apprise/utils/templates.py | 84 ++ test/test_api.py | 2 +- test/test_apprise_utils.py | 897 ++++++++-------- test/test_plugin_email.py | 242 +++-- 136 files changed, 2699 insertions(+), 2176 deletions(-) create mode 100644 apprise/plugins/email/__init__.py rename apprise/plugins/{email.py => email/base.py} (59%) create mode 100644 apprise/plugins/email/common.py create mode 100644 apprise/plugins/email/templates.py create mode 100644 apprise/utils/__init__.py create mode 100644 apprise/utils/base64.py create mode 100644 apprise/utils/cwe312.py create mode 100644 apprise/utils/disk.py create mode 100644 apprise/utils/logic.py create mode 100644 apprise/utils/module.py rename apprise/{utils.py => utils/parse.py} (68%) create mode 100644 apprise/utils/pgp.py create mode 100644 apprise/utils/singleton.py create mode 100644 apprise/utils/templates.py diff --git a/apprise/apprise.py b/apprise/apprise.py index 05a2ee3cc..16125009a 100644 --- a/apprise/apprise.py +++ b/apprise/apprise.py @@ -32,11 +32,10 @@ from itertools import chain from . import common from .conversion import convert_between -from .utils import is_exclusive_match +from .utils.logic import is_exclusive_match +from .utils.parse import parse_list, parse_urls +from .utils.cwe312 import cwe312_url from .manager_plugins import NotificationManager -from .utils import parse_list -from .utils import parse_urls -from .utils import cwe312_url from .emojis import apply_emojis from .logger import logger from .asset import AppriseAsset diff --git a/apprise/apprise_attachment.py b/apprise/apprise_attachment.py index ecf415ec9..7b491eef1 100644 --- a/apprise/apprise_attachment.py +++ b/apprise/apprise_attachment.py @@ -33,7 +33,7 @@ from .logger import logger from .common import ContentLocation from .common import CONTENT_LOCATIONS -from .utils import GET_SCHEMA_RE +from .utils.parse import GET_SCHEMA_RE # Grant access to our Notification Manager Singleton A_MGR = AttachmentManager() diff --git a/apprise/apprise_config.py b/apprise/apprise_config.py index 080f70d30..c96b69f24 100644 --- a/apprise/apprise_config.py +++ b/apprise/apprise_config.py @@ -32,9 +32,8 @@ from . import URLBase from .asset import AppriseAsset from . import common -from .utils import GET_SCHEMA_RE -from .utils import parse_list -from .utils import is_exclusive_match +from .utils.parse import GET_SCHEMA_RE, parse_list +from .utils.logic import is_exclusive_match from .logger import logger # Grant access to our Configuration Manager Singleton diff --git a/apprise/asset.py b/apprise/asset.py index 2f08a6661..d952e9415 100644 --- a/apprise/asset.py +++ b/apprise/asset.py @@ -143,6 +143,12 @@ class AppriseAsset: # Defines the encoding of the content passed into Apprise encoding = 'utf-8' + # Automatically generate our Pretty Good Privacy (PGP) keys if one isn't + # present and our environment configuration allows for it. + # For example, a case where the environment wouldn't allow for it would be + # if Persistent Storage was set to `memory` + pgp_autogen = True + # For more detail see CWE-312 @ # https://cwe.mitre.org/data/definitions/312.html # diff --git a/apprise/attachment/base.py b/apprise/attachment/base.py index ed938a984..b3743e036 100644 --- a/apprise/attachment/base.py +++ b/apprise/attachment/base.py @@ -32,7 +32,7 @@ import base64 from .. import exception from ..url import URLBase -from ..utils import parse_bool +from ..utils.parse import parse_bool from ..common import ContentLocation from ..locale import gettext_lazy as _ diff --git a/apprise/attachment/file.py b/apprise/attachment/file.py index e23f5b6bb..f0aeb72b6 100644 --- a/apprise/attachment/file.py +++ b/apprise/attachment/file.py @@ -29,7 +29,7 @@ import re import os from .base import AttachBase -from ..utils import path_decode +from ..utils.disk import path_decode from ..common import ContentLocation from ..locale import gettext_lazy as _ diff --git a/apprise/cli.py b/apprise/cli.py index 3c7f19365..4072a645b 100644 --- a/apprise/cli.py +++ b/apprise/cli.py @@ -43,7 +43,8 @@ from . import AppriseConfig from . import PersistentStore -from .utils import dir_size, bytes_to_str, parse_list, path_decode +from .utils.parse import parse_list +from .utils.disk import dir_size, bytes_to_str, path_decode from .common import NOTIFY_TYPES from .common import NOTIFY_FORMATS from .common import PERSISTENT_STORE_MODES diff --git a/apprise/config/base.py b/apprise/config/base.py index 953cee394..03a4423a9 100644 --- a/apprise/config/base.py +++ b/apprise/config/base.py @@ -35,11 +35,8 @@ from .. import common from ..asset import AppriseAsset from ..url import URLBase -from ..utils import GET_SCHEMA_RE -from ..utils import parse_list -from ..utils import parse_bool -from ..utils import parse_urls -from ..utils import cwe312_url +from ..utils.parse import GET_SCHEMA_RE, parse_list, parse_bool, parse_urls +from ..utils.cwe312 import cwe312_url from ..manager_config import ConfigurationManager from ..manager_plugins import NotificationManager diff --git a/apprise/config/file.py b/apprise/config/file.py index 9340f62bb..89224e2ea 100644 --- a/apprise/config/file.py +++ b/apprise/config/file.py @@ -29,7 +29,7 @@ import re import os from .base import ConfigBase -from ..utils import path_decode +from ..utils.disk import path_decode from ..common import ConfigFormat from ..common import ContentIncludeMode from ..locale import gettext_lazy as _ diff --git a/apprise/decorators/base.py b/apprise/decorators/base.py index 688fd96dc..e7cf7b666 100644 --- a/apprise/decorators/base.py +++ b/apprise/decorators/base.py @@ -29,10 +29,8 @@ from ..plugins.base import NotifyBase from ..manager_plugins import NotificationManager -from ..utils import URL_DETAILS_RE -from ..utils import parse_url -from ..utils import url_assembly -from ..utils import dict_full_update +from ..utils.parse import URL_DETAILS_RE, parse_url, url_assembly +from ..utils.logic import dict_full_update from .. import common from ..logger import logger import inspect diff --git a/apprise/exception.py b/apprise/exception.py index 40967f5aa..a11f28248 100644 --- a/apprise/exception.py +++ b/apprise/exception.py @@ -37,6 +37,14 @@ def __init__(self, message, error_code=0): self.error_code = error_code +class ApprisePluginException(AppriseException): + """ + Class object for handling exceptions raised from within a plugin + """ + def __init__(self, message, error_code=600): + super().__init__(message, error_code=error_code) + + class AppriseDiskIOError(AppriseException): """ Thrown when an disk i/o error occurs diff --git a/apprise/manager.py b/apprise/manager.py index ab7f6c994..afc9c1a32 100644 --- a/apprise/manager.py +++ b/apprise/manager.py @@ -33,10 +33,10 @@ import hashlib import inspect import threading -from .utils import import_module -from .utils import Singleton -from .utils import parse_list -from .utils import path_decode +from .utils.module import import_module +from .utils.singleton import Singleton +from .utils.parse import parse_list +from .utils.disk import path_decode from os.path import dirname from os.path import abspath from os.path import join @@ -244,8 +244,10 @@ def load_modules(self, path=None, name=None, force=False): for schema in schemas: if schema in self._schema_map: logger.error( - "{} schema ({}) mismatch detected - {} to {}" - .format(self.name, schema, self._schema_map, + "{} schema ({}) mismatch detected -" + ' {} already maps to {}' + .format(self.name, schema, + self._schema_map[schema], plugin)) continue diff --git a/apprise/persistent_store.py b/apprise/persistent_store.py index ca7048517..6151beb5e 100644 --- a/apprise/persistent_store.py +++ b/apprise/persistent_store.py @@ -37,7 +37,7 @@ import time import hashlib from .common import PersistentStoreMode, PERSISTENT_STORE_MODES -from .utils import path_decode +from .utils.disk import path_decode from .logger import logger # Used for writing/reading time stored in cache file diff --git a/apprise/plugins/__init__.py b/apprise/plugins/__init__.py index bfce14371..62ddeaa5f 100644 --- a/apprise/plugins/__init__.py +++ b/apprise/plugins/__init__.py @@ -36,9 +36,8 @@ from ..common import NOTIFY_IMAGE_SIZES from ..common import NotifyType from ..common import NOTIFY_TYPES -from ..utils import parse_list -from ..utils import cwe312_url -from ..utils import GET_SCHEMA_RE +from ..utils.cwe312 import cwe312_url +from ..utils.parse import parse_list, GET_SCHEMA_RE from ..logger import logger from ..locale import gettext_lazy as _ from ..locale import LazyTranslation diff --git a/apprise/plugins/africas_talking.py b/apprise/plugins/africas_talking.py index af8a78577..98b2a208e 100644 --- a/apprise/plugins/africas_talking.py +++ b/apprise/plugins/africas_talking.py @@ -35,10 +35,8 @@ from .base import NotifyBase from ..common import NotifyType -from ..utils import is_phone_no -from ..utils import parse_bool -from ..utils import parse_phone_no -from ..utils import validate_regex +from ..utils.parse import ( + is_phone_no, parse_bool, parse_phone_no, validate_regex) from ..locale import gettext_lazy as _ diff --git a/apprise/plugins/apprise_api.py b/apprise/plugins/apprise_api.py index d6156438f..bd1177930 100644 --- a/apprise/plugins/apprise_api.py +++ b/apprise/plugins/apprise_api.py @@ -34,8 +34,7 @@ from .base import NotifyBase from ..url import PrivacyMode from ..common import NotifyType -from ..utils import parse_list -from ..utils import validate_regex +from ..utils.parse import parse_list, validate_regex from ..locale import gettext_lazy as _ diff --git a/apprise/plugins/aprs.py b/apprise/plugins/aprs.py index d87025fee..d3c9dc1a2 100644 --- a/apprise/plugins/aprs.py +++ b/apprise/plugins/aprs.py @@ -74,8 +74,7 @@ from ..locale import gettext_lazy as _ from ..url import PrivacyMode from ..common import NotifyType -from ..utils import is_call_sign -from ..utils import parse_call_sign +from ..utils.parse import is_call_sign, parse_call_sign from .. import __version__ import re diff --git a/apprise/plugins/bark.py b/apprise/plugins/bark.py index c9f1fedef..0e415a290 100644 --- a/apprise/plugins/bark.py +++ b/apprise/plugins/bark.py @@ -36,8 +36,7 @@ from ..url import PrivacyMode from ..common import NotifyImageSize from ..common import NotifyType -from ..utils import parse_list -from ..utils import parse_bool +from ..utils.parse import parse_list, parse_bool from ..locale import gettext_lazy as _ diff --git a/apprise/plugins/base.py b/apprise/plugins/base.py index 1c490defa..b7f774423 100644 --- a/apprise/plugins/base.py +++ b/apprise/plugins/base.py @@ -32,7 +32,7 @@ from ..url import URLBase from ..common import NotifyType -from ..utils import parse_bool +from ..utils.parse import parse_bool from ..common import NOTIFY_TYPES from ..common import NotifyFormat from ..common import NOTIFY_FORMATS diff --git a/apprise/plugins/bulksms.py b/apprise/plugins/bulksms.py index f53f61267..ce0daef49 100644 --- a/apprise/plugins/bulksms.py +++ b/apprise/plugins/bulksms.py @@ -39,9 +39,7 @@ from .base import NotifyBase from ..url import PrivacyMode from ..common import NotifyType -from ..utils import is_phone_no -from ..utils import parse_phone_no -from ..utils import parse_bool +from ..utils.parse import is_phone_no, parse_phone_no, parse_bool from ..locale import gettext_lazy as _ diff --git a/apprise/plugins/bulkvs.py b/apprise/plugins/bulkvs.py index a02d8ab8c..14a1369ed 100644 --- a/apprise/plugins/bulkvs.py +++ b/apprise/plugins/bulkvs.py @@ -38,9 +38,7 @@ from .base import NotifyBase from ..url import PrivacyMode from ..common import NotifyType -from ..utils import is_phone_no -from ..utils import parse_phone_no -from ..utils import parse_bool +from ..utils.parse import is_phone_no, parse_phone_no, parse_bool from ..locale import gettext_lazy as _ diff --git a/apprise/plugins/burstsms.py b/apprise/plugins/burstsms.py index 3b6f2669a..898f98641 100644 --- a/apprise/plugins/burstsms.py +++ b/apprise/plugins/burstsms.py @@ -36,10 +36,8 @@ from .base import NotifyBase from ..url import PrivacyMode from ..common import NotifyType -from ..utils import is_phone_no -from ..utils import parse_phone_no -from ..utils import parse_bool -from ..utils import validate_regex +from ..utils.parse import ( + is_phone_no, parse_phone_no, parse_bool, validate_regex) from ..locale import gettext_lazy as _ diff --git a/apprise/plugins/chantify.py b/apprise/plugins/chantify.py index e7c5f63e9..e9be66161 100644 --- a/apprise/plugins/chantify.py +++ b/apprise/plugins/chantify.py @@ -37,7 +37,7 @@ from .base import NotifyBase from ..common import NotifyType -from ..utils import validate_regex +from ..utils.parse import validate_regex from ..locale import gettext_lazy as _ diff --git a/apprise/plugins/clicksend.py b/apprise/plugins/clicksend.py index 7f28ac913..92a2405e0 100644 --- a/apprise/plugins/clicksend.py +++ b/apprise/plugins/clicksend.py @@ -45,9 +45,7 @@ from .base import NotifyBase from ..url import PrivacyMode from ..common import NotifyType -from ..utils import is_phone_no -from ..utils import parse_phone_no -from ..utils import parse_bool +from ..utils.parse import is_phone_no, parse_phone_no, parse_bool from ..locale import gettext_lazy as _ # Extend HTTP Error Messages diff --git a/apprise/plugins/d7networks.py b/apprise/plugins/d7networks.py index ff2e31b05..8b35458d5 100644 --- a/apprise/plugins/d7networks.py +++ b/apprise/plugins/d7networks.py @@ -41,10 +41,8 @@ from .base import NotifyBase from ..common import NotifyType -from ..utils import is_phone_no -from ..utils import parse_phone_no -from ..utils import validate_regex -from ..utils import parse_bool +from ..utils.parse import ( + is_phone_no, parse_phone_no, validate_regex, parse_bool) from ..locale import gettext_lazy as _ # Extend HTTP Error Messages diff --git a/apprise/plugins/dapnet.py b/apprise/plugins/dapnet.py index 725174c14..2d25759eb 100644 --- a/apprise/plugins/dapnet.py +++ b/apprise/plugins/dapnet.py @@ -55,10 +55,8 @@ from ..locale import gettext_lazy as _ from ..url import PrivacyMode from ..common import NotifyType -from ..utils import is_call_sign -from ..utils import parse_call_sign -from ..utils import parse_list -from ..utils import parse_bool +from ..utils.parse import ( + is_call_sign, parse_call_sign, parse_list, parse_bool) class DapnetPriority: diff --git a/apprise/plugins/dbus.py b/apprise/plugins/dbus.py index 9a22a85f8..5d99c7e0e 100644 --- a/apprise/plugins/dbus.py +++ b/apprise/plugins/dbus.py @@ -30,7 +30,7 @@ from .base import NotifyBase from ..common import NotifyImageSize from ..common import NotifyType -from ..utils import parse_bool +from ..utils.parse import parse_bool from ..locale import gettext_lazy as _ # Default our global support flag diff --git a/apprise/plugins/dingtalk.py b/apprise/plugins/dingtalk.py index e675f5302..2380d2e0a 100644 --- a/apprise/plugins/dingtalk.py +++ b/apprise/plugins/dingtalk.py @@ -38,8 +38,7 @@ from ..url import PrivacyMode from ..common import NotifyFormat from ..common import NotifyType -from ..utils import parse_list -from ..utils import validate_regex +from ..utils.parse import parse_list, validate_regex from ..locale import gettext_lazy as _ # Register at https://dingtalk.com diff --git a/apprise/plugins/discord.py b/apprise/plugins/discord.py index e41e22cdc..d2eb7541d 100644 --- a/apprise/plugins/discord.py +++ b/apprise/plugins/discord.py @@ -54,8 +54,7 @@ from ..common import NotifyImageSize from ..common import NotifyFormat from ..common import NotifyType -from ..utils import parse_bool -from ..utils import validate_regex +from ..utils.parse import parse_bool, validate_regex from ..locale import gettext_lazy as _ from ..attachment.base import AttachBase diff --git a/apprise/plugins/email/__init__.py b/apprise/plugins/email/__init__.py new file mode 100644 index 000000000..31afabcab --- /dev/null +++ b/apprise/plugins/email/__init__.py @@ -0,0 +1,53 @@ +# -*- coding: utf-8 -*- +# BSD 2-Clause License +# +# Apprise - Push Notification Library. +# Copyright (c) 2024, Chris Caron +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are met: +# +# 1. Redistributions of source code must retain the above copyright notice, +# this list of conditions and the following disclaimer. +# +# 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. +# +# 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. + +from email import charset + +from .base import NotifyEmail +from .common import ( + AppriseEmailException, EmailMessage, SecureMailMode, SECURE_MODES, + WebBaseLogin) +from .templates import EMAIL_TEMPLATES + +# Globally Default encoding mode set to Quoted Printable. +charset.add_charset('utf-8', charset.QP, charset.QP, 'utf-8') + +__all__ = [ + # Reference + 'NotifyEmail', + + # Pretty Good Privacy + 'ApprisePGPController', 'ApprisePGPException', + + # Other + 'AppriseEmailException', 'EmailMessage', 'SecureMailMode', 'SECURE_MODES', + 'WebBaseLogin', + + # Additional entries that may be useful to some developers + 'EMAIL_TEMPLATES', 'PGP_SUPPORT', +] diff --git a/apprise/plugins/email.py b/apprise/plugins/email/base.py similarity index 59% rename from apprise/plugins/email.py rename to apprise/plugins/email/base.py index 8651c08a8..7f29fa26c 100644 --- a/apprise/plugins/email.py +++ b/apprise/plugins/email/base.py @@ -26,325 +26,32 @@ # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE # POSSIBILITY OF SUCH DAMAGE. -import dataclasses -import os import re import smtplib -import typing as t from email.mime.text import MIMEText from email.mime.application import MIMEApplication from email.mime.multipart import MIMEMultipart from email.mime.base import MIMEBase from email.utils import formataddr, make_msgid from email.header import Header -from email import charset -import hashlib from socket import error as SocketError from datetime import datetime -from datetime import timedelta from datetime import timezone -from ..apprise_attachment import AppriseAttachment -from .base import NotifyBase -from ..url import PrivacyMode -from ..common import NotifyFormat, NotifyType, PersistentStoreMode -from ..conversion import convert_between -from ..utils import is_ipaddr, is_email, parse_emails, is_hostname, parse_bool -from ..locale import gettext_lazy as _ - -try: - import pgpy - # Pretty Good Privacy (PGP) Support enabled - PGP_SUPPORT = True - -except ImportError: - # Pretty Good Privacy (PGP) Support disabled - PGP_SUPPORT = False - -# Globally Default encoding mode set to Quoted Printable. -charset.add_charset('utf-8', charset.QP, charset.QP, 'utf-8') - - -class WebBaseLogin: - """ - This class is just used in conjunction of the default emailers - to best formulate a login to it using the data detected - """ - # User Login must be Email Based - EMAIL = 'Email' - - # User Login must UserID Based - USERID = 'UserID' - - -# Secure Email Modes -class SecureMailMode: - INSECURE = "insecure" - SSL = "ssl" - STARTTLS = "starttls" - - -# Define all of the secure modes (used during validation) -SECURE_MODES = { - SecureMailMode.STARTTLS: { - 'default_port': 587, - }, - SecureMailMode.SSL: { - 'default_port': 465, - }, - SecureMailMode.INSECURE: { - 'default_port': 25, - }, -} - -# To attempt to make this script stupid proof, if we detect an email address -# that is part of the this table, we can pre-use a lot more defaults if they -# aren't otherwise specified on the users input. -EMAIL_TEMPLATES = ( - # Google GMail - ( - 'Google Mail', - re.compile( - r'^((?P