From 064f3ef58797fa4ee1374db586d8d61cb98d1128 Mon Sep 17 00:00:00 2001 From: richard Date: Wed, 7 Nov 2001 05:29:26 +0000 Subject: [PATCH] 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. git-svn-id: http://svn.roundup-tracker.org/svnroot/roundup/trunk@378 57a73879-2fb5-44c3-a270-3262357dd7e2 --- roundup-mailgw | 39 +++++++++++++++++++++++++++++++++++++-- roundup/mailgw.py | 12 +++++++++--- 2 files changed, 46 insertions(+), 5 deletions(-) diff --git a/roundup-mailgw b/roundup-mailgw index 8e5e775..6aad854 100755 --- a/roundup-mailgw +++ b/roundup-mailgw @@ -16,7 +16,7 @@ # BASIS, AND THERE IS NO OBLIGATION WHATSOEVER TO PROVIDE MAINTENANCE, # SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. # -# $Id: roundup-mailgw,v 1.8 2001-11-01 22:04:37 richard Exp $ +# $Id: roundup-mailgw,v 1.9 2001-11-07 05:29:26 richard Exp $ import sys if int(sys.version[0]) < 2: @@ -40,10 +40,45 @@ instance = roundup.instance.open(instance_home) # invoke the mail handler db = instance.open('admin') handler = instance.MailGW(db) -handler.main(sys.stdin) + +# if there's no more arguments, read a single message from stdin +if len(sys.argv) < 2: + handler.main(sys.stdin) + +# otherwise, there's a spool file to read from +import fcntl, FCNTL +spool_file = sys.argv[2] + +# open the spool file and lock it +f = open(spool_file, 'r+') +fcntl.flock(f.fileno(), FCNTL.LOCK_EX) + +# handle and clear the mailbox +try: + from mailbox import UnixMailbox + import mimetools + mailbox = UnixMailbox(f, factory=mimetools.Message) + # grab one message + message = mailbox.next() + while message: + # call the instance mail handler + handler.handle_Message(message) + message = mailbox.next() + # nuke the file contents + os.ftruncate(f.fileno(), 0) +except: + import traceback + traceback.print_exc() +fcntl.flock(f.fileno(), FCNTL.LOCK_UN) # # $Log: not supported by cvs2svn $ +# Revision 1.8 2001/11/01 22:04:37 richard +# Started work on supporting a pop3-fetching server +# Fixed bugs: +# . bug #477104 ] HTML tag error in roundup-server +# . bug #477107 ] HTTP header problem +# # Revision 1.7 2001/08/07 00:24:42 richard # stupid typo # diff --git a/roundup/mailgw.py b/roundup/mailgw.py index b430f05..d11b112 100644 --- a/roundup/mailgw.py +++ b/roundup/mailgw.py @@ -72,7 +72,7 @@ are calling the create() method to create a new node). If an auditor raises an exception, the original message is bounced back to the sender with the explanatory message given in the exception. -$Id: mailgw.py,v 1.28 2001-11-01 22:04:37 richard Exp $ +$Id: mailgw.py,v 1.29 2001-11-07 05:29:26 richard Exp $ ''' @@ -152,10 +152,10 @@ class MailGW: m.append(s.getvalue()) m.append('---- failed message follows ----') try: - fp.seek(0) + message.fp.seek(0) except: pass - m.append(fp.read()) + m.append(message.fp.read()) if m: try: smtp = smtplib.SMTP(self.MAILHOST) @@ -449,6 +449,12 @@ def parseContent(content, blank_line=re.compile(r'[\r\n]+\s*[\r\n]+'), # # $Log: not supported by cvs2svn $ +# Revision 1.28 2001/11/01 22:04:37 richard +# Started work on supporting a pop3-fetching server +# Fixed bugs: +# . bug #477104 ] HTML tag error in roundup-server +# . bug #477107 ] HTTP header problem +# # Revision 1.27 2001/10/30 11:26:10 richard # Case-insensitive match for ISSUE_TRACKER_EMAIL in address in e-mail. # -- 2.30.2