summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBruno Wagner Goncalves <bwagner@thoughtworks.com>2014-09-25 20:44:01 -0300
committerBruno Wagner Goncalves <bwagner@thoughtworks.com>2014-09-25 20:44:01 -0300
commitd7f4798a90ffc933bed76030ce965e7dc1ead55a (patch)
tree0cefe383e505b57f823727f196ccc82fdfb1b97c
parente10893d493d3b6c38f1336e82c5cc0f0a2b5c053 (diff)
Drafts working now for both create and update
-rw-r--r--service/pixelated/adapter/mail_service.py4
-rw-r--r--service/pixelated/adapter/pixelated_mail.py3
-rw-r--r--service/pixelated/adapter/pixelated_mailbox.py6
-rw-r--r--service/pixelated/adapter/pixelated_mailboxes.py6
-rw-r--r--service/pixelated/adapter/soledad_querier.py11
-rw-r--r--service/pixelated/user_agent.py4
6 files changed, 21 insertions, 13 deletions
diff --git a/service/pixelated/adapter/mail_service.py b/service/pixelated/adapter/mail_service.py
index 6606ac41..c4b0c0e5 100644
--- a/service/pixelated/adapter/mail_service.py
+++ b/service/pixelated/adapter/mail_service.py
@@ -47,8 +47,8 @@ class MailService:
def create_draft(self, mail):
return self.mailboxes.add_draft(mail)
- def update_draft(self, mail):
- return self.mailboxes.update_draft(mail)
+ def update_draft(self, ident, new_version):
+ return self.mailboxes.update_draft(ident, new_version)
def send_draft(self, mail):
pass
diff --git a/service/pixelated/adapter/pixelated_mail.py b/service/pixelated/adapter/pixelated_mail.py
index d1b6bf36..44ebd08c 100644
--- a/service/pixelated/adapter/pixelated_mail.py
+++ b/service/pixelated/adapter/pixelated_mail.py
@@ -47,7 +47,6 @@ class InputMail:
'body': self.body
}
-
@staticmethod
def from_dict(mail_dict):
input_mail = InputMail()
@@ -262,7 +261,6 @@ class PixelatedMail:
'body': self.body
}
-
@staticmethod
def from_dict(mail_dict):
return from_dict(mail_dict)
@@ -284,4 +282,3 @@ def from_dict(mail_dict):
mail.tags = set(mail_dict.get('tags', []))
mail.status = set(mail_dict.get('status', []))
return mail
-
diff --git a/service/pixelated/adapter/pixelated_mailbox.py b/service/pixelated/adapter/pixelated_mailbox.py
index 91e2cc4d..aa00a24f 100644
--- a/service/pixelated/adapter/pixelated_mailbox.py
+++ b/service/pixelated/adapter/pixelated_mailbox.py
@@ -63,9 +63,9 @@ class PixelatedMailbox:
def add(self, mail, use_smtp_format=False):
self.querier.create_mail(mail, self.mailbox_name)
- def remove(self, mail):
- mail.mark_as_deleted()
-
+ def remove(self, ident):
+ mail = self.querier.mail(ident)
+ self.querier.remove_mail(mail)
self.leap_mailbox.expunge()
@classmethod
diff --git a/service/pixelated/adapter/pixelated_mailboxes.py b/service/pixelated/adapter/pixelated_mailboxes.py
index 43fa3620..890e86e1 100644
--- a/service/pixelated/adapter/pixelated_mailboxes.py
+++ b/service/pixelated/adapter/pixelated_mailboxes.py
@@ -34,9 +34,9 @@ class PixelatedMailBoxes():
self.drafts().add(mail, use_smtp_format=True)
return mail
- def update_draft(self, mail):
- new_mail = self.add_draft(mail)
- self.drafts().remove(mail)
+ def update_draft(self, ident, new_version):
+ new_mail = self.add_draft(new_version)
+ self.drafts().remove(ident)
return new_mail
def move_to_trash(self, mail):
diff --git a/service/pixelated/adapter/soledad_querier.py b/service/pixelated/adapter/soledad_querier.py
index 16196e2a..179d10f1 100644
--- a/service/pixelated/adapter/soledad_querier.py
+++ b/service/pixelated/adapter/soledad_querier.py
@@ -44,6 +44,17 @@ class SoledadQuerier:
new_docs = [self.soledad.create_doc(doc) for doc in mail._get_for_save(next_uid=uid)]
self._update_index(new_docs)
+ def mail(self, ident):
+ fdoc = self.soledad.get_from_index('by-type-and-contenthash', 'flags', ident)[0]
+ hdoc = self.soledad.get_from_index('by-type-and-contenthash', 'head', ident)[0]
+ bdoc = self.soledad.get_from_index('by-type-and-payloadhash', 'cnt', hdoc.content['body'])[0]
+ return PixelatedMail.from_soledad(fdoc, hdoc, bdoc, soledad_querier=self)
+
+ def remove_mail(self, mail):
+ _mail = self.mail(mail.ident)
+ self.soledad.delete_doc(_mail.bdoc)
+ self.soledad.delete_doc(_mail.hdoc)
+ self.soledad.delete_doc(_mail.fdoc)
def _next_uid_for_mailbox(self, mailbox_name):
mails = self.all_mails_by_mailbox(mailbox_name)
diff --git a/service/pixelated/user_agent.py b/service/pixelated/user_agent.py
index aa4b8a86..e6533ea6 100644
--- a/service/pixelated/user_agent.py
+++ b/service/pixelated/user_agent.py
@@ -72,8 +72,8 @@ def send_mail():
@app.route('/mails', methods=['PUT'])
def update_draft():
- _mail = PixelatedMail.from_dict(request.json)
- ident = mail_service.update_draft(_mail)
+ _mail = InputMail.from_dict(request.json)
+ ident = mail_service.update_draft(request.json['ident'], _mail).ident
return respond_json({'ident': ident})