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

Delta Between Two Patch Sets: sitescripts/formmail/web/formmail.py

Issue 5920587679531008: Issue 1946 - Include form-mail sender address in message content (Closed)
Left Patch Set: Created April 17, 2015, 1:57 a.m.
Right Patch Set: Issue 1946 - Use datetime.now().strftime() instead of strftime() Created April 17, 2015, 2:31 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
Left: Side by side diff | Download
Right: Side by side diff | Download
« no previous file with change/comment | « sitescripts/formmail/template/eyeo.mail ('k') | no next file » | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
1 # coding: utf-8 1 # coding: utf-8
2 2
3 # This file is part of the Adblock Plus web scripts, 3 # This file is part of the Adblock Plus web scripts,
4 # Copyright (C) 2006-2015 Eyeo GmbH 4 # Copyright (C) 2006-2015 Eyeo GmbH
5 # 5 #
6 # Adblock Plus is free software: you can redistribute it and/or modify 6 # Adblock Plus is free software: you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License version 3 as 7 # it under the terms of the GNU General Public License version 3 as
8 # published by the Free Software Foundation. 8 # published by the Free Software Foundation.
9 # 9 #
10 # Adblock Plus is distributed in the hope that it will be useful, 10 # Adblock Plus is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of 11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details. 13 # GNU General Public License for more details.
14 # 14 #
15 # You should have received a copy of the GNU General Public License 15 # You should have received a copy of the GNU General Public License
16 # along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>. 16 # along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>.
17 17
18 import re 18 import re
19 import time 19 import datetime
20 from urlparse import parse_qsl 20 from urlparse import parse_qsl
21 from sitescripts.utils import get_config, sendMail, setupStderr 21 from sitescripts.utils import get_config, sendMail, setupStderr
22 from sitescripts.web import url_handler 22 from sitescripts.web import url_handler
23 23
24 @url_handler('/formmail') 24 @url_handler('/formmail')
25 def handleRequest(environ, start_response): 25 def handleRequest(environ, start_response):
26 setupStderr(environ['wsgi.errors']) 26 setupStderr(environ['wsgi.errors'])
27 27
28 start_response('200 OK', [('Content-Type', 'text/plain; charset=utf-8')]) 28 start_response('200 OK', [('Content-Type', 'text/plain; charset=utf-8')])
29 if environ['REQUEST_METHOD'].upper() != 'POST' or not environ.get('CONTENT_TYP E', '').startswith('application/x-www-form-urlencoded'): 29 if environ['REQUEST_METHOD'].upper() != 'POST' or not environ.get('CONTENT_TYP E', '').startswith('application/x-www-form-urlencoded'):
30 return 'Unsupported request method' 30 return 'Unsupported request method'
31 31
32 try: 32 try:
33 request_body_length = int(environ['CONTENT_LENGTH']) 33 request_body_length = int(environ['CONTENT_LENGTH'])
34 except: 34 except:
35 return 'Invalid or missing Content-Length header' 35 return 'Invalid or missing Content-Length header'
36 36
37 request_body = environ['wsgi.input'].read(request_body_length) 37 request_body = environ['wsgi.input'].read(request_body_length)
38 params = {} 38 params = {}
39
mathias 2015/04/17 02:00:06 That accidental white-space is removed already.
40 for key, value in parse_qsl(request_body): 39 for key, value in parse_qsl(request_body):
41 params[key] = value.decode('utf-8').strip() 40 params[key] = value.decode('utf-8').strip()
42 41
43 if not 'name' in params or params['name'] == '': 42 if not 'name' in params or params['name'] == '':
44 return 'No name entered' 43 return 'No name entered'
45 if not 'email' in params or params['email'] == '': 44 if not 'email' in params or params['email'] == '':
46 return 'No email address entered' 45 return 'No email address entered'
47 if not 'subject' in params or params['subject'] == '': 46 if not 'subject' in params or params['subject'] == '':
48 return 'No subject entered' 47 return 'No subject entered'
49 if not 'message' in params or params['message'] == '': 48 if not 'message' in params or params['message'] == '':
50 return 'No message entered' 49 return 'No message entered'
51 50
52 if not re.match(r'^\w[\w.+!-]+@\w[\w.-]+\.[a-zA-Z]{2,6}$', params['email']): 51 if not re.match(r'^\w[\w.+!-]+@\w[\w.-]+\.[a-zA-Z]{2,6}$', params['email']):
53 return 'Invalid email address' 52 return 'Invalid email address'
54 53
55 params['strftime'] = time.strftime 54 params['time'] = datetime.datetime.now()
Wladimir Palant 2015/04/17 13:46:32 This seems wrong - strftime isn't a parameter, it'
mathias 2015/04/17 14:32:55 Done.
56 sendMail(get_config().get('formmail', 'template'), params) 55 sendMail(get_config().get('formmail', 'template'), params)
57 return 'Message sent' 56 return 'Message sent'
LEFTRIGHT

Powered by Google App Engine
This is Rietveld