From efc4df1bd73bb58fd170105f364fb0e80a0a2c97 Mon Sep 17 00:00:00 2001 From: Nicolas Sebrecht Date: Sun, 22 Feb 2015 14:08:39 +0100 Subject: [PATCH] LocalStatusSQLite: labels: don't fail if database returns unexpected None value This requires more researches. See https://github.com/OfflineIMAP/offlineimap/issues/103 . Signed-off-by: Nicolas Sebrecht --- offlineimap/folder/LocalStatusSQLite.py | 16 +++++++++++++++- offlineimap/folder/UIDMaps.py | 9 ++++----- 2 files changed, 19 insertions(+), 6 deletions(-) diff --git a/offlineimap/folder/LocalStatusSQLite.py b/offlineimap/folder/LocalStatusSQLite.py index bcce8ec..64adcd1 100644 --- a/offlineimap/folder/LocalStatusSQLite.py +++ b/offlineimap/folder/LocalStatusSQLite.py @@ -203,7 +203,21 @@ class LocalStatusSQLiteFolder(BaseFolder): uid = row[0] self.messagelist[uid] = self.msglist_item_initializer(uid) flags = set(row[1]) - labels = set([lb.strip() for lb in row[3].split(',') if len(lb.strip()) > 0]) + try: + labels = set([lb.strip() for lb in + row[3].split(',') if len(lb.strip()) > 0]) + except AttributeError: + # FIXME: This except clause was introduced because row[3] from + # database can be found of unexpected type NoneType. See + # https://github.com/OfflineIMAP/offlineimap/issues/103 + # + # We are fixing the type here but this would require more + # researches to find the true root cause. row[3] is expected to + # be a (empty) string, not None. + # + # Also, since database might return None, we have to fix the + # database, too. + labels = set() self.messagelist[uid]['flags'] = flags self.messagelist[uid]['labels'] = labels self.messagelist[uid]['mtime'] = row[2] diff --git a/offlineimap/folder/UIDMaps.py b/offlineimap/folder/UIDMaps.py index e8ca9a7..04a986b 100644 --- a/offlineimap/folder/UIDMaps.py +++ b/offlineimap/folder/UIDMaps.py @@ -208,7 +208,7 @@ class MappedIMAPFolder(IMAPFolder): if uid < 0: return uid - #if msg uid already exists, just modify the flags + # If msg uid already exists, just modify the flags. if uid in self.r2l: self.savemessageflags(uid, flags) return uid @@ -238,11 +238,10 @@ class MappedIMAPFolder(IMAPFolder): # Interface from BaseFolder def savemessageflags(self, uid, flags): - """ - - Note that this function does not check against dryrun settings, + """Note that this function does not check against dryrun settings, so you need to ensure that it is never called in a dryrun mode.""" + self._mb.savemessageflags(self.r2l[uid], flags) # Interface from BaseFolder @@ -304,7 +303,7 @@ class MappedIMAPFolder(IMAPFolder): # Interface from BaseFolder def deletemessagesflags(self, uidlist, flags): self._mb.deletemessagesflags(self._uidlist(self.r2l, uidlist), - flags) + flags) # Interface from BaseFolder def deletemessage(self, uid):