From 50049e17edff98762839d55650b6516f2d5e81ab Mon Sep 17 00:00:00 2001 From: Patrick Maia Date: Thu, 14 Aug 2014 11:52:52 -0300 Subject: You can now list all tags and creating an email identify the tags --- service/app/adapter/mail_service.py | 6 ++++-- service/app/adapter/pixelated_mail.py | 38 +++++++++++++++++++++++++---------- 2 files changed, 31 insertions(+), 13 deletions(-) (limited to 'service/app/adapter') diff --git a/service/app/adapter/mail_service.py b/service/app/adapter/mail_service.py index 25fb5188..b5ae09f2 100644 --- a/service/app/adapter/mail_service.py +++ b/service/app/adapter/mail_service.py @@ -5,6 +5,8 @@ from app.bitmask_libraries.config import LeapConfig from app.bitmask_libraries.provider import LeapProvider from app.bitmask_libraries.session import LeapSessionFactory from app.bitmask_libraries.auth import LeapCredentials +from app.adapter.pixelated_mail import PixelatedMail +from app.tags import Tags import logging @@ -36,7 +38,7 @@ class MailService: self.server_name = 'example.wazokazi.is' self.mailbox_name = 'INBOX' self.leapdir = os.path.join(os.path.abspath("."), "leap") - + self.tags = Tags() self._open_leap_session() except: traceback.print_exc(file=sys.stdout) @@ -108,7 +110,7 @@ class MailService: raise NotImplementedError() def all_tags(self): - raise NotImplementedError() + return self.tags def all_contacts(self, query): raise NotImplementedError() diff --git a/service/app/adapter/pixelated_mail.py b/service/app/adapter/pixelated_mail.py index 412414ed..cdfd9a29 100644 --- a/service/app/adapter/pixelated_mail.py +++ b/service/app/adapter/pixelated_mail.py @@ -1,4 +1,5 @@ from app.tags import Tag +from app.tags import Tags class PixelatedMail: @@ -25,28 +26,43 @@ class PixelatedMail: def __init__(self, leap_mail): self.leap_mail = leap_mail self.body = leap_mail.bdoc.content['raw'] - self.headers = self.extract_headers(leap_mail) + self.headers = self.extract_headers() self.ident = leap_mail.getUID() - self.status = self.extract_status(leap_mail) + self.status = self.extract_status() self.security_casing = {} - self.tags = self.extract_tags(leap_mail) + self.tags = self.extract_tags() - def extract_status(self, leap_mail): - flags = leap_mail.getFlags() + def extract_status(self): + flags = self.leap_mail.getFlags() return [converted for flag, converted in self.LEAP_FLAGS_STATUSES.items() if flag in flags] - def extract_headers(self, leap_mail): + def extract_headers(self): temporary_headers = {} - for header, value in leap_mail.hdoc.content['headers'].items(): + for header, value in self.leap_mail.hdoc.content['headers'].items(): temporary_headers[header.lower()] = value return temporary_headers - def extract_tags(self, leap_mail): - flags = leap_mail.getFlags() - converted_tags = [Tag(converted) for flag, converted in self.LEAP_FLAGS_TAGS.items() if flag in flags] - tags = converted_tags + [Tag(flag) for flag in leap_mail.getFlags() if flag not in self.LEAP_FLAGS] + def extract_tags(self): + flags = self.leap_mail.getFlags() + tag_names = self._converted_tags(flags) + self._custom_tags(flags) + tags = [] + for tag in tag_names: + tags.append(Tag(tag)) return tags + def _converted_tags(self, flags): + return [converted for flag, converted in self.LEAP_FLAGS_TAGS.items() if flag in flags] + + def _custom_tags(self, flags): + return [self._remove_prefix(flag) for flag in self.leap_mail.getFlags() if flag.startswith('tag_')] + + def _remove_prefix(self, flag_name): + return flag_name.replace('tag_', '', 1) + + def update_tags(self, tags): + self.tags = [Tag(tag) for tag in tags] + return self.tags + def has_tag(self, tag): return Tag(tag) in self.tags -- cgit v1.2.3