summaryrefslogtreecommitdiff
path: root/service
diff options
context:
space:
mode:
authorFolker Bernitt <fbernitt@thoughtworks.com>2015-07-23 18:10:20 +0200
committerFolker Bernitt <fbernitt@thoughtworks.com>2015-08-11 17:00:27 +0200
commitca2be15686064d3ece97261df72560a4f91ade4d (patch)
treef3802b42da093eecb0858d1d167e9c837cfdbe8c /service
parent4de9e17f4cd1f597251552408080c1a82c45720f (diff)
Added include_body to get_mail.
Diffstat (limited to 'service')
-rw-r--r--service/pixelated/adapter/mailstore/leap_mailstore.py19
-rw-r--r--service/test/unit/adapter/mailstore/test_leap_mailstore.py27
2 files changed, 40 insertions, 6 deletions
diff --git a/service/pixelated/adapter/mailstore/leap_mailstore.py b/service/pixelated/adapter/mailstore/leap_mailstore.py
index a39f4eae..893eb52b 100644
--- a/service/pixelated/adapter/mailstore/leap_mailstore.py
+++ b/service/pixelated/adapter/mailstore/leap_mailstore.py
@@ -38,6 +38,7 @@ class LeapMail(Mail):
'header': {k.lower(): v for k, v in self.headers.items()},
'ident': self._mail_id,
'tags': self._tags,
+ 'body': self._body
}
@@ -49,12 +50,13 @@ class LeapMailStore(MailStore):
self.soledad = soledad
@defer.inlineCallbacks
- def get_mail(self, mail_id):
+ def get_mail(self, mail_id, include_body=False):
try:
message = yield SoledadMailAdaptor().get_msg_from_mdoc_id(Message, self.soledad, mail_id)
+ leap_mail = yield self._leap_message_to_leap_mail(mail_id, message, include_body)
- defer.returnValue(self._leap_message_to_leap_mail(mail_id, message))
- except AttributeError:
+ defer.returnValue(leap_mail)
+ except AttributeError, e:
defer.returnValue(None)
def get_mails(self, mail_ids):
@@ -64,6 +66,13 @@ class LeapMailStore(MailStore):
return defer.gatherResults(deferreds, consumeErrors=True)
- def _leap_message_to_leap_mail(self, mail_id, message):
- return LeapMail(mail_id, message.get_headers(), message.get_tags())
+ @defer.inlineCallbacks
+ def _leap_message_to_leap_mail(self, mail_id, message, include_body):
+ if include_body:
+ body = (yield message._wrapper.get_body(self.soledad)).raw
+ else:
+ body = None
+ mail = LeapMail(mail_id, message.get_headers(), message.get_tags(), body=body)
+
+ defer.returnValue(mail)
diff --git a/service/test/unit/adapter/mailstore/test_leap_mailstore.py b/service/test/unit/adapter/mailstore/test_leap_mailstore.py
index e8138aa6..cee1dfd2 100644
--- a/service/test/unit/adapter/mailstore/test_leap_mailstore.py
+++ b/service/test/unit/adapter/mailstore/test_leap_mailstore.py
@@ -13,9 +13,11 @@
#
# You should have received a copy of the GNU Affero General Public License
# along with Pixelated. If not, see <http://www.gnu.org/licenses/>.
+import json
from uuid import uuid4
from email.parser import Parser
import os
+from leap.soledad.common.document import SoledadDocument
from twisted.internet.defer import FirstError
from twisted.trial.unittest import TestCase
@@ -50,10 +52,17 @@ class TestLeapMail(TestCase):
},
'ident': 'doc id',
'tags': ('foo', 'bar'),
+ 'body': None
}
self.assertEqual(expected, mail.as_dict())
+ def test_as_dict_with_body(self):
+ body = 'some body content'
+ mail = LeapMail('doc id', {'From': 'test@example.test', 'Subject': 'A test Mail', 'To': 'receiver@example.test'}, ('foo', 'bar'), body=body)
+
+ self.assertEqual(body, mail.as_dict()['body'])
+
class TestLeapMailStore(TestCase):
def setUp(self):
@@ -120,6 +129,18 @@ class TestLeapMailStore(TestCase):
except FirstError:
pass
+ @defer.inlineCallbacks
+ def test_get_mail_with_body(self):
+ mdoc_id = self._add_mail_fixture_to_soledad('mbox00000000')
+
+ store = LeapMailStore(self.account, self.soledad)
+
+ mail = yield store.get_mail(mdoc_id, include_body=True)
+
+ expeted_body = 'Dignissimos ducimus veritatis. Est tenetur consequatur quia occaecati. Vel sit sit voluptas.\n\nEarum distinctio eos. Accusantium qui sint ut quia assumenda. Facere dignissimos inventore autem sit amet. Pariatur voluptatem sint est.\n\nUt recusandae praesentium aspernatur. Exercitationem amet placeat deserunt quae consequatur eum. Unde doloremque suscipit quia.\n\n'
+
+ self.assertEqual(expeted_body, mail.body)
+
def _add_mail_fixture_to_soledad(self, mail_file):
mail = self._load_mail_from_file(mail_file)
@@ -135,7 +156,11 @@ class TestLeapMailStore(TestCase):
when(self.soledad).get_doc(mdoc_id).thenReturn(defer.succeed(msg.get_wrapper().mdoc.serialize()))
when(self.soledad).get_doc(fdoc_id).thenReturn(defer.succeed(msg.get_wrapper().fdoc.serialize()))
when(self.soledad).get_doc(hdoc_id).thenReturn(defer.succeed(msg.get_wrapper().hdoc.serialize()))
- when(self.soledad).get_doc(cdoc_id).thenReturn(defer.succeed(msg.get_wrapper().cdocs[1].serialize()))
+
+ content = SoledadDocument(doc_id=cdoc_id, json=json.dumps(msg.get_wrapper().cdocs[1].serialize()))
+
+ when(self.soledad).get_doc(cdoc_id).thenReturn(defer.succeed(content))
+ # when(self.soledad).get_doc(cdoc_id).thenReturn(defer.succeed(msg.get_wrapper().cdocs[1].serialize()))
return mdoc_id