Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Unified Diff: sitescripts/utils.py

Issue 5177883412660224: Issue 2234 - Add a WSGI controller to collect email addresses for the Adblock Browser iOS launch (Closed)
Patch Set: Removed "beta" from email text Created April 24, 2015, 12:55 p.m.
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « sitescripts/submit_email/web/submit_email.py ('k') | sitescripts/web.py » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: sitescripts/utils.py
===================================================================
--- a/sitescripts/utils.py
+++ b/sitescripts/utils.py
@@ -113,6 +113,25 @@
else:
subprocess.Popen([config.get('DEFAULT', 'mailer'), '-t'], stdin=subprocess.PIPE).communicate(mail.encode('utf-8'))
+def encode_email_address(email):
+ '''
+ Validates and encodes an email address.
+
+ The validation implemented here is very rudamentery and not meant
+ to be complete, as full email validation can get extremly complicated
+ and is rarely needed. This function is primarily making sure that the
+ email address contains no whitespaces and only valid ASCII characters.
+ '''
+ match = re.search(r'^([^@\s]+)@([^@\s]+)$', email)
+ if not match:
+ raise ValueError
+
+ try:
+ return email.encode('ascii')
+ except UnicodeEncodeError:
+ return '%s@%s' % (match.group(1).encode('ascii'),
+ match.group(2).encode('idna'))
+
_template_cache = {}
def get_template(template, autoescape=True):
« no previous file with comments | « sitescripts/submit_email/web/submit_email.py ('k') | sitescripts/web.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld