mirror of
https://github.com/jwinterm/modoboa.git
synced 2026-10-21 06:18:45 +02:00
Important update of the plugin engine.
New plugin that allows the handling of an Amavisd-new SQL quarantine. NB: a DB connections manager has been added inside the lib because Django does not support multiple connections at the same time. The main consequence is that we don't use an ORM and that we have to rewrite a small wrapper that supports several DB (mysql, postgresql, etc.). Adding a dependancy to an existing ORM module (like SQLalchemy) is heavy, we don't want that for now.
This commit is contained in:
@@ -0,0 +1,22 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
"""
|
||||
|
||||
"""
|
||||
connections = {}
|
||||
|
||||
def mysql_newconnection(host, dbname, login, password):
|
||||
import MySQLdb
|
||||
return MySQLdb.connect(host=host, db=dbname, user=login, passwd=password)
|
||||
|
||||
def getconnection(name):
|
||||
if not name in connections.keys():
|
||||
from django.conf import settings
|
||||
|
||||
cfg = settings.DB_CONNECTIONS[name]
|
||||
if cfg["driver"] == "mysql":
|
||||
conn = mysql_newconnection(cfg["host"], cfg["dbname"], cfg["login"],
|
||||
cfg["password"])
|
||||
connections[name] = conn
|
||||
return connections[name]
|
||||
|
||||
+11
-1
@@ -9,7 +9,9 @@ core application and additional components.
|
||||
events = ["CreateDomain",
|
||||
"DeleteDomain",
|
||||
"CreateMailbox",
|
||||
"DeleteMailbox"]
|
||||
"DeleteMailbox",
|
||||
|
||||
"UserMenuDisplay"]
|
||||
|
||||
callbacks = {}
|
||||
|
||||
@@ -27,3 +29,11 @@ def raiseEvent(event, **kwargs):
|
||||
for callback in callbacks[event]:
|
||||
callback(**kwargs)
|
||||
return 1
|
||||
|
||||
def raiseQueryEvent(event, **kwargs):
|
||||
result = []
|
||||
if not event in events or not event in callbacks.keys():
|
||||
return result
|
||||
for callback in callbacks[event]:
|
||||
result += callback(**kwargs)
|
||||
return result
|
||||
|
||||
Reference in New Issue
Block a user