From 211105d97964cb6026b8dafb696738bdfd311eab Mon Sep 17 00:00:00 2001 From: Timo Kankare Date: Sun, 4 Sep 2016 16:32:03 +0300 Subject: [PATCH] Added backends package and skeletons for IMAP and POP3 backends. Backend is initialized to the Account in AccountManager. --- Mailnag/backends/__init__.py | 24 ++++++++++++++++++++++++ Mailnag/backends/imap.py | 28 ++++++++++++++++++++++++++++ Mailnag/backends/pop3.py | 28 ++++++++++++++++++++++++++++ Mailnag/common/accounts.py | 12 ++++++++++-- 4 files changed, 90 insertions(+), 2 deletions(-) create mode 100644 Mailnag/backends/__init__.py create mode 100644 Mailnag/backends/imap.py create mode 100644 Mailnag/backends/pop3.py diff --git a/Mailnag/backends/__init__.py b/Mailnag/backends/__init__.py new file mode 100644 index 0000000..0140d55 --- /dev/null +++ b/Mailnag/backends/__init__.py @@ -0,0 +1,24 @@ +# -*- coding: utf-8 -*- +# +# __init__.py +# +# Copyright 2016 Timo Kankare +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, +# MA 02110-1301, USA. +# + +"""Backends to implement mail box specific functionality, like IMAP and POP3.""" + diff --git a/Mailnag/backends/imap.py b/Mailnag/backends/imap.py new file mode 100644 index 0000000..416eec6 --- /dev/null +++ b/Mailnag/backends/imap.py @@ -0,0 +1,28 @@ +# -*- coding: utf-8 -*- +# +# imap.py +# +# Copyright 2011 - 2016 Patrick Ulbrich +# Copyright 2016 Timo Kankare +# Copyright 2016 Thomas Haider +# Copyright 2011 Ralf Hersel +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, +# MA 02110-1301, USA. +# + +class ImapBackend: + pass + diff --git a/Mailnag/backends/pop3.py b/Mailnag/backends/pop3.py new file mode 100644 index 0000000..57cb48c --- /dev/null +++ b/Mailnag/backends/pop3.py @@ -0,0 +1,28 @@ +# -*- coding: utf-8 -*- +# +# imap.py +# +# Copyright 2011 - 2016 Patrick Ulbrich +# Copyright 2016 Timo Kankare +# Copyright 2016 Thomas Haider +# Copyright 2011 Ralf Hersel +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, +# MA 02110-1301, USA. +# + +class Pop3Backend: + pass + diff --git a/Mailnag/common/accounts.py b/Mailnag/common/accounts.py index a5c5bec..9659ea4 100644 --- a/Mailnag/common/accounts.py +++ b/Mailnag/common/accounts.py @@ -28,6 +28,8 @@ import poplib import logging import json import Mailnag.common.imaplib2 as imaplib +from Mailnag.backends.imap import ImapBackend +from Mailnag.backends.pop3 import Pop3Backend from Mailnag.common.utils import splitstr account_defaults = { @@ -50,7 +52,7 @@ CREDENTIAL_KEY = 'Mailnag password for %s://%s@%s' # class Account: def __init__(self, enabled = False, name = '', user = '', \ - password = '', oauth2string = '', server = '', port = '', ssl = True, imap = True, idle = True, folders = []): + password = '', oauth2string = '', server = '', port = '', ssl = True, imap = True, idle = True, folders = [], backend = None): self.enabled = enabled # bool self.name = name @@ -63,6 +65,7 @@ class Account: self.imap = imap # bool self.idle = idle # bool self.folders = folders + self.backend = backend self._conn = None @@ -287,7 +290,12 @@ class AccountManager: protocol = 'imap' if imap else 'pop' password = self._credentialstore.get(CREDENTIAL_KEY % (protocol, user, server)) - acc = Account(enabled, name, user, password, '', server, port, ssl, imap, idle, folders) + if imap: + backend = ImapBackend() + else: + bakcend = Pop3Backend() + + acc = Account(enabled, name, user, password, '', server, port, ssl, imap, idle, folders, backend) self._accounts.append(acc) i = i + 1