mirror of
https://github.com/jwinterm/modoboa.git
synced 2026-10-19 05:58:34 +02:00
21 lines
525 B
Python
21 lines
525 B
Python
"""Custom form validators."""
|
|
|
|
from email.utils import getaddresses
|
|
|
|
from django.utils.encoding import force_text
|
|
from django.core.validators import validate_email
|
|
|
|
|
|
class EmailListValidator(object):
|
|
|
|
"""Validate a comma separated list of email."""
|
|
|
|
def __call__(self, value):
|
|
value = force_text(value)
|
|
emails = [unicode.strip(email) for email in value.split(",")]
|
|
addresses = getaddresses(emails)
|
|
[validate_email(e) for r, e in addresses]
|
|
|
|
validate_email_list = EmailListValidator()
|
|
|