Skip to content
Open
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
2 changes: 1 addition & 1 deletion Mailnag/backends/imap.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
17 changes: 12 additions & 5 deletions Mailnag/common/imaplib2.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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', ()),
Expand Down Expand Up @@ -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:
Expand All @@ -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')
Expand Down
35 changes: 22 additions & 13 deletions Mailnag/common/plugins.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@
#

import os
import imp
import importlib.util
import importlib.machinery
import inspect
import logging
from enum import Enum
Expand Down Expand Up @@ -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)

Expand Down
7 changes: 6 additions & 1 deletion Mailnag/configuration/configwindow.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down