diff options
author | Lisa Junger <ljunger@thoughtworks.com> | 2014-09-10 17:45:04 +0200 |
---|---|---|
committer | Patrick Maia <pmaia@thoughtworks.com> | 2014-09-15 11:50:47 -0300 |
commit | 1ef6f1de8d698c3e70d3e5e6016099190d2ab342 (patch) | |
tree | d48e96a38af14536bcd2801537512063460adbb7 /service/pixelated | |
parent | 4eeca4b0e3ba10ad08a937d08546384f1c67351c (diff) |
added drafts.
Diffstat (limited to 'service/pixelated')
-rw-r--r-- | service/pixelated/adapter/mail_service.py | 10 | ||||
-rw-r--r-- | service/pixelated/adapter/pixelated_mail.py | 4 | ||||
-rw-r--r-- | service/pixelated/adapter/pixelated_mail_sender.py | 2 | ||||
-rw-r--r-- | service/pixelated/adapter/pixelated_mailbox.py | 3 | ||||
-rw-r--r-- | service/pixelated/adapter/pixelated_mailboxes.py | 9 | ||||
-rw-r--r-- | service/pixelated/user_agent.py | 7 |
6 files changed, 27 insertions, 8 deletions
diff --git a/service/pixelated/adapter/mail_service.py b/service/pixelated/adapter/mail_service.py index debdc9b7..1183dae2 100644 --- a/service/pixelated/adapter/mail_service.py +++ b/service/pixelated/adapter/mail_service.py @@ -47,6 +47,13 @@ class MailService: def send(self, mail): self.mail_sender.sendmail(mail) + def create_draft(self, mail): + drafts = self.mailboxes.drafts() + drafts.add(mail) + + def send_draft(self, mail): + pass + def all_tags(self): return self.tag_service.all_tags() @@ -74,9 +81,6 @@ class MailService: def save_draft(self, draft): raise NotImplementedError() - def send_draft(self, draft): - raise NotImplementedError() - def draft_reply_for(self, mail_id): raise NotImplementedError() diff --git a/service/pixelated/adapter/pixelated_mail.py b/service/pixelated/adapter/pixelated_mail.py index 2aead409..df9b4bbe 100644 --- a/service/pixelated/adapter/pixelated_mail.py +++ b/service/pixelated/adapter/pixelated_mail.py @@ -142,9 +142,9 @@ class PixelatedMail: mime_multipart.attach(MIMEText(self.body, 'plain')) return mime_multipart - def to_smtp_format(self, _from=None): + def to_smtp_format(self): mime_multipart = self.to_mime_multipart() - mime_multipart['From'] = _from + mime_multipart['From'] = PixelatedMail.from_email_address return mime_multipart.as_string() @staticmethod diff --git a/service/pixelated/adapter/pixelated_mail_sender.py b/service/pixelated/adapter/pixelated_mail_sender.py index 486816ac..4189517d 100644 --- a/service/pixelated/adapter/pixelated_mail_sender.py +++ b/service/pixelated/adapter/pixelated_mail_sender.py @@ -28,5 +28,5 @@ class PixelatedMailSender(): self.smtp_client.sendmail( self.account_email_address, recipients, - mail.to_smtp_format(_from=self.account_email_address) + mail.to_smtp_format() ) diff --git a/service/pixelated/adapter/pixelated_mailbox.py b/service/pixelated/adapter/pixelated_mailbox.py index cc44ede7..191c171b 100644 --- a/service/pixelated/adapter/pixelated_mailbox.py +++ b/service/pixelated/adapter/pixelated_mailbox.py @@ -58,6 +58,9 @@ class PixelatedMailbox: original_flags = mail.leap_mail.getFlags() self.leap_mailbox.addMessage(mail.raw_message(), original_flags) + def add(self, mail): + self.leap_mailbox.messages.add_msg(mail.to_smtp_format()) + @classmethod def create(cls, account, mailbox_name='INBOX'): return PixelatedMailbox(account.getMailbox(mailbox_name)) diff --git a/service/pixelated/adapter/pixelated_mailboxes.py b/service/pixelated/adapter/pixelated_mailboxes.py index c003f3fd..50d0ddc4 100644 --- a/service/pixelated/adapter/pixelated_mailboxes.py +++ b/service/pixelated/adapter/pixelated_mailboxes.py @@ -2,9 +2,18 @@ from pixelated.adapter.pixelated_mailbox import PixelatedMailbox class PixelatedMailBoxes(): + def __init__(self, account): self.account = account + def _create_or_get(self, mailbox_name): + if mailbox_name not in self.account.mailboxes: + self.account.addMailbox(mailbox_name) + return PixelatedMailbox.create(self.account, mailbox_name) + + def drafts(self): + return self._create_or_get('DRAFTS') + @property def mailboxes(self): return [PixelatedMailbox.create(self.account, leap_mailbox_name) for leap_mailbox_name in diff --git a/service/pixelated/user_agent.py b/service/pixelated/user_agent.py index c018b1bb..643d0a30 100644 --- a/service/pixelated/user_agent.py +++ b/service/pixelated/user_agent.py @@ -51,7 +51,6 @@ def respond_json(entity): @app.route('/disabled_features') def disabled_features(): return respond_json([ - 'saveDraft', 'draftReply', 'signatureStatus', 'encryptionStatus', @@ -62,7 +61,10 @@ def disabled_features(): @app.route('/mails', methods=['POST']) def send_mail(): mail = PixelatedMail.from_dict(request.json) - mail_service.send(mail) + if mail.ident: + mail_service.send_draft(mail) + else: + mail_service.create_draft(mail) return respond_json(None) @@ -163,6 +165,7 @@ def register_new_user(username): def start_user_agent(debug_enabled): leap_session = LeapSession.open(app.config['LEAP_USERNAME'], app.config['LEAP_PASSWORD'], app.config['LEAP_SERVER_NAME']) + PixelatedMail.from_email_address = leap_session.account_email() pixelated_mailboxes = PixelatedMailBoxes(leap_session.account) pixelated_mail_sender = PixelatedMailSender(leap_session.account_email()) |