summaryrefslogtreecommitdiff
path: root/service/pixelated/adapter/pixelated_mailbox.py
diff options
context:
space:
mode:
authorPatrick Maia and Victor Shyba <pixelated-team+pmaia+vshyba@thoughtworks.com>2014-09-05 22:45:55 +0000
committerPatrick Maia <pmaia@thoughtworks.com>2014-09-05 22:46:17 +0000
commit3c79a54ab332e15f31a4a57a4a9baabf4b62e26a (patch)
treece6b592049227da18b0500f4695b0feb490a944d /service/pixelated/adapter/pixelated_mailbox.py
parentd2cf8b51904420917a5f86986ce7c02e89935998 (diff)
#51 - persists new tags globally (in a local file) and shows on tag list
Diffstat (limited to 'service/pixelated/adapter/pixelated_mailbox.py')
-rw-r--r--service/pixelated/adapter/pixelated_mailbox.py37
1 files changed, 19 insertions, 18 deletions
diff --git a/service/pixelated/adapter/pixelated_mailbox.py b/service/pixelated/adapter/pixelated_mailbox.py
index 06e0cccc..3424ddd7 100644
--- a/service/pixelated/adapter/pixelated_mailbox.py
+++ b/service/pixelated/adapter/pixelated_mailbox.py
@@ -17,14 +17,19 @@
from pixelated.adapter.pixelated_mail import PixelatedMail
from pixelated.adapter.tag import Tag
+from pixelated.adapter.tag_index import TagIndex
class PixelatedMailbox:
- SPECIAL_TAGS = ['inbox', 'sent', 'drafts', 'trash']
+ SPECIAL_TAGS = set([Tag('inbox', True), Tag('sent', True), Tag('drafts', True), Tag('trash', True)])
- def __init__(self, leap_mailbox):
+ def __init__(self, leap_mailbox, index_file_path):
self.leap_mailbox = leap_mailbox
+ self.tag_index = TagIndex(index_file_path)
+ for tag in self.SPECIAL_TAGS:
+ if tag not in self.tag_index.values():
+ self.tag_index.set(tag)
@property
def messages(self):
@@ -47,22 +52,18 @@ class PixelatedMailbox:
return PixelatedMail.from_leap_mail(message)
def all_tags(self):
- return Tag.from_flags(self._getFlags())
-
- def _getFlags(self):
- # XXX Temporary workaround while getFlags from leap is disabled
- mbox = self.leap_mailbox._get_mbox_doc()
- if not mbox:
- return self.leap_mailbox.getFlags()
- return mbox.content.get(self.leap_mailbox.FLAGS_KEY, [])
-
- def update_tags(self, tags):
- new_flags = set(tag.to_flag() for tag in tags)
- current_flags = set(self._getFlags())
-
- flags = tuple(current_flags.union(new_flags))
- self.leap_mailbox.setFlags(flags)
+ return self.tag_index.values().union(self.SPECIAL_TAGS)
+
+ def notify_tags_updated(self, added_tags, removed_tags, mail_ident):
+ for removed_tag in removed_tags:
+ tag = self.tag_index.get(removed_tag)
+ tag.decrement(mail_ident)
+ self.tag_index.set(tag)
+ for added_tag in added_tags:
+ tag = self.tag_index.get(added_tag) or Tag(added_tag)
+ tag.increment(mail_ident)
+ self.tag_index.set(tag)
@classmethod
def create(cls, account, mailbox_name='INBOX'):
- return PixelatedMailbox(account.getMailbox(mailbox_name))
+ return PixelatedMailbox(account.getMailbox(mailbox_name), '~/.pixelated_index')