#!/usr/bin/python
"""rss2email: get RSS feeds emailed to you
-http://www.aaronsw.com/2002/rss2email
+http://rss2email.infogami.com
Usage:
new [emailaddress] (create new feedfile)
list
delete n
"""
-__version__ = "2.60"
+__version__ = "2.61"
__author__ = "Aaron Swartz (me@aaronsw.com)"
__copyright__ = "(C) 2004 Aaron Swartz. GNU GPL 2."
___contributors__ = ["Dean Jackson", "Brian Lalor", "Joey Hess",
# If you have an HTTP Proxy set this in the format 'http://your.proxy.here:8080/'
PROXY=""
+# To most correctly encode emails with international characters, we iterate through the list below and use the first character set that works
+# Eventually (and theoretically) ISO-8859-1 and UTF-8 are our catch-all failsafes
+CHARSET_LIST='US-ASCII', 'BIG5', 'ISO-2022-JP', 'ISO-8859-1', 'UTF-8'
+
from email.MIMEText import MIMEText
from email.Header import Header
from email.Utils import parseaddr, formataddr
The email will be properly MIME encoded and delivered though SMTP to
localhost port 25. This is easy to change if you want something different.
- The charset of the email will be the first one out of US-ASCII, ISO-8859-1
- and UTF-8 that can represent all the characters occurring in the email.
+ The charset of the email will be the first one out of the list
+ that can represent all the characters occurring in the email.
"""
# Header class is smart enough to try US-ASCII, then the charset we
header_charset = 'ISO-8859-1'
# We must choose the body charset manually
- for body_charset in 'US-ASCII', 'ISO-8859-1', 'UTF-8':
+ for body_charset in CHARSET_LIST:
try:
body.encode(body_charset)
except UnicodeError:
if SMTP_SEND:
if not smtpserver:
import smtplib
- from smtplib import SMTP
try:
smtpserver = smtplib.SMTP(SMTP_SERVER)
if AUTHREQUIRED:
try:
+ smtpserver.ehlo()
+ smtpserver.starttls()
+ smtpserver.ehlo()
smtpserver.login(SMTP_USER, SMTP_PASS)
except KeyboardInterrupt:
raise
unix = 0
try:
import fcntl
- if sys.version.find('sunos') != -1:
+ if sys.version.find('sunos') == -1:
unix = 1
except:
pass
import threading
class TimeoutError(Exception): pass
+class InputError(Exception): pass
+
def timelimit(timeout, function):
# def internal(function):
def internal2(*args, **kw):
if 'id' in entry and entry.id: return entry.id
content = getContent(entry)
- if content: return md5.new(unu(content)).hexdigest()
+ if content and content != "\n": return md5.new(unu(content)).hexdigest()
if 'link' in entry: return entry.link
if 'title' in entry: return md5.new(unu(entry.title)).hexdigest()
else:
title = getContent(entry)[:70]
- title = title.replace("\n", " ")
+ title = title.replace("\n", " ").strip()
datetime = time.gmtime()
name = getName(r, entry)
fromhdr = '"'+ name + '" <' + from_addr + ">"
tohdr = (f.to or default_to)
- subjecthdr = html2text(title).strip()
+ subjecthdr = title
datehdr = time.strftime("%a, %d %b %Y %H:%M:%S -0000", datetime)
useragenthdr = "rss2email"
extraheaders = {'Date': datehdr, 'User-Agent': useragenthdr}
unlock(feeds, feedfileObject)
if __name__ == '__main__':
- ie, args = "InputError", sys.argv
+ args = sys.argv
try:
- if len(args) < 3: raise ie, "insufficient args"
+ if len(args) < 3: raise InputError, "insufficient args"
feedfile, action, args = args[1], args[2], args[3:]
if action == "run":
elif action == "email":
if not args:
- raise ie, "Action '%s' requires an argument" % action
+ raise InputError, "Action '%s' requires an argument" % action
else:
email(args[0])
elif action == "delete":
if not args:
- raise ie, "Action '%s' requires an argument" % action
+ raise InputError, "Action '%s' requires an argument" % action
elif args[0].isdigit():
delete(int(args[0]))
else:
- raise ie, "Action '%s' requires a number as its argument" % action
+ raise InputError, "Action '%s' requires a number as its argument" % action
else:
- raise ie, "invalid action"
+ raise InputError, "Invalid action"
- except ie, e:
+ except InputError, e:
print "E:", e
print
print __doc__