[Nym3-commit] r95 - trunk
nym3-devel@lists.noreply.org
nym3-devel@lists.noreply.org
Thu, 05 Aug 2004 19:58:34 +0200
Author: jr
Date: 2004-08-05 19:58:32 +0200 (Thu, 05 Aug 2004)
New Revision: 95
Modified:
trunk/Mail.py
trunk/User.py
Log:
- use tmpfile and add tmpFileMsg(Mail.py)
- use this function in User.send(User.py)
Modified: trunk/Mail.py
===================================================================
--- trunk/Mail.py 2004-08-05 15:35:34 UTC (rev 94)
+++ trunk/Mail.py 2004-08-05 17:58:32 UTC (rev 95)
@@ -1,6 +1,8 @@
# $Id$
import re
+import os
+import tempfile
import random
import base64
import string
@@ -32,19 +34,18 @@
return res + 'X-Octets: ' + repr(len(msg)) + "\n" + body
+def myWrite(f, m):
+ def aux(m, l):
+ w = os.write(f,m)
+ aux(m[w:], l-w)
+ aux(m, len(m))
+
def tmpFileMsg(body):
- """write body in a temp file name and return the name of that file
+ """write body in a temp file name and return a file name of this file
"""
- while True:
- try:
- fname = '/tmp/' + Mail.mid2filename(Mail.genMid())
- fname = string.strip(fname)
- f = open(fname, 'w') #change w so that it creates the file if it does not exist an raise an error otherwise
- f.write(body)
- f.close()
- break
- except:
- pass
+ (fd, fname) = tempfile.mkstemp()
+ myWrite(f,body)
+ os.close(fd)
return fname
Modified: trunk/User.py
===================================================================
--- trunk/User.py 2004-08-05 15:35:34 UTC (rev 94)
+++ trunk/User.py 2004-08-05 17:58:32 UTC (rev 95)
@@ -159,12 +159,7 @@
return Config.path + os.sep + self.data['username'] + '.surbs'
def send(self, msg):
- fname = '/tmp/' + Mail.mid2filename(Mail.genMid())
- # TODO : chose a temp file.
- fname = string.strip(fname)
- f = open(fname, 'w')
- f.write(msg)
- f.close()
+ fname = Mail.tmpFileMsg(msg)
ec = os.system("mixminion send -R " + self.surbfile() + " -i " + fname)
os.unlink(fname)
return ec