当前位置: 首页>>代码示例>>Python>>正文


Python email_utils.split_mailbox函数代码示例

本文整理汇总了Python中modoboa.lib.email_utils.split_mailbox函数的典型用法代码示例。如果您正苦于以下问题:Python split_mailbox函数的具体用法?Python split_mailbox怎么用?Python split_mailbox使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了split_mailbox函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: from_csv

    def from_csv(self, user, row, expected_elements=5):
        """Create a new alias from a CSV file entry

        """
        if len(row) < expected_elements:
            raise BadRequest(_("Invalid line: %s" % row))
        localpart, domname = split_mailbox(row[1].strip())
        try:
            domain = Domain.objects.get(name=domname)
        except Domain.DoesNotExist:
            raise BadRequest(_("Domain '%s' does not exist" % domname))
        if not user.can_access(domain):
            raise PermDeniedException
        try:
            Alias.objects.get(address=localpart, domain__name=domain)
        except Alias.DoesNotExist:
            pass
        else:
            raise Conflict
        self.address = localpart
        self.domain = domain
        self.enabled = (row[2].strip() in ["True", "1", "yes", "y"])
        int_rcpts = []
        ext_rcpts = []
        for rcpt in row[3:]:
            rcpt = rcpt.strip()
            if not rcpt:
                continue
            localpart, domname = split_mailbox(rcpt)
            try:
                Domain.objects.get(name=domname)
            except Domain.DoesNotExist:
                ext_rcpts += [rcpt]
                continue
            try:
                target = Alias.objects.get(
                    domain__name=domname, address=localpart
                )
                if target.full_address == self.full_address:
                    target = None
            except Alias.DoesNotExist:
                target = None
            if target is None:
                try:
                    target = Mailbox.objects.get(address=localpart,
                                                 domain__name=domname)
                except Mailbox.DoesNotExist:
                    raise BadRequest(_("Local recipient %s not found" % rcpt))
            int_rcpts += [target]
        self.save(int_rcpts=int_rcpts, ext_rcpts=ext_rcpts)
        self.post_create(user)
开发者ID:kaxdev,项目名称:modoboa,代码行数:51,代码来源:alias.py

示例2: clean

    def clean(self):
        """Custom fields validation.

        Check if quota is >= 0 only when the domain value is not used.
        """
        cleaned_data = super(AccountFormMail, self).clean()
        condition = (
            not cleaned_data["quota_act"] and
            cleaned_data["quota"] is not None and
            cleaned_data["quota"] < 0)
        if condition:
            self.add_error("quota", _("Must be a positive integer"))
        self.aliases = []
        self.sender_addresses = []
        for name, value in list(cleaned_data.items()):
            if value == "":
                continue
            if name.startswith("aliases"):
                local_part, domname = split_mailbox(value)
                if not models.Domain.objects.filter(name=domname).exists():
                    self.add_error(name, _("Local domain does not exist"))
                    continue
                self.aliases.append(value.lower())
            elif name.startswith("senderaddress"):
                self.sender_addresses.append(value.lower())
        return cleaned_data
开发者ID:whyscream,项目名称:modoboa,代码行数:26,代码来源:account.py

示例3: _update_aliases

 def _update_aliases(self, user, account):
     """Update mailbox aliases."""
     qset = self.mb.aliasrecipient_set.select_related("alias").filter(
         alias__internal=False)
     for ralias in qset:
         if ralias.alias.address not in self.aliases:
             alias = ralias.alias
             ralias.delete()
             if alias.recipients_count > 0:
                 continue
             alias.delete()
         else:
             self.aliases.remove(ralias.alias.address)
     if not self.aliases:
         return
     core_signals.can_create_object.send(
         self.__class__, context=user, object_type="mailbox_aliases",
         count=len(self.aliases))
     core_signals.can_create_object.send(
         self.__class__, context=self.mb.domain,
         object_type="mailbox_aliases", count=len(self.aliases))
     for alias in self.aliases:
         if self.mb.aliasrecipient_set.select_related("alias").filter(
                 alias__address=alias).exists():
             continue
         local_part, domname = split_mailbox(alias)
         al = Alias(address=alias, enabled=account.is_active)
         al.domain = Domain.objects.get(name=domname)
         al.save()
         al.set_recipients([self.mb.full_address])
         al.post_create(user)
开发者ID:iecsp,项目名称:modoboa,代码行数:31,代码来源:account.py

