[Mailman-Users] custom handler

Mark Sapiro mark at msapiro.net
Thu Feb 16 01:00:07 CET 2012


George, Harry G wrote:

>I'm stuck on the basic development cycle for "custom handlers".   Symptom is that it is remembering an early attempt and not loading the latest version of my handler.     Also, I'm now trying to use syslog (to post or to error) as a way to get/read/understand msg and msgdata -- is there a better way?


Every time you modify your handler, you have to restart Mailman.

For logging, use Mailman's syslog. Include

from Mailman.Logging.Syslog import syslog

in your handler and then use statements of the form

    syslog('debug', format, var1, var2, ...)

to write to Mailman's 'debug' log, e.g. to report the values of
variables like listname, hostname, url and filepath, you might use

    syslog('debug', 'listname: %s, hostname: %s, url: %s, path: %s',
           listname, hostname, url, filepath)


>I have a list (dlms_1) that I want to use with no hint of mailman being invloved (no listnames, not "mailman").
>
>At Mark Sapiro's recommendation, I've been looking at custom handler:
>http://wiki.list.org/pages/viewpage.action?pageId=4030615
>
>I've made a working directory within the mailman context:
>/usr3/mailman/
>    bin/
>    Mailman/
>        Handlers/
>             (Custom__dlms_1.py goes here)
>    custom/
>         dlms_1/
>             go                       #cp handler and run config_list
>             custpipe__dlms_1.py      #set mlist.pipeline
>             Custom__dlms_1.py        #where I'll do my work
>    ...
>
>Process:
>1. Edit Custom__dlms_1.py.
>2. Run "go"
>3. Send email from MS outlook to dlms_1 list.
>4. No response or posting, so check post and error logs
>5. Nothing new in post, but erro log has
>#-----------------------
>  File "/usr3/mailman/Mailman/Queue/Runner.py", line 170, in _onefile
>    keepqueued = self._dispose(mlist, msg, msgdata)
>  File "/usr3/mailman/Mailman/Queue/IncomingRunner.py", line 130, in _dispose
>    more = self._dopipeline(mlist, msg, msgdata, pipeline)
>  File "/usr3/mailman/Mailman/Queue/IncomingRunner.py", line 153, in _dopipelin
>
>    sys.modules[modname].process(mlist, msg, msgdata)
>  File "/usr3/mailman/Mailman/Handlers/Custom__dlms_1.py", line 66, in process
>AttributeError: 'str' object has no attribute 'append'
>
>Feb 15 09:00:17 2012 (3662) SHUNTING: 1329325217.251622+f51327464d18dafebf2da57
>ede3fbc086fd8fcc
>#---------------------------
> 
>There is no line 66 in the current Custom_dlms_1.py.


Are there 65 lines? If so, the error is not detected until end of file
is reached. Also, see below.


>I did try several variations before trimming to the current skeleton.
>
>#---go---
>#=================================================
># Install handler
>#=================================================
>cp Custom__dlms_1.py /usr3/mailman/Mailman/Handlers
>
>#=================================================
># Config for new pipe
>#=================================================
>/usr3/mailman/bin/config_list -i custpipe__dlms_1.py dlms_1
>
>#---custpipe__dlms_1.py---
>mlist.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',
>    'Custom__dlms_1',    #<--- custom here
>    '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',
>    ]


I would suggest putting your handler after CookHeaders to deal with the
headers it may add. Also, I didn't mention this previously, but the
sending process in SMTPDirect.py will add Sender: and Errors-To:
headers and set the envelope sender to dlms_1-bounces at list_domain. If
you don't want that, you can set a different address in your handler
by setting

    msgdata.envsender = 'address at example.com'

but this will break automated bounce processing for the list.


>#---Custom__dlms_1.py---
>#I started with MyHandler, Decorate, and CookedHeaders as exemplars, but backtracked to this skeleton
>
>import re
>
>from Mailman import Utils
>from Mailman import Errors
>from Mailman.i18n import _
>from Mailman.Handlers import Hold
>from Mailman.Handlers import Moderate
>from Mailman.Logging.Syslog import syslog
>
>
>def process(mlist, msg, msgdata):
>    syslog('post','msgdata=%s' % msgdata)


Since msgdata is a dictionary, %s is not the best format to use. Also
syslog will interpolate arguments 3 - n into the format (arg 2). What
you have will work, but I would write

    syslog('debug', 'msgdata=%r', msgdata)

or

    syslog('debug', 'msgdata=%s', repr(msgdata))

>#-----------------------------------------------


If the above was the entire content of
/usr3/mailman/Mailman/Handlers/Custom__dlms_1.py when you got the
above traceback, that kind of issue often results from Python
incompatibilities. Is it possible that
/usr3/mailman/Mailman/Handlers/Custom__dlms_1.pyc  exists and was
created by other than by the import in Mailman's IncomingRunner
process using a different Python?

-- 
Mark Sapiro <mark at msapiro.net>        The highway is for gamblers,
San Francisco Bay Area, California    better use your sense - B. Dylan



More information about the Mailman-Users mailing list