After recently transferring a bunch of mailing lists from Majordomo to Mailman, one of the features that was missed by the users was the ‘–LongSig’ feature of Majordomo. Very useful, but not available in Mailman. Using the ‘–LongSig’ tag in an email meant that anything after that was removed by Mailman and this especially useful if you work in a company that insists on putting 20 lines of boilerplate disclaimers at the end of every email sent. On a mailing list, this can annoy people.
So, Mailman being written in Python, it is simple enough to extend it’s functionality.
Mailman processes all emails through Handlers. The standard Mailman installation includes a load of Handlers (in the
Mailman/Handlers directory) and specified in the
Mailman/Default.py configuration file, the GLOBAL_PIPELINE variable. My installation contained:
GLOBAL_PIPELINE = [ # These are the modules that do tasks common to all delivery paths. 'SpamDetect', 'Approve', 'Replybot', 'Moderate', 'Hold', 'MimeDel', 'Scrubber', 'Emergency', 'Tagger', 'CalcRecips', 'AvoidDuplicates', 'Cleanse', 'CleanseDKIM', 'CookHeaders', # And now we send the message to the digest mbox file, and to the arch and # news queues. Runners will provide further processing of the message, # specific to those delivery paths. 'ToDigest', 'ToArchive', 'ToUsenet', # Now we'll do a few extra things specific to the member delivery # (outgoing) path, finally leaving the message in the outgoing queue. 'AfterDelivery', 'Acknowledge', 'ToOutgoing', ]
So, we want to create a Handler that can be added in to this list of Handlers. The Mailman FAQ has a section on http://wiki.list.org/pages/viewpage.action?pageId=4030615 that will get me started.
Right, so here is the code:
# Copyright (C) 2007 Tim Pushman (jalal @ gnomedia) # # This program is free software; you can redistribute it and/or # modify it under the terms of the GNU General Public License # as published by the Free Software Foundation; either version 2 # of the License, or (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, # USA. """Remove the LongSig from the message.""" from types import ListType from Mailman.Message import Message LONGSIG = '\n\n--LongSig' # the main process definition def process(mlist, msg, msgdata): payload = msg.get_payload() if not isinstance(payload, ListType): if payload.rfind( LONGSIG ) != -1: sections = payload.split( LONGSIG, 1 ) payload = sections + '\n[ *** LongSig auto truncated *** ]' msg.set_payload( payload )
As you can see, the code is scanning for two new lines and then the ‘–LongSig’ marker. I’ve included the two new lines so that I could actually write an email to the list and describe how it worked without running the risk of having the email truncated (if the line wrapped to place the tag at the start of the line).
The next thing is to put the Handler into the GLOBAL_PIPELINE for the mailing lists. The Mailman FAQ entry above discusses different ways of doing this, and I used the ‘config_list’ method described near the end, as I didn’t want it on all the lists.
I hope you find it useful, I searched the net for something like this and couldn’t find anything.