diff options
author | Kali Kaneko <kali@leap.se> | 2015-01-04 03:37:18 -0400 |
---|---|---|
committer | Kali Kaneko <kali@leap.se> | 2015-02-11 14:05:43 -0400 |
commit | 84888155b09b3af6a755262b28728de2f851c8cb (patch) | |
tree | c45a09f7fee1ce1e83d3c36839993f0f1653d9dd /src/leap/mail/mailbox_indexer.py | |
parent | fa60b76ce9cdf6684945c6bc724f10818104166b (diff) |
tests for mail.mail module: Message
Diffstat (limited to 'src/leap/mail/mailbox_indexer.py')
-rw-r--r-- | src/leap/mail/mailbox_indexer.py | 22 |
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( |