<html><body><div style="color:#000; background-color:#fff; font-family:times new roman, new york, times, serif;font-size:12pt"><div><span><br></span></div><br><div style="font-family: times new roman, new york, times, serif; font-size: 12pt;"><div style="font-family: times new roman, new york, times, serif; font-size: 12pt;">
When our LocalStatus cache is corrupt, ie e.g. it contains lines not in<br>the form number:number, we would previously just raise a ValueError<br>stating things like "too many values". In case we encounter clearly<br>corrupt LocalStatus cache entries, clearly raise an exception stating<br>the filename and the line, so that people can attempt to repair it.<br><br>Signed-off-by: Sebastian Spaeth &lt;<a ymailto="mailto:Sebastian@SSpaeth.de" href="mailto:Sebastian@SSpaeth.de">Sebastian@SSpaeth.de</a>&gt;<br>---<br>Unfortunately, we currently just continue with the next folder when we<br>currently encounter this. I would prefer we abort offlineimap completely<br>on a corrupt cache file. But this will have to wait until we get proper<br>error messages (which are high up on my list)<br><br>This patch is based on master and should go in mainline, I guess.<br> offlineimap/folder/LocalStatus.py |&nbsp;  10 ++++++++--<br> 1 files changed, 8 insertions(+), 2
 deletions(-)<br><br>diff --git a/offlineimap/folder/LocalStatus.py b/offlineimap/folder/LocalStatus.py<br>index 623829a..4bbcb26 100644<br>--- a/offlineimap/folder/LocalStatus.py<br>+++ b/offlineimap/folder/LocalStatus.py<br>@@ -78,8 +78,14 @@ class LocalStatusFolder(BaseFolder):<br>&nbsp; &nbsp; &nbsp; &nbsp;  assert(line == magicline)<br>&nbsp; &nbsp; &nbsp; &nbsp;  for line in file.xreadlines():<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;  line = line.strip()<br>-&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; uid, flags = line.split(':')<br>-&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; uid = long(uid)<br>+&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; try:<br>+&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; uid, flags = line.split(':')<br>+&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; uid = long(uid)<br>+&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; except ValueError as e:<br>+&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; errstr =
 "Corrupt line '%s' in cache file '%s'" \<br>+&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;  % (line, self.filename)<br>+&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; self.ui.warn(errstr)<br>+&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; raise ValueError(errstr)<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;  flags = [x for x in flags]<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;  self.messagelist[uid] = {'uid': uid, 'flags': flags}<br>&nbsp; &nbsp; &nbsp; &nbsp;  file.close()<br>-- <br>1.7.4.1<br><br><br>================================================<br><br>Hi Sebastian, and thanks for the patch.<br><br>It uses some python 2.6 syntax for the exception handling, and compile failed.&nbsp; <br><br>So I modified 2 lines, to get it to compile and work, on debian lenny's python 2.5<br>See:&nbsp;
 http://www.velocityreviews.com/forums/t704024-help-resolve-a-syntax-error-on-as-keyword-python-2-5-a.html<br><br>except ValueError, e:<br>&nbsp;&nbsp; errstr = "Corrupt line '%s' in cache file '%s'"  % (line, self.filename)<br><br>And it was printing only the line number, until I put the entire "errstr =" statement on one line (as above).<br><br>The output was:<br><br>This is OfflineIMAP 6.3.3<br>Python: 2.5.2 (r252:60911, Jan 24 2010, 14:53:14) <br>[GCC 4.3.2]<br>Platform: linux2<br>Args: ['./offlineimap.py', '-1', '-a', 'username2', '-l', 'output.log.user2.2011-05-03.txt']<br>MainThread: OfflineIMAP 6.3.3<br>Copyright (C) 2002 - 2010 John Goerzen &lt;john@complete.org&gt;<br><br>This software comes with ABSOLUTELY NO WARRANTY; see the file<br>COPYING for details.&nbsp; This is free software, and you are welcome<br>to distribute it under the conditions laid out in COPYING.<br>MainThread: ***** Processing account username2<br>MainThread: Copying folder
 structure from IMAP to MappedIMAP<br>MainThread: Establishing connection to mail.mydomain.com:993.<br>MainThread: Establishing connection to localhost:143.<br>WARNING: Corrupt line '4023&nbsp; P &nbsp;&nbsp; 0:S' in cache file '/root/.offlineimap/Account-username2/LocalStatus/INBOX'<br>WARNING: ERROR in syncfolder for username2 folder INBOX: Traceback (most recent call last):<br>&nbsp; File "/root/nicolas33-offlineimap-v633/offlineimap/accounts.py", line 313, in syncfolder<br>&nbsp;&nbsp;&nbsp; statusfolder.cachemessagelist()<br>&nbsp; File "/root/nicolas33-offlineimap-v633/offlineimap/folder/LocalStatus.py", line 89, in cachemessagelist<br>&nbsp;&nbsp;&nbsp; raise ValueError(errstr)&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; #new<br>ValueError: Corrupt line '4023&nbsp; P &nbsp;&nbsp; 0:S' in cache file
 '/root/.offlineimap/Account-username2/LocalStatus/INBOX'<br><br>Folder sync [username2]: Syncing INBOX.Drafts: IMAP -&gt; MappedIMAP<br>Folder sync [username2]: Syncing INBOX.Junk: IMAP -&gt; MappedIMAP<br>Folder sync [username2]: Syncing INBOX.Sent: IMAP -&gt; MappedIMAP<br>Folder sync [username2]: Syncing INBOX.Trash: IMAP -&gt; MappedIMAP<br>MainThread: ***** Finished processing account username2<br><br>I checked the file ~/.offlineimap/Account-username2/LocalStatus/INBOX<br><br>Indeed that corrupt line is there.&nbsp; but it's a sequence of non-consecutive numbers... Here is an excerpt:<br><br>40213:<br>40214:<br>40215:<br>40217:R<br>40218:S<br>40229:S<br>4023(0x00)(0x00)P(0x00)(0x01)(0x00)(0x00)(0x00)0:S<br>40261:S<br>40262:S<br>40264:<br>40269:S<br>40270:<br>40276:<br>40279:R<br><br><br>The big question: how do you recommend regenerating these damaged lines of data without losing any email in this user's INBOX?<br><br>Will an email be deleted if
 it doesn't have its corresponding number in this file?&nbsp; <br><br>Or...&nbsp; is it the opposite, will this file automatically regenerate the missing number of any email that is not listed in it ?<br><br><br>Chris<br><br></div></div></div></body></html>