diff options
author | Bruno Wagner Goncalves <bwagner@thoughtworks.com> | 2014-08-13 14:27:00 -0300 |
---|---|---|
committer | Bruno Wagner Goncalves <bwagner@thoughtworks.com> | 2014-08-13 14:27:00 -0300 |
commit | e61fdb9721872614f8672b715dadb9cbd23a84ee (patch) | |
tree | 3b27d8fdc19469479500d35f21213d1492ff2791 /service/app | |
parent | 39b6faf7b1ce4a20cc43bdd4951997f8760f45b7 (diff) |
Pixelated mail class and test
Diffstat (limited to 'service/app')
-rw-r--r-- | service/app/adapter/pixelated_mail.py | 62 |
1 files changed, 62 insertions, 0 deletions
diff --git a/service/app/adapter/pixelated_mail.py b/service/app/adapter/pixelated_mail.py new file mode 100644 index 00000000..412414ed --- /dev/null +++ b/service/app/adapter/pixelated_mail.py @@ -0,0 +1,62 @@ +from app.tags import Tag + + +class PixelatedMail: + + LEAP_FLAGS = ['\\Seen', + '\\Answered', + '\\Flagged', + '\\Deleted', + '\\Draft', + '\\Recent', + 'List'] + + LEAP_FLAGS_STATUSES = { + '\\Seen': 'read', + '\\Answered': 'replied' + } + + LEAP_FLAGS_TAGS = { + '\\Deleted': 'trash', + '\\Draft': 'drafts', + '\\Recent': 'inbox' + } + + 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.ident = leap_mail.getUID() + self.status = self.extract_status(leap_mail) + self.security_casing = {} + self.tags = self.extract_tags(leap_mail) + + def extract_status(self, leap_mail): + flags = leap_mail.getFlags() + return [converted for flag, converted in self.LEAP_FLAGS_STATUSES.items() if flag in flags] + + def extract_headers(self, leap_mail): + temporary_headers = {} + for header, value in 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] + return tags + + def has_tag(self, tag): + return Tag(tag) in self.tags + + def as_dict(self): + tags = [tag.name for tag in self.tags] + return { + 'header': self.headers, + 'ident': self.ident, + 'tags': tags, + 'status': self.status, + 'security_casing': self.security_casing, + 'body': self.body + } |