diff --git a/Mailnag/backends/imap.py b/Mailnag/backends/imap.py index 91ecd66..f6e74dd 100644 --- a/Mailnag/backends/imap.py +++ b/Mailnag/backends/imap.py @@ -148,7 +148,7 @@ def mark_as_seen(self, mails): if folder != last_folder: conn.select(f'"{folder}"', readonly = False) last_folder = folder - status, data = conn.uid("STORE", m.flags['uid'], "+FLAGS", "(\Seen)") + status, data = conn.uid("STORE", m.flags['uid'], "+FLAGS", r"(\Seen)") except: logging.warning("Failed to set mail with uid %s to seen on server (account: '%s').", m.flags['uid'], acc.name) diff --git a/Mailnag/common/imaplib2.py b/Mailnag/common/imaplib2.py index dfce0b4..70fa8d3 100644 --- a/Mailnag/common/imaplib2.py +++ b/Mailnag/common/imaplib2.py @@ -309,6 +309,7 @@ def __init__(self, host=None, port=None, debug=None, debug_file=None, identifier self.compressor = None # COMPRESS/DEFLATE if not None self.decompressor = None self._tls_established = False + self._ssl_context = None # Create unique tag for this session, # and compile tagged response matcher. @@ -492,7 +493,13 @@ def ssl_wrap_socket(self): ssl_version = TLS_MAP[self.tls_level][self.ssl_version] - self.sock = ssl.wrap_socket(self.sock, self.keyfile, self.certfile, ca_certs=self.ca_certs, cert_reqs=cert_reqs, ssl_version=ssl_version) + self._ssl_context = ssl.SSLContext(ssl_version) + self._ssl_context.verify_mode = cert_reqs + if self.ca_certs: + self._ssl_context.load_verify_locations(self.ca_certs) + if self.keyfile and self.certfile: + self._ssl_context.load_cert_chain(self.certfile, self.keyfile) + self.sock = self._ssl_context.wrap_socket(self.sock, server_hostname=self.host) ssl_exc = ssl.SSLError self.read_fd = self.sock.fileno() except ImportError: @@ -2459,7 +2466,7 @@ def ParseFlags(resp): ('select', ('imaplib2_test2',)), ('search', (None, 'SUBJECT', '"IMAP4 test"')), ('fetch', ('1:*', '(FLAGS INTERNALDATE RFC822)')), - ('store', ('1', 'FLAGS', '(\Deleted)')), + ('store', ('1', 'FLAGS', r'(\Deleted)')), ('namespace', ()), ('expunge', ()), ('recent', ()), @@ -2564,7 +2571,7 @@ def run(cmd, args, cb=True): if not uid: continue run('uid', ('FETCH', uid[-1], '(FLAGS INTERNALDATE RFC822.SIZE RFC822.HEADER RFC822.TEXT)')) - run('uid', ('STORE', uid[-1], 'FLAGS', '(\Deleted)')) + run('uid', ('STORE', uid[-1], 'FLAGS', r'(\Deleted)')) run('expunge', ()) if 'IDLE' in M.capabilities: @@ -2578,10 +2585,10 @@ def run(cmd, args, cb=True): dat = run('fetch', (num, '(FLAGS INTERNALDATE RFC822)'), cb=False) M._mesg('fetch %s => %s' % (num, repr(dat))) run('idle', (2,)) - run('store', (num, '-FLAGS', '(\Seen)'), cb=False), + run('store', (num, '-FLAGS', r'(\Seen)'), cb=False), dat = run('fetch', (num, '(FLAGS INTERNALDATE RFC822)'), cb=False) M._mesg('fetch %s => %s' % (num, repr(dat))) - run('uid', ('STORE', num, 'FLAGS', '(\Deleted)')) + run('uid', ('STORE', num, 'FLAGS', r'(\Deleted)')) run('expunge', ()) if idle_intr: M._mesg('HIT CTRL-C to interrupt IDLE') diff --git a/Mailnag/common/plugins.py b/Mailnag/common/plugins.py index d9bf572..be5ed31 100644 --- a/Mailnag/common/plugins.py +++ b/Mailnag/common/plugins.py @@ -17,7 +17,8 @@ # import os -import imp +import importlib.util +import importlib.machinery import inspect import logging from enum import Enum @@ -255,22 +256,30 @@ def _load_plugin_types(): for f in os.listdir(path): mod = None modname, ext = os.path.splitext(f) + filename = os.path.join(path, f) try: if ext.lower() == '.py': - if not os.path.exists(os.path.join(path, modname + '.pyc')): - mod = imp.load_source(modname, os.path.join(path, f)) + loader = importlib.machinery.SourceFileLoader(modname, filename) elif ext.lower() == '.pyc': - mod = imp.load_compiled(modname, os.path.join(path, f)) - - if mod != None: - for t in dir(mod): - t = getattr(mod, t) - if inspect.isclass(t) and \ - (inspect.getmodule(t) == mod) and \ - issubclass(t, Plugin): - plugin_types.append((modname, t)) - + loader = importlib.machinery.SourcelessFileLoader(modname, filename) + else: + continue + + spec = importlib.util.spec_from_file_location(modname, filename, loader=loader) + + if spec is None: + continue + + mod = importlib.util.module_from_spec(spec) + loader.exec_module(mod) + + for attr_name in dir(mod): + attr = getattr(mod, attr_name) + if not inspect.isclass(attr): + continue + if issubclass(attr, Plugin) and attr != Plugin: + plugin_types.append((modname, attr)) except: logging.exception("Error while opening plugin file '%s'" % f) diff --git a/Mailnag/configuration/configwindow.py b/Mailnag/configuration/configwindow.py index bc7799d..9ee2d05 100644 --- a/Mailnag/configuration/configwindow.py +++ b/Mailnag/configuration/configwindow.py @@ -245,7 +245,12 @@ def _create_autostart(self): if not os.path.exists(autostart_folder): os.makedirs(autostart_folder) - shutil.copyfile(src, dst) + try: + shutil.copyfile(src, dst) + except Exception as e: + import logging + logging.info(f"failed setting autostart: {e}") + return # If mailag-config was started from a local directory, # patch the exec path of the autostart .desktop file accordingly.