VirtualMailManager/catchall.py
author Pascal Volk <user@localhost.localdomain.org>
Sun, 16 Sep 2012 17:05:33 +0000
changeset 614 1ec3497a6733
parent 611 8e9b0046bc8f
child 618 d8736bb80bdc
permissions -rw-r--r--
VMM: Moved transport-validation to common.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
504
f180ead60568 First version of a CatchallAlias class
martin f. krafft <madduck@madduck.net>
parents:
diff changeset
     1
# -*- coding: UTF-8 -*-
f180ead60568 First version of a CatchallAlias class
martin f. krafft <madduck@madduck.net>
parents:
diff changeset
     2
# Copyright (c) 2012 martin f. krafft
f180ead60568 First version of a CatchallAlias class
martin f. krafft <madduck@madduck.net>
parents:
diff changeset
     3
# See COPYING for distribution information.
f180ead60568 First version of a CatchallAlias class
martin f. krafft <madduck@madduck.net>
parents:
diff changeset
     4
"""
f180ead60568 First version of a CatchallAlias class
martin f. krafft <madduck@madduck.net>
parents:
diff changeset
     5
    VirtualMailManager.catchall
f180ead60568 First version of a CatchallAlias class
martin f. krafft <madduck@madduck.net>
parents:
diff changeset
     6
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~
f180ead60568 First version of a CatchallAlias class
martin f. krafft <madduck@madduck.net>
parents:
diff changeset
     7
f180ead60568 First version of a CatchallAlias class
martin f. krafft <madduck@madduck.net>
parents:
diff changeset
     8
    Virtual Mail Manager's CatchallAlias class to manage domain catch-all
f180ead60568 First version of a CatchallAlias class
martin f. krafft <madduck@madduck.net>
parents:
diff changeset
     9
    aliases.
f180ead60568 First version of a CatchallAlias class
martin f. krafft <madduck@madduck.net>
parents:
diff changeset
    10
f180ead60568 First version of a CatchallAlias class
martin f. krafft <madduck@madduck.net>
parents:
diff changeset
    11
    This is heavily based on (more or less a copy of) the Alias class, because
f180ead60568 First version of a CatchallAlias class
martin f. krafft <madduck@madduck.net>
parents:
diff changeset
    12
    fundamentally, catchall aliases are aliases, but without a localpart.
f180ead60568 First version of a CatchallAlias class
martin f. krafft <madduck@madduck.net>
parents:
diff changeset
    13
    While Alias could potentially derive from CatchallAlias to reuse some of
f180ead60568 First version of a CatchallAlias class
martin f. krafft <madduck@madduck.net>
parents:
diff changeset
    14
    the functionality, it's probably not worth it. I found no sensible way to
f180ead60568 First version of a CatchallAlias class
martin f. krafft <madduck@madduck.net>
parents:
diff changeset
    15
    derive CatchallAlias from Alias, or at least none that would harness the
f180ead60568 First version of a CatchallAlias class
martin f. krafft <madduck@madduck.net>
parents:
diff changeset
    16
    powers of polymorphism.
f180ead60568 First version of a CatchallAlias class
martin f. krafft <madduck@madduck.net>
parents:
diff changeset
    17
f180ead60568 First version of a CatchallAlias class
martin f. krafft <madduck@madduck.net>
parents:
diff changeset
    18
    Yet, we reuse the AliasError exception class, which makes sense.
f180ead60568 First version of a CatchallAlias class
martin f. krafft <madduck@madduck.net>
parents:
diff changeset
    19
"""
f180ead60568 First version of a CatchallAlias class
martin f. krafft <madduck@madduck.net>
parents:
diff changeset
    20
f180ead60568 First version of a CatchallAlias class
martin f. krafft <madduck@madduck.net>
parents:
diff changeset
    21
from VirtualMailManager.domain import get_gid
f180ead60568 First version of a CatchallAlias class
martin f. krafft <madduck@madduck.net>
parents:
diff changeset
    22
from VirtualMailManager.emailaddress import \
f180ead60568 First version of a CatchallAlias class
martin f. krafft <madduck@madduck.net>
parents:
diff changeset
    23
     EmailAddress, DestinationEmailAddress as DestAddr
