Mercurial > p > roundup > code
annotate roundup-mailgw @ 367:5140ccaaab1b
Modified roundup-mailgw so it can read e-mails from a local mail spool file.
Truncates the spool file after parsing.
Fixed a couple of small bugs introduced in roundup.mailgw when I started
the popgw.
| author | Richard Jones <richard@users.sourceforge.net> |
|---|---|
| date | Wed, 07 Nov 2001 05:29:26 +0000 |
| parents | ab16997d9cda |
| children | 0020819bf9b8 |
| rev | line source |
|---|---|
|
27
e5e9ea306a09
moving the bin files to facilitate out-of-the-boxness
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1 #! /usr/bin/python |
|
213
d45384bc6420
Added the copyright/license notice to (nearly) all files...
Richard Jones <richard@users.sourceforge.net>
parents:
204
diff
changeset
|
2 # |
|
d45384bc6420
Added the copyright/license notice to (nearly) all files...
Richard Jones <richard@users.sourceforge.net>
parents:
204
diff
changeset
|
3 # Copyright (c) 2001 Bizar Software Pty Ltd (http://www.bizarsoftware.com.au/) |
|
d45384bc6420
Added the copyright/license notice to (nearly) all files...
Richard Jones <richard@users.sourceforge.net>
parents:
204
diff
changeset
|
4 # This module is free software, and you may redistribute it and/or modify |
|
d45384bc6420
Added the copyright/license notice to (nearly) all files...
Richard Jones <richard@users.sourceforge.net>
parents:
204
diff
changeset
|
5 # under the same terms as Python, so long as this copyright message and |
|
d45384bc6420
Added the copyright/license notice to (nearly) all files...
Richard Jones <richard@users.sourceforge.net>
parents:
204
diff
changeset
|
6 # disclaimer are retained in their original form. |
|
d45384bc6420
Added the copyright/license notice to (nearly) all files...
Richard Jones <richard@users.sourceforge.net>
parents:
204
diff
changeset
|
7 # |
| 214 | 8 # IN NO EVENT SHALL BIZAR SOFTWARE PTY LTD BE LIABLE TO ANY PARTY FOR |
|
213
d45384bc6420
Added the copyright/license notice to (nearly) all files...
Richard Jones <richard@users.sourceforge.net>
parents:
204
diff
changeset
|
9 # DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING |
|
d45384bc6420
Added the copyright/license notice to (nearly) all files...
Richard Jones <richard@users.sourceforge.net>
parents:
204
diff
changeset
|
10 # OUT OF THE USE OF THIS CODE, EVEN IF THE AUTHOR HAS BEEN ADVISED OF THE |
|
d45384bc6420
Added the copyright/license notice to (nearly) all files...
Richard Jones <richard@users.sourceforge.net>
parents:
204
diff
changeset
|
11 # POSSIBILITY OF SUCH DAMAGE. |
|
d45384bc6420
Added the copyright/license notice to (nearly) all files...
Richard Jones <richard@users.sourceforge.net>
parents:
204
diff
changeset
|
12 # |
|
d45384bc6420
Added the copyright/license notice to (nearly) all files...
Richard Jones <richard@users.sourceforge.net>
parents:
204
diff
changeset
|
13 # BIZAR SOFTWARE PTY LTD SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, |
|
d45384bc6420
Added the copyright/license notice to (nearly) all files...
Richard Jones <richard@users.sourceforge.net>
parents:
204
diff
changeset
|
14 # BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS |
|
d45384bc6420
Added the copyright/license notice to (nearly) all files...
Richard Jones <richard@users.sourceforge.net>
parents:
204
diff
changeset
|
15 # FOR A PARTICULAR PURPOSE. THE CODE PROVIDED HEREUNDER IS ON AN "AS IS" |
|
d45384bc6420
Added the copyright/license notice to (nearly) all files...
Richard Jones <richard@users.sourceforge.net>
parents:
204
diff
changeset
|
16 # BASIS, AND THERE IS NO OBLIGATION WHATSOEVER TO PROVIDE MAINTENANCE, |
|
d45384bc6420
Added the copyright/license notice to (nearly) all files...
Richard Jones <richard@users.sourceforge.net>
parents:
204
diff
changeset
|
17 # SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. |
|
d45384bc6420
Added the copyright/license notice to (nearly) all files...
Richard Jones <richard@users.sourceforge.net>
parents:
204
diff
changeset
|
18 # |
|
367
5140ccaaab1b
Modified roundup-mailgw so it can read e-mails from a local mail spool file.
Richard Jones <richard@users.sourceforge.net>
parents:
343
diff
changeset
|
19 # $Id: roundup-mailgw,v 1.9 2001-11-07 05:29:26 richard Exp $ |
|
27
e5e9ea306a09
moving the bin files to facilitate out-of-the-boxness
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
20 |
|
e5e9ea306a09
moving the bin files to facilitate out-of-the-boxness
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
21 import sys |
|
e5e9ea306a09
moving the bin files to facilitate out-of-the-boxness
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
22 if int(sys.version[0]) < 2: |
|
e5e9ea306a09
moving the bin files to facilitate out-of-the-boxness
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
23 print "Roundup requires Python 2.0 or newer." |
|
e5e9ea306a09
moving the bin files to facilitate out-of-the-boxness
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
24 sys.exit(1) |
|
e5e9ea306a09
moving the bin files to facilitate out-of-the-boxness
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
25 |
|
e5e9ea306a09
moving the bin files to facilitate out-of-the-boxness
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
26 # figure the instance home |
|
e5e9ea306a09
moving the bin files to facilitate out-of-the-boxness
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
27 import os |
|
e5e9ea306a09
moving the bin files to facilitate out-of-the-boxness
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
28 if len(sys.argv) > 1: |
|
e5e9ea306a09
moving the bin files to facilitate out-of-the-boxness
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
29 instance_home = sys.argv[1] |
|
e5e9ea306a09
moving the bin files to facilitate out-of-the-boxness
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
30 else: |
|
e5e9ea306a09
moving the bin files to facilitate out-of-the-boxness
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
31 instance_home = os.environ.get('ROUNDUP_INSTANCE', '') |
|
e5e9ea306a09
moving the bin files to facilitate out-of-the-boxness
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
32 if not instance_home: |
|
e5e9ea306a09
moving the bin files to facilitate out-of-the-boxness
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
33 print 'No instance home specified' |
|
e5e9ea306a09
moving the bin files to facilitate out-of-the-boxness
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
34 sys.exit(1) |
|
e5e9ea306a09
moving the bin files to facilitate out-of-the-boxness
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
35 |
|
e5e9ea306a09
moving the bin files to facilitate out-of-the-boxness
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
36 # get the instance |
|
204
c1461733cbf9
Instances are now opened by a special function...
Richard Jones <richard@users.sourceforge.net>
parents:
193
diff
changeset
|
37 import roundup.instance |
|
c1461733cbf9
Instances are now opened by a special function...
Richard Jones <richard@users.sourceforge.net>
parents:
193
diff
changeset
|
38 instance = roundup.instance.open(instance_home) |
|
27
e5e9ea306a09
moving the bin files to facilitate out-of-the-boxness
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
39 |
|
343
ab16997d9cda
Started work on supporting a pop3-fetching server
Richard Jones <richard@users.sourceforge.net>
parents:
214
diff
changeset
|
40 # invoke the mail handler |
|
27
e5e9ea306a09
moving the bin files to facilitate out-of-the-boxness
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
41 db = instance.open('admin') |
|
e5e9ea306a09
moving the bin files to facilitate out-of-the-boxness
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
42 handler = instance.MailGW(db) |
|
367
5140ccaaab1b
Modified roundup-mailgw so it can read e-mails from a local mail spool file.
Richard Jones <richard@users.sourceforge.net>
parents:
343
diff
changeset
|
43 |
|
5140ccaaab1b
Modified roundup-mailgw so it can read e-mails from a local mail spool file.
Richard Jones <richard@users.sourceforge.net>
parents:
343
diff
changeset
|
44 # if there's no more arguments, read a single message from stdin |
|
5140ccaaab1b
Modified roundup-mailgw so it can read e-mails from a local mail spool file.
Richard Jones <richard@users.sourceforge.net>
parents:
343
diff
changeset
|
45 if len(sys.argv) < 2: |
|
5140ccaaab1b
Modified roundup-mailgw so it can read e-mails from a local mail spool file.
Richard Jones <richard@users.sourceforge.net>
parents:
343
diff
changeset
|
46 handler.main(sys.stdin) |
|
5140ccaaab1b
Modified roundup-mailgw so it can read e-mails from a local mail spool file.
Richard Jones <richard@users.sourceforge.net>
parents:
343
diff
changeset
|
47 |
|
5140ccaaab1b
Modified roundup-mailgw so it can read e-mails from a local mail spool file.
Richard Jones <richard@users.sourceforge.net>
parents:
343
diff
changeset
|
48 # otherwise, there's a spool file to read from |
|
5140ccaaab1b
Modified roundup-mailgw so it can read e-mails from a local mail spool file.
Richard Jones <richard@users.sourceforge.net>
parents:
343
diff
changeset
|
49 import fcntl, FCNTL |
|
5140ccaaab1b
Modified roundup-mailgw so it can read e-mails from a local mail spool file.
Richard Jones <richard@users.sourceforge.net>
parents:
343
diff
changeset
|
50 spool_file = sys.argv[2] |
|
5140ccaaab1b
Modified roundup-mailgw so it can read e-mails from a local mail spool file.
Richard Jones <richard@users.sourceforge.net>
parents:
343
diff
changeset
|
51 |
|
5140ccaaab1b
Modified roundup-mailgw so it can read e-mails from a local mail spool file.
Richard Jones <richard@users.sourceforge.net>
parents:
343
diff
changeset
|
52 # open the spool file and lock it |
|
5140ccaaab1b
Modified roundup-mailgw so it can read e-mails from a local mail spool file.
Richard Jones <richard@users.sourceforge.net>
parents:
343
diff
changeset
|
53 f = open(spool_file, 'r+') |
|
5140ccaaab1b
Modified roundup-mailgw so it can read e-mails from a local mail spool file.
Richard Jones <richard@users.sourceforge.net>
parents:
343
diff
changeset
|
54 fcntl.flock(f.fileno(), FCNTL.LOCK_EX) |
|
5140ccaaab1b
Modified roundup-mailgw so it can read e-mails from a local mail spool file.
Richard Jones <richard@users.sourceforge.net>
parents:
343
diff
changeset
|
55 |
|
5140ccaaab1b
Modified roundup-mailgw so it can read e-mails from a local mail spool file.
Richard Jones <richard@users.sourceforge.net>
parents:
343
diff
changeset
|
56 # handle and clear the mailbox |
|
5140ccaaab1b
Modified roundup-mailgw so it can read e-mails from a local mail spool file.
Richard Jones <richard@users.sourceforge.net>
parents:
343
diff
changeset
|
57 try: |
|
5140ccaaab1b
Modified roundup-mailgw so it can read e-mails from a local mail spool file.
Richard Jones <richard@users.sourceforge.net>
parents:
343
diff
changeset
|
58 from mailbox import UnixMailbox |
|
5140ccaaab1b
Modified roundup-mailgw so it can read e-mails from a local mail spool file.
Richard Jones <richard@users.sourceforge.net>
parents:
343
diff
changeset
|
59 import mimetools |
|
5140ccaaab1b
Modified roundup-mailgw so it can read e-mails from a local mail spool file.
Richard Jones <richard@users.sourceforge.net>
parents:
343
diff
changeset
|
60 mailbox = UnixMailbox(f, factory=mimetools.Message) |
|
5140ccaaab1b
Modified roundup-mailgw so it can read e-mails from a local mail spool file.
Richard Jones <richard@users.sourceforge.net>
parents:
343
diff
changeset
|
61 # grab one message |
|
5140ccaaab1b
Modified roundup-mailgw so it can read e-mails from a local mail spool file.
Richard Jones <richard@users.sourceforge.net>
parents:
343
diff
changeset
|
62 message = mailbox.next() |
|
5140ccaaab1b
Modified roundup-mailgw so it can read e-mails from a local mail spool file.
Richard Jones <richard@users.sourceforge.net>
parents:
343
diff
changeset
|
63 while message: |
|
5140ccaaab1b
Modified roundup-mailgw so it can read e-mails from a local mail spool file.
Richard Jones <richard@users.sourceforge.net>
parents:
343
diff
changeset
|
64 # call the instance mail handler |
|
5140ccaaab1b
Modified roundup-mailgw so it can read e-mails from a local mail spool file.
Richard Jones <richard@users.sourceforge.net>
parents:
343
diff
changeset
|
65 handler.handle_Message(message) |
|
5140ccaaab1b
Modified roundup-mailgw so it can read e-mails from a local mail spool file.
Richard Jones <richard@users.sourceforge.net>
parents:
343
diff
changeset
|
66 message = mailbox.next() |
|
5140ccaaab1b
Modified roundup-mailgw so it can read e-mails from a local mail spool file.
Richard Jones <richard@users.sourceforge.net>
parents:
343
diff
changeset
|
67 # nuke the file contents |
|
5140ccaaab1b
Modified roundup-mailgw so it can read e-mails from a local mail spool file.
Richard Jones <richard@users.sourceforge.net>
parents:
343
diff
changeset
|
68 os.ftruncate(f.fileno(), 0) |
|
5140ccaaab1b
Modified roundup-mailgw so it can read e-mails from a local mail spool file.
Richard Jones <richard@users.sourceforge.net>
parents:
343
diff
changeset
|
69 except: |
|
5140ccaaab1b
Modified roundup-mailgw so it can read e-mails from a local mail spool file.
Richard Jones <richard@users.sourceforge.net>
parents:
343
diff
changeset
|
70 import traceback |
|
5140ccaaab1b
Modified roundup-mailgw so it can read e-mails from a local mail spool file.
Richard Jones <richard@users.sourceforge.net>
parents:
343
diff
changeset
|
71 traceback.print_exc() |
|
5140ccaaab1b
Modified roundup-mailgw so it can read e-mails from a local mail spool file.
Richard Jones <richard@users.sourceforge.net>
parents:
343
diff
changeset
|
72 fcntl.flock(f.fileno(), FCNTL.LOCK_UN) |
|
27
e5e9ea306a09
moving the bin files to facilitate out-of-the-boxness
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
73 |
|
e5e9ea306a09
moving the bin files to facilitate out-of-the-boxness
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
74 # |
|
e5e9ea306a09
moving the bin files to facilitate out-of-the-boxness
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
75 # $Log: not supported by cvs2svn $ |
|
367
5140ccaaab1b
Modified roundup-mailgw so it can read e-mails from a local mail spool file.
Richard Jones <richard@users.sourceforge.net>
parents:
343
diff
changeset
|
76 # Revision 1.8 2001/11/01 22:04:37 richard |
|
5140ccaaab1b
Modified roundup-mailgw so it can read e-mails from a local mail spool file.
Richard Jones <richard@users.sourceforge.net>
parents:
343
diff
changeset
|
77 # Started work on supporting a pop3-fetching server |
|
5140ccaaab1b
Modified roundup-mailgw so it can read e-mails from a local mail spool file.
Richard Jones <richard@users.sourceforge.net>
parents:
343
diff
changeset
|
78 # Fixed bugs: |
|
5140ccaaab1b
Modified roundup-mailgw so it can read e-mails from a local mail spool file.
Richard Jones <richard@users.sourceforge.net>
parents:
343
diff
changeset
|
79 # . bug #477104 ] HTML tag error in roundup-server |
|
5140ccaaab1b
Modified roundup-mailgw so it can read e-mails from a local mail spool file.
Richard Jones <richard@users.sourceforge.net>
parents:
343
diff
changeset
|
80 # . bug #477107 ] HTTP header problem |
|
5140ccaaab1b
Modified roundup-mailgw so it can read e-mails from a local mail spool file.
Richard Jones <richard@users.sourceforge.net>
parents:
343
diff
changeset
|
81 # |
|
343
ab16997d9cda
Started work on supporting a pop3-fetching server
Richard Jones <richard@users.sourceforge.net>
parents:
214
diff
changeset
|
82 # Revision 1.7 2001/08/07 00:24:42 richard |
|
ab16997d9cda
Started work on supporting a pop3-fetching server
Richard Jones <richard@users.sourceforge.net>
parents:
214
diff
changeset
|
83 # stupid typo |
|
ab16997d9cda
Started work on supporting a pop3-fetching server
Richard Jones <richard@users.sourceforge.net>
parents:
214
diff
changeset
|
84 # |
| 214 | 85 # Revision 1.6 2001/08/07 00:15:51 richard |
| 86 # Added the copyright/license notice to (nearly) all files at request of | |
| 87 # Bizar Software. | |
| 88 # | |
|
213
d45384bc6420
Added the copyright/license notice to (nearly) all files...
Richard Jones <richard@users.sourceforge.net>
parents:
204
diff
changeset
|
89 # Revision 1.5 2001/08/05 07:44:25 richard |
|
d45384bc6420
Added the copyright/license notice to (nearly) all files...
Richard Jones <richard@users.sourceforge.net>
parents:
204
diff
changeset
|
90 # Instances are now opened by a special function that generates a unique |
|
d45384bc6420
Added the copyright/license notice to (nearly) all files...
Richard Jones <richard@users.sourceforge.net>
parents:
204
diff
changeset
|
91 # module name for the instances on import time. |
|
d45384bc6420
Added the copyright/license notice to (nearly) all files...
Richard Jones <richard@users.sourceforge.net>
parents:
204
diff
changeset
|
92 # |
|
204
c1461733cbf9
Instances are now opened by a special function...
Richard Jones <richard@users.sourceforge.net>
parents:
193
diff
changeset
|
93 # Revision 1.4 2001/08/03 01:28:33 richard |
|
c1461733cbf9
Instances are now opened by a special function...
Richard Jones <richard@users.sourceforge.net>
parents:
193
diff
changeset
|
94 # Used the much nicer load_package, pointed out by Steve Majewski. |
|
c1461733cbf9
Instances are now opened by a special function...
Richard Jones <richard@users.sourceforge.net>
parents:
193
diff
changeset
|
95 # |
|
193
241a0323aacb
Used the much nicer load_package, pointed out by Steve Majewski.
Richard Jones <richard@users.sourceforge.net>
parents:
190
diff
changeset
|
96 # Revision 1.3 2001/08/03 00:59:34 richard |
|
241a0323aacb
Used the much nicer load_package, pointed out by Steve Majewski.
Richard Jones <richard@users.sourceforge.net>
parents:
190
diff
changeset
|
97 # Instance import now imports the instance using imp.load_module so that |
|
241a0323aacb
Used the much nicer load_package, pointed out by Steve Majewski.
Richard Jones <richard@users.sourceforge.net>
parents:
190
diff
changeset
|
98 # we can have instance homes of "roundup" or other existing python package |
|
241a0323aacb
Used the much nicer load_package, pointed out by Steve Majewski.
Richard Jones <richard@users.sourceforge.net>
parents:
190
diff
changeset
|
99 # names. |
|
241a0323aacb
Used the much nicer load_package, pointed out by Steve Majewski.
Richard Jones <richard@users.sourceforge.net>
parents:
190
diff
changeset
|
100 # |
|
190
996eaf90c01e
Instance import now imports the instance using imp.load_module...
Richard Jones <richard@users.sourceforge.net>
parents:
127
diff
changeset
|
101 # Revision 1.2 2001/07/29 07:01:39 richard |
|
996eaf90c01e
Instance import now imports the instance using imp.load_module...
Richard Jones <richard@users.sourceforge.net>
parents:
127
diff
changeset
|
102 # Added vim command to all source so that we don't get no steenkin' tabs :) |
|
996eaf90c01e
Instance import now imports the instance using imp.load_module...
Richard Jones <richard@users.sourceforge.net>
parents:
127
diff
changeset
|
103 # |
|
127
0791d13baea7
Added vim command to all source so that we don't get no steenkin' tabs :)
Richard Jones <richard@users.sourceforge.net>
parents:
27
diff
changeset
|
104 # Revision 1.1 2001/07/23 03:46:48 richard |
|
0791d13baea7
Added vim command to all source so that we don't get no steenkin' tabs :)
Richard Jones <richard@users.sourceforge.net>
parents:
27
diff
changeset
|
105 # moving the bin files to facilitate out-of-the-boxness |
|
0791d13baea7
Added vim command to all source so that we don't get no steenkin' tabs :)
Richard Jones <richard@users.sourceforge.net>
parents:
27
diff
changeset
|
106 # |
|
27
e5e9ea306a09
moving the bin files to facilitate out-of-the-boxness
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
107 # Revision 1.1 2001/07/22 11:15:45 richard |
|
e5e9ea306a09
moving the bin files to facilitate out-of-the-boxness
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
108 # More Grande Splite stuff |
|
e5e9ea306a09
moving the bin files to facilitate out-of-the-boxness
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
109 # |
|
e5e9ea306a09
moving the bin files to facilitate out-of-the-boxness
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
110 # |
|
127
0791d13baea7
Added vim command to all source so that we don't get no steenkin' tabs :)
Richard Jones <richard@users.sourceforge.net>
parents:
27
diff
changeset
|
111 # vim: set filetype=python ts=4 sw=4 et si |
