1 #!/usr/bin/env python 2 # 3 # Copyright (C) 2010 by the Free Software Foundation, Inc. 4 # 5 # This program is free software; you can redistribute it and/or 6 # modify it under the terms of the GNU General Public License 7 # as published by the Free Software Foundation; either version 2 8 # of the License, or (at your option) any later version. 9 # 10 # This program is distributed in the hope that it will be useful, 11 # but WITHOUT ANY WARRANTY; without even the implied warranty of 12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 # GNU General Public License for more details. 14 # 15 # You should have received a copy of the GNU General Public License 16 # along with this program; if not, write to the Free Software 17 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, 18 # USA. 19 20 """This is a template for constructing an external archiver for situations 21 where one wants to archive posts in Mailman's pipermail archive, but also 22 wants to invoke some other process on the archived message after its URL 23 and/or path are known. 24 25 It assumes this is invoked by mm_cfg.py settings like 26 PUBLIC_EXTERNAL_ARCHIVER = '/path/to/Ext_Arch.py %(hostname)s %(listname)s' 27 PRIVATE_EXTERNAL_ARCHIVER = '/path/to/Ext_Arch.py %(hostname)s %(listname)s' 28 29 The path in the sys.path.insert() below must be adjusted to the actual path 30 to Mailman's bin/ directory, or you can simply put this script in Mailman's 31 bin/ directory and it will work without the sys.path.insert() and of course, 32 you must add the code you want to the ext_process function. 33 """ 34 35 import sys 36 sys.path.insert(0,'/usr/local/mailman/bin') 37 import paths 38 39 import os 40 import email 41 42 from cStringIO import StringIO 43 44 from Mailman import Message 45 from Mailman import MailList 46 from Mailman.Archiver import HyperArch 47 from Mailman.Logging.Syslog import syslog 48 from Mailman.Logging.Utils import LogStdErr 49 50 # For debugging, log stderr to Mailman's 'debug' log 51 LogStdErr('debug', 'mailmanctl', manual_reprime=0) 52 53 def ext_process(listname, hostname, url, filepath, msg): 54 """Here's where you put your code to deal with the just archived message. 55 56 Arguments here are the list name, the host name, the URL to the just 57 archived message, the file system path to the just archived message and 58 the message object. 59 60 These can be replaced or augmented as needed. 61 """ 62 syslog('debug', 'listname: %s, hostname: %s, url: %s, path: %s, msg: %s', 63 listname, hostname, url, filepath, msg) 64 return 65 66 def main(): 67 """This is the mainline. 68 69 It first invokes the pipermail archiver to add the message to the archive, 70 then calls the function above to do whatever with the archived message 71 after it's URL and path are known. 72 """ 73 74 listname = sys.argv 75 hostname = sys.argv 76 77 # We must get the list unlocked here because it is already locked in 78 # ArchRunner. This is safe because we aren't actually changing our list 79 # object. ArchRunner's lock plus pipermail's archive lock will prevent 80 # any race conditions. 81 mlist = MailList.MailList(listname, lock=False) 82 83 # We need a seekable file for processUnixMailbox() 84 f = StringIO(sys.stdin.read()) 85 86 # If we don't need a Message.Message instance, we can skip the next and 87 # the imports of email and Message above. 88 msg = email.message_from_file(f, Message.Message) 89 90 h = HyperArch.HyperArchive(mlist) 91 # Get the message number for the next message 92 sequence = h.sequence 93 # and add the message. 94 h.processUnixMailbox(f) 95 f.close() 96 97 # Get the archive name, etc. 98 archive = h.archive 99 msgno = '%06d' % sequence 100 filename = msgno + '.html' 101 filepath = os.path.join(h.basedir, archive, filename) 102 h.close() 103 104 url = '%s%s/%s' % (mlist.GetBaseArchiveURL(), archive, filename) 105 106 ext_process(listname, hostname, url, filepath, msg) 107 108 if __name__ == '__main__': 109 main()
Attached FilesTo refer to attachments on a page, use attachment:filename, as shown below in the list of files. Do NOT use the URL of the [get] link, since this is subject to change and can break easily.
You are not allowed to attach a file to this page.