f180ead60568 First version of a CatchallAlias class
martin f. krafft <madduck@madduck.net>
parents:
diff changeset
    24
from VirtualMailManager.errors import AliasError as AErr
f180ead60568 First version of a CatchallAlias class
martin f. krafft <madduck@madduck.net>
parents:
diff changeset
    25
from VirtualMailManager.ext.postconf import Postconf
f180ead60568 First version of a CatchallAlias class
martin f. krafft <madduck@madduck.net>
parents:
diff changeset
    26
from VirtualMailManager.pycompat import all
f180ead60568 First version of a CatchallAlias class
martin f. krafft <madduck@madduck.net>
parents:
diff changeset
    27
from VirtualMailManager.constants import \
f180ead60568 First version of a CatchallAlias class
martin f. krafft <madduck@madduck.net>
parents:
diff changeset
    28
     ALIAS_EXCEEDS_EXPANSION_LIMIT, NO_SUCH_ALIAS, NO_SUCH_DOMAIN
f180ead60568 First version of a CatchallAlias class
martin f. krafft <madduck@madduck.net>
parents:
diff changeset
    29
f180ead60568 First version of a CatchallAlias class
martin f. krafft <madduck@madduck.net>
parents:
diff changeset
    30
f180ead60568 First version of a CatchallAlias class
martin f. krafft <madduck@madduck.net>
parents:
diff changeset
    31
_ = lambda msg: msg
f180ead60568 First version of a CatchallAlias class
martin f. krafft <madduck@madduck.net>
parents:
diff changeset
    32
cfg_dget = lambda option: None
f180ead60568 First version of a CatchallAlias class
martin f. krafft <madduck@madduck.net>
parents:
diff changeset
    33
f180ead60568 First version of a CatchallAlias class
martin f. krafft <madduck@madduck.net>
parents:
diff changeset
    34
f180ead60568 First version of a CatchallAlias class
martin f. krafft <madduck@madduck.net>
parents:
diff changeset
    35
class CatchallAlias(object):
f180ead60568 First version of a CatchallAlias class
martin f. krafft <madduck@madduck.net>
parents:
diff changeset
    36
    """Class to manage domain catch-all aliases."""
f180ead60568 First version of a CatchallAlias class
martin f. krafft <madduck@madduck.net>
parents:
diff changeset
    37
    __slots__ = ('_domain', '_dests', '_gid', '_dbh')
f180ead60568 First version of a CatchallAlias class
martin f. krafft <madduck@madduck.net>
parents:
diff changeset
    38
f180ead60568 First version of a CatchallAlias class
martin f. krafft <madduck@madduck.net>
parents:
diff changeset
    39
    def __init__(self, dbh, domain):
f180ead60568 First version of a CatchallAlias class
martin f. krafft <madduck@madduck.net>
parents:
diff changeset
    40
        self._domain = domain
f180ead60568 First version of a CatchallAlias class
martin f. krafft <madduck@madduck.net>
parents:
diff changeset
    41
        self._dbh = dbh
507
2aae58cddfa9 Correct syntax errors
martin f. krafft <madduck@madduck.net>
parents: 504
diff changeset
    42
        self._gid = get_gid(self._dbh, self.domain)
504
f180ead60568 First version of a CatchallAlias class
martin f. krafft <madduck@madduck.net>
parents:
diff changeset
    43
        if not self._gid:
f180ead60568 First version of a CatchallAlias class
martin f. krafft <madduck@madduck.net>
parents:
diff changeset
    44
            raise AErr(_(u"The domain '%s' does not exist.") %
513
557c4703986c Fix syntax errors
martin f. krafft <madduck@madduck.net>
parents: 509
diff changeset
    45
                       self.domain, NO_SUCH_DOMAIN)
504
f180ead60568 First version of a CatchallAlias class
martin f. krafft <madduck@madduck.net>
parents:
diff changeset
    46
        self._dests = []
f180ead60568 First version of a CatchallAlias class
martin f. krafft <madduck@madduck.net>
parents:
diff changeset
    47
f180ead60568 First version of a CatchallAlias class
martin f. krafft <madduck@madduck.net>
parents:
diff changeset
    48
        self._load_dests()
f180ead60568 First version of a CatchallAlias class
martin f. krafft <madduck@madduck.net>
parents:
diff changeset
    49
f180ead60568 First version of a CatchallAlias class
martin f. krafft <madduck@madduck.net>
parents:
diff changeset
    50
    def _load_dests(self):
f180ead60568 First version of a CatchallAlias class
martin f. krafft <madduck@madduck.net>
parents:
diff changeset
    51
        """Loads all known destination addresses into the _dests list."""
f180ead60568 First version of a CatchallAlias class
martin f. krafft <madduck@madduck.net>
parents:
diff changeset
    52
        dbc = self._dbh.cursor()
f180ead60568 First version of a CatchallAlias class
martin f. krafft <madduck@madduck.net>
parents:
diff changeset
    53
        dbc.execute('SELECT destination FROM catchall WHERE gid = %s',
507
2aae58cddfa9 Correct syntax errors
martin f. krafft <madduck@madduck.net>
parents: 504
diff changeset
    54
                    (self._gid,))
504
f180ead60568 First version of a CatchallAlias class
martin f. krafft <madduck@madduck.net>
parents:
diff changeset
    55
        dests = dbc.fetchall()
f180ead60568 First version of a CatchallAlias class
martin f. krafft <madduck@madduck.net>
parents:
diff changeset
    56
        if dbc.rowcount > 0:
f180ead60568 First version of a CatchallAlias class
martin f. krafft <madduck@madduck.net>
parents:
diff changeset
    57
            self._dests.extend(DestAddr(dest[0], self._dbh) for dest in dests)
f180ead60568 First version of a CatchallAlias class
martin f. krafft <madduck@madduck.net>
parents:
diff changeset
    58
        dbc.close()
f180ead60568 First version of a CatchallAlias class
martin f. krafft <madduck@madduck.net>
parents:
diff changeset
    59
f180ead60568 First version of a CatchallAlias class
martin f. krafft <madduck@madduck.net>
parents:
diff changeset
    60
    def _check_expansion(self, count_new):
f180ead60568 First version of a CatchallAlias class
martin f. krafft <madduck@madduck.net>
parents:
diff changeset
    61
        """Checks the current expansion limit of the alias."""
f180ead60568 First version of a CatchallAlias class
martin f. krafft <madduck@madduck.net>
parents:
diff changeset
    62
        postconf = Postconf(cfg_dget('bin.postconf'))
f180ead60568 First version of a CatchallAlias class
martin f. krafft <madduck@madduck.net>
parents:
diff changeset
    63
        limit = long(postconf.read('virtual_alias_expansion_limit'))
f180ead60568 First version of a CatchallAlias class
martin f. krafft <madduck@madduck.net>
parents:
diff changeset
    64
        dcount = len(self._dests)
f180ead60568 First version of a CatchallAlias class
martin f. krafft <madduck@madduck.net>
parents:
diff changeset
    65
        failed = False
f180ead60568 First version of a CatchallAlias class
martin f. krafft <madduck@madduck.net>
parents:
diff changeset
    66
        if dcount == limit or dcount + count_new > limit:
f180ead60568 First version of a CatchallAlias class
martin f. krafft <madduck@madduck.net>
parents:
diff changeset
    67
            failed = True
f180ead60568 First version of a CatchallAlias class
martin f. krafft <madduck@madduck.net>
parents:
diff changeset
    68
            errmsg = _(
608
0ed93eb8b364 VMM: Corrected/updated some msgids.
Pascal Volk <user@localhost.localdomain.org>
parents: 513
diff changeset
    69
u"""Cannot add %(count_new)i new destination(s) to catch-all alias for
504
f180ead60568 First version of a CatchallAlias class
martin f. krafft <madduck@madduck.net>
parents:
diff changeset
    70
domain '%(domain)s'. Currently this alias expands into %(count)i/%(limit)i
f180ead60568 First version of a CatchallAlias class
martin f. krafft <madduck@madduck.net>
parents:
diff changeset
    71
recipients. %(count_new)i additional destination(s) will render this alias
f180ead60568 First version of a CatchallAlias class
martin f. krafft <madduck@madduck.net>
parents:
diff changeset
    72
unusable.
f180ead60568 First version of a CatchallAlias class
martin f. krafft <madduck@madduck.net>
parents:
diff changeset
    73
Hint: Increase Postfix' virtual_alias_expansion_limit""")
f180ead60568 First version of a CatchallAlias class
martin f. krafft <madduck@madduck.net>
parents:
diff changeset
    74
        elif dcount > limit:
