summaryrefslogtreecommitdiff
path: root/service/pixelated/adapter/mail_service.py
diff options
context:
space:
mode:
authorDuda Dornelles <ddornell@thoughtworks.com>2014-09-11 14:25:19 -0300
committerDuda Dornelles <ddornell@thoughtworks.com>2014-09-11 14:25:19 -0300
commit332e7d54e0e4c3d71e20a9dc8d9957298e6dcb90 (patch)
tree3be446548f7149e32def8eadf595cb1ce4f4a8ac /service/pixelated/adapter/mail_service.py
parente0cd19256171b18eee571808f7fc12cd042faf19 (diff)
Refactoring tags functionality into TagService
Diffstat (limited to 'service/pixelated/adapter/mail_service.py')
-rw-r--r--service/pixelated/adapter/mail_service.py20
1 files changed, 9 insertions, 11 deletions
diff --git a/service/pixelated/adapter/mail_service.py b/service/pixelated/adapter/mail_service.py
index 7f0d111b..52c1abc7 100644
--- a/service/pixelated/adapter/mail_service.py
+++ b/service/pixelated/adapter/mail_service.py
@@ -13,25 +13,23 @@
#
# 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.tag_service import TagService
class MailService:
__slots__ = ['leap_session', 'account', 'mailbox_name']
- def __init__(self, mailboxes, mail_sender):
+ ALL_MAILS_QUERY = {'tags': ['all']}
+
+ def __init__(self, mailboxes, mail_sender, tag_service=TagService.get_instance()):
+ self.tag_service = tag_service
self.mailboxes = mailboxes
self.mail_sender = mail_sender
-
- @property
- def mailbox(self):
- return self.mailboxes.inbox()
+ self.tag_service.load_index(self.mails(MailService.ALL_MAILS_QUERY))
def mails(self, query):
_mails = None
- if not query['tags']:
- return self.mailbox.mails()
-
if query['tags']:
_mails = self.mailboxes.mails_by_tag(query['tags'])
@@ -40,17 +38,17 @@ class MailService:
def update_tags(self, mail_id, new_tags):
mail = self.mail(mail_id)
added, removed = mail.update_tags(set(new_tags))
- self.mailbox.notify_tags_updated(added, removed, mail_id)
+ self.tag_service.notify_tags_updated(added, removed, mail_id)
return new_tags
def mail(self, mail_id):
- return self.mailbox.mail(mail_id)
+ return self.mailboxes.mail(mail_id)
def send(self, mail):
self.mail_sender.sendmail(mail)
def all_tags(self):
- return self.mailbox.all_tags()
+ return self.tag_service.all_tags()
def thread(self, thread_id):
raise NotImplementedError()