summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDuda Dornelles <ddornell@thoughtworks.com>2014-08-27 15:05:22 -0300
committerDuda Dornelles <ddornell@thoughtworks.com>2014-08-28 16:34:20 -0300
commit5207cd71baabc3203d3f7982d98168469139327d (patch)
treeef2ce92656f350b005742976e37230d950b60d6a
parentc51c1024299fcf69cc67388b7dc35760a0414d12 (diff)
Duda/Neissi adding to_mime_multipart method to pixelated mail
-rw-r--r--service/pixelated/adapter/pixelated_mail.py9
-rw-r--r--service/test/adapter/pixelated_mail_test.py44
2 files changed, 36 insertions, 17 deletions
diff --git a/service/pixelated/adapter/pixelated_mail.py b/service/pixelated/adapter/pixelated_mail.py
index f9bce3cf..547927a6 100644
--- a/service/pixelated/adapter/pixelated_mail.py
+++ b/service/pixelated/adapter/pixelated_mail.py
@@ -16,6 +16,8 @@
from pixelated.adapter.tag import Tag
from pixelated.adapter.status import Status
import dateutil.parser as dateparser
+from email.MIMEMultipart import MIMEMultipart
+from email.MIMEText import MIMEText
class PixelatedMail:
@@ -71,6 +73,13 @@ class PixelatedMail:
'body': self.body
}
+ def to_mime_multipart(self):
+ mime_multipart = MIMEMultipart()
+ mime_multipart['To'] = self.headers['to'][0]
+ mime_multipart['Subject'] = self.headers['subject']
+ mime_multipart.attach(MIMEText(self.body, 'plain'))
+ return mime_multipart
+
@staticmethod
def from_dict(mail_dict):
mail = PixelatedMail()
diff --git a/service/test/adapter/pixelated_mail_test.py b/service/test/adapter/pixelated_mail_test.py
index 81e9f340..b6bf623f 100644
--- a/service/test/adapter/pixelated_mail_test.py
+++ b/service/test/adapter/pixelated_mail_test.py
@@ -21,6 +21,17 @@ import test_helper
class TestPixelatedMail(unittest.TestCase):
+ mail_dict = {
+ 'body': 'Este \xe9 o corpo',
+ 'header': {
+ 'cc': ['cc@pixelated.org'],
+ 'to': ['to@pixelated.org'],
+ 'subject': 'Oi',
+ 'bcc': ['bcc@pixelated.org']
+ },
+ 'ident': '',
+ 'tags': ['sent']
+ }
def test_leap_recent_flag_is_translated_to_inbox_tag(self):
pixelated_mail = PixelatedMail.from_leap_mail(test_helper.leap_mail(leap_flags=['\\Recent']))
@@ -48,23 +59,12 @@ class TestPixelatedMail(unittest.TestCase):
self.assertEquals(set([Tag('custom_tag'), Tag('inbox')]), pixelated_mail.tags)
def test_from_dict(self):
- mail_dict = {
- 'body': 'Este \xe9 o corpo',
- 'header': {
- 'cc': ['cc@pixelated.com'],
- 'to': ['to@pixelated.com'],
- 'subject': 'Oi',
- 'bcc': ['bcc@pixelated.com']
- },
- 'ident': '',
- 'tags': ['sent']
- }
-
- mail = PixelatedMail.from_dict(mail_dict)
-
- self.assertEqual(mail.headers['cc'], ['cc@pixelated.com'])
- self.assertEqual(mail.headers['to'], ['to@pixelated.com'])
- self.assertEqual(mail.headers['bcc'], ['bcc@pixelated.com'])
+
+ mail = PixelatedMail.from_dict(self.mail_dict)
+
+ self.assertEqual(mail.headers['cc'], ['cc@pixelated.org'])
+ self.assertEqual(mail.headers['to'], ['to@pixelated.org'])
+ self.assertEqual(mail.headers['bcc'], ['bcc@pixelated.org'])
self.assertEqual(mail.headers['subject'], 'Oi')
self.assertEqual(mail.ident, '')
self.assertEqual(mail.tags, ['sent'])
@@ -75,3 +75,13 @@ class TestPixelatedMail(unittest.TestCase):
current_tags, removed_tags = pixelated_mail.update_tags(set([Tag('custom_1'), Tag('custom_3')]))
self.assertEquals(set([Tag('custom_3'), Tag('custom_1')]), current_tags)
self.assertEquals(set([Tag('custom_2')]), removed_tags)
+
+ def test_to_mime_multipart(self):
+ mail = PixelatedMail.from_dict(self.mail_dict)
+
+ mime_multipart = mail.to_mime_multipart()
+
+ self.assertRegexpMatches(mime_multipart.as_string(), "\nTo: to@pixelated.org\n")
+ self.assertRegexpMatches(mime_multipart.as_string(), "\nSubject: Oi\n")
+ self.assertRegexpMatches(mime_multipart.as_string(), "\nEste \xe9 o corpo")
+