f180ead60568 First version of a CatchallAlias class
martin f. krafft <madduck@madduck.net>
parents:
diff changeset
    75
            failed = True
f180ead60568 First version of a CatchallAlias class
martin f. krafft <madduck@madduck.net>
parents:
diff changeset
    76
            errmsg = _(
611
8e9b0046bc8f PEP8: Fixed all PEP8 related issues.
Pascal Volk <user@localhost.localdomain.org>
parents: 608
diff changeset
    77
u"""Cannot add %(count_new)i new destination(s) to catch-all alias for domain
8e9b0046bc8f PEP8: Fixed all PEP8 related issues.
Pascal Volk <user@localhost.localdomain.org>
parents: 608
diff changeset
    78
'%(domain)s'. This alias already exceeds its expansion limit \
8e9b0046bc8f PEP8: Fixed all PEP8 related issues.
Pascal Volk <user@localhost.localdomain.org>
parents: 608
diff changeset
    79
(%(count)i/%(limit)i).
504
f180ead60568 First version of a CatchallAlias class
martin f. krafft <madduck@madduck.net>
parents:
diff changeset
    80
So its unusable, all messages addressed to this alias will be bounced.
f180ead60568 First version of a CatchallAlias class
martin f. krafft <madduck@madduck.net>
parents:
diff changeset
    81
Hint: Delete some destination addresses.""")
f180ead60568 First version of a CatchallAlias class
martin f. krafft <madduck@madduck.net>
parents:
diff changeset
    82
        if failed:
f180ead60568 First version of a CatchallAlias class
martin f. krafft <madduck@madduck.net>
parents:
diff changeset
    83
            raise AErr(errmsg % {'domain': self._domain, 'count': dcount,
f180ead60568 First version of a CatchallAlias class
martin f. krafft <madduck@madduck.net>
parents:
diff changeset
    84
                                 'limit': limit, 'count_new': count_new},
f180ead60568 First version of a CatchallAlias class
martin f. krafft <madduck@madduck.net>
parents:
diff changeset
    85
                       ALIAS_EXCEEDS_EXPANSION_LIMIT)
f180ead60568 First version of a CatchallAlias class
martin f. krafft <madduck@madduck.net>
parents:
diff changeset
    86
f180ead60568 First version of a CatchallAlias class
martin f. krafft <madduck@madduck.net>
parents:
diff changeset
    87
    def _delete(self, destination=None):
f180ead60568 First version of a CatchallAlias class
martin f. krafft <madduck@madduck.net>
parents:
diff changeset
    88
        """Deletes a destination from the catchall alias, if ``destination``
f180ead60568 First version of a CatchallAlias class
martin f. krafft <madduck@madduck.net>
parents:
diff changeset
    89
        is not ``None``.  If ``destination`` is None, the catchall alias with
f180ead60568 First version of a CatchallAlias class
martin f. krafft <madduck@madduck.net>
parents:
diff changeset
    90
        all its destination addresses will be deleted.
f180ead60568 First version of a CatchallAlias class
martin f. krafft <madduck@madduck.net>
parents:
diff changeset
    91
f180ead60568 First version of a CatchallAlias class
martin f. krafft <madduck@madduck.net>
parents:
diff changeset
    92
        """
f180ead60568 First version of a CatchallAlias class
martin f. krafft <madduck@madduck.net>
parents:
diff changeset
    93
        dbc = self._dbh.cursor()
f180ead60568 First version of a CatchallAlias class
martin f. krafft <madduck@madduck.net>
parents:
diff changeset
    94
        if not destination:
509
1a9247e9763f Correct syntax errors
martin f. krafft <madduck@madduck.net>
parents: 507
diff changeset
    95
            dbc.execute('DELETE FROM catchall WHERE gid = %s', (self._gid,))
504
f180ead60568 First version of a CatchallAlias class
martin f. krafft <madduck@madduck.net>
parents:
diff changeset
    96
        else:
