mirror of
https://github.com/pulb/mailnag.git
synced 2026-05-06 18:16:55 +02:00
Added backends package and skeletons for IMAP and POP3 backends.
Backend is initialized to the Account in AccountManager.
This commit is contained in:
24
Mailnag/backends/__init__.py
Normal file
24
Mailnag/backends/__init__.py
Normal file
@@ -0,0 +1,24 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
#
|
||||
# __init__.py
|
||||
#
|
||||
# Copyright 2016 Timo Kankare <timo.kankare@iki.fi>
|
||||
#
|
||||
# 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."""
|
||||
|
||||
28
Mailnag/backends/imap.py
Normal file
28
Mailnag/backends/imap.py
Normal file
@@ -0,0 +1,28 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
#
|
||||
# imap.py
|
||||
#
|
||||
# Copyright 2011 - 2016 Patrick Ulbrich <zulu99@gmx.net>
|
||||
# Copyright 2016 Timo Kankare <timo.kankare@iki.fi>
|
||||
# Copyright 2016 Thomas Haider <t.haider@deprecate.de>
|
||||
# Copyright 2011 Ralf Hersel <ralf.hersel@gmx.net>
|
||||
#
|
||||
# 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
|
||||
|
||||
28
Mailnag/backends/pop3.py
Normal file
28
Mailnag/backends/pop3.py
Normal file
@@ -0,0 +1,28 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
#
|
||||
# imap.py
|
||||
#
|
||||
# Copyright 2011 - 2016 Patrick Ulbrich <zulu99@gmx.net>
|
||||
# Copyright 2016 Timo Kankare <timo.kankare@iki.fi>
|
||||
# Copyright 2016 Thomas Haider <t.haider@deprecate.de>
|
||||
# Copyright 2011 Ralf Hersel <ralf.hersel@gmx.net>
|
||||
#
|
||||
# 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
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user