VirtualMailManager/alias.py
branchv0.7.x
changeset 643 df1e3b67882a
parent 637 ca6621caff2f
child 676 2bc11dada296
equal deleted inserted replaced
642:4cd9d0a9f42f 643:df1e3b67882a
    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' does not exist.") %
    34             raise AErr(_("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 
    49         dbc.close()
    49         dbc.close()
    50 
    50 
    51     def _check_expansion(self, count_new):
    51     def _check_expansion(self, count_new):
    52         """Checks the current expansion limit of the alias."""
    52         """Checks the current expansion limit of the alias."""
    53         postconf = Postconf(cfg_dget('bin.postconf'))
    53         postconf = Postconf(cfg_dget('bin.postconf'))
    54         limit = long(postconf.read('virtual_alias_expansion_limit'))
    54         limit = int(postconf.read('virtual_alias_expansion_limit'))
    55         dcount = len(self._dests)
    55         dcount = len(self._dests)
    56         failed = False
    56         failed = False
    57         if dcount == limit or dcount + count_new > limit:
    57         if dcount == limit or dcount + count_new > limit:
    58             failed = True
    58             failed = True
    59             errmsg = _(
    59             errmsg = _(
    60 u"""Cannot add %(count_new)i new destination(s) to alias '%(address)s'.
    60 """Cannot add %(count_new)i new destination(s) to alias '%(address)s'.
    61 Currently this alias expands into %(count)i/%(limit)i recipients.
    61 Currently this alias expands into %(count)i/%(limit)i recipients.
    62 %(count_new)i additional destination(s) will render this alias unusable.
    62 %(count_new)i additional destination(s) will render this alias unusable.
    63 Hint: Increase Postfix' virtual_alias_expansion_limit""")
    63 Hint: Increase Postfix' virtual_alias_expansion_limit""")
    64         elif dcount > limit:
    64         elif dcount > limit:
    65             failed = True
    65             failed = True
    66             errmsg = _(
    66             errmsg = _(
    67 u"""Cannot add %(count_new)i new destination(s) to alias '%(address)s'.
    67 """Cannot add %(count_new)i new destination(s) to alias '%(address)s'.
    68 This alias already exceeds its expansion limit (%(count)i/%(limit)i).
    68 This alias already exceeds its expansion limit (%(count)i/%(limit)i).
    69 So its unusable, all messages addressed to this alias will be bounced.
    69 So its unusable, all messages addressed to this alias will be bounced.
    70 Hint: Delete some destination addresses.""")
    70 Hint: Delete some destination addresses.""")
    71         if failed:
    71         if failed:
    72             raise AErr(errmsg % {'address': self._addr, 'count': dcount,
    72             raise AErr(errmsg % {'address': self._addr, 'count': dcount,
   149         if self._addr in destinations:
   149         if self._addr in destinations:
   150             destinations.remove(self._addr)
   150             destinations.remove(self._addr)
   151             if not warnings is None:
   151             if not warnings is None:
   152                 warnings.append(self._addr)
   152                 warnings.append(self._addr)
   153         if not self._dests:
   153         if not self._dests:
   154             raise AErr(_(u"The alias '%s' does not exist.") % self._addr,
   154             raise AErr(_("The alias '%s' does not exist.") % self._addr,
   155                        NO_SUCH_ALIAS)
   155                        NO_SUCH_ALIAS)
   156         unknown = destinations.difference(set(self._dests))
   156         unknown = destinations.difference(set(self._dests))
   157         if unknown:
   157         if unknown:
   158             destinations.intersection_update(set(self._dests))
   158             destinations.intersection_update(set(self._dests))
   159             if not warnings is None:
   159             if not warnings is None:
   160                 warnings.extend(unknown)
   160                 warnings.extend(unknown)
   161         if not destinations:
   161         if not destinations:
   162             raise AErr(_(u"No suitable destinations left to remove from alias "
   162             raise AErr(_("No suitable destinations left to remove from alias "
   163                          u"'%s'.") % self._addr, NO_SUCH_ALIAS)
   163                          "'%s'.") % self._addr, NO_SUCH_ALIAS)
   164         self._delete(destinations)
   164         self._delete(destinations)
   165         for destination in destinations:
   165         for destination in destinations:
   166             self._dests.remove(destination)
   166             self._dests.remove(destination)
   167 
   167 
   168     def get_destinations(self):
   168     def get_destinations(self):
   169         """Returns an iterator for all destinations of the alias."""
   169         """Returns an iterator for all destinations of the alias."""
   170         if not self._dests:
   170         if not self._dests:
   171             raise AErr(_(u"The alias '%s' does not exist.") % self._addr,
   171             raise AErr(_("The alias '%s' does not exist.") % self._addr,
   172                        NO_SUCH_ALIAS)
   172                        NO_SUCH_ALIAS)
   173         return iter(self._dests)
   173         return iter(self._dests)
   174 
   174 
   175     def delete(self):
   175     def delete(self):
   176         """Deletes the alias with all its destinations."""
   176         """Deletes the alias with all its destinations."""
   177         if not self._dests:
   177         if not self._dests:
   178             raise AErr(_(u"The alias '%s' does not exist.") % self._addr,
   178             raise AErr(_("The alias '%s' does not exist.") % self._addr,
   179                        NO_SUCH_ALIAS)
   179                        NO_SUCH_ALIAS)
   180         self._delete()
   180         self._delete()
   181         del self._dests[:]
   181         del self._dests[:]
   182 
   182 
   183 del _, cfg_dget
   183 del _, cfg_dget