Add mailing list headers to newsletters
[platal.git] / bin / devel / lists.foreach_template.py
1 #!/usr/bin/env python
2 #***************************************************************************
3 #* Copyright (C) 2003-2013 Polytechnique.org *
4 #* http://opensource.polytechnique.org/ *
5 #* *
6 #* This program is free software; you can redistribute it and/or modify *
7 #* it under the terms of the GNU General Public License as published by *
8 #* the Free Software Foundation; either version 2 of the License, or *
9 #* (at your option) any later version. *
10 #* *
11 #* This program is distributed in the hope that it will be useful, *
12 #* but WITHOUT ANY WARRANTY; without even the implied warranty of *
13 #* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
14 #* GNU General Public License for more details. *
15 #* *
16 #* You should have received a copy of the GNU General Public License *
17 #* along with this program; if not, write to the Free Software *
18 #* Foundation, Inc., *
19 #* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA *
20 #***************************************************************************
21
22 import base64, MySQLdb, os, getopt, sys, MySQLdb.converters, sha, signal
23
24 sys.path.append('/usr/lib/mailman/bin')
25
26 from pwd import getpwnam
27 from grp import getgrnam
28
29 from SimpleXMLRPCServer import SimpleXMLRPCServer
30 from SimpleXMLRPCServer import SimpleXMLRPCRequestHandler
31
32 import paths
33 from Mailman import MailList
34 from Mailman import Utils
35 from Mailman import Message
36 from Mailman import Errors
37 from Mailman import mm_cfg
38 from Mailman import i18n
39 from Mailman.UserDesc import UserDesc
40 from Mailman.ListAdmin import readMessage
41 from email.Iterators import typed_subpart_iterator
42
43
44 uid = getpwnam(mm_cfg.MAILMAN_USER)[2]
45 gid = getgrnam(mm_cfg.MAILMAN_GROUP)[2]
46
47 if not os.getuid():
48 os.setregid(gid,gid)
49 os.setreuid(uid,uid)
50
51 if ( os.getuid() is not uid ) or ( os.getgid() is not gid):
52 sys.exit(0)
53
54
55 for listname in Utils.list_names():
56 try:
57 mlist = MailList.MailList(listname,lock=0)
58 except:
59 print 'ERROR for '+listname
60 continue
61 try:
62 mlist.Lock()
63
64 ############################################
65 # do treatement here
66 ############################################
67
68 mlist.Save()
69 mlist.Unlock()
70 print 'OK for '+listname
71 except:
72 print 'ERROR for '+listname
73 continue
74
75 print 'DONE'
76
77 # vim:set et: