- 追加された行はこの色です。
- 削除された行はこの色です。
*Mailman Tips 2 [#bf7ef92e]
[[Mailman on FreeBSD]]~
[[Mailman Tips]]~
[[Mailman Tips 2]]~
[[Mailman Tips 3]]~
[[Mailman Tips 4]]~
#contents
**リストのメールアドレスを取り出す [#aa6b7009]
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分に自動更新する
**「通し番号」の自動更新?? [#v062918a]
【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.py test
// Importing set_post_id...
// Running set_post_id.py()...
// Traceback (most recent call last):
// File "/usr/local/mailman/bin/withlist", line 297, in ?
// main()
// File "/usr/local/mailman/bin/withlist", line 269, in main
// func = getattr(mod, callable)
// AttributeError: 'module' object has no attribute 'py'
//
// これは、コマンドラインに、set_post_id.py と、「.py」が付いていたため(^^;
// 正しくは、↓
【結果】
% /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/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([total|today|yesterday]);