Permalink
Browse files

Fix a bug that makes invalid (pesudo-) maildir files when the subject…

… string contains newlines. Now uses str.splitlines() to handle all newlines, meaning every crazy special line ending case should be covered.
  • Loading branch information...
Albin Stjerna
Albin Stjerna committed Nov 8, 2012
1 parent d7da860 commit 1cb87da62e499090e7565ceb6c4cf67d6a7bec23
Showing with 6 additions and 2 deletions.
  1. +6 −2 sluk.py
View
@@ -192,7 +192,6 @@ def update_feeds(update_feed_name="All"):
try:
parsed = feedparser.parse(feed, etag
= cache[feed]["etag"])
-
# Needs time in tuple form. Somewhere, there was a bug that made
# it necessary to do this outside of the call to feedparser,
@@ -288,7 +287,12 @@ def update_feeds(update_feed_name="All"):
# create text/html message only
msg = MIMEText(content, "html")
- msg['Subject'] = title
+ # This wierd .splitlines() business takes care of any newline
+ # characters that might have snuck into the title (those would
+ # otherwise mess up the mail file). This was directly copied
+ # from a Stack Overflow thread:
+ # http://stackoverflow.com/questions/2201633/replace-newlines-in-a-unicode-string
+ msg['Subject'] = ''.join(unicode(title, 'utf-8').splitlines())
msg['From'] = feed_name + " <sluk@" + os.uname()[1] + ">"
msg['To'] = "sluk@" + os.uname()[1]

0 comments on commit 1cb87da

Please sign in to comment.