Mercurial > libervia-backend
comparison src/plugins/plugin_misc_maildir.py @ 1837:7a8a19e4fa6c
plugin maildir: added an option to block intercepted normal messages:
NOTE: this plugin is old and experimental, it need a good review/cleaning.
author | Goffi <goffi@goffi.org> |
---|---|
date | Mon, 25 Jan 2016 18:04:24 +0100 |
parents | 3265a2639182 |
children | 2daf7b4c6756 |
comparison
equal
deleted
inserted
replaced
1836:fb94f92dc740 | 1837:7a8a19e4fa6c |
---|---|
15 # GNU Affero General Public License for more details. | 15 # GNU Affero General Public License for more details. |
16 | 16 |
17 # You should have received a copy of the GNU Affero General Public License | 17 # You should have received a copy of the GNU Affero General Public License |
18 # along with this program. If not, see <http://www.gnu.org/licenses/>. | 18 # along with this program. If not, see <http://www.gnu.org/licenses/>. |
19 | 19 |
20 from sat.core.i18n import _ | 20 from sat.core.i18n import D_, _ |
21 from sat.core.constants import Const as C | 21 from sat.core.constants import Const as C |
22 from sat.core.log import getLogger | 22 from sat.core.log import getLogger |
23 log = getLogger(__name__) | 23 log = getLogger(__name__) |
24 import warnings | 24 import warnings |
25 warnings.filterwarnings('ignore', 'the MimeWriter', DeprecationWarning, 'twisted') # FIXME: to be removed, see http://twistedmatrix.com/trac/ticket/4038 | 25 warnings.filterwarnings('ignore', 'the MimeWriter', DeprecationWarning, 'twisted') # FIXME: to be removed, see http://twistedmatrix.com/trac/ticket/4038 |
26 from twisted.internet import protocol | 26 from twisted.mail import maildir |
27 from twisted.words.protocols import jabber | |
28 from twisted.cred import portal, checkers | |
29 from twisted.mail import imap4, maildir | |
30 from email.parser import Parser | |
31 import email.message | 27 import email.message |
32 import email.utils | 28 import email.utils |
33 from email.charset import Charset | |
34 import os | 29 import os |
35 from cStringIO import StringIO | |
36 from twisted.internet import reactor | |
37 from sat.core.exceptions import ProfileUnknownError | 30 from sat.core.exceptions import ProfileUnknownError |
38 from sat.memory.persistent import PersistentBinaryDict | 31 from sat.memory.persistent import PersistentBinaryDict |
39 | 32 |
40 from zope.interface import implements | |
41 | 33 |
42 PLUGIN_INFO = { | 34 PLUGIN_INFO = { |
43 "name": "Maildir Plugin", | 35 "name": "Maildir Plugin", |
44 "import_name": "Maildir", | 36 "import_name": "Maildir", |
45 "type": "Misc", | 37 "type": "Misc", |
49 "handler": "no", | 41 "handler": "no", |
50 "description": _("""Intercept "normal" type messages, and put them in a Maildir type box""") | 42 "description": _("""Intercept "normal" type messages, and put them in a Maildir type box""") |
51 } | 43 } |
52 | 44 |
53 MAILDIR_PATH = "Maildir" | 45 MAILDIR_PATH = "Maildir" |
46 CATEGORY = D_("Mail Server") | |
47 NAME = D_('Block "normal" messages propagation') | |
48 # FIXME: (very) old and (very) experimental code, need a big cleaning/review | |
54 | 49 |
55 | 50 |
56 class MaildirError(Exception): | 51 class MaildirError(Exception): |
57 pass | 52 pass |
58 | 53 |
59 | 54 |
60 class MaildirBox(object): | 55 class MaildirBox(object): |
56 params = """ | |
57 <params> | |
58 <individual> | |
59 <category name='{category_name}' label='{category_label}'> | |
60 <param name='{name}' label='{label}' value="false" type="bool" security="4" /> | |
61 </category> | |
62 </individual> | |
63 </params> | |
64 """.format(category_name=CATEGORY, | |
65 category_label=_(CATEGORY), | |
66 name=NAME, | |
67 label=_(NAME), | |
68 ) | |
61 | 69 |
62 def __init__(self, host): | 70 def __init__(self, host): |
63 log.info(_("Plugin Maildir initialization")) | 71 log.info(_("Plugin Maildir initialization")) |
64 self.host = host | 72 self.host = host |
73 host.memory.updateParams(self.params) | |
65 | 74 |
66 self.__observed = {} | 75 self.__observed = {} |
67 self.data = {} # list of profile spectific data. key = profile, value = PersistentBinaryDict where key=mailbox name, | 76 self.data = {} # list of profile spectific data. key = profile, value = PersistentBinaryDict where key=mailbox name, |
68 # and value is a dictionnary with the following value | 77 # and value is a dictionnary with the following value |
69 # - cur_idx: value of the current unique integer increment (UID) | 78 # - cur_idx: value of the current unique integer increment (UID) |
70 # - message_id (as returned by MaildirMailbox): a tuple of (UID, [flag1, flag2, ...]) | 79 # - message_id (as returned by MaildirMailbox): a tuple of (UID, [flag1, flag2, ...]) |
71 pList = host.memory.getProfilesList # shorter :) | |
72 self.__mailboxes = {} # key: profile, value: {boxname: MailboxUser instance} | 80 self.__mailboxes = {} # key: profile, value: {boxname: MailboxUser instance} |
73 | 81 |
74 #the triggers | 82 #the triggers |
75 host.trigger.add("MessageReceived", self.messageReceivedTrigger) | 83 host.trigger.add("MessageReceived", self.messageReceivedTrigger) |
76 | 84 |
99 if e.name == "body": | 107 if e.name == "body": |
100 mess_type = message['type'] if message.hasAttribute('type') else 'normal' | 108 mess_type = message['type'] if message.hasAttribute('type') else 'normal' |
101 if mess_type != 'normal': | 109 if mess_type != 'normal': |
102 return True | 110 return True |
103 self.accessMessageBox("INBOX", profile_key=profile).addMessage(message) | 111 self.accessMessageBox("INBOX", profile_key=profile).addMessage(message) |
104 return False | 112 return not self.host.memory.getParamA(NAME, CATEGORY, profile_key=profile) |
105 | 113 |
106 def accessMessageBox(self, boxname, observer=None, profile_key=C.PROF_KEY_NONE): | 114 def accessMessageBox(self, boxname, observer=None, profile_key=C.PROF_KEY_NONE): |
107 """Create and return a MailboxUser instance | 115 """Create and return a MailboxUser instance |
108 @param boxname: name of the box | 116 @param boxname: name of the box |
109 @param observer: method to call when a NewMessage arrive""" | 117 @param observer: method to call when a NewMessage arrive""" |