f180ead60568 First version of a CatchallAlias class
martin f. krafft <madduck@madduck.net>
parents:
diff changeset
    97
            dbc.execute('DELETE FROM catchall WHERE gid = %s '
f180ead60568 First version of a CatchallAlias class
martin f. krafft <madduck@madduck.net>
parents:
diff changeset
    98
                        'AND destination = %s', (self._gid, str(destination)))
f180ead60568 First version of a CatchallAlias class
martin f. krafft <madduck@madduck.net>
parents:
diff changeset
    99
        if dbc.rowcount > 0:
f180ead60568 First version of a CatchallAlias class
martin f. krafft <madduck@madduck.net>
parents:
diff changeset
   100
            self._dbh.commit()
f180ead60568 First version of a CatchallAlias class
martin f. krafft <madduck@madduck.net>
parents:
diff changeset
   101
        dbc.close()
f180ead60568 First version of a CatchallAlias class
martin f. krafft <madduck@madduck.net>
parents:
diff changeset
   102
f180ead60568 First version of a CatchallAlias class
martin f. krafft <madduck@madduck.net>
parents:
diff changeset
   103
    def __len__(self):
f180ead60568 First version of a CatchallAlias class
martin f. krafft <madduck@madduck.net>
parents:
diff changeset
   104
        """Returns the number of destinations of the catchall alias."""
f180ead60568 First version of a CatchallAlias class
martin f. krafft <madduck@madduck.net>
parents:
diff changeset
   105
        return len(self._dests)
f180ead60568 First version of a CatchallAlias class
martin f. krafft <madduck@madduck.net>
parents:
diff changeset
   106
f180ead60568 First version of a CatchallAlias class
martin f. krafft <madduck@madduck.net>
parents:
diff changeset
   107
    @property
f180ead60568 First version of a CatchallAlias class
martin f. krafft <madduck@madduck.net>
parents:
diff changeset
   108
    def domain(self):
f180ead60568 First version of a CatchallAlias class
martin f. krafft <madduck@madduck.net>
parents:
diff changeset
   109
        """The Alias' domain."""
f180ead60568 First version of a CatchallAlias class
martin f. krafft <madduck@madduck.net>
parents:
diff changeset
   110
        return self._domain
f180ead60568 First version of a CatchallAlias class
martin f. krafft <madduck@madduck.net>
parents:
diff changeset
   111
f180ead60568 First version of a CatchallAlias class
martin f. krafft <madduck@madduck.net>
parents:
diff changeset
   112
    def add_destinations(self, destinations, warnings=None):
f180ead60568 First version of a CatchallAlias class
martin f. krafft <madduck@madduck.net>
parents:
diff changeset
   113
        """Adds the `EmailAddress`es from *destinations* list to the
f180ead60568 First version of a CatchallAlias class
martin f. krafft <madduck@madduck.net>
parents:
diff changeset
   114
        destinations of the catchall alias.
f180ead60568 First version of a CatchallAlias class
martin f. krafft <madduck@madduck.net>
parents:
diff changeset
   115
f180ead60568 First version of a CatchallAlias class
martin f. krafft <madduck@madduck.net>
parents:
diff changeset
   116
        Destinations, that are already assigned to the alias, will be
f180ead60568 First version of a CatchallAlias class
martin f. krafft <madduck@madduck.net>
parents:
diff changeset
   117
        removed from *destinations*.  When done, this method will return
f180ead60568 First version of a CatchallAlias class
martin f. krafft <madduck@madduck.net>
parents:
diff changeset
   118
        a set with all destinations, that were saved in the database.
f180ead60568 First version of a CatchallAlias class
martin f. krafft <madduck@madduck.net>
parents:
diff changeset
   119
        """
f180ead60568 First version of a CatchallAlias class
martin f. krafft <madduck@madduck.net>
parents:
diff changeset
   120
        destinations = set(destinations)
f180ead60568 First version of a CatchallAlias class
martin f. krafft <madduck@madduck.net>
parents:
diff changeset
   121
        assert destinations and \
f180ead60568 First version of a CatchallAlias class
martin f. krafft <madduck@madduck.net>
parents:
diff changeset
   122
                all(isinstance(dest, EmailAddress) for dest in destinations)
f180ead60568 First version of a CatchallAlias class
martin f. krafft <madduck@madduck.net>
parents:
diff changeset
   123
        if not warnings is None:
