mirror of
https://github.com/jwinterm/modoboa.git
synced 2026-11-27 11:24:28 +01:00
First working version of the new 'message filters' plugin. Currently, only the raw edition mode is available. I also include my own MANAGESIEVE client implementation.
see #139
This commit is contained in:
+33
-11
@@ -12,6 +12,7 @@ from django.template.loader import render_to_string
|
||||
from django.utils.translation import ugettext as _
|
||||
from django.utils import simplejson
|
||||
from modoboa.lib import parameters
|
||||
from modoboa.auth.lib import decrypt
|
||||
|
||||
def exec_cmd(cmd, **kwargs):
|
||||
import subprocess
|
||||
@@ -94,6 +95,8 @@ def ajax_response(request, status="ok", respmsg=None,
|
||||
ctx[k] = v
|
||||
if template is not None:
|
||||
content = _render_to_string(request, template, ctx)
|
||||
elif kwargs.has_key("content"):
|
||||
content = kwargs["content"]
|
||||
else:
|
||||
content = ""
|
||||
jsonctx = {"status" : status, "content" : content}
|
||||
@@ -156,17 +159,6 @@ def db_table_exists(table, cursor=None):
|
||||
else:
|
||||
return table in table_names
|
||||
|
||||
class Singleton(type):
|
||||
def __init__(cls, name, bases, dict):
|
||||
super(Singleton, cls).__init__(name, bases, dict)
|
||||
cls.instance = None
|
||||
|
||||
def __call__(cls, *args, **kwargs):
|
||||
if cls.instance is None:
|
||||
cls.instance = super(Singleton, cls).__call__(*args, **kwargs)
|
||||
return cls.instance
|
||||
|
||||
|
||||
def _check_password(password, crypted):
|
||||
scheme = parameters.get_admin("PASSWORD_SCHEME", app="admin")
|
||||
if scheme == "crypt":
|
||||
@@ -193,3 +185,33 @@ def split_mailbox(mailbox):
|
||||
domain = parts[-1]
|
||||
address = "@".join(parts[:-1])
|
||||
return (address, domain)
|
||||
|
||||
class ConnectionsManager(type):
|
||||
"""Singleton pattern implementation
|
||||
|
||||
This class is specialized in connection management.
|
||||
"""
|
||||
def __init__(cls, name, bases, dict):
|
||||
super(ConnectionsManager, cls).__init__(name, bases, dict)
|
||||
cls.instances = {}
|
||||
|
||||
def __call__(cls, **kwargs):
|
||||
key = None
|
||||
if kwargs.has_key("user"):
|
||||
key = kwargs["user"]
|
||||
else:
|
||||
return None
|
||||
if not cls.instances.has_key(key):
|
||||
cls.instances[key] = None
|
||||
if kwargs.has_key("password"):
|
||||
kwargs["password"] = decrypt(kwargs["password"])
|
||||
|
||||
if cls.instances[key] is None:
|
||||
cls.instances[key] = \
|
||||
super(ConnectionsManager, cls).__call__(**kwargs)
|
||||
else:
|
||||
cls.instances[key].refresh(key, kwargs["password"])
|
||||
return cls.instances[key]
|
||||
|
||||
class ConnectionError(Exception):
|
||||
pass
|
||||
|
||||
@@ -0,0 +1,73 @@
|
||||
# encoding: utf-8
|
||||
import datetime
|
||||
from south.db import db
|
||||
from south.v2 import DataMigration
|
||||
from django.db import models
|
||||
|
||||
class Migration(DataMigration):
|
||||
|
||||
def forwards(self, orm):
|
||||
"Write your forwards methods here."
|
||||
p = orm.Parameter.objects.get(name="webmail.SECRET_KEY")
|
||||
p.name = "auth.SECRET_KEY"
|
||||
p.save()
|
||||
|
||||
def backwards(self, orm):
|
||||
"Write your backwards methods here."
|
||||
p = orm.Parameter.objects.get(name="auth.SECRET_KEY")
|
||||
p.name = "webmail.SECRET_KEY"
|
||||
p.save()
|
||||
|
||||
models = {
|
||||
'auth.group': {
|
||||
'Meta': {'object_name': 'Group'},
|
||||
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
|
||||
'name': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '80'}),
|
||||
'permissions': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['auth.Permission']", 'symmetrical': 'False', 'blank': 'True'})
|
||||
},
|
||||
'auth.permission': {
|
||||
'Meta': {'ordering': "('content_type__app_label', 'content_type__model', 'codename')", 'unique_together': "(('content_type', 'codename'),)", 'object_name': 'Permission'},
|
||||
'codename': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
|
||||
'content_type': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['contenttypes.ContentType']"}),
|
||||
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
|
||||
'name': ('django.db.models.fields.CharField', [], {'max_length': '50'})
|
||||
},
|
||||
'auth.user': {
|
||||
'Meta': {'object_name': 'User'},
|
||||
'date_joined': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime.now'}),
|
||||
'email': ('django.db.models.fields.EmailField', [], {'max_length': '75', 'blank': 'True'}),
|
||||
'first_name': ('django.db.models.fields.CharField', [], {'max_length': '30', 'blank': 'True'}),
|
||||
'groups': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['auth.Group']", 'symmetrical': 'False', 'blank': 'True'}),
|
||||
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
|
||||
'is_active': ('django.db.models.fields.BooleanField', [], {'default': 'True'}),
|
||||
'is_staff': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
|
||||
'is_superuser': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
|
||||
'last_login': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime.now'}),
|
||||
'last_name': ('django.db.models.fields.CharField', [], {'max_length': '30', 'blank': 'True'}),
|
||||
'password': ('django.db.models.fields.CharField', [], {'max_length': '128'}),
|
||||
'user_permissions': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['auth.Permission']", 'symmetrical': 'False', 'blank': 'True'}),
|
||||
'username': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '30'})
|
||||
},
|
||||
'contenttypes.contenttype': {
|
||||
'Meta': {'ordering': "('name',)", 'unique_together': "(('app_label', 'model'),)", 'object_name': 'ContentType', 'db_table': "'django_content_type'"},
|
||||
'app_label': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
|
||||
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
|
||||
'model': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
|
||||
'name': ('django.db.models.fields.CharField', [], {'max_length': '100'})
|
||||
},
|
||||
'lib.parameter': {
|
||||
'Meta': {'object_name': 'Parameter'},
|
||||
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
|
||||
'name': ('django.db.models.fields.CharField', [], {'max_length': '255'}),
|
||||
'value': ('django.db.models.fields.CharField', [], {'max_length': '255'})
|
||||
},
|
||||
'lib.userparameter': {
|
||||
'Meta': {'object_name': 'UserParameter'},
|
||||
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
|
||||
'name': ('django.db.models.fields.CharField', [], {'max_length': '255'}),
|
||||
'user': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['auth.User']"}),
|
||||
'value': ('django.db.models.fields.CharField', [], {'max_length': '255'})
|
||||
}
|
||||
}
|
||||
|
||||
complete_apps = ['lib']
|
||||
Reference in New Issue
Block a user