diff options
author | Duda Dornelles <ddornell@thoughtworks.com> | 2014-08-26 19:11:01 -0300 |
---|---|---|
committer | Duda Dornelles <ddornell@thoughtworks.com> | 2014-08-26 19:11:01 -0300 |
commit | cf3ea5411adb12dd1bdc12ec01a17b37d974c7c3 (patch) | |
tree | 52b203175aee472099efb29bb47033b870cc9a8d /service/pixelated/adapter | |
parent | 6095a286a0298c10df3b7bfa163f2f5240b580cd (diff) |
refactoring pixelatedMail constructor so we can have 'two' (from_dict and from_leap_mail)
Diffstat (limited to 'service/pixelated/adapter')
-rw-r--r-- | service/pixelated/adapter/mail_service.py | 4 | ||||
-rw-r--r-- | service/pixelated/adapter/pixelated_mail.py | 36 |
2 files changed, 25 insertions, 15 deletions
diff --git a/service/pixelated/adapter/mail_service.py b/service/pixelated/adapter/mail_service.py index 54deb488..82925870 100644 --- a/service/pixelated/adapter/mail_service.py +++ b/service/pixelated/adapter/mail_service.py @@ -52,7 +52,7 @@ class MailService: def mails(self, query): mails = self.mailbox.messages or [] - mails = [PixelatedMail(mail) for mail in mails] + mails = [PixelatedMail.from_leap_mail(mail) for mail in mails] return mails def update_tags(self, mail_id, new_tags): @@ -77,7 +77,7 @@ class MailService: def mail(self, mail_id): for message in self.mailbox.messages: if message.getUID() == int(mail_id): - return PixelatedMail(message) + return PixelatedMail.from_leap_mail(message) def all_tags(self): return self.tags diff --git a/service/pixelated/adapter/pixelated_mail.py b/service/pixelated/adapter/pixelated_mail.py index 081eb846..4169bb23 100644 --- a/service/pixelated/adapter/pixelated_mail.py +++ b/service/pixelated/adapter/pixelated_mail.py @@ -39,21 +39,27 @@ class PixelatedMail: '\\Recent': 'inbox' } - def __init__(self, leap_mail): - self.leap_mail = leap_mail - self.body = leap_mail.bdoc.content['raw'] - self.headers = self.extract_headers() - self.date = dateparser.parse(self.headers['date']) - self.ident = leap_mail.getUID() - self.status = self.extract_status() - self.security_casing = {} - self.tags = self.extract_tags() - - def extract_status(self): + def __init__(self): + pass + + @staticmethod + def from_leap_mail(leap_mail): + mail = PixelatedMail() + mail.leap_mail = leap_mail + mail.body = leap_mail.bdoc.content['raw'] + mail.headers = mail._extract_headers() + mail.date = dateparser.parse(mail.headers['date']) + mail.ident = leap_mail.getUID() + mail.status = mail._extract_status() + mail.security_casing = {} + mail.tags = mail._extract_tags() + return mail + + 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): + def _extract_headers(self): temporary_headers = {} for header, value in self.leap_mail.hdoc.content['headers'].items(): temporary_headers[header.lower()] = value @@ -61,7 +67,7 @@ class PixelatedMail: temporary_headers['to'] = [temporary_headers['to']] return temporary_headers - def extract_tags(self): + def _extract_tags(self): flags = self.leap_mail.getFlags() tag_names = self._converted_tags(flags) + self._custom_tags(flags) tags = [] @@ -95,3 +101,7 @@ class PixelatedMail: 'security_casing': self.security_casing, 'body': self.body } + + @staticmethod + def from_dict(mail_dict): + return PixelatedMail() |