Mercurial > libervia-backend
changeset 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 | fb94f92dc740 |
children | b3b25dbac585 |
files | src/plugins/plugin_misc_maildir.py |
diffstat | 1 files changed, 20 insertions(+), 12 deletions(-) [+] |
line wrap: on
line diff
--- a/src/plugins/plugin_misc_maildir.py Mon Jan 25 17:03:45 2016 +0100 +++ b/src/plugins/plugin_misc_maildir.py Mon Jan 25 18:04:24 2016 +0100 @@ -17,27 +17,19 @@ # You should have received a copy of the GNU Affero General Public License # along with this program. If not, see <http://www.gnu.org/licenses/>. -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 @@ } 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 MaildirBox(object): + params = """ + <params> + <individual> + <category name='{category_name}' label='{category_label}'> + <param name='{name}' label='{label}' value="false" type="bool" security="4" /> + </category> + </individual> + </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 @@ 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