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分に自動更新する

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

【2010_10_30】
guard# cat /usr/local/mailman/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) + 1
  m.Save()
guard#
【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 (改行コードに注意:LF)

して、/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

移行作業履歴

  980  12:43   cd /usr/local/mailman
  985  13:46   mv archives archives_dist
  986  13:47   mv data data_dist
  987  13:47   mv lists lists_dist
  988  13:47   mv logs logs_dist
  989  13:48   cp -rp /usr/Backups/Guard/usr/local/mailman/archives /usr/local/mailman/archives
  990  13:49   ll
  991  13:50   cp -rp /usr/Backups/Guard/usr/local/mailman/data /usr/local/mailman/data
  992  13:50   cp -rp /usr/Backups/Guard/usr/local/mailman/lists /usr/local/mailman/lists
  993  13:50   cp -rp /usr/Backups/Guard/usr/local/mailman/logs /usr/local/mailman/logs
  994  13:50   ll
  995  13:55   ps aux | grep mailman
  996  13:55   /usr/local/etc/rc.d/mailman restart
  997  13:56   /usr/local/etc/rc.d/mailman q
  998  13:56   /usr/local/etc/rc.d/mailman restart
  999  13:57   reboot
 1000  13:57   bsd-update fetch
 1001  14:28   cd /usr/local/mailman
 1002  14:28   bin/withlist -l -r fix_url test tfc2.thousand-winds.jp
 1003  14:29   /usr/local/etc/rc.d/mailman restart
 1004  14:34   bin/withlist -l -r fix_url test tfc2.thousand-winds.jp
 1005  14:52   /usr/local/mailman/bin/check_perms -f
 1006  14:53   /usr/local/mailman/bin/check_perms -f
 1007  14:53   bin/withlist -l -r fix_url test tfc2.thousand-winds.jp
 1008  14:54   /usr/local/etc/rc.d/mailman restart
 1009  14:54   /usr/local/mailman/bin/check_perms -f
 1013  15:24   cp -rp /usr/Backups/Guard/root/bin/ /root/bin
 1014  15:36   cp /usr/Backups/Guard/usr/local/mailman/bin/set_post_id.py /usr/local/mailman/bin/
 1015  15:43   cp /usr/Backups/Guard/usr/local/mailman/cron/crontab-sp.in /usr/local/mailman/cron/
 1016  15:46   crontab -u mailman /usr/local/mailman/cron/crontab-sp.in
 1017  15:49   history

Counter: 3348, today: 1, yesterday: 0

トップ   編集 凍結 差分 履歴 添付 複製 名前変更 リロード   新規 一覧 検索 最終更新   ヘルプ   最終更新のRSS
Last-modified: 2018-02-28 (水) 14:54:05