f180ead60568 First version of a CatchallAlias class
martin f. krafft <madduck@madduck.net>
parents:
diff changeset
   124
            assert isinstance(warnings, list)
f180ead60568 First version of a CatchallAlias class
martin f. krafft <madduck@madduck.net>
parents:
diff changeset
   125
        duplicates = destinations.intersection(set(self._dests))
f180ead60568 First version of a CatchallAlias class
martin f. krafft <madduck@madduck.net>
parents:
diff changeset
   126
        if duplicates:
f180ead60568 First version of a CatchallAlias class
martin f. krafft <madduck@madduck.net>
parents:
diff changeset
   127
            destinations.difference_update(set(self._dests))
f180ead60568 First version of a CatchallAlias class
martin f. krafft <madduck@madduck.net>
parents:
diff changeset
   128
            if not warnings is None:
f180ead60568 First version of a CatchallAlias class
martin f. krafft <madduck@madduck.net>
parents:
diff changeset
   129
                warnings.extend(duplicates)
f180ead60568 First version of a CatchallAlias class
martin f. krafft <madduck@madduck.net>
parents:
diff changeset
   130
        if not destinations:
f180ead60568 First version of a CatchallAlias class
martin f. krafft <madduck@madduck.net>
parents:
diff changeset
   131
            return destinations
f180ead60568 First version of a CatchallAlias class
martin f. krafft <madduck@madduck.net>
parents:
diff changeset
   132
        self._check_expansion(len(destinations))
f180ead60568 First version of a CatchallAlias class
martin f. krafft <madduck@madduck.net>
parents:
diff changeset
   133
        dbc = self._dbh.cursor()
f180ead60568 First version of a CatchallAlias class
martin f. krafft <madduck@madduck.net>
parents:
diff changeset
   134
        dbc.executemany("INSERT INTO catchall (gid, destination) "
f180ead60568 First version of a CatchallAlias class
martin f. krafft <madduck@madduck.net>
parents:
diff changeset
   135
                        "VALUES (%d, %%s)" % self._gid,
f180ead60568 First version of a CatchallAlias class
martin f. krafft <madduck@madduck.net>
parents:
diff changeset
   136
                        ((str(destination),) for destination in destinations))
f180ead60568 First version of a CatchallAlias class
martin f. krafft <madduck@madduck.net>
parents:
diff changeset
   137
        self._dbh.commit()
f180ead60568 First version of a CatchallAlias class
martin f. krafft <madduck@madduck.net>
parents:
diff changeset
   138
        dbc.close()
f180ead60568 First version of a CatchallAlias class
martin f. krafft <madduck@madduck.net>
parents:
diff changeset
   139
        self._dests.extend(destinations)
f180ead60568 First version of a CatchallAlias class
martin f. krafft <madduck@madduck.net>
parents:
diff changeset
   140
        return destinations
f180ead60568 First version of a CatchallAlias class
martin f. krafft <madduck@madduck.net>
parents:
diff changeset
   141
f180ead60568 First version of a CatchallAlias class
martin f. krafft <madduck@madduck.net>
parents:
diff changeset
   142
    def del_destination(self, destination):
f180ead60568 First version of a CatchallAlias class
martin f. krafft <madduck@madduck.net>
parents:
diff changeset
   143
        """Deletes the specified ``destination`` address from the catchall
f180ead60568 First version of a CatchallAlias class
martin f. krafft <madduck@madduck.net>
parents:
diff changeset
   144
        alias."""
f180ead60568 First version of a CatchallAlias class
martin f. krafft <madduck@madduck.net>
parents:
diff changeset
   145
        assert isinstance(destination, EmailAddress)
f180ead60568 First version of a CatchallAlias class
martin f. krafft <madduck@madduck.net>
parents:
diff changeset
   146
        if not self._dests:
608
0ed93eb8b364 VMM: Corrected/updated some msgids.
Pascal Volk <user@localhost.localdomain.org>
parents: 513
diff changeset
   147
            raise AErr(_(u"There are no catch-all aliases defined for "
504
f180ead60568 First version of a CatchallAlias class
martin f. krafft <madduck@madduck.net>
parents:
diff changeset
   148
                         u"domain '%s'.") % self._domain, NO_SUCH_ALIAS)
