40 localpart, domain = address.split('@') |
40 localpart, domain = address.split('@') |
41 except ValueError: |
41 except ValueError: |
42 raise VMMEAE(_(u"Missing '@' sign in e-mail address “%s”.") % |
42 raise VMMEAE(_(u"Missing '@' sign in e-mail address “%s”.") % |
43 address, ERR.INVALID_ADDRESS) |
43 address, ERR.INVALID_ADDRESS) |
44 except AttributeError: |
44 except AttributeError: |
45 raise VMMEAE(_(u"“%s” looks not like an e-mail address.") % |
45 raise VMMEAE(_(u"“%s” doesn't look like an e-mail address.") % |
46 address, ERR.INVALID_ADDRESS) |
46 address, ERR.INVALID_ADDRESS) |
47 if len(domain) > 0: |
47 if len(domain) > 0: |
48 domain = VMM.VirtualMailManager.chkDomainname(domain) |
48 domain = VMM.VirtualMailManager.chkDomainname(domain) |
49 else: |
49 else: |
50 raise VMMEAE(_(u"Missing domain name after “%s@”.") % |
50 raise VMMEAE(_(u"Missing domain name after “%s@”.") % |
51 localpart, ERR.DOMAIN_NO_NAME) |
51 localpart, ERR.DOMAIN_NO_NAME) |
52 localpart = self.__chkLocalpart(localpart) |
52 localpart = self.__chkLocalpart(localpart) |
53 self._localpart, self._domainname = localpart, domain |
53 self._localpart, self._domainname = localpart, domain |
54 |
54 |
55 def __chkLocalpart(self, localpart): |
55 def __chkLocalpart(self, localpart): |
56 """Validates the local part of an e-mail address. |
56 """Validates the local-part of an e-mail address. |
57 |
57 |
58 Keyword arguments: |
58 Arguments: |
59 localpart -- of the e-mail address that should be validated (str) |
59 localpart -- local-part of the e-mail address that should be validated (str) |
60 """ |
60 """ |
61 if len(localpart) < 1: |
61 if len(localpart) < 1: |
62 raise VMMEAE(_(u'No localpart specified.'), |
62 raise VMMEAE(_(u'No local-part specified.'), |
63 ERR.LOCALPART_INVALID) |
63 ERR.LOCALPART_INVALID) |
64 if len(localpart) > 64: |
64 if len(localpart) > 64: |
65 raise VMMEAE(_(u'The local part “%s” is too long') % |
65 raise VMMEAE(_(u'The local-part “%s” is too long') % |
66 localpart, ERR.LOCALPART_TOO_LONG) |
66 localpart, ERR.LOCALPART_TOO_LONG) |
67 ic = set(re.findall(RE_LOCALPART, localpart)) |
67 ic = set(re.findall(RE_LOCALPART, localpart)) |
68 if len(ic): |
68 if len(ic): |
69 ichrs = '' |
69 ichrs = '' |
70 for c in ic: |
70 for c in ic: |
71 ichrs += u"“%s” " % c |
71 ichrs += u"“%s” " % c |
72 raise VMMEAE(_(u"The local part “%(lpart)s” contains invalid\ |
72 raise VMMEAE(_(u"The local-part “%(lpart)s” contains invalid\ |
73 characters: %(ichrs)s") % {'lpart': localpart, 'ichrs': ichrs}, |
73 characters: %(ichrs)s") % {'lpart': localpart, 'ichrs': ichrs}, |
74 ERR.LOCALPART_INVALID) |
74 ERR.LOCALPART_INVALID) |
75 return localpart |
75 return localpart |
76 |
76 |