From 27e6434132c6355a85fe9c8e3f0308404e482be5 Mon Sep 17 00:00:00 2001 From: Goffi Date: Mon, 25 Jan 2016 18:04:24 +0100 Subject: [PATCH] plugin maildir: added an option to block intercepted normal messages: NOTE: this plugin is old and experimental, it need a good review/cleaning. --- src/plugins/plugin_misc_maildir.py | 32 +++++++++++++++++++----------- 1 file changed, 20 insertions(+), 12 deletions(-) diff --git a/src/plugins/plugin_misc_maildir.py b/src/plugins/plugin_misc_maildir.py index da60f8d1..cabd6b27 100755 --- a/src/plugins/plugin_misc_maildir.py +++ b/src/plugins/plugin_misc_maildir.py @@ -17,27 +17,19 @@ # You should have received a copy of the GNU Affero General Public License # along with this program. If not, see . -from sat.core.i18n import _ +from sat.core.i18n import D_, _ from sat.core.constants import Const as C from sat.core.log import getLogger log = getLogger(__name__) import warnings warnings.filterwarnings('ignore', 'the MimeWriter', DeprecationWarning, 'twisted') # FIXME: to be removed, see http://twistedmatrix.com/trac/ticket/4038 -from twisted.internet import protocol -from twisted.words.protocols import jabber -from twisted.cred import portal, checkers -from twisted.mail import imap4, maildir -from email.parser import Parser +from twisted.mail import maildir import email.message import email.utils -from email.charset import Charset import os -from cStringIO import StringIO -from twisted.internet import reactor from sat.core.exceptions import ProfileUnknownError from sat.memory.persistent import PersistentBinaryDict -from zope.interface import implements PLUGIN_INFO = { "name": "Maildir Plugin", @@ -51,6 +43,9 @@ PLUGIN_INFO = { } MAILDIR_PATH = "Maildir" +CATEGORY = D_("Mail Server") +NAME = D_('Block "normal" messages propagation') +# FIXME: (very) old and (very) experimental code, need a big cleaning/review class MaildirError(Exception): @@ -58,17 +53,30 @@ class MaildirError(Exception): class MaildirBox(object): + params = """ + + + + + + + + """.format(category_name=CATEGORY, + category_label=_(CATEGORY), + name=NAME, + label=_(NAME), + ) def __init__(self, host): log.info(_("Plugin Maildir initialization")) self.host = host + host.memory.updateParams(self.params) self.__observed = {} self.data = {} # list of profile spectific data. key = profile, value = PersistentBinaryDict where key=mailbox name, # and value is a dictionnary with the following value # - cur_idx: value of the current unique integer increment (UID) # - message_id (as returned by MaildirMailbox): a tuple of (UID, [flag1, flag2, ...]) - pList = host.memory.getProfilesList # shorter :) self.__mailboxes = {} # key: profile, value: {boxname: MailboxUser instance} #the triggers @@ -101,7 +109,7 @@ class MaildirBox(object): if mess_type != 'normal': return True self.accessMessageBox("INBOX", profile_key=profile).addMessage(message) - return False + return not self.host.memory.getParamA(NAME, CATEGORY, profile_key=profile) def accessMessageBox(self, boxname, observer=None, profile_key=C.PROF_KEY_NONE): """Create and return a MailboxUser instance