File tree Expand file tree Collapse file tree 1 file changed +15
-1
lines changed
Expand file tree Collapse file tree 1 file changed +15
-1
lines changed Original file line number Diff line number Diff line change 55
66from . import Request , ValidationError
77
8+ # Src: http://code.djangoproject.com/svn/django/trunk/django/core/validators.py
9+ email_re = re .compile (
10+ r"(^[-!#$%&'*+/=?^_`{}|~0-9A-Z]+(\.[-!#$%&'*+/=?^_`{}|~0-9A-Z]+)*" # dot-atom
11+ # quoted-string, see also http://tools.ietf.org/html/rfc2822#section-3.2.5
12+ r'|^"([\001-\010\013\014\016-\037!#-\[\]-\177]|\\[\001-\011\013\014\016-\177])*"'
13+ r')@((?:[A-Z0-9](?:[A-Z0-9-]{0,61}[A-Z0-9])?\.)+[A-Z]{2,6}\.?$)' # domain
14+ r'|\[(25[0-5]|2[0-4]\d|[0-1]?\d?\d)(\.(25[0-5]|2[0-4]\d|[0-1]?\d?\d)){3}\]$' , re .IGNORECASE ) # literal form, ipv4 address (SMTP 4.1.3)
15+
816
917class List (Request ):
1018
@@ -17,7 +25,7 @@ class Add(Request):
1725
1826 def clean_body (self ):
1927 def is_email (email ):
20- return re .match (r'.*' , email ) # TODO: email regex ;)
28+ return bool ( email_re .match (email ) ) # TODO: email regex ;)
2129 if not self .body :
2230 raise ValidationError ("'%s' request needs emails"
2331 % (self .__class__ .__name__ ))
@@ -28,3 +36,9 @@ def is_email(email):
2836class Delete (Request ):
2937
3038 uri = 'user/emails'
39+
40+ def clean_body (self ):
41+ if not self .body :
42+ raise ValidationError ("'%s' request needs emails"
43+ % (self .__class__ .__name__ ))
44+ return self .body
You can’t perform that action at this time.
0 commit comments