summaryrefslogtreecommitdiff
path: root/alot/account.py
diff options
context:
space:
mode:
authorJustus Winter <4winter@informatik.uni-hamburg.de>2011-12-25 12:30:08 +0100
committerJustus Winter <4winter@informatik.uni-hamburg.de>2011-12-25 15:38:20 +0100
commitf5cf0a238aa87c0ff6721f7de842be5078ad7ee5 (patch)
treef660cde10ffed86def1a4f51d2a613803f6a5ddf /alot/account.py
parent8764b24d98683731f06cd1c142d04ef5d64c0fd7 (diff)
Add mails to the notmuch index and add tags in Account.store_mail
Diffstat (limited to 'alot/account.py')
-rw-r--r--alot/account.py16
1 files changed, 14 insertions, 2 deletions
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