Skip to content

Commit 749da9d

Browse files
author
Richard Jones
committed
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.
1 parent fdec297 commit 749da9d

File tree

2 files changed

+46
-5
lines changed

2 files changed

+46
-5
lines changed

roundup-mailgw

Lines changed: 37 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
# BASIS, AND THERE IS NO OBLIGATION WHATSOEVER TO PROVIDE MAINTENANCE,
1717
# SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
1818
#
19-
# $Id: roundup-mailgw,v 1.8 2001-11-01 22:04:37 richard Exp $
19+
# $Id: roundup-mailgw,v 1.9 2001-11-07 05:29:26 richard Exp $
2020

2121
import sys
2222
if int(sys.version[0]) < 2:
@@ -40,10 +40,45 @@ instance = roundup.instance.open(instance_home)
4040
# invoke the mail handler
4141
db = instance.open('admin')
4242
handler = instance.MailGW(db)
43-
handler.main(sys.stdin)
43+
44+
# if there's no more arguments, read a single message from stdin
45+
if len(sys.argv) < 2:
46+
handler.main(sys.stdin)
47+
48+
# otherwise, there's a spool file to read from
49+
import fcntl, FCNTL
50+
spool_file = sys.argv[2]
51+
52+
# open the spool file and lock it
53+
f = open(spool_file, 'r+')
54+
fcntl.flock(f.fileno(), FCNTL.LOCK_EX)
55+
56+
# handle and clear the mailbox
57+
try:
58+
from mailbox import UnixMailbox
59+
import mimetools
60+
mailbox = UnixMailbox(f, factory=mimetools.Message)
61+
# grab one message
62+
message = mailbox.next()
63+
while message:
64+
# call the instance mail handler
65+
handler.handle_Message(message)
66+
message = mailbox.next()
67+
# nuke the file contents
68+
os.ftruncate(f.fileno(), 0)
69+
except:
70+
import traceback
71+
traceback.print_exc()
72+
fcntl.flock(f.fileno(), FCNTL.LOCK_UN)
4473

4574
#
4675
# $Log: not supported by cvs2svn $
76+
# Revision 1.8 2001/11/01 22:04:37 richard
77+
# Started work on supporting a pop3-fetching server
78+
# Fixed bugs:
79+
# . bug #477104 ] HTML tag error in roundup-server
80+
# . bug #477107 ] HTTP header problem
81+
#
4782
# Revision 1.7 2001/08/07 00:24:42 richard
4883
# stupid typo
4984
#

roundup/mailgw.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ class node. Any parts of other types are each stored in separate files
7272
an exception, the original message is bounced back to the sender with the
7373
explanatory message given in the exception.
7474
75-
$Id: mailgw.py,v 1.28 2001-11-01 22:04:37 richard Exp $
75+
$Id: mailgw.py,v 1.29 2001-11-07 05:29:26 richard Exp $
7676
'''
7777

7878

@@ -152,10 +152,10 @@ def handle_Message(self, message):
152152
m.append(s.getvalue())
153153
m.append('---- failed message follows ----')
154154
try:
155-
fp.seek(0)
155+
message.fp.seek(0)
156156
except:
157157
pass
158-
m.append(fp.read())
158+
m.append(message.fp.read())
159159
if m:
160160
try:
161161
smtp = smtplib.SMTP(self.MAILHOST)
@@ -449,6 +449,12 @@ def parseContent(content, blank_line=re.compile(r'[\r\n]+\s*[\r\n]+'),
449449

450450
#
451451
# $Log: not supported by cvs2svn $
452+
# Revision 1.28 2001/11/01 22:04:37 richard
453+
# Started work on supporting a pop3-fetching server
454+
# Fixed bugs:
455+
# . bug #477104 ] HTML tag error in roundup-server
456+
# . bug #477107 ] HTTP header problem
457+
#
452458
# Revision 1.27 2001/10/30 11:26:10 richard
453459
# Case-insensitive match for ISSUE_TRACKER_EMAIL in address in e-mail.
454460
#

0 commit comments

Comments
 (0)