1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
|
#! /usr/bin/env python
#
# Copyright (C) 1998,1999,2000 by the Free Software Foundation, Inc.
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
"Invoked by cron, checks for pending list requests and mails the admin if any."
import sys
import time
import string
import paths
from Mailman import MailList
from Mailman import mm_cfg
from Mailman import Utils
from Mailman import Message
from Mailman.Handlers import HandlerAPI
# Work around known problems with some RedHat cron daemons
import signal
signal.signal(signal.SIGCHLD, signal.SIG_DFL)
def main():
for name in Utils.list_names():
# the list must be locked in order to open the requests database
mlist = MailList.MailList(name)
try:
count = mlist.NumRequestsPending()
if count:
text = Utils.maketext(
'checkdbs.txt',
{'count' : count,
'host_name': mlist.host_name,
'adminDB' : mlist.GetScriptURL('admindb', absolute=1),
'real_name': mlist.real_name,
}, mlist.preferred_language)
text = text + '\n' + pending_requests(mlist)
subject = '%d %s admin request(s) waiting' % (
count, mlist.real_name)
admin = mlist.GetAdminEmail()
msg = Message.UserNotification(admin, admin, subject, text)
HandlerAPI.DeliverToUser(mlist, msg)
finally:
mlist.Save()
mlist.Unlock()
def pending_requests(mlist):
pending = []
first = 1
for id in mlist.GetSubscriptionIds():
if first:
pending.append('Pending subscriptions:')
first = 0
when, addr, passwd, digest = mlist.GetRecord(id)
pending.append(' %s %s' % (addr, time.ctime(when)))
first = 1
for id in mlist.GetHeldMessageIds():
if first:
pending.append('\nPending posts:')
first = 0
info = mlist.GetRecord(id)
if len(info) == 5:
# pre-2.0beta3 compatibility
when, sender, subject, reason, text = mlist.GetRecord(id)
else:
when, sender, subject, reason, text, msgdata = mlist.GetRecord(id)
pending.append(' From: %s on %s\n Cause: %s' %
(sender, time.ctime(when), reason))
pending.append('')
return string.join(pending, '\n')
if __name__ == '__main__':
main()
|