[Mailman-Developers] handler to auto detach attachment and link it to a website keeping html

Mark Sapiro mark at msapiro.net
Thu Apr 24 01:27:37 CEST 2014


On 04/23/2014 08:31 AM, Sylvain Viart wrote:

> Le 23/04/2014 15:30, Mark Sapiro a écrit :
>>
>> E.g., put the above three lines in a file and run
>>
>> bin/config_list -i /path/to/file listname.
> 
> Works great as you said! :-)
> I wasn't sure how to use this tool. I supposed you have to dump the
> whole config first with -o, add my stuff and reload the whole…
> But it's state's keeping between call of bin/config_list… Cool.


No. config_list will only set/change those things that are in it's
input. So for what you want to do, an input file with just those three
lines is what you want.


> # config_list -v -i t.py testlist
> # withlist -i testlist
> Loading list testlist (unlocked)
> The variable `m' is the testlist MailList instance
>>>> m.ftp_remote_host
> 'ftp.example.com'
> 
> this one gives nothing…
> # config_list -o - testlist | grep ftp
> 
> Can I guess that this tool don't exactly dump the full list state?
> It can't be used for duplicating or full backup for instance?


Config_list is a very powerful tool. It's input file is actually Python
and is exectuted, so you can do almost anything with it. See the -i
option description in 'config_list -h'.

You can set things in two ways. The first paragraph refers to putting
stuff like

ftp_remote_host = 'ftp.example.com'

in the input. This works to set attributes that already exist in the
list object. It will warn you if the attribute is 'non-standard', i.e.
doesn't appear in the web admin UI, but it will set it if it is already
an attribute of the list. It won't work in your case (at least the first
time) because ftp_remote_host is a "variable that isn't already an
attribute of the list object (and) is ignored"

The second paragraph says you have access to the list object through the
variable 'mlist', so you can set anything, existing or not, via syntax like

mlist.ftp_remote_host = 'ftp.example.com'

On the other hand, 'config_list -o' writes only those standard
attributes that appear in the web admin UI.


> My test this morning was failing because of wrong usage… See bellow.
> I tested your script set_attributes
> <http://fog.ccsf.edu/%7Emsapiro/scripts/set_attributes>
> 
>    Mark Sapiro's page : scripts that automate certain mailing list
>    management tasks <http://fog.ccsf.edu/~msapiro/scripts/
>    <http://fog.ccsf.edu/%7Emsapiro/scripts/>>
> 
> 
> Which gives:
> 
> # /usr/lib/mailman/bin/list_set_attributes "ftp_remote_host =
> 'ftp.example.org'" testlist
> attribute "ftp_remote_host" changed
> Non-standard property restored: ftp_remote_host


Which means you probably had already put it there some other way or the
output would have been "attribute "ftp_remote_host" ignored"


...
> 
>> Note, I just removed the information about using extend.py from the FAQ
>> at <http://wiki.list.org/x/l4A9> because the only reason it was there
>> was for the situation where GLOBAL_PIPELINE would change in the future,
>> and it won't work for that anyway because the list's existing pipeline
>> attribute will override it.
>>
> 
> Hum… I'm using it. How I'm supposed to modify the pipeline, so?…


As I say above, the first time you accessed the list with the extend.py
as above, you set the pipeline and maybe other attributes. Once those
attributes exist in the list object, you can't change them via the
extend.py mechanism. Well you can if you also save the list via
mlist.Save() after resetting them, but I don't recommended that which is
why I removed the extend.py stuff from the FAQ.

Use either withlist or config_list to set these attributes.


> /usr/lib/mailman/bin/version
> Using Mailman version: 2.1.15
> 
> Using config_list ok… Hum probably not…
> 
> # cat t.py
> import copy
> from Mailman import mm_cfg
> mlist.pipeline = copy.copy(mm_cfg.GLOBAL_PIPELINE)
> # The next line inserts MyHandler ahead of Moderate.
> mlist.pipeline.insert(mlist.pipeline.index('Moderate'), 'MyHandler')
> 
> 
> # config_list -v -i t.py testlist
> attribute "mm_cfg" ignored
> attribute "copy" ignored


1) Open Mailman/Defaults.py

2) Copy the definition of GLOBAL_PIPELINE

3) paste it into a new file changing the name from GLOBAL_PIPELINE to
mlist.pipeline and add your handler so it becomes

mlist.pipeline = [
    'SpamDetect',
    'Approve',
    'Replybot',
    # inserting MyHandler here.
    'MyHandler',
    'Moderate',
    'Hold',
    'MimeDel',
    'Scrubber',
    'Emergency',
    'Tagger',
    'CalcRecips',
    'AvoidDuplicates',
    'Cleanse',
    'CleanseDKIM',
    'CookHeaders',
    'ToDigest',
    'ToArchive',
    'ToUsenet',
    'AfterDelivery',
    'Acknowledge',
    'WrapMessage',
    'ToOutgoing',
    ]

I also removed the comments and added one. This becomes the input to
config_list (t.py in your example).

Note that if I understand the purpose of your handler, it should come
(not necessarily immediately) after 'Hold'. You really don't want to
archive attachments for messages you might reject or discard.

-- 
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-Developers mailing list