VirtualMailManager/EmailAddress.py
branchv0.6.x
changeset 185 6e1ef32fbd82
parent 162 0ac9ef587769
child 193 a259bdeaab5c
equal deleted inserted replaced
184:d0425225ce52 185:6e1ef32fbd82
     2 # Copyright (c) 2008 - 2010, Pascal Volk
     2 # Copyright (c) 2008 - 2010, Pascal Volk
     3 # See COPYING for distribution information.
     3 # See COPYING for distribution information.
     4 
     4 
     5 """Virtual Mail Manager's EmailAddress class to handle e-mail addresses."""
     5 """Virtual Mail Manager's EmailAddress class to handle e-mail addresses."""
     6 
     6 
     7 from __main__ import re, ERR
     7 import re
     8 from Exceptions import VMMEmailAddressException as VMMEAE
     8 
     9 import VirtualMailManager as VMM
     9 import VirtualMailManager.constants.ERROR as ERR
       
    10 from VirtualMailManager import chk_domainname
       
    11 from VirtualMailManager.Exceptions import VMMEmailAddressException as VMMEAE
    10 
    12 
    11 RE_LOCALPART = """[^\w!#$%&'\*\+-\.\/=?^_`{\|}~]"""
    13 RE_LOCALPART = """[^\w!#$%&'\*\+-\.\/=?^_`{\|}~]"""
    12 
    14 
    13 class EmailAddress(object):
    15 class EmailAddress(object):
    14     __slots__ = ('_localpart', '_domainname')
    16     __slots__ = ('_localpart', '_domainname')
    38     def __chkAddress(self, address):
    40     def __chkAddress(self, address):
    39         try:
    41         try:
    40             localpart, domain = address.split('@')
    42             localpart, domain = address.split('@')
    41         except ValueError:
    43         except ValueError:
    42             raise VMMEAE(_(u"Missing '@' sign in e-mail address “%s”.") %
    44             raise VMMEAE(_(u"Missing '@' sign in e-mail address “%s”.") %
    43                 address, ERR.INVALID_ADDRESS)
    45                          address, ERR.INVALID_ADDRESS)
    44         except AttributeError:
    46         except AttributeError:
    45             raise VMMEAE(_(u"“%s” doesn't look like an e-mail address.") %
    47             raise VMMEAE(_(u"“%s” doesn't look like an e-mail address.") %
    46                 address, ERR.INVALID_ADDRESS)
    48                          address, ERR.INVALID_ADDRESS)
    47         if len(domain) > 0:
    49         if len(domain) > 0:
    48             domain = VMM.VirtualMailManager.chkDomainname(domain)
    50             domain = chk_domainname(domain)
    49         else:
    51         else:
    50             raise VMMEAE(_(u"Missing domain name after “%s@”.") %
    52             raise VMMEAE(_(u"Missing domain name after “%s@”.") % localpart,
    51                     localpart, ERR.DOMAIN_NO_NAME)
    53                          ERR.DOMAIN_NO_NAME)
    52         localpart = self.__chkLocalpart(localpart)
    54         localpart = self.__chkLocalpart(localpart)
    53         self._localpart, self._domainname = localpart, domain
    55         self._localpart, self._domainname = localpart, domain
    54 
    56 
    55     def __chkLocalpart(self, localpart):
    57     def __chkLocalpart(self, localpart):
    56         """Validates the local-part of an e-mail address.
    58         """Validates the local-part of an e-mail address.