plugin maildir: added an option to block intercepted normal messages:
NOTE: this plugin is old and experimental, it need a good review/cleaning.
This commit is contained in:
parent
d7bca38b31
commit
27e6434132
1 changed files with 20 additions and 12 deletions
|
|
@ -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 @@ 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 = """
|
||||
<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 @@ 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
|
||||
|
|
|
|||
Loading…
Reference in a new issue