示例4: _migrate_mailboxes

    def _migrate_mailboxes(self, domain, options, creator):
        """Migrate mailboxes of a single domain."""
        print "\tMigrating mailboxes"
        old_mboxes = pf_models.Mailbox.objects \
            .using(options["_from"]).filter(domain=domain.name)
        for old_mb in old_mboxes:
            new_user = core_models.User()
            new_user.username = old_mb.username
            new_user.first_name = old_mb.name.partition(' ')[0]
            new_user.last_name = old_mb.name.partition(' ')[2]
            new_user.email = old_mb.username
            new_user.is_active = old_mb.active
            if old_mb.created:
                new_user.date_joined = old_mb.created
            set_account_password(
                new_user, old_mb.password, options["passwords_scheme"])
            new_user.save(creator=creator, using=options["_to"])
            new_user.role = "SimpleUsers"

            local_part = split_mailbox(old_mb.username)[0]
            new_mb = admin_models.Mailbox(
                user=new_user, address=local_part, domain=domain)
            self._migrate_dates(new_mb, old_mb)
            new_mb.set_quota(old_mb.quota / 1024000, override_rules=True)
            new_mb.save(creator=creator, using=options["_to"])
开发者ID:modoboa,项目名称:modoboa-pfxadmin-migrate,代码行数:25,代码来源:migrate_from_postfixadmin.py

示例5: use_external_recipients_cb

def use_external_recipients_cb(sender, **kwargs):
    localpart, domname = split_mailbox(kwargs['recipients'])
    return (
        AliasPipe.objects.filter(
            address=localpart, domain__name=domname
        ).first() is not None
    )
开发者ID:bearstech,项目名称:modoboa-alias-pipe,代码行数:7,代码来源:modo_extension.py

示例6: _update_aliases

    def _update_aliases(self, user, account):
        """Update mailbox aliases."""
        aliases = []
        for name, value in self.cleaned_data.iteritems():
            if not name.startswith("aliases"):
                continue
            if value == "":
                continue
            aliases.append(value.lower())

        for alias in self.mb.alias_set.all():
            if alias.full_address not in aliases:
                if len(alias.get_recipients()) >= 2:
                    continue
                alias.delete()
            else:
                aliases.remove(alias.full_address)
        if not aliases:
            return
        events.raiseEvent(
            "CanCreate", user, "mailbox_aliases", len(aliases)
        )
        for alias in aliases:
            local_part, domname = split_mailbox(alias)
            try:
                self.mb.alias_set.get(address=local_part, domain__name=domname)
            except Alias.DoesNotExist:
                pass
            else:
                continue
            al = Alias(address=local_part, enabled=account.is_active)
            al.domain = Domain.objects.get(name=domname)
            al.save(int_rcpts=[self.mb])
            al.post_create(user)
开发者ID:kaxdev,项目名称:modoboa,代码行数:34,代码来源:account.py

示例7: account_auto_created

def account_auto_created(sender, user, **kwargs):
    """New account has been auto-created, build the rest."""
    if not param_tools.get_global_parameter("auto_create_domain_and_mailbox"):
        return
    localpart, domname = split_mailbox(user.username)
    if user.role != 'SimpleUsers' and domname is None:
        return
    sadmins = core_models.User.objects.filter(is_superuser=True)
    try:
        domain = models.Domain.objects.get(name=domname)
    except models.Domain.DoesNotExist:
        label = lib.check_if_domain_exists(
            domname, [(models.DomainAlias, _("domain alias"))])
        if label is not None:
            return
        domain = models.Domain(
            name=domname, enabled=True, default_mailbox_quota=0)
        domain.save(creator=sadmins[0])
        for su in sadmins[1:]:
            permissions.grant_access_to_object(su, domain)
    qset = models.Mailbox.objects.filter(domain=domain, address=localpart)
    if not qset.exists():
        mb = models.Mailbox(
            address=localpart, domain=domain, user=user, use_domain_quota=True
        )
        mb.set_quota(override_rules=True)
        mb.save(creator=sadmins[0])
        for su in sadmins[1:]:
            permissions.grant_access_to_object(su, mb)
开发者ID:bearstech,项目名称:modoboa,代码行数:29,代码来源:handlers.py

