]> granicus.if.org Git - python/commitdiff
Added createmessage() -- Lars Wirzenius.
authorGuido van Rossum <guido@python.org>
Fri, 25 Jul 1997 14:59:10 +0000 (14:59 +0000)
committerGuido van Rossum <guido@python.org>
Fri, 25 Jul 1997 14:59:10 +0000 (14:59 +0000)
Lib/mhlib.py

index 34fc3b0b29ff9e3cde332a7a3a95d6bba051d4de..838b2f76a7c4d5a1b61de1e4fdb0426528f7dd64 100644 (file)
@@ -601,6 +601,32 @@ class Folder:
                except os.error:
                    pass
 
+    # Create a message, with text from the open file txt.
+    def createmessage(self, n, txt):
+       path = self.getmessagefilename(n)
+       backuppath = self.getmessagefilename(',%d' % n)
+       try:
+           os.rename(path, backuppath)
+       except os.error:
+           pass
+       ok = 0
+       BUFSIZE = 16*1024
+       try:
+           f = open(path, "w")
+           while 1:
+               buf = txt.read(BUFSIZE)
+               if not buf:
+                   break
+               f.write(buf)
+           f.close()
+           ok = 1
+       finally:
+           if not ok:
+               try:
+                   os.unlink(path)
+               except os.error:
+                   pass
+
     # Remove one or more messages from all sequeuces (including last)
     # -- but not from 'cur'!!!
     def removefromallsequences(self, list):