Skip to content

Commit 0ce8e06

Browse files
committed
Catch additional connectivity errors; ignore optional dependencies
1 parent 4991542 commit 0ce8e06

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

emailproxy.py

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
__author__ = 'Simon Robinson'
77
__copyright__ = 'Copyright (c) 2024 Simon Robinson'
88
__license__ = 'Apache 2.0'
9-
__version__ = '2024-01-17' # ISO 8601 (YYYY-MM-DD)
9+
__version__ = '2024-01-20' # ISO 8601 (YYYY-MM-DD)
1010
__package_version__ = '.'.join([str(int(i)) for i in __version__.split('-')]) # for pyproject.toml usage only
1111

1212
import abc
@@ -340,6 +340,7 @@ def save(store_id, config_dict):
340340

341341

342342
class AWSSecretsManagerCacheStore(CacheStore):
343+
# noinspection PyUnresolvedReferences
343344
@staticmethod
344345
def _get_boto3_client(store_id):
345346
try:
@@ -568,7 +569,7 @@ def save():
568569
return
569570

570571
if CACHE_STORE != CONFIG_FILE_PATH:
571-
# in `--cache-store` mode we ignore everything except _CACHED_OPTION_KEYS (OAuth 2.0 tokens, etc)
572+
# in `--cache-store` mode we ignore everything except _CACHED_OPTION_KEYS (OAuth 2.0 tokens, etc.)
572573
output_config_parser = configparser.ConfigParser(interpolation=None)
573574
output_config_parser.read_dict(AppConfig._PARSER) # a deep copy of the current configuration
574575
config_accounts = [s for s in output_config_parser.sections() if '@' in s]
@@ -678,6 +679,7 @@ class TokenRefreshError(Exception):
678679

679680
@staticmethod
680681
def get_oauth2_credentials(username, password, reload_remote_accounts=True):
682+
# noinspection GrazieInspection
681683
"""Using the given username (i.e., email address) and password, reads account details from AppConfig and
682684
handles OAuth 2.0 token request and renewal, saving the updated details back to AppConfig (or removing them
683685
if invalid). Returns either (True, '[OAuth2 string for authentication]') or (False, '[Error message]')"""
@@ -1067,6 +1069,7 @@ def get_oauth2_authorisation_tokens(token_url, redirect_uri, client_id, client_s
10671069
Log.debug('Error requesting access token - received invalid response:', e.message)
10681070
raise e
10691071

1072+
# noinspection PyUnresolvedReferences
10701073
@staticmethod
10711074
def get_service_account_authorisation_token(key_type, key_path_or_contents, oauth2_scope, username):
10721075
"""Requests an authorisation token via a Service Account key (currently Google Cloud only)"""
@@ -1144,7 +1147,7 @@ def encode_oauth2_string(input_string):
11441147

11451148
@staticmethod
11461149
def strip_quotes(text):
1147-
"""Remove double quotes (i.e., " characters) around a string - used for IMAP LOGIN command"""
1150+
"""Remove double quotes (i.e., "" characters) around a string - used for IMAP LOGIN command"""
11481151
if text.startswith('"') and text.endswith('"'):
11491152
return text[1:-1].replace(r'\"', '"') # also need to fix any escaped quotes within the string
11501153
return text
@@ -1794,10 +1797,11 @@ def handle_error(self):
17941797
error_type, value = Log.get_last_error()
17951798
if error_type == TimeoutError and value.errno == errno.ETIMEDOUT or \
17961799
issubclass(error_type, ConnectionError) and value.errno in [errno.ECONNRESET, errno.ECONNREFUSED] or \
1797-
error_type == OSError and value.errno in [0, errno.ENETDOWN, errno.EHOSTDOWN, errno.EHOSTUNREACH]:
1800+
error_type == OSError and value.errno in [0, errno.ENETDOWN, errno.ENETUNREACH, errno.EHOSTDOWN,
1801+
errno.EHOSTUNREACH]:
17981802
# TimeoutError 60 = 'Operation timed out'; ConnectionError 54 = 'Connection reset by peer', 61 = 'Connection
1799-
# refused; OSError 0 = 'Error' (typically network failure), 50 = 'Network is down', 64 = 'Host is down';
1800-
# 65 = 'No route to host'
1803+
# refused; OSError 0 = 'Error' (typically network failure), 50 = 'Network is down', 51 = 'Network is
1804+
# unreachable'; 64 = 'Host is down'; 65 = 'No route to host'
18011805
Log.info(self.info_string(), 'Caught network error (server) - is there a network connection?',
18021806
'Error type', error_type, 'with message:', value)
18031807
self.close()

0 commit comments

Comments
 (0)