示例8: get_or_build_user

 def get_or_build_user(self, username, ldap_user):
     """
     This must return a (User, created) 2-tuple for the given
     LDAP user.  username is the Django-friendly username of
     the user. ldap_user.dn is the user's DN and
     ldap_user.attrs contains all of their LDAP attributes.
     """
     group = "SimpleUsers"
     admin_groups = self.global_params["ldap_admin_groups"].split(";")
     for grp in admin_groups:
         if grp.strip() in ldap_user.group_names:
             group = "DomainAdmins"
             break
     if group == "SimpleUsers":
         lpart, domain = split_mailbox(username)
         if domain is None:
             return None
     user, created = User.objects.get_or_create(
         username__iexact=username,
         defaults={
             "username": username.lower(),
             "is_local": False,
             "language": settings.LANGUAGE_CODE
         }
     )
     if created:
         populate_callback(user, group)
     return user, created
开发者ID:brucewu16899,项目名称:modoboa,代码行数:28,代码来源:authbackends.py

示例9: update_from_dict

 def update_from_dict(self, user, values):
     """Update mailbox from a dictionary."""
     newaddress = None
     if values["email"] != self.full_address:
         newaddress = values["email"]
     elif (self.user.group == "SimpleUsers" and
           self.user.username != self.full_address):
         newaddress = self.user.username
     if newaddress is not None:
         local_part, domname = split_mailbox(newaddress)
         domain = Domain.objects.filter(name=domname).first()
         if domain is None:
             raise lib_exceptions.NotFound(_("Domain does not exist"))
         if not user.can_access(domain):
             raise lib_exceptions.PermDeniedException
     if "use_domain_quota" in values:
         self.use_domain_quota = values["use_domain_quota"]
     override_rules = True \
         if not self.quota or user.has_perm("admin.add_domain") \
         else False
     self.set_quota(values["quota"], override_rules)
     if newaddress:
         self.rename(local_part, domain)
     self.save()
     events.raiseEvent("MailboxModified", self)
开发者ID:cubicuboctahedron,项目名称:modoboa,代码行数:25,代码来源:mailbox.py

示例10: get_or_create_user

 def get_or_create_user(self, username, ldap_user):
     """
     This must return a (User, created) 2-tuple for the given
     LDAP user.  username is the Django-friendly username of
     the user. ldap_user.dn is the user's DN and
     ldap_user.attrs contains all of their LDAP attributes.
     """
     group = 'SimpleUsers'
     admin_groups = parameters \
         .get_admin('LDAP_ADMIN_GROUPS', app='core').split(';')
     for grp in admin_groups:
         if grp.strip() in ldap_user.group_names:
             group = 'DomainAdmins'
             break
     if group == 'SimpleUsers':
         lpart, domain = split_mailbox(username)
         if domain is None:
             return None
     user, created = User.objects.get_or_create(
         username__iexact=username,
         defaults={'username': username.lower(), 'is_local': False}
     )
     if created:
         populate_callback(user, group)
     return user, created
开发者ID:Norcoen,项目名称:modoboa,代码行数:25,代码来源:authbackends.py

示例11: from_csv

    def from_csv(self, user, row, expected_elements=5):
        """Create a new alias from a CSV file entry

        """
        if len(row) < expected_elements:
            raise BadRequest(_("Invalid line: %s" % row))
        address = row[1].strip()
        localpart, domname = split_mailbox(address)
        try:
            domain = Domain.objects.get(name=domname)
        except Domain.DoesNotExist:
            raise BadRequest(_("Domain '%s' does not exist" % domname))
        if not user.can_access(domain):
            raise PermDeniedException
        core_signals.can_create_object.send(
            sender="import", context=user, object_type="mailbox_aliases")
        core_signals.can_create_object.send(
            sender="import", context=domain, object_type="mailbox_aliases")
        if Alias.objects.filter(address=address).exists():
            raise Conflict
        self.address = address
        self.domain = domain
        self.enabled = (row[2].strip() in ["True", "1", "yes", "y"])
        self.save()
        self.set_recipients([raddress.strip() for raddress in row[3:]])
        self.post_create(user)
开发者ID:cubicuboctahedron,项目名称:modoboa,代码行数:26,代码来源:alias.py

示例12: update_mailbox

    def update_mailbox(self, user, account):
        newaddress = None
        if self.cleaned_data["email"] != self.mb.full_address:
            newaddress = self.cleaned_data["email"]
        elif (account.group == "SimpleUsers" and
              account.username != self.mb.full_address):
            newaddress = account.username
        if newaddress is not None:
            self.mb.old_full_address = self.mb.full_address
            local_part, domname = split_mailbox(newaddress)
            try:
                domain = Domain.objects.get(name=domname)
            except Domain.DoesNotExist:
                raise NotFound(_("Domain does not exist"))
            if not user.can_access(domain):
                raise PermDeniedException
            self.mb.rename(local_part, domain)

        self.mb.use_domain_quota = self.cleaned_data["quota_act"]
        override_rules = True \
            if not self.mb.quota or user.has_perm("admin.add_domain") \
            else False
        self.mb.set_quota(self.cleaned_data["quota"], override_rules)
        self.mb.save()
        events.raiseEvent('MailboxModified', self.mb)
