VirtualMailManager/alias.py
branchv0.6.x
changeset 417 8209da83e256
parent 379 7518d927d443
child 424 46c296c6e231
equal deleted inserted replaced
416:f32b323fd347 417:8209da83e256
    29         assert isinstance(address, EmailAddress)
    29         assert isinstance(address, EmailAddress)
    30         self._addr = address
    30         self._addr = address
    31         self._dbh = dbh
    31         self._dbh = dbh
    32         self._gid = get_gid(self._dbh, self._addr.domainname)
    32         self._gid = get_gid(self._dbh, self._addr.domainname)
    33         if not self._gid:
    33         if not self._gid:
    34             raise AErr(_(u"The domain '%s' doesn't exist.") %
    34             raise AErr(_(u"The domain '%s' does not exist.") %
    35                        self._addr.domainname, NO_SUCH_DOMAIN)
    35                        self._addr.domainname, NO_SUCH_DOMAIN)
    36         self._dests = []
    36         self._dests = []
    37 
    37 
    38         self._load_dests()
    38         self._load_dests()
    39 
    39 
    54         dcount = len(self._dests)
    54         dcount = len(self._dests)
    55         failed = False
    55         failed = False
    56         if dcount == limit or dcount + count_new > limit:
    56         if dcount == limit or dcount + count_new > limit:
    57             failed = True
    57             failed = True
    58             errmsg = _(
    58             errmsg = _(
    59 u"""Can't add %(count_new)i new destination(s) to alias '%(address)s'.
    59 u"""Cannot add %(count_new)i new destination(s) to alias '%(address)s'.
    60 Currently this alias expands into %(count)i/%(limit)i recipients.
    60 Currently this alias expands into %(count)i/%(limit)i recipients.
    61 %(count_new)i additional destination(s) will render this alias unusable.
    61 %(count_new)i additional destination(s) will render this alias unusable.
    62 Hint: Increase Postfix' virtual_alias_expansion_limit""")
    62 Hint: Increase Postfix' virtual_alias_expansion_limit""")
    63         elif dcount > limit:
    63         elif dcount > limit:
    64             failed = True
    64             failed = True
    65             errmsg = _(
    65             errmsg = _(
    66 u"""Can't add %(count_new)i new destination(s) to alias '%(address)s'.
    66 u"""Cannot add %(count_new)i new destination(s) to alias '%(address)s'.
    67 This alias already exceeds its expansion limit (%(count)i/%(limit)i).
    67 This alias already exceeds its expansion limit (%(count)i/%(limit)i).
    68 So its unusable, all messages addressed to this alias will be bounced.
    68 So its unusable, all messages addressed to this alias will be bounced.
    69 Hint: Delete some destination addresses.""")
    69 Hint: Delete some destination addresses.""")
    70         if failed:
    70         if failed:
    71             raise AErr(errmsg % {'address': self._addr, 'count': dcount,
    71             raise AErr(errmsg % {'address': self._addr, 'count': dcount,
   136 
   136 
   137     def del_destination(self, destination):
   137     def del_destination(self, destination):
   138         """Deletes the specified ``destination`` address from the alias."""
   138         """Deletes the specified ``destination`` address from the alias."""
   139         assert isinstance(destination, EmailAddress)
   139         assert isinstance(destination, EmailAddress)
   140         if not self._dests:
   140         if not self._dests:
   141             raise AErr(_(u"The alias '%s' doesn't exist.") % self._addr,
   141             raise AErr(_(u"The alias '%s' does not exist.") % self._addr,
   142                        NO_SUCH_ALIAS)
   142                        NO_SUCH_ALIAS)
   143         if not destination in self._dests:
   143         if not destination in self._dests:
   144             raise AErr(_(u"The address '%(addr)s' isn't a destination of "
   144             raise AErr(_(u"The address '%(addr)s' is not a destination of "
   145                          u"the alias '%(alias)s'.") % {'addr': self._addr,
   145                          u"the alias '%(alias)s'.") % {'addr': self._addr,
   146                        'alias': destination}, NO_SUCH_ALIAS)
   146                        'alias': destination}, NO_SUCH_ALIAS)
   147         self._delete(destination)
   147         self._delete(destination)
   148         self._dests.remove(destination)
   148         self._dests.remove(destination)
   149 
   149 
   150     def get_destinations(self):
   150     def get_destinations(self):
   151         """Returns an iterator for all destinations of the alias."""
   151         """Returns an iterator for all destinations of the alias."""
   152         if not self._dests:
   152         if not self._dests:
   153             raise AErr(_(u"The alias '%s' doesn't exist.") % self._addr,
   153             raise AErr(_(u"The alias '%s' does not exist.") % self._addr,
   154                        NO_SUCH_ALIAS)
   154                        NO_SUCH_ALIAS)
   155         return iter(self._dests)
   155         return iter(self._dests)
   156 
   156 
   157     def delete(self):
   157     def delete(self):
   158         """Deletes the alias with all its destinations."""
   158         """Deletes the alias with all its destinations."""
   159         if not self._dests:
   159         if not self._dests:
   160             raise AErr(_(u"The alias '%s' doesn't exist.") % self._addr,
   160             raise AErr(_(u"The alias '%s' does not exist.") % self._addr,
   161                        NO_SUCH_ALIAS)
   161                        NO_SUCH_ALIAS)
   162         self._delete()
   162         self._delete()
   163         del self._dests[:]
   163         del self._dests[:]
   164 
   164 
   165 del _, cfg_dget
   165 del _, cfg_dget