# HG changeset patch # User Sebastien Decugis # Date 1281420445 -32400 # Node ID 559393b8973fedd5c9911a608ba5a64bea9f032b Initial version: support for searching the archives diff -r 000000000000 -r 559393b8973f trac_plugin/MailmanPlugin.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/trac_plugin/MailmanPlugin.py Tue Aug 10 15:07:25 2010 +0900 @@ -0,0 +1,61 @@ +from trac.core import * +from trac.search import ISearchSource, shorten_result +from trac.mimeview.api import Mimeview +from datetime import datetime +import pytz +import SwishE + +""" Mailing-list search plugin for Trac + This plugin relies on a working swish-e index for mailing-list. + See for example: + http://svn.rot13.org/index.cgi/swish/view/trunk/mailman/index_mailman.pl + (assuming the archives are generated by pipermail) + + It also requires the swish-e python wrapper from + http://py-swish-e.berlios.de/ + + The configuration is static in this file for now, it might be moved to + configuration file or an admin panel later. Each mailing-list is defined by: + ( short name, index file, label ). +""" + +MailmanConfig=( + ( 'help', '/var/swish/indexes/help.index', 'help@freediameter.net'), + ( 'dev', '/var/swish/indexes/dev.index', 'dev@freediameter.net') + ) + +class MailmanPlugin(Component): + """ Search mailing-list archives. """ + implements(ISearchSource) + + # ISearchSource methods + def get_search_filters(self, req): + for MLShort, MLIndex, MLLabel in MailmanConfig: + yield ('ML-' + MLShort, MLLabel) + + def get_search_results(self, req, terms, filters): + # Prepare keywords + query = '' + for word in terms : + query = query + word + ' ' + query.rstrip(' ') + tokyo_tz = pytz.timezone('Asia/Tokyo') + + for MLShort, MLIndex, MLLabel in MailmanConfig: + if 'ML-' + MLShort in filters: + self.env.log.debug ('Searching "%s" in index %s' % (query, MLIndex) ) + # perform the search + handle = SwishE.new( MLIndex ) + #handle.setSort('swishrank') + for result in handle.query(query): + date = datetime.fromtimestamp(result.getproperty('sent')) + content = Mimeview(self.env).to_unicode(result.getproperty('swishdescription')) + #(href, title, date, author, excerpt). + yield(result.getproperty('swishdocpath'), + result.getproperty('swishtitle') , + date.replace(tzinfo=tokyo_tz), + # result.getproperty('name') + ' <' + result.getproperty('email') + '> in ' + MLLabel, + result.getproperty('name') + ' <' + result.getproperty('email') + '>', + shorten_result(content, query)) + +