Version 0.6 !!

This commit is contained in:
tonio
2009-06-19 13:54:05 +02:00
parent 968122d50b
commit 55f6c56c9f
19 changed files with 280 additions and 47 deletions
+8 -8
View File
@@ -18,9 +18,7 @@ class Domain(models.Model):
def create_dir(self):
path = "%s/%s" % (settings.STORAGE_PATH, self.name)
if exec_as_vuser("mkdir %s" % path):
return False
return True
return exec_as_vuser("mkdir %s" % path)
def rename_dir(self, newname):
code, output = exec_pipe("sudo -u %s mv %s/%s %s/%s" \
@@ -74,14 +72,16 @@ class Mailbox(models.Model):
except AttributeError:
mbtype = "maildir"
if mbtype == "mbox":
template = ["Inbox", "Drafts", "Sent", "Trash", "Junk"]
for dir in template:
exec_as_vuser("touch %s/%s" % (path, dir))
self.path = "%s/%s/Inbox" % (domain.name, self.address)
else:
template = [".Drafts/", ".Sent/", ".Trash/", ".Junk/"]
for dir in template:
for sdir in ["cur", "new", "tmp"]:
exec_as_vuser("mkdir -p %s/%s/%s" % (path, dir, sdir))
self.path = "%s/%s/" % (domain.name, self.address)
else:
exec_as_vuser("mkdir %s/.maildir/" % path)
exec_as_vuser("mkdir -p %s/.maildir/%s/%s" % (path, dir, sdir))
self.path = "%s/%s/.maildir/" % (domain.name, self.address)
return True
+7
View File
@@ -14,6 +14,7 @@ from mailng.admin.models import Domain, Mailbox, Alias
from forms import MailboxForm, DomainForm, AliasForm, PermissionForm
from mailng.lib.authbackends import crypt_password
from mailng.lib import _render, _ctx_ok, _ctx_ko
from mailng.lib import events
def is_superuser(user):
if not user.is_superuser:
@@ -50,6 +51,7 @@ def newdomain(request):
domain = form.save(commit=False)
if domain.create_dir():
form.save()
events.raiseEvent("CreateDomain", dom=domain)
ctx = _ctx_ok(reverse(admin.views.domains))
return HttpResponse(simplejson.dumps(ctx),
mimetype="application/json")
@@ -98,6 +100,7 @@ def editdomain(request, dom_id):
@permission_required("admin.delete_domain")
def deldomain(request, dom_id):
domain = Domain.objects.get(pk=dom_id)
events.raiseEvent("DeleteDomain", dom=domain)
domain.delete_dir()
domain.delete()
return HttpResponseRedirect('/mailng/admin/')
@@ -157,6 +160,9 @@ def newmailbox(request, dom_id=None):
mb.quota = domain.quota
mb.full_address = "%s@%s" % (mb.address, domain.name)
mb.save()
events.raiseEvent("CreateMailbox", mbox=mb)
ctx = _ctx_ok(reverse(admin.views.mailboxes, args=[domain.id]))
return HttpResponse(simplejson.dumps(ctx),
mimetype="application/json")
@@ -221,6 +227,7 @@ def editmailbox(request, dom_id, mbox_id=None):
@permission_required("admin.delete_mailbox")
def delmailbox(request, dom_id, mbox_id=None):
mb = Mailbox.objects.get(pk=mbox_id)
events.raiseEvent("DeleteMailbox", mbox=mb)
mb.delete_dir()
mb.user.delete()
mb.delete()