CVS: tmda/TMDA ChangeLog,1.291,1.292 Deliver.py,1.17,1.18

"Jason R. Mastaler" <[email protected]>
Newsgroups gmane.mail.spam.tmda.cvs
Message-ID <[email protected]>
Update of /cvsroot/tmda/tmda/TMDA
In directory sc8-pr-cvs1:/tmp/cvs-serv23907/TMDA

Modified Files:
	ChangeLog Deliver.py 
Log Message:
Maildir delivery improvements from Charlie Cazabon.  Use os.open() and
os.fdopen() in place of __builtins__.open() to create the file; this
lets it use the O_CREAT and O_EXCL flags.


Index: ChangeLog
===================================================================
RCS file: /cvsroot/tmda/tmda/TMDA/ChangeLog,v
retrieving revision 1.291
retrieving revision 1.292
diff -u -r1.291 -r1.292
--- ChangeLog	13 Oct 2003 19:33:24 -0000	1.291
+++ ChangeLog	14 Oct 2003 17:59:03 -0000	1.292
@@ -1,3 +1,8 @@
+2003-10-14  Jason R. Mastaler  <[email protected]>
+
+	* Deliver.py (Deliver.__deliver_maildir): Use os.open() and
+	os.fdopen() in place of __builtins__.open() to create the file.
+	
 2003-10-13  Jason R. Mastaler  <[email protected]>
 
 	* Defaults.py (OUTGOINGMAIL): Change default to 'sendmail'.

Index: Deliver.py
===================================================================
RCS file: /cvsroot/tmda/tmda/TMDA/Deliver.py,v
retrieving revision 1.17
retrieving revision 1.18
diff -u -r1.17 -r1.18
--- Deliver.py	23 Jul 2003 19:52:47 -0000	1.17
+++ Deliver.py	14 Oct 2003 17:59:03 -0000	1.18
@@ -291,7 +291,7 @@
         See <URL:http://cr.yp.to/proto/maildir.html> and
             <URL:http://www.qmail.org/man/man5/maildir.html>
 
-        Based on code from getmail
+        Uses code from getmail
         <URL:http://www.qcc.sk.ca/~charlesc/software/getmail-2.0/>
         Copyright (C) 2001 Charles Cazabon, and licensed under the GNU
         General Public License version 2.
@@ -318,8 +318,11 @@
         signal.alarm(24 * 60 * 60)
 
         dir_tmp = os.path.join(maildir, 'tmp')
+        dir_cur = os.path.join(maildir, 'cur')
         dir_new = os.path.join(maildir, 'new')
-        if not (os.path.isdir(dir_tmp) and os.path.isdir(dir_new)):
+        if not (os.path.isdir(dir_tmp) and 
+                os.path.isdir(dir_cur) and
+                os.path.isdir(dir_new)):
             raise Errors.DeliveryError, 'not a Maildir! (%s)' % maildir
 
         now = time.time()
@@ -343,7 +346,8 @@
 
         # Open file to write.
         try:
-            fp = open(fname_tmp, 'wb')
+            fd = os.open(fname_tmp, os.O_WRONLY | os.O_CREAT | os.O_EXCL, 0600)
+            fp = os.fdopen(fd, 'wb', 4096)
             os.chmod(fname_tmp, 0600)
             try:
                 # If root, change the message to be owned by the
@@ -356,9 +360,10 @@
             fp.flush()
             os.fsync(fp.fileno())
             fp.close()
-        except IOError:
+        except (OSError, IOError), o:
             signal.alarm(0)
-            raise Errors.DeliveryError, 'Failure writing file ' + fname_tmp
+            raise Errors.DeliveryError, \
+                  'Failure writing file %s (%s)' % (fname_tmp, o)
 
         fstatus = os.stat(fname_tmp)
         # e.g, 1043715037.V20d04I18bfb.hrothgar.la.mastaler.com
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.