summaryrefslogtreecommitdiff
path: root/service/app/adapter
diff options
context:
space:
mode:
authorVictor Shyba <victor.shyba@gmail.com>2014-08-11 13:22:14 -0300
committerVictor Shyba <victor.shyba@gmail.com>2014-08-11 13:22:14 -0300
commit0d2f72acbf0541cb01b0d4321278539ff1120802 (patch)
treed3d20f6af1fbc845637659e50785f9e5e660a01c /service/app/adapter
parent1001079b06db84134bae419f993af127ad9bec05 (diff)
Mails is now working and the tags call is returning hardcoded values for now
Diffstat (limited to 'service/app/adapter')
-rw-r--r--service/app/adapter/mail_converter.py24
-rw-r--r--service/app/adapter/mail_service.py12
2 files changed, 28 insertions, 8 deletions
diff --git a/service/app/adapter/mail_converter.py b/service/app/adapter/mail_converter.py
index a77fcdb7..cf793a7a 100644
--- a/service/app/adapter/mail_converter.py
+++ b/service/app/adapter/mail_converter.py
@@ -1,11 +1,33 @@
+import dateutil.parser as dateparser
+
class MailConverter:
def __init__(self, mail_service):
pass
+ def date_to_iso(self, date):
+ return dateparser.parse(date).isoformat()
+
def from_mail(self, imap_mail):
- return inbox_mail
+ headers = imap_mail.hdoc.content['headers']
+ body = imap_mail.bdoc.content
+
+ return {
+ 'header': {
+ 'from': [headers['From']],
+ 'to': [headers['To']],
+ 'cc': headers.get('CC', []),
+ 'bcc': headers.get('BCC', []),
+ 'date': self.date_to_iso(headers['Date']),
+ 'subject': headers['Subject']
+ },
+ 'ident': imap_mail.getUID(),
+ 'tags': imap_mail.getFlags(),
+ 'status': [],
+ 'security_casing': {},
+ 'body': body['raw']
+ }
def to_mail(self, pixelated_mail, account):
raise NotImplementedError()
diff --git a/service/app/adapter/mail_service.py b/service/app/adapter/mail_service.py
index 7b33c290..a08b73f9 100644
--- a/service/app/adapter/mail_service.py
+++ b/service/app/adapter/mail_service.py
@@ -49,11 +49,7 @@ class MailService:
self.mailbox = self.account.getMailbox(self.mailbox_name)
def mails(self, query):
- if query.get('tags', False) and len(query['tags']):
- mailbox = self._switch_mailbox(query['tags'][0])
- return [m for m in mailbox.messages] if mailbox else []
- else:
- return []
+ return self.mailbox.messages or []
def _switch_mailbox(self, name):
mailbox = None
@@ -79,7 +75,9 @@ class MailService:
return []
def mail(self, mail_id):
- raise NotImplementedError()
+ for message in self.mailbox.messages:
+ if message.getUID() == int(mail_id):
+ return message
def thread(self, thread_id):
raise NotImplementedError()
@@ -116,4 +114,4 @@ class MailService:
if __name__ == '__main__':
print('Running Standalone')
- client = Client()
+ client = Client() \ No newline at end of file