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 <nicolas.s-dev@laposte.net>
This commit is contained in:
Nicolas Sebrecht 2015-02-22 14:08:39 +01:00
parent ca06819e70
commit efc4df1bd7
2 changed files with 19 additions and 6 deletions

View File

@ -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]

View File

@ -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