Lines 564-583
class absolutePath(simple):
Link Here
|
564 |
|
564 |
|
565 |
class emailAddress(simple): |
565 |
class emailAddress(simple): |
566 |
name='emailAddress' |
566 |
name='emailAddress' |
567 |
min_length=4 |
567 |
valid_localpart_characters = set("abcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ!#$%&'*+-/=?^`{|}~.") |
568 |
max_length=256 |
568 |
valid_domainpart_label_characters = set("abcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ-") |
569 |
_re = re.compile('((^[a-zA-Z0-9])[a-zA-Z0-9._-]*)@[a-zA-Z0-9._-]+$') |
569 |
|
|
|
570 |
def validate_localpart(self, localpart): |
571 |
# quoted local parts are not allowed by this function, for example "John Doe"@example.com |
572 |
# escaping via \ is also not allowed by this function, for example John\@Doe@example.com |
573 |
if not localpart: |
574 |
raise univention.admin.uexceptions.valueError,_('Not a valid email address! (local-part is empty)') |
575 |
if len(localpart) > 64: |
576 |
raise univention.admin.uexceptions.valueError,_('Not a valid email address! (local-part longer than 64 characters)') |
577 |
for char in localpart: |
578 |
if not char in self.valid_localpart_characters: |
579 |
raise univention.admin.uexceptions.valueError,_('Not a valid email address! (invalid character "%s")') % char |
580 |
if localpart[0] == '.' or localpart[-1] == '.': |
581 |
raise univention.admin.uexceptions.valueError,_('Not a valid email address! ("." may not be the first or last character of local-part)') |
582 |
if localpart.find('..') != -1: |
583 |
raise univention.admin.uexceptions.valueError,_('Not a valid email address! (multiple consecutive "." not allowed in local-part)') |
584 |
return localpart |
585 |
|
586 |
def validate_domainpart(self, domainpart): |
587 |
# only DNS-domain-names are allowed |
588 |
if not domainpart: |
589 |
raise univention.admin.uexceptions.valueError,_('Not a valid email address! (domain-part is empty)') |
590 |
if len(domainpart) > 255: |
591 |
raise univention.admin.uexceptions.valueError,_('Not a valid email address! (domain-part longer than 255 characters)') |
592 |
labels = domainpart.split('.') |
593 |
if '' in labels[:-1]: # ignore last part because a domain may end with a '.' |
594 |
raise univention.admin.uexceptions.valueError,_('Not a valid email address! (empty domain-part labels are not allowed)') |
595 |
for label in labels: |
596 |
if len(label) > 63: |
597 |
raise univention.admin.uexceptions.valueError,_('Not a valid email address! (domain-part labels may not be longer than 63 characters)') |
598 |
for char in label: |
599 |
if not char in self.valid_domainpart_label_characters: |
600 |
raise univention.admin.uexceptions.valueError,_('Not a valid email address! (invalid character "%s" in domain-part label)') % char |
601 |
if label.startswith('-') or label.endswith('-'): |
602 |
raise univention.admin.uexceptions.valueError,_('Not a valid email address! (domain-part labels may not start or end with a "-")') |
603 |
return '.'.join(labels) |
570 |
|
604 |
|
571 |
def parse(self, text): |
605 |
def parse(self, text): |
572 |
if self._re.match(text) != None: |
606 |
if len(text) > 256: |
573 |
return text |
607 |
raise univention.admin.uexceptions.valueError,_('Not a valid email address! (may not be longer than 256 characters)') |
574 |
raise univention.admin.uexceptions.valueError,_("Not a valid email address!") |
608 |
number_of_at_chars = len([x for x in text if x == '@']) |
|
|
609 |
if number_of_at_chars == 0: |
610 |
raise univention.admin.uexceptions.valueError,_('Not a valid email address! (No "@"-character to separate local-part and domain-part)') |
611 |
if number_of_at_chars > 1: |
612 |
raise univention.admin.uexceptions.valueError,_('Not a valid email address! (No more than 1 "@"-character allowed)') |
613 |
(localpart, domainpart) = text.split('@') |
614 |
return '@'.join((self.validate_localpart(localpart), self.validate_domainpart(domainpart))) |
575 |
|
615 |
|
576 |
class emailAddressTemplate(simple): |
616 |
class emailAddressTemplate(simple): |
577 |
name='emailAddress' |
617 |
name='emailAddress' |
578 |
min_length=4 |
618 |
min_length=4 |
579 |
max_length=0 |
619 |
max_length=0 |
580 |
_re = re.compile('((^[a-zA-Z<>\[\]:])[a-zA-Z0-9<>\[\]:._-]*)@[a-zA-Z0-9._-]+$') |
620 |
_re = re.compile("((^[-!#$%'*+/=?^`{|}~a-zA-Z<>\[\]:])[-!#$%'*+/=?^`{|}~a-zA-Z0-9<>\[\]:._-]*)@[a-zA-Z0-9._-]+$") |
581 |
|
621 |
|
582 |
def parse(self, text): |
622 |
def parse(self, text): |
583 |
if self._re.match(text) != None: |
623 |
if self._re.match(text) != None: |