]> code.delx.au - offlineimap/blobdiff - offlineimap/folder/LocalStatus.py
typo in previous
[offlineimap] / offlineimap / folder / LocalStatus.py
index 195eff63dbd7ea3e44617fde4f6d879c17ff4114..4bb83ee64784f5b74f789ddd08c861e1bcc106ca 100644 (file)
@@ -1,5 +1,5 @@
 # Local status cache virtual folder
-# Copyright (C) 2002 - 2003 John Goerzen
+# Copyright (C) 2002 - 2008 John Goerzen
 # <jgoerzen@complete.org>
 #
 #    This program is free software; you can redistribute it and/or modify
@@ -14,7 +14,7 @@
 #
 #    You should have received a copy of the GNU General Public License
 #    along with this program; if not, write to the Free Software
-#    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+#    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
 
 from Base import BaseFolder
 import os, threading
@@ -67,6 +67,11 @@ class LocalStatusFolder(BaseFolder):
         file = open(self.filename, "rt")
         self.messagelist = {}
         line = file.readline().strip()
+        if not line and not line.read():
+            # The status file is empty - should not have happened,
+            # but somehow did.
+            file.close()
+            return
         assert(line == magicline)
         for line in file.xreadlines():
             line = line.strip()
@@ -90,15 +95,25 @@ class LocalStatusFolder(BaseFolder):
                 flags.sort()
                 flags = ''.join(flags)
                 file.write("%s:%s\n" % (msg['uid'], flags))
+            file.flush()
+            os.fsync(file.fileno())
             file.close()
             os.rename(self.filename + ".tmp", self.filename)
+
+            try:
+                fd = os.open(os.path.dirname(self.filename), os.O_RDONLY)
+                os.fsync(fd)
+                os.close(fd)
+            except:
+                pass
+
         finally:
             self.savelock.release()
 
     def getmessagelist(self):
         return self.messagelist
 
-    def savemessage(self, uid, content, flags):
+    def savemessage(self, uid, content, flags, rtime):
         if uid < 0:
             # We cannot assign a uid.
             return uid
@@ -107,13 +122,16 @@ class LocalStatusFolder(BaseFolder):
             self.savemessageflags(uid, flags)
             return uid
 
-        self.messagelist[uid] = {'uid': uid, 'flags': flags}
+        self.messagelist[uid] = {'uid': uid, 'flags': flags, 'time': rtime}
         self.autosave()
         return uid
 
     def getmessageflags(self, uid):
         return self.messagelist[uid]['flags']
 
+    def getmessagetime(self, uid):
+        return self.messagelist[uid]['time']
+
     def savemessageflags(self, uid, flags):
         self.messagelist[uid]['flags'] = flags
         self.autosave()