24 from VirtualMailManager import ENCODING, ace2idna, exec_ok |
24 from VirtualMailManager import ENCODING, ace2idna, exec_ok |
25 from VirtualMailManager.Account import Account |
25 from VirtualMailManager.Account import Account |
26 from VirtualMailManager.Alias import Alias |
26 from VirtualMailManager.Alias import Alias |
27 from VirtualMailManager.AliasDomain import AliasDomain |
27 from VirtualMailManager.AliasDomain import AliasDomain |
28 from VirtualMailManager.Config import Config as Cfg |
28 from VirtualMailManager.Config import Config as Cfg |
29 from VirtualMailManager.Domain import Domain |
29 from VirtualMailManager.Domain import Domain, get_gid |
30 from VirtualMailManager.EmailAddress import EmailAddress |
30 from VirtualMailManager.EmailAddress import EmailAddress |
31 from VirtualMailManager.errors import VMMError, AliasError |
31 from VirtualMailManager.errors import VMMError, AliasError, DomainError |
32 from VirtualMailManager.Relocated import Relocated |
32 from VirtualMailManager.Relocated import Relocated |
33 from VirtualMailManager.ext.Postconf import Postconf |
33 from VirtualMailManager.ext.Postconf import Postconf |
34 |
34 |
35 |
35 |
36 SALTCHARS = './0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ' |
36 SALTCHARS = './0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ' |
392 def hasWarnings(self): |
392 def hasWarnings(self): |
393 """Checks if warnings are present, returns bool.""" |
393 """Checks if warnings are present, returns bool.""" |
394 return bool(len(self.__warnings)) |
394 return bool(len(self.__warnings)) |
395 |
395 |
396 def getWarnings(self): |
396 def getWarnings(self): |
397 """Returns a list with all available warnings.""" |
397 """Returns a list with all available warnings and resets all |
398 return self.__warnings |
398 warnings. |
|
399 |
|
400 """ |
|
401 ret_val = self.__warnings[:] |
|
402 del self.__warnings[:] |
|
403 return ret_val |
399 |
404 |
400 def cfgDget(self, option): |
405 def cfgDget(self, option): |
401 return self._Cfg.dget(option) |
406 return self._Cfg.dget(option) |
402 |
407 |
403 def cfgPget(self, option): |
408 def cfgPget(self, option): |
527 self._Cfg.dget('account.pop3'), |
532 self._Cfg.dget('account.pop3'), |
528 self._Cfg.dget('account.imap'), |
533 self._Cfg.dget('account.imap'), |
529 self._Cfg.dget('account.sieve')) |
534 self._Cfg.dget('account.sieve')) |
530 self.__mailDirMake(acc.getDir('domain'), acc.getUID(), acc.getGID()) |
535 self.__mailDirMake(acc.getDir('domain'), acc.getUID(), acc.getGID()) |
531 |
536 |
532 def aliasAdd(self, aliasaddress, targetaddress): |
537 def aliasAdd(self, aliasaddress, *targetaddresses): |
533 """Creates a new `Alias` entry for the given *aliasaddress* with |
538 """Creates a new `Alias` entry for the given *aliasaddress* with |
534 the given *targetaddress*.""" |
539 the given *targetaddresses*.""" |
535 alias = self.__getAlias(aliasaddress) |
540 alias = self.__getAlias(aliasaddress) |
536 destination = EmailAddress(targetaddress) |
541 destinations = [EmailAddress(address) for address in targetaddresses] |
537 alias.add_destination(destination, |
542 warnings = [] |
538 long(self._postconf.read('virtual_alias_expansion_limit'))) |
543 destinations = alias.add_destinations(destinations, |
539 gid = self.__getDomain(destination.domainname).getID() |
544 long(self._postconf.read('virtual_alias_expansion_limit')), |
540 if gid > 0 and (not Handler.accountExists(self._dbh, destination) and |
545 warnings) |
541 not Handler.aliasExists(self._dbh, destination)): |
546 if warnings: |
542 self.__warnings.append( |
547 self.__warnings.append(_('Ignored destination addresses:')) |
543 _(u"The destination account/alias “%s” doesn't exist.") % |
548 self.__warnings.extend((' * %s' % w for w in warnings)) |
544 destination) |
549 for destination in destinations: |
|
550 try: |
|
551 gid = get_gid(self._dbh, destination.domainname) |
|
552 except DomainError, e: |
|
553 if e.code == ERR.NO_SUCH_DOMAIN: |
|
554 continue |
|
555 else: |
|
556 raise |
|
557 if gid > 0 and \ |
|
558 (not Handler.accountExists(self._dbh, destination) and |
|
559 not Handler.aliasExists(self._dbh, destination)): |
|
560 self.__warnings.append( |
|
561 _(u"The destination account/alias %r doesn't exist.") % |
|
562 str(destination)) |
545 |
563 |
546 def userDelete(self, emailaddress, force=None): |
564 def userDelete(self, emailaddress, force=None): |
547 if force not in [None, 'delalias']: |
565 if force not in [None, 'delalias']: |
548 raise VMMError(_(u"Invalid argument: “%s”") % force, |
566 raise VMMError(_(u"Invalid argument: “%s”") % force, |
549 ERR.INVALID_AGUMENT) |
567 ERR.INVALID_AGUMENT) |