f180ead60568 First version of a CatchallAlias class
martin f. krafft <madduck@madduck.net>
parents:
diff changeset
   149
        if not destination in self._dests:
f180ead60568 First version of a CatchallAlias class
martin f. krafft <madduck@madduck.net>
parents:
diff changeset
   150
            raise AErr(_(u"The address '%(addr)s' is not a destination of "
608
0ed93eb8b364 VMM: Corrected/updated some msgids.
Pascal Volk <user@localhost.localdomain.org>
parents: 513
diff changeset
   151
                         u"the catch-all alias for domain '%(domain)s'.")
504
f180ead60568 First version of a CatchallAlias class
martin f. krafft <madduck@madduck.net>
parents:
diff changeset
   152
                       % {'addr': destination, 'domain': self._domain},
f180ead60568 First version of a CatchallAlias class
martin f. krafft <madduck@madduck.net>
parents:
diff changeset
   153
                       NO_SUCH_ALIAS)
f180ead60568 First version of a CatchallAlias class
martin f. krafft <madduck@madduck.net>
parents:
diff changeset
   154
        self._delete(destination)
f180ead60568 First version of a CatchallAlias class
martin f. krafft <madduck@madduck.net>
parents:
diff changeset
   155
        self._dests.remove(destination)
f180ead60568 First version of a CatchallAlias class
martin f. krafft <madduck@madduck.net>
parents:
diff changeset
   156
f180ead60568 First version of a CatchallAlias class
martin f. krafft <madduck@madduck.net>
parents:
diff changeset
   157
    def get_destinations(self):
f180ead60568 First version of a CatchallAlias class
martin f. krafft <madduck@madduck.net>
parents:
diff changeset
   158
        """Returns an iterator for all destinations of the catchall alias."""
f180ead60568 First version of a CatchallAlias class
martin f. krafft <madduck@madduck.net>
parents:
diff changeset
   159
        if not self._dests:
608
0ed93eb8b364 VMM: Corrected/updated some msgids.
Pascal Volk <user@localhost.localdomain.org>
parents: 513
diff changeset
   160
            raise AErr(_(u"There are no catch-all aliases defined for "
504
f180ead60568 First version of a CatchallAlias class
martin f. krafft <madduck@madduck.net>
parents:
diff changeset
   161
                         u"domain '%s'.") % self._domain, NO_SUCH_ALIAS)
f180ead60568 First version of a CatchallAlias class
martin f. krafft <madduck@madduck.net>
parents:
diff changeset
   162
        return iter(self._dests)
f180ead60568 First version of a CatchallAlias class
martin f. krafft <madduck@madduck.net>
parents:
diff changeset
   163
f180ead60568 First version of a CatchallAlias class
martin f. krafft <madduck@madduck.net>
parents:
diff changeset
   164
    def delete(self):
f180ead60568 First version of a CatchallAlias class
martin f. krafft <madduck@madduck.net>
parents:
diff changeset
   165
        """Deletes all catchall destinations for the domain."""
f180ead60568 First version of a CatchallAlias class
martin f. krafft <madduck@madduck.net>
parents:
diff changeset
   166
        if not self._dests:
608
0ed93eb8b364 VMM: Corrected/updated some msgids.
Pascal Volk <user@localhost.localdomain.org>
parents: 513
diff changeset
   167
            raise AErr(_(u"There are no catch-all aliases defined for "
504
f180ead60568 First version of a CatchallAlias class
martin f. krafft <madduck@madduck.net>
parents:
diff changeset
   168
                         u"domain '%s'.") % self._domain, NO_SUCH_ALIAS)
f180ead60568 First version of a CatchallAlias class
martin f. krafft <madduck@madduck.net>
parents:
diff changeset
   169
        self._delete()
f180ead60568 First version of a CatchallAlias class
martin f. krafft <madduck@madduck.net>
parents:
diff changeset
   170
        del self._dests[:]
f180ead60568 First version of a CatchallAlias class
martin f. krafft <madduck@madduck.net>
parents:
diff changeset
   171
f180ead60568 First version of a CatchallAlias class
martin f. krafft <madduck@madduck.net>
parents:
diff changeset
   172
del _, cfg_dget