Code

Install roundup.cgi to share/roundup
[roundup.git] / roundup-popgw
1 #! /usr/bin/python
2 #
3 # Copyright (c) 2001 Bizar Software Pty Ltd (http://www.bizarsoftware.com.au/)
4 # This module is free software, and you may redistribute it and/or modify
5 # under the same terms as Python, so long as this copyright message and
6 # disclaimer are retained in their original form.
7 #
8 # IN NO EVENT SHALL BIZAR SOFTWARE PTY LTD BE LIABLE TO ANY PARTY FOR
9 # DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING
10 # OUT OF THE USE OF THIS CODE, EVEN IF THE AUTHOR HAS BEEN ADVISED OF THE
11 # POSSIBILITY OF SUCH DAMAGE.
12 #
13 # BIZAR SOFTWARE PTY LTD SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING,
14 # BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
15 # FOR A PARTICULAR PURPOSE.  THE CODE PROVIDED HEREUNDER IS ON AN "AS IS"
16 # BASIS, AND THERE IS NO OBLIGATION WHATSOEVER TO PROVIDE MAINTENANCE,
17 # SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
18
19 # $Id: roundup-popgw,v 1.3 2001-11-01 22:20:39 richard Exp $
21 import sys
22 if int(sys.version[0]) < 2:
23     print "Roundup requires Python 2.0 or newer."
24     sys.exit(1)
26 # figure the instance home
27 import os
28 if len(sys.argv) > 1:
29     instance_home = sys.argv[1]
30 else:
31     instance_home = os.environ.get('ROUNDUP_INSTANCE', '')
32 if not instance_home:
33     print 'No instance home specified'
34     sys.exit(1)
36 # get the instance
37 import roundup.instance
38 instance = roundup.instance.open(instance_home)
40 # invoke the mail handler
41 db = instance.open('admin')
42 handler = instance.MailGW(db)
44 import getpass, poplib
45 from rfc822 import Message
47 M = poplib.POP3('localhost')
48 M.user(getpass.getuser())
49 M.pass_(getpass.getpass())
50 numMessages = len(M.list()[1])
51 for i in range(numMessages):
52     for j in M.retr(i+1)[1]:
53         s = cStringIO.StringIO('\n'.join(j))
54         s.seek(0)
55         handler.handle_Message(Message(s))
57 #
58 # $Log: not supported by cvs2svn $
59 # Revision 1.2  2001/11/01 22:09:36  richard
60 # make popgw use the Message interface
61 #
62 # Revision 1.1  2001/11/01 22:07:11  richard
63 # Completely untested pop gateway. It's a start.
64 #
65 #
66 #
67 # vim: set filetype=python ts=4 sw=4 et si