add separate models for mail addresses, domains and mailboxes
This commit is contained in:
parent
402c02203d
commit
618a9b8c11
5 changed files with 343 additions and 8 deletions
|
@ -1,11 +1,64 @@
|
|||
from django.db import models
|
||||
from django.utils.encoding import python_2_unicode_compatible
|
||||
from django.utils.translation import ugettext as _
|
||||
from passlib.hash import sha512_crypt
|
||||
|
||||
|
||||
@python_2_unicode_compatible
|
||||
class MailDomain(models.Model):
|
||||
domain = models.CharField(max_length=128, unique=True)
|
||||
|
||||
class Meta:
|
||||
verbose_name = _('Mail domain')
|
||||
verbose_name_plural = _('Mail domains')
|
||||
|
||||
def __str__(self):
|
||||
return self.domain
|
||||
|
||||
|
||||
class Mailbox(models.Model):
|
||||
username = models.CharField(max_length=128)
|
||||
domain = models.CharField(max_length=128)
|
||||
password = models.CharField(max_length=64)
|
||||
username = models.CharField(max_length=128, unique=True)
|
||||
domain = models.ForeignKey(MailDomain)
|
||||
password = models.CharField(max_length=255)
|
||||
home = models.CharField(max_length=255)
|
||||
uid = models.PositiveSmallIntegerField()
|
||||
gid = models.PositiveSmallIntegerField()
|
||||
active = models.BooleanField(default=True)
|
||||
|
||||
class Meta:
|
||||
verbose_name = _('Mailbox')
|
||||
verbose_name_plural = _('Mailboxes')
|
||||
|
||||
def set_password(self, password):
|
||||
self.password = sha512_crypt.encrypt(password)
|
||||
|
||||
|
||||
@python_2_unicode_compatible
|
||||
class MailAddress(models.Model):
|
||||
localpart = models.CharField(max_length=128)
|
||||
domain = models.ForeignKey(MailDomain)
|
||||
active = models.BooleanField(default=True)
|
||||
|
||||
class Meta:
|
||||
unique_together = ('localpart', 'domain')
|
||||
verbose_name = _('Mail address')
|
||||
verbose_name_plural = _('Mail addresses')
|
||||
|
||||
def __str__(self):
|
||||
return "{0}@{1}".format(self.localpart, self.domain)
|
||||
|
||||
|
||||
class MailAddressMailbox(models.Model):
|
||||
mailaddress = models.ForeignKey(MailAddress)
|
||||
mailbox = models.ForeignKey(Mailbox)
|
||||
|
||||
class Meta:
|
||||
unique_together = ('mailaddress', 'mailbox')
|
||||
|
||||
|
||||
class MailAddressForward(models.Model):
|
||||
mailaddress = models.ForeignKey(MailAddress)
|
||||
target = models.EmailField(max_length=254)
|
||||
|
||||
class Meta:
|
||||
unique_together = ('mailaddress', 'target')
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue