diff -ruN mailman.orig/Mailman/Archiver/HyperArch.py mailman/Mailman/Archiver/HyperArch.py --- mailman.orig/Mailman/Archiver/HyperArch.py 2014-02-03 08:06:48.000000000 -0500 +++ mailman/Mailman/Archiver/HyperArch.py 2014-06-01 13:45:55.000000000 -0400 @@ -1102,6 +1102,101 @@ self.depth = depth self.write_index_entry(article) + + + def RSS(self): + """ Generates a valid RSS feed for mails in self.database + """ + try: + import datetime + import PyRSS2Gen + import hashlib + except Exception, e: + syslog('error', 'error loading libraries for RSS generation: %s', e) + return 0 + + mlist = self.maillist + + mailitems = [] + try: + date, msgid = self.database.dateIndex.first() + mailitems.append(msgid) + except KeyError: + pass + + while 1: + try: + date, msgid = self.database.dateIndex.next() + mailitems.append(msgid) + mailitems = mailitems[-mm_cfg.RSS_NUM_MAILS:] + except KeyError: + break + + # Generate URLs for the messages + baseurl = mlist.GetBaseArchiveURL() + for i in range(len(mailitems)): + article = mailitems[i] = self.database.getArticle(self.archive, mailitems[i]) + vol_name = self.dateToVolName(float(article.date)) + filename = article.filename + article.url = '%s/%s/%s' % (baseurl, vol_name, filename) + + #Read the body again, it's not loaded in cache.. ticket: + #http://sourceforge.net/tracker/?func=detail&atid=100103&aid=835332&group_id=103 + sf = '%s/%s/%s' % (self.basedir, vol_name, filename) + try: + f = open(sf) + article.loadbody_fromHTML(f) + f.close() + except: + pass + + + class MMPyRSS2Gen(PyRSS2Gen.RSSItem): + #Add own values to our PyRSS2Gen class + def add_values(self, key, val): + if not hasattr(self, 'attr'): + self.attr = {} + self.attr[key] = val + + def publish_extensions(self, handler): + for key in self.attr.keys(): + PyRSS2Gen._opt_element(handler, key, self.attr[key]) + + def format_date(l): + try: + lt = time.localtime(int(l)) + x = time.strftime("%a, %d %b %Y %H:%M:%S GMT", lt) + except Exception, e: + syslog('error', 'error loading date for RSS generation: %s',l, e) + x = datetime.datetime.now() + return x + + items = [] + for article in mailitems: + item = MMPyRSS2Gen( + title = CGIescape(article.subject), + link = CGIescape(article.url), + author = CGIescape(article.decoded.get('author')), + description = article._get_body(), + guid = PyRSS2Gen.Guid(CGIescape(article.url)), + pubDate = format_date(article.date), + ) + item.add_values("thread", CGIescape(article.threadKey)) + #print "article _message_id %s" % article._message_id + item.add_values("msgid", hashlib.md5(article.msgid).hexdigest()) + items.append(item) + + rss = PyRSS2Gen.RSS2( + title = CGIescape(mlist.real_name), + link = CGIescape(mlist.GetScriptURL('listinfo', absolute=1)), + description = CGIescape(mlist.description), + lastBuildDate = datetime.datetime.now(), + items = items, + ) + return rss + + + def write_TOC(self): self.sortarchives() omask = os.umask(002) @@ -1112,6 +1207,21 @@ toc.write(self.html_TOC()) toc.close() + if (self.maillist.real_name.lower() not in [list.lower() for list in mm_cfg.RSS_LISTS]): + #Don't need to update RSS + return; + + try: + rssf = open(os.path.join(self.basedir,'rss.xml'),'w') + finally: + os.umask(omask) + rss = self.RSS() + if (rss): + rss.write_xml(rssf) + rssf.close() + + + def write_article(self, index, article, path): # called by add_article omask = os.umask(002) diff -ruN mailman.orig/Mailman/Defaults.py mailman/Mailman/Defaults.py --- mailman.orig/Mailman/Defaults.py 2014-02-03 08:06:48.000000000 -0500 +++ mailman/Mailman/Defaults.py 2014-06-01 13:48:43.000000000 -0400 @@ -428,6 +428,12 @@ # publically available? PUBLIC_MBOX = No +# Lists for which the RSS will be generated. +RSS_LISTS = ['mailman',] + +# Mails included in the RSS +RSS_NUM_MAILS = 250 + #####