Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactored Apprise mailto:// and apprise.utils module #1255

Merged
merged 1 commit into from
Dec 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions apprise/apprise.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion apprise/apprise_attachment.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
5 changes: 2 additions & 3 deletions apprise/apprise_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 6 additions & 0 deletions apprise/asset.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
#
Expand Down
2 changes: 1 addition & 1 deletion apprise/attachment/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 _

Expand Down
2 changes: 1 addition & 1 deletion apprise/attachment/file.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 _

Expand Down
3 changes: 2 additions & 1 deletion apprise/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 2 additions & 5 deletions apprise/config/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion apprise/config/file.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 _
Expand Down
6 changes: 2 additions & 4 deletions apprise/decorators/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 8 additions & 0 deletions apprise/exception.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
14 changes: 8 additions & 6 deletions apprise/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion apprise/persistent_store.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 2 additions & 3 deletions apprise/plugins/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 2 additions & 4 deletions apprise/plugins/africas_talking.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 _


Expand Down
3 changes: 1 addition & 2 deletions apprise/plugins/apprise_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 _


Expand Down
3 changes: 1 addition & 2 deletions apprise/plugins/aprs.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
3 changes: 1 addition & 2 deletions apprise/plugins/bark.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 _


Expand Down
2 changes: 1 addition & 1 deletion apprise/plugins/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 1 addition & 3 deletions apprise/plugins/bulksms.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 _


Expand Down
4 changes: 1 addition & 3 deletions apprise/plugins/bulkvs.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 _


Expand Down
6 changes: 2 additions & 4 deletions apprise/plugins/burstsms.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 _


Expand Down
2 changes: 1 addition & 1 deletion apprise/plugins/chantify.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 _


Expand Down
4 changes: 1 addition & 3 deletions apprise/plugins/clicksend.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 2 additions & 4 deletions apprise/plugins/d7networks.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 2 additions & 4 deletions apprise/plugins/dapnet.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion apprise/plugins/dbus.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 1 addition & 2 deletions apprise/plugins/dingtalk.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 1 addition & 2 deletions apprise/plugins/discord.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
53 changes: 53 additions & 0 deletions apprise/plugins/email/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
# -*- coding: utf-8 -*-
# BSD 2-Clause License
#
# Apprise - Push Notification Library.
# Copyright (c) 2024, Chris Caron <[email protected]>
#
# 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',
]
Loading
Loading