summaryrefslogtreecommitdiff
path: root/service/pixelated/adapter/services
diff options
context:
space:
mode:
authorDuda Dornelles <ddornell@thoughtworks.com>2015-02-03 18:58:13 -0200
committerDuda Dornelles <ddornell@thoughtworks.com>2015-02-03 18:58:13 -0200
commit9e7643588e124290879a9ae82f20fa628a9c090a (patch)
treebd7979919eb1bd8be573afd2fdc8fbbf7115ad17 /service/pixelated/adapter/services
parent543e43ce85bb5d8863dbbf2a458af92d21b018cf (diff)
Movinge MailsResource#render_POST logic to MailService and some search_engine calls to Mailbox
Diffstat (limited to 'service/pixelated/adapter/services')
-rw-r--r--service/pixelated/adapter/services/mail_service.py11
-rw-r--r--service/pixelated/adapter/services/mailbox.py15
-rw-r--r--service/pixelated/adapter/services/mailboxes.py5
3 files changed, 20 insertions, 11 deletions
diff --git a/service/pixelated/adapter/services/mail_service.py b/service/pixelated/adapter/services/mail_service.py
index ab0b16bd..da74c0ef 100644
--- a/service/pixelated/adapter/services/mail_service.py
+++ b/service/pixelated/adapter/services/mail_service.py
@@ -13,6 +13,7 @@
#
# You should have received a copy of the GNU Affero General Public License
# along with Pixelated. If not, see <http://www.gnu.org/licenses/>.
+from pixelated.adapter.model.mail import InputMail
class MailService:
@@ -47,10 +48,16 @@ class MailService:
def mail_exists(self, mail_id):
return not(not(self.querier.get_header_by_chash(mail_id)))
- def send(self, mail):
+ def send_mail(self, content_dict):
+ mail = InputMail.from_dict(content_dict)
+ draft_id = content_dict.get('ident')
+
self.mail_sender.sendmail(mail)
+ sent_mail = self.move_to_sent(draft_id, mail)
+
+ return sent_mail
- def move_to_send(self, last_draft_ident, mail):
+ def move_to_sent(self, last_draft_ident, mail):
if last_draft_ident:
self.mailboxes.drafts().remove(last_draft_ident)
return self.mailboxes.sent().add(mail)
diff --git a/service/pixelated/adapter/services/mailbox.py b/service/pixelated/adapter/services/mailbox.py
index 40d9cb8e..f934abcc 100644
--- a/service/pixelated/adapter/services/mailbox.py
+++ b/service/pixelated/adapter/services/mailbox.py
@@ -17,25 +17,26 @@
class Mailbox:
- def __init__(self, mailbox_name, querier):
+ def __init__(self, mailbox_name, querier, search_engine):
self.mailbox_name = mailbox_name
self.mailbox_tag = mailbox_name.lower()
+ self.search_engine = search_engine
self.querier = querier
def mail(self, mail_id):
return self.querier.mail(mail_id)
def add(self, mail):
- return self.querier.create_mail(mail, self.mailbox_name)
+ added_mail = self.querier.create_mail(mail, self.mailbox_name)
+ self.search_engine.index_mail(added_mail)
+ return added_mail
def remove(self, ident):
mail = self.querier.mail(ident)
- self.remove_mail(mail)
-
- def remove_mail(self, mail):
+ self.search_engine.remove_from_index(mail.ident)
mail.remove_all_tags()
self.querier.remove_mail(mail)
@classmethod
- def create(cls, mailbox_name, soledad_querier):
- return Mailbox(mailbox_name, soledad_querier)
+ def create(cls, mailbox_name, soledad_querier, search_engine):
+ return Mailbox(mailbox_name, soledad_querier, search_engine)
diff --git a/service/pixelated/adapter/services/mailboxes.py b/service/pixelated/adapter/services/mailboxes.py
index 51d4add9..0a1c9a4b 100644
--- a/service/pixelated/adapter/services/mailboxes.py
+++ b/service/pixelated/adapter/services/mailboxes.py
@@ -19,9 +19,10 @@ from pixelated.adapter.listeners.mailbox_indexer_listener import MailboxIndexerL
class Mailboxes():
- def __init__(self, account, soledad_querier):
+ def __init__(self, account, soledad_querier, search_engine):
self.account = account
self.querier = soledad_querier
+ self.search_engine = search_engine
for mailbox_name in account.mailboxes:
MailboxIndexerListener.listen(self.account, mailbox_name, soledad_querier)
@@ -30,7 +31,7 @@ class Mailboxes():
if mailbox_name not in self.account.mailboxes:
self.account.addMailbox(mailbox_name)
MailboxIndexerListener.listen(self.account, mailbox_name, self.querier)
- return Mailbox.create(mailbox_name, self.querier)
+ return Mailbox.create(mailbox_name, self.querier, self.search_engine)
def inbox(self):
return self._create_or_get('INBOX')