diff options
-rw-r--r-- | alot/buffer.py | 9 | ||||
-rw-r--r-- | alot/db.py | 44 | ||||
-rw-r--r-- | settings.py | 2 |
3 files changed, 33 insertions, 22 deletions
diff --git a/alot/buffer.py b/alot/buffer.py index 9bad1520..718c285e 100644 --- a/alot/buffer.py +++ b/alot/buffer.py @@ -160,14 +160,7 @@ class SingleThreadBuffer(Buffer): def read_thread(self, thread): self.message_count = thread.get_total_messages() self.subject = thread.get_subject() - self.messages = list() - for m in thread.get_toplevel_messages(): - self._build_pile(self.messages, m) - - def _build_pile(self, acc, msg, depth=0): - acc.append((depth, msg)) - for m in msg.get_replies(): - self._build_pile(acc, m, depth + 1) + self.messages = [(0, m) for m in thread.get_toplevel_messages()] def rebuild(self): msgs = list() @@ -5,6 +5,11 @@ import email class DBManager: + """ + keeps track of your index parameters, can create notmuch.Query + objects from its Database on demand and implements a bunch of + database specific functions. + """ def __init__(self, path=None, ro=False): self.ro = ro self.path = path @@ -16,10 +21,19 @@ class DBManager: threads = self.query(querystring).search_threads() return [thread.get_thread_id() for thread in threads] - def get_message(self, mid, writeable=False): - query = self.query('id:' + mid, writeable=writeable) - # TODO raise exceptions here in 0<case msgcount>1 - return Message(self, query.search_messages().next()) + def find_message(self, mid): + db = Database(path=self.path) + return db.find_message(mid) + + def get_message(self, mid): + """returns the message with the given id and wrapps it in a Message + + :param mid: the message id of the message to look up + :type mid: str. + :returns: Message -- the message. + + """ + return Message(self,self.find_message(mid)) def get_thread(self, tid, writeable=False): query = self.query('thread:' + tid, writeable=writeable) @@ -32,6 +46,15 @@ class DBManager: return [tag for tag in db.get_all_tags()] def query(self, querystring, writeable=False): + """creates notmuch.Query objects on demand + + :param querystring: The query string to use for the lookup + :type query: str. + :param writeable: Try to return a writeable Query object + :type state: bool. + :returns: notmuch.Query -- the query object. + + """ if writeable: mode = Database.MODE.READ_WRITE else: @@ -44,7 +67,7 @@ class Thread: def __init__(self, dbman, thread): self.dbman = dbman self.tid = thread.get_thread_id() - self.strrep = "WRAPPER:" + str(thread) + self.strrep = str(thread) self.total_messages = thread.get_total_messages() self.topmessages = [m.get_message_id() for m in thread.get_toplevel_messages()] self.authors = thread.get_authors() @@ -78,8 +101,6 @@ class Thread: return self.tid def get_tags(self): - # sets do not always behave like lists. - # so returning a list as it might be expected return list(self.tags) def get_authors(self): @@ -122,18 +143,15 @@ class Message: def get_replies(self): #this doesn't work. see Note in doc -> more work here. - return [self.dbman.get_message(mid) for mid in self.replies] + return [self.dbman.find_message(mid) for mid in self.replies] def get_tags(self): - # sets do not always behave like lists. - # so returning a list as it might be expected return list(self.tags) def get_email(self): if not self.email: self.email = self.read_mail(self.filename) return self.email - # self.email = self.read_mail(self.filename) def read_mail(self, filename): try: @@ -146,7 +164,7 @@ class Message: return eml def add_tags(self, tags): - msg = self.dbman.get_message(self.mid) + msg = self.dbman.find_message(self.mid) msg.freeze() for tag in tags: msg.add_tag(tag) @@ -155,7 +173,7 @@ class Message: msg.thaw() def remove_tags(self, tags): - msg = self.dbman.get_message(self.mid) + msg = self.dbman.find_message(self.mid) msg.freeze() for tag in tags: msg.remove_tag(tag) diff --git a/settings.py b/settings.py index f1779900..a97bdfe5 100644 --- a/settings.py +++ b/settings.py @@ -16,7 +16,7 @@ palette = [ ('threadline_tags', 'yellow', '', '', '', ''), ('threadline_authors', 'dark green', '', '', '', ''), ('threadline_subject', 'light gray', '', '', '', ''), - ('threadline_date_linefocus', 'light gray', 'dgray', '', '', ''), + ('threadline_date_linefocus', 'light gray', 'dark gray', '', '', ''), ('threadline_mailcount_linefocus', 'light gray', 'dark gray', '', '', ''), ('threadline_tags_linefocus', 'yellow,bold', 'dark gray', '', '', ''), ('threadline_authors_linefocus', 'dark green', 'dark gray', '', '', ''), |