|
7 | 7 | from html.parser import HTMLParser
|
8 | 8 | from urllib.parse import parse_qsl, quote, unquote, urlencode, urlsplit, urlunsplit
|
9 | 9 |
|
10 |
| -from django.core.exceptions import SuspiciousOperation |
| 10 | +from django.core.exceptions import SuspiciousOperation, ValidationError |
| 11 | +from django.core.validators import EmailValidator |
11 | 12 | from django.utils.encoding import punycode
|
12 | 13 | from django.utils.functional import Promise, cached_property, keep_lazy, keep_lazy_text
|
13 | 14 | from django.utils.http import RFC3986_GENDELIMS, RFC3986_SUBDELIMS
|
@@ -455,20 +456,9 @@ def trim_punctuation(self, word):
|
455 | 456 | @staticmethod
|
456 | 457 | def is_email_simple(value):
|
457 | 458 | """Return True if value looks like an email address."""
|
458 |
| - # An @ must be in the middle of the value. |
459 |
| - if "@" not in value or value.startswith("@") or value.endswith("@"): |
460 |
| - return False |
461 | 459 | try:
|
462 |
| - p1, p2 = value.split("@") |
463 |
| - except ValueError: |
464 |
| - # value contains more than one @. |
465 |
| - return False |
466 |
| - # Max length for domain name labels is 63 characters per RFC 1034. |
467 |
| - # Helps to avoid ReDoS vectors in the domain part. |
468 |
| - if len(p2) > 63: |
469 |
| - return False |
470 |
| - # Dot must be in p2 (e.g. example.com) |
471 |
| - if "." not in p2 or p2.startswith("."): |
| 460 | + EmailValidator(allowlist=[])(value) |
| 461 | + except ValidationError: |
472 | 462 | return False
|
473 | 463 | return True
|
474 | 464 |
|
|
0 commit comments