import cgi
import dbm
+import re
+
from HTMLParser import HTMLParser
class HTML2Text(HTMLParser):
self.curdata = self.curdata + data.decode("utf-8")
def handle_charref(self, name):
- entity = unichr(int(name))
+ try:
+ entity = unichr(int(name))
+ except:
+ if name[0] == 'x':
+ try:
+ entity = unichr(int('0%s' %(name,), 16))
+ except:
+ entity = u'#%s' %(name,)
+ else:
+ entity = u'#%s' %(name,)
self.curdata = self.curdata + unicode(entity.encode('utf-8'), \
"utf-8")
if item.has_key("content"):
content = item["content"][0]["value"]
else:
- content = item["summary"]
+ if item.has_key("description"):
+ content = item["description"]
+ else:
+ content = u''
md5sum = md5.md5(content.encode("utf-8")).hexdigest()
pass
msg.add_header("Date", createddate)
subj_gen = HTML2Text()
- subj_gen.feed(item["title"].encode("utf-8"))
+ title = item["title"].encode("utf-8")
+ title = re.sub(u'<', u'<', title)
+ title = re.sub(u'>', u'>', title)
+ subj_gen.feed(title)
msg.add_header("Subject", subj_gen.gettext())
msg.set_default_type("text/plain")