From f5cf0a238aa87c0ff6721f7de842be5078ad7ee5 Mon Sep 17 00:00:00 2001 From: Justus Winter <4winter@informatik.uni-hamburg.de> Date: Sun, 25 Dec 2011 12:30:08 +0100 Subject: Add mails to the notmuch index and add tags in Account.store_mail --- alot/account.py | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) (limited to 'alot/account.py') diff --git a/alot/account.py b/alot/account.py index 74decc86..3a9aa82c 100644 --- a/alot/account.py +++ b/alot/account.py @@ -4,6 +4,7 @@ import time import re import email import os +import glob import shlex from ConfigParser import SafeConfigParser from urlparse import urlparse @@ -81,7 +82,7 @@ class Account(object): elif mburl.scheme == 'mmdf': self.draft_box = mailbox.MMDF(mburl.path) - def store_mail(self, mbx, mail): + def store_mail(self, mbx, mail, tags = None): """ stores given mail in mailbox. If mailbox is maildir, set the S-flag. @@ -89,6 +90,8 @@ class Account(object): :type mbx: :class:`mailbox.Mailbox` :param mail: the mail to store :type mail: :class:`email.message.Message` or str + :param tags: if given, add the mail to the notmuch index and tag it + :type tags: list of str """ mbx.lock() if isinstance(mbx, mailbox.Maildir): @@ -96,10 +99,19 @@ class Account(object): msg.set_flags('S') else: msg = mailbox.Message(mail) - mbx.add(mail) + message_id = mbx.add(mail) mbx.flush() mbx.unlock() + if isinstance(mbx, mailbox.Maildir) and tags != None: + # this is a dirty hack to get the path to the newly added file + # I wish the mailbox module were more helpful... + path = glob.glob(os.path.join(mbx._path, '*', message_id + '*'))[0] + + message = self.dbman.add_message(path) + message.add_tags(tags) + self.dbman.flush() + def store_sent_mail(self, mail): """ stores mail (:class:`email.message.Message` or str) in send-store if -- cgit v1.2.3