[Mailman-Users] reject oversize messages rather than hold formoderation?

Mark Sapiro mark at msapiro.net
Sun Nov 25 03:31:41 CET 2007

Eric Smith wrote:

>Is there any easy way to get Mailman to reject oversize messages,
>rather than holding them for moderation, or does anyone have a patch?
>I'm really getting sick of dealing with those.
>I spent a few minutes looking at whether I could hack it in myself.
>I quickly found the code that makes the "hold" decision for oversized
>messages, in Mailman/Handlers/Hold.py, but it wasn't obvious how to change
>it to do a rejection rather than a hold.

OK. You found

        if bodylen/1024.0 > mlist.max_message_size:
            hold_for_approval(mlist, msg, msgdata,

All you have to do is change it to

        if bodylen/1024.0 > mlist.max_message_size:
            rej_msg = 'Message too big: limit = %d KB' %
            raise Errors.RejectMessage, rej_msg

Watch out for wrapped lines in both of the above code fragments. Of
course, you can make rej_msg anything you want.

>The structure of Mailman seems confusing to me.  It appears that it is
>organized in terms of making all of the "hold" decisions in one place,
>and the "reject" decisions in another.  I'd have expected it to identify
>the possible problems with a message, and allow list-admin-configurable
>policy decisions to be made for each of those problems.  But perhaps the
>current structure makes sense to those who have better knowledge of
>Mailman internals.

Each incoming message is passed through a pipeline of handlers (defined
in Defaults.py as GLOBAL_PIPELINE). This continues until the pipeline
is exhausted or an exception is raised. To reject a message, raise
Errors.RejectMessage with an appropriate reject notice. To discard a
message, raise Errors.DiscardMessage, although if you want to honor
the list's forward_auto_discards setting, call Moderate.do_discard().

Holding is more complicated because of the various possible
notifications and other things that need to be done, so normally you
call Hold.hold_for_approval().

Descisions are distributed through various handlers because we want to
modularize the various functions like spam detection, membership tests
and miscellaneous holds, yet at least spam detection and membership
tests can hold, reject or discard a message based on list settings.

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