summaryrefslogtreecommitdiff
path: root/service/pixelated
diff options
context:
space:
mode:
authorPatrick Maia and Victor Shyba <pixelated-team+pmaia+vshyba@thoughtworks.com>2014-08-26 22:19:48 +0000
committerPatrick Maia <pmaia@thoughtworks.com>2014-08-26 22:33:02 +0000
commit3a22e05d083986b8111d7e98831f79960b83b993 (patch)
treef2ff30ffa2961bd91ac20afbcc4e77a590201391 /service/pixelated
parent6592bfad8cb90d7256de949b181ed9d0b684afec (diff)
- #51 - retrieves tag from leap and introduces PixelatedMailbox abstraction
Diffstat (limited to 'service/pixelated')
-rw-r--r--service/pixelated/adapter/mail_service.py18
-rw-r--r--service/pixelated/adapter/pixelated_mailbox.py43
2 files changed, 51 insertions, 10 deletions
diff --git a/service/pixelated/adapter/mail_service.py b/service/pixelated/adapter/mail_service.py
index f2db8d16..edb6936b 100644
--- a/service/pixelated/adapter/mail_service.py
+++ b/service/pixelated/adapter/mail_service.py
@@ -22,6 +22,7 @@ from pixelated.bitmask_libraries.provider import LeapProvider
from pixelated.bitmask_libraries.session import LeapSessionFactory
from pixelated.bitmask_libraries.auth import LeapCredentials
from pixelated.adapter.pixelated_mail import PixelatedMail
+from pixelated.adapter.pixelated_mailbox import PixelatedMailbox
class MailService:
@@ -46,12 +47,10 @@ class MailService:
@property
def mailbox(self):
- return self.account.getMailbox(self.mailbox_name)
+ return PixelatedMailbox(self.account.getMailbox(self.mailbox_name))
def mails(self, query):
- mails = self.mailbox.messages or []
- mails = [PixelatedMail.from_leap_mail(mail) for mail in mails]
- return mails
+ return self.mailbox.mails()
def update_tags(self, mail_id, new_tags):
mail = self.mail(mail_id)
@@ -66,20 +65,19 @@ class MailService:
# self.tags.add(tag)
def _update_flags(self, new_tags, mail_id):
- new_tags_flag_name = ['tag_' + tag.name for tag in new_tags if tag.name not in ['inbox', 'drafts', 'sent', 'trash']]
+ new_tags_flag_name = ['tag_' + tag.name for tag in new_tags if tag.name not in PixelatedMailbox.SPECIAL_TAGS]
self.set_flags(mail_id, new_tags_flag_name)
def set_flags(self, mail_id, new_tags_flag_name):
observer = defer.Deferred()
- self.mailbox.messages.set_flags(self.mailbox, [mail_id], tuple(new_tags_flag_name), 1, observer)
+ leap_mailbox = self.account.getMailbox(self.mailbox_name)
+ self.mailbox.messages.set_flags(leap_mailbox, [mail_id], tuple(new_tags_flag_name), 1, observer)
def mail(self, mail_id):
- for message in self.mailbox.messages:
- if message.getUID() == int(mail_id):
- return PixelatedMail.from_leap_mail(message)
+ return self.mailbox.mail(mail_id)
def all_tags(self):
- return []
+ return self.mailbox.all_tags();
def thread(self, thread_id):
raise NotImplementedError()
diff --git a/service/pixelated/adapter/pixelated_mailbox.py b/service/pixelated/adapter/pixelated_mailbox.py
new file mode 100644
index 00000000..52ca4655
--- /dev/null
+++ b/service/pixelated/adapter/pixelated_mailbox.py
@@ -0,0 +1,43 @@
+
+#
+# Copyright (c) 2014 ThoughtWorks, Inc.
+#
+# Pixelated is free software: you can redistribute it and/or modify
+# it under the terms of the GNU Affero General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# Pixelated is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU Affero General Public License for more details.
+#
+# You should have received a copy of the GNU Affero General Public License
+# along with Pixelated. If not, see <http://www.gnu.org/licenses/>.
+
+from pixelated.adapter.pixelated_mail import PixelatedMail
+from pixelated.adapter.tag import Tag
+
+class PixelatedMailbox:
+
+ SPECIAL_TAGS = ['inbox', 'sent', 'drafts', 'trash']
+
+ def __init__(self, leap_mailbox):
+ self.leap_mailbox = leap_mailbox
+
+ @property
+ def messages(self):
+ return self.leap_mailbox.messages
+
+ def mails(self):
+ mails = self.leap_mailbox.messages or []
+ mails = [PixelatedMail.from_leap_mail(mail) for mail in mails]
+ return mails
+
+ def mail(self, mail_id):
+ for message in self.leap_mailbox.messages:
+ if message.getUID() == int(mail_id):
+ return PixelatedMail.from_leap_mail(message)
+
+ def all_tags(self):
+ return Tag.from_flags(self.leap_mailbox.getFlags())