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

Unified Diff: sitescripts/templateFilters.py

Issue 6246174612783104: Issue 535 - Contact form cannot deal with commas in sender`s name (Closed)
Patch Set: Created May 22, 2014, 8:13 a.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/reports/bin/mailDigests.py ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: sitescripts/templateFilters.py
===================================================================
--- a/sitescripts/templateFilters.py
+++ b/sitescripts/templateFilters.py
@@ -10,17 +10,17 @@
# Adblock Plus is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>.
-import re, email.header, urllib, time, json
+import re, email.header, email.utils, urllib, time, json
from datetime import date
from jinja2.utils import Markup
from urlparse import urlparse
def formattime(value):
try:
return time.strftime('%Y-%m-%d %H:%M UTC', time.gmtime(int(value)))
except Exception, e:
@@ -123,18 +123,25 @@ def subscriptionSort(value, prioritizeRe
value.sort(lambda a, b: (
cmp(a.type, b.type) or
cmp(a.deprecated, b.deprecated) or
cmp(a.name.lower(), b.name.lower())
))
return value
def formatmime(text):
+ # See http://bugs.python.org/issue5871 (not really fixed), Header() will
+ # happily accept non-printable characters including newlines. Make sure to
+ # remove them.
+ text = re.sub(r'[\x00-\x1F]', '', text)
return email.header.Header(text).encode()
+def emailaddr((name, addr)):
+ return email.utils.formataddr((name, addr))
+
def ljust(value, width=80):
return unicode(value).ljust(width)
def rjust(value, width=80):
return unicode(value).rjust(width)
def ltruncate(value, length=255, end='...'):
value = unicode(value)
@@ -170,15 +177,16 @@ filters = {
'timerelative': formatrelativetime,
'url': formaturl,
'keepnewlines': formatnewlines,
'filtercount': formatfiltercount,
'buglinks': formatBugLinks,
'urlencode': urlencode,
'subscriptionSort': subscriptionSort,
'mime': formatmime,
+ 'emailaddr': emailaddr,
Sebastian Noack 2014/05/23 13:16:18 There is no need to define the emailaddr function
Wladimir Palant 2014/05/23 13:28:29 True, in the initial version this wasn't the case.
'ljust': ljust,
'rjust': rjust,
'ltruncate': ltruncate,
'weekday': formatweekday,
'bytes': formatbytes,
'json': toJSON,
}
« no previous file with comments | « sitescripts/reports/bin/mailDigests.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld