Fix email header injection
authorEtienne Millon <etienne.millon@gmail.com>
Fri, 25 May 2012 16:04:08 +0000 (18:04 +0200)
committerMatěj Cepl <mcepl@redhat.com>
Mon, 18 Feb 2013 19:15:36 +0000 (20:15 +0100)
Bug: http://bugs.python.org/issue5871
Bug-Debian: http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=526064

rss2email.py

index 69998dbeff7c1f0dad9b5fb95b22f1177257fed7..a6c3cbec1789b21ecd1656921375f491b67d5487 100755 (executable)
@@ -111,9 +111,16 @@ PROXY=""
 CHARSET_LIST='US-ASCII', 'ISO-8859-1', 'UTF-8', 'BIG5', 'ISO-2022-JP'
 
 from email.MIMEText import MIMEText
-from email.Header import Header
+from email.Header import Header as _Header
 from email.Utils import parseaddr, formataddr
-                         
+
+class Header(_Header):
+    # Work-around for <http://bugs.python.org/issue5871>
+    def append(self, s=None, *args, **kwargs):
+        if s is not None:
+            s = s.replace('\n', ' ').replace('\r', ' ')
+        _Header.append(self, s, *args, **kwargs)
+
 # Note: You can also override the send function.
 
 def send(sender, recipient, subject, body, contenttype, extraheaders=None, smtpserver=None):