[PATCH] Output more detailed error on corrupt LocalStatus

chris coleman christocoleman at yahoo.com
Tue May 3 19:13:28 BST 2011




When our LocalStatus cache is corrupt, ie e.g. it contains lines not in
the form number:number, we would previously just raise a ValueError
stating things like "too many values". In case we encounter clearly
corrupt LocalStatus cache entries, clearly raise an exception stating
the filename and the line, so that people can attempt to repair it.

Signed-off-by: Sebastian Spaeth <Sebastian at SSpaeth.de>
---
Unfortunately, we currently just continue with the next folder when we
currently encounter this. I would prefer we abort offlineimap completely
on a corrupt cache file. But this will have to wait until we get proper
error messages (which are high up on my list)

This patch is based on master and should go in mainline, I guess.
offlineimap/folder/LocalStatus.py |   10 ++++++++--
1 files changed, 8 insertions(+), 2 deletions(-)

diff --git a/offlineimap/folder/LocalStatus.py b/offlineimap/folder/LocalStatus.py
index 623829a..4bbcb26 100644
--- a/offlineimap/folder/LocalStatus.py
+++ b/offlineimap/folder/LocalStatus.py
@@ -78,8 +78,14 @@ class LocalStatusFolder(BaseFolder):
         assert(line == magicline)
         for line in file.xreadlines():
             line = line.strip()
-            uid, flags = line.split(':')
-            uid = long(uid)
+            try:
+                uid, flags = line.split(':')
+                uid = long(uid)
+            except ValueError as e:
+                errstr = "Corrupt line '%s' in cache file '%s'" \
+                         % (line, self.filename)
+                self.ui.warn(errstr)
+                raise ValueError(errstr)
             flags = [x for x in flags]
             self.messagelist[uid] = {'uid': uid, 'flags': flags}
         file.close()
-- 
1.7.4.1


================================================

Hi Sebastian, and thanks for the patch.

It uses some python 2.6 syntax for the exception handling, and compile failed.  

So I modified 2 lines, to get it to compile and work, on debian lenny's python 2.5
See:  http://www.velocityreviews.com/forums/t704024-help-resolve-a-syntax-error-on-as-keyword-python-2-5-a.html

except ValueError, e:
   errstr = "Corrupt line '%s' in cache file '%s'"  % (line, self.filename)

And it was printing only the line number, until I put the entire "errstr =" statement on one line (as above).

The output was:

This is OfflineIMAP 6.3.3
Python: 2.5.2 (r252:60911, Jan 24 2010, 14:53:14) 
[GCC 4.3.2]
Platform: linux2
Args: ['./offlineimap.py', '-1', '-a', 'username2', '-l', 'output.log.user2.2011-05-03.txt']
MainThread: OfflineIMAP 6.3.3
Copyright (C) 2002 - 2010 John Goerzen <john at complete.org>

This software comes with ABSOLUTELY NO WARRANTY; see the file
COPYING for details.  This is free software, and you are welcome
to distribute it under the conditions laid out in COPYING.
MainThread: ***** Processing account username2
MainThread: Copying folder structure from IMAP to MappedIMAP
MainThread: Establishing connection to mail.mydomain.com:993.
MainThread: Establishing connection to localhost:143.
WARNING: Corrupt line '4023  P    0:S' in cache file '/root/.offlineimap/Account-username2/LocalStatus/INBOX'
WARNING: ERROR in syncfolder for username2 folder INBOX: Traceback (most recent call last):
  File "/root/nicolas33-offlineimap-v633/offlineimap/accounts.py", line 313, in syncfolder
    statusfolder.cachemessagelist()
  File "/root/nicolas33-offlineimap-v633/offlineimap/folder/LocalStatus.py", line 89, in cachemessagelist
    raise ValueError(errstr)                            #new
ValueError: Corrupt line '4023  P    0:S' in cache file '/root/.offlineimap/Account-username2/LocalStatus/INBOX'

Folder sync [username2]: Syncing INBOX.Drafts: IMAP -> MappedIMAP
Folder sync [username2]: Syncing INBOX.Junk: IMAP -> MappedIMAP
Folder sync [username2]: Syncing INBOX.Sent: IMAP -> MappedIMAP
Folder sync [username2]: Syncing INBOX.Trash: IMAP -> MappedIMAP
MainThread: ***** Finished processing account username2

I checked the file ~/.offlineimap/Account-username2/LocalStatus/INBOX

Indeed that corrupt line is there.  but it's a sequence of non-consecutive numbers... Here is an excerpt:

40213:
40214:
40215:
40217:R
40218:S
40229:S
4023(0x00)(0x00)P(0x00)(0x01)(0x00)(0x00)(0x00)0:S
40261:S
40262:S
40264:
40269:S
40270:
40276:
40279:R


The big question: how do you recommend regenerating these damaged lines of data without losing any email in this user's INBOX?

Will an email be deleted if it doesn't have its corresponding number in this file?  

Or...  is it the opposite, will this file automatically regenerate the missing number of any email that is not listed in it ?


Chris
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://alioth-lists.debian.net/pipermail/offlineimap-project/attachments/20110503/b23f2360/attachment-0001.html>


More information about the OfflineIMAP-project mailing list