summaryrefslogtreecommitdiff
path: root/src/leap/mail/mailbox_indexer.py
diff options
context:
space:
mode:
authorKali Kaneko <kali@leap.se>2015-01-04 03:37:18 -0400
committerKali Kaneko <kali@leap.se>2015-01-21 15:07:19 -0400
commit60eecafcc8a516985f900ef81bc7941a5234930a (patch)
treec45a09f7fee1ce1e83d3c36839993f0f1653d9dd /src/leap/mail/mailbox_indexer.py
parent30387b83756ba078d04f4af701e3f595e30d9c50 (diff)
tests for mail.mail module: Message
Diffstat (limited to 'src/leap/mail/mailbox_indexer.py')
-rw-r--r--src/leap/mail/mailbox_indexer.py22
1 files changed, 18 insertions, 4 deletions
diff --git a/src/leap/mail/mailbox_indexer.py b/src/leap/mail/mailbox_indexer.py
index bc298ea..1ceaec0 100644
--- a/src/leap/mail/mailbox_indexer.py
+++ b/src/leap/mail/mailbox_indexer.py
@@ -22,6 +22,17 @@ import re
from leap.mail.constants import METAMSGID_RE
+def _maybe_first_query_item(thing):
+ """
+ Return the first item the returned query result, or None
+ if empty.
+ """
+ try:
+ return thing[0][0]
+ except IndexError:
+ return None
+
+
class WrongMetaDocIDError(Exception):
pass
@@ -124,7 +135,7 @@ class MailboxIndexer(object):
raise WrongMetaDocIDError("Wrong format for the MetaMsg doc_id")
def get_rowid(result):
- return result[0][0]
+ return _maybe_first_query_item(result)
sql = ("INSERT INTO {preffix}{name} VALUES ("
"NULL, ?)".format(
@@ -192,7 +203,7 @@ class MailboxIndexer(object):
:rtype: Deferred
"""
def get_hash(result):
- return result[0][0]
+ return _maybe_first_query_item(result)
sql = ("SELECT hash from {preffix}{name} "
"WHERE uid=?".format(
@@ -217,7 +228,7 @@ class MailboxIndexer(object):
:rtype: Deferred
"""
def get_count(result):
- return result[0][0]
+ return _maybe_first_query_item(result)
sql = ("SELECT Count(*) FROM {preffix}{name};".format(
preffix=self.table_preffix, name=mailbox))
@@ -243,7 +254,10 @@ class MailboxIndexer(object):
assert mailbox
def increment(result):
- return result[0][0] + 1
+ uid = _maybe_first_query_item(result)
+ if uid is None:
+ return None
+ return uid + 1
sql = ("SELECT MAX(rowid) FROM {preffix}{name} "
"LIMIT 1;").format(