Mailman Tips 2

Mailman on FreeBSD
Mailman Tips
Mailman Tips 2
Mailman Tips 3
Mailman Tips 4

リストのメールアドレスを取り出す

Mailman の list_name というメーリングリストのメールアドレスは、 /usr/local/mailman/lists/list_name に保存されているが、Majordomo のような一行一アドレスというファイル構造にはなっていない。
外部アプリでユーザ認証を行う際にはそのままでは難しいので、メールアドレスをテキストで取り出したい。

/usr/local/mailman/bin/list_members list_name > /usr/local/mailman/lists/list_name/list_member

とするとlist_memberという一行一アドレスのファイルが出来る。 自動生成するには、たとえば、/root/bin/mailman_mailaddress2text.sh というファイルに

#!/bin/sh
/usr/local/mailman/bin/list_members list_name > /usr/local/mailman/lists/list_name/list_member

とし、実行権を与えて、/etc/crontab に、

55	2	*	*	*	root	/root/bin/mailman_mailaddress2text.sh

と記述しておけば、毎日2時55分に自動更新する

「通し番号」の自動更新??

【Q】
通し番号を、毎日0時に[list_name:071212000]という様式にしたい(西暦の下二桁、月、日、通
し番号3桁)のですが、どのような方法がお勧めでしょうか。
【A】
bin/withlist はそれ用に作られたスクリプトを呼び出して実行することができますので、次のよ
うなスクリプトを bin ディレクトリに作成しておいて、cron 実行すればよいかと思います。

$ cat bin/set_post_id.py
import time

def set_post_id(m):
   today = time.strftime('%y%m%d', time.localtime())
   m.post_id = float(int(today, 10) * 1000)
   m.Save()

cron で実行するコマンドは次のようになります。
<prefix>/bin/withlist -l -r set_post_id <listname>

subject_prefix の方は、
[listname:%09d]
補足説明
% python
Python 2.4.4 (#2, May  1 2007, 08:45:15)
[GCC 3.4.6 [FreeBSD] 20060305] on freebsd6
Type "help", "copyright", "credits" or "license" for more information.
>>> import time
>>> time.localtime()
(2007, 12, 13, 13, 47, 15, 3, 347, 0)
>>> time.strftime('%y%m%d', time.localtime())
'071213'
>>> int(time.strftime('%y%m%d', time.localtime()), 10)
71213
>>> int(time.strftime('%y%m%d', time.localtime()), 10) * 1000
71213000
>>> float(int(time.strftime('%y%m%d', time.localtime()), 10) * 1000)
71213000.0
>>>
【結果】
% /usr/local/bin/python2.4 -S /usr/local/mailman/bin/withlist -l -r set_post_id test
Importing set_post_id...
Running set_post_id.set_post_id()...
Loading list test (locked)
Unlocking (but not saving) list: test
Finalizing

で、テストすると、
[Test:071212000] 【通し番号のテスト】
[Test:071212001] Re: 【通し番号のテスト】
[Test:071212002] Re: 【通し番号のテスト】
という具合になりました。:-)

毎日自動更新するように、

vi /usr/local/mailman/cron/crontab-sp.in
01 0 * * * /usr/local/bin/python -S /usr/local/mailman/bin/withlist -ql -r set_post_id core_sandbox 
#01 0 * * * /usr/local/bin/python -S /usr/local/mailman/bin/withlist -l -r set_post_id core_sandbox
#01 0 * * * /usr/local/bin/python2.4 -S /usr/local/mailman/bin/withlist -l -r set_post_id test
#01 0 * * * /usr/local/bin/python2.4 -S /usr/local/mailman/bin/withlist -ql -r set_post_id test

と書き加えて

crontab -u mailman /usr/local/mailman/cron/crontab-sp.in

して、/var/cron/tabs/mailman に変更を反映させる。

cat /var/cron/tabs/mailman
# DO NOT EDIT THIS FILE - edit the master and reinstall.
# (/usr/local/mailman/cron/crontab-sp.in installed on Wed Dec 12 17:54:09 2007)
# (Cron version -- $FreeBSD: src/usr.sbin/cron/crontab/crontab.c,v 1.22.2.1 2006/09/03 17:32:32 brooks Exp $)
   :          :          :
   :          :          :
# At 3:27am every night, regenerate the gzip'd archive file.  Only
# turn this on if the internal archiver is used and
# GZIP_ARCHIVE_TXT_FILES is false in mm_cfg.py
27 3 * * * /usr/local/bin/python2.4 -S /usr/local/mailman/cron/nightly_gzip
01 0 * * * /usr/local/bin/python2.4 -S /usr/local/mailman/bin/withlist -l -r set_post_id test
#01 0 * * * /usr/local/bin/python2.4 -S /usr/local/mailman/bin/withlist -ql -r set_post_id test

Counter: 3360, today: 1, yesterday: 1

トップ   新規 一覧 検索 最終更新   ヘルプ   最終更新のRSS