开发者ID:haitao-wang,项目名称:modoboa,代码行数:25,代码来源:account.py

示例13: account_auto_created

def account_auto_created(user):
    from modoboa.core.models import User
    from modoboa.lib.permissions import grant_access_to_object
    from .lib import check_if_domain_exists

    if parameters.get_admin("AUTO_CREATE_DOMAIN_AND_MAILBOX") == "no":
        return
    localpart, domname = split_mailbox(user.username)
    if user.group != 'SimpleUsers' and domname is None:
        return
    sadmins = User.objects.filter(is_superuser=True)
    try:
        domain = Domain.objects.get(name=domname)
    except Domain.DoesNotExist:
        label = check_if_domain_exists(
            domname, [(DomainAlias, _('domain alias'))])
        if label is not None:
            return
        domain = Domain(name=domname, enabled=True, quota=0)
        domain.save(creator=sadmins[0])
        for su in sadmins[1:]:
            grant_access_to_object(su, domain)
    try:
        mb = Mailbox.objects.get(domain=domain, address=localpart)
    except Mailbox.DoesNotExist:
        mb = Mailbox(
            address=localpart, domain=domain, user=user, use_domain_quota=True
        )
        mb.set_quota(override_rules=True)
        mb.save(creator=sadmins[0])
        for su in sadmins[1:]:
            grant_access_to_object(su, mb)
开发者ID:ezhishui,项目名称:modoboa,代码行数:32,代码来源:callbacks.py

示例14: _create_mailbox

 def _create_mailbox(self, creator, account, data):
     """Create a new Mailbox instance."""
     full_address = data.pop("full_address")
     address, domain_name = email_utils.split_mailbox(full_address)
     domain = get_object_or_404(
         admin_models.Domain, name=domain_name)
     if not creator.can_access(domain):
         raise serializers.ValidationError({
             "domain": _("Permission denied.")})
     try:
         core_signals.can_create_object.send(
             sender=self.__class__, context=creator,
             klass=admin_models.Mailbox)
         core_signals.can_create_object.send(
             sender=self.__class__, context=domain,
             object_type="mailboxes")
     except lib_exceptions.ModoboaException as inst:
         raise serializers.ValidationError({
             "domain": force_text(inst)})
     quota = data.pop("quota", None)
     mb = admin_models.Mailbox(
         user=account, address=address, domain=domain, **data)
     mb.set_quota(quota, creator.has_perm("admin.add_domain"))
     mb.save(creator=creator)
     account.email = full_address
     return mb
开发者ID:bearstech,项目名称:modoboa,代码行数:26,代码来源:serializers.py

示例15: save

 def save(self):
     """Custom save method."""
     usernames = {}
     for name, value in self.cleaned_data.iteritems():
         if not name.startswith("username") or not value:
             continue
         res = re.match(r"[^_]+_(\d+)$", name)
         pos = int(res.group(1)) if res else None
         usernames[value] = pos
     for rule in self.calendar.rules.select_related().all():
         if rule.mailbox.full_address not in usernames:
             rule.delete()
     for username, pos in usernames.iteritems():
         local_part, domname = split_mailbox(username)
         try:
             mbox = Mailbox.objects.get(
                 address=local_part, domain__name=domname
             )
         except Mailbox.DoesNotExist:
             raise BadRequest(_("Mailbox %s does not exist"))
         if pos:
             raccess = self.cleaned_data.get("read_access_%d" % pos, False)
             waccess = self.cleaned_data.get("write_access_%d" % pos, False)
         else:
             raccess = self.cleaned_data.get("read_access", False)
             waccess = self.cleaned_data.get("write_access", False)
         acr, created = AccessRule.objects.get_or_create(
             mailbox=mbox, calendar=self.calendar
         )
         acr.read = raccess
         acr.write = waccess
         acr.save()
开发者ID:disko,项目名称:modoboa-radicale,代码行数:32,代码来源:forms.py


注:本文中的modoboa.lib.email_utils.split_mailbox函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。