summaryrefslogtreecommitdiff
path: root/py-fake-service
diff options
context:
space:
mode:
authorAlexandre Pretto Nunes <anunes@thoughtworks.com>2014-08-14 15:16:56 -0300
committerAlexandre Pretto Nunes <anunes@thoughtworks.com>2014-08-14 15:19:46 -0300
commitdde0dc6bb735cebe946c6fd8c5d7c8cfd6028cc8 (patch)
treeca5282488b85467d4fb0ae16b853611bc23422c6 /py-fake-service
parent5b1ad127f11519f519f75be9148d17d4e034b1e6 (diff)
Enable fake server to correctly serve html emails
Diffstat (limited to 'py-fake-service')
-rw-r--r--py-fake-service/app/adapter/mail.py15
-rw-r--r--py-fake-service/app/adapter/mail_service.py14
2 files changed, 15 insertions, 14 deletions
diff --git a/py-fake-service/app/adapter/mail.py b/py-fake-service/app/adapter/mail.py
index 1cbe065f..5e0483fc 100644
--- a/py-fake-service/app/adapter/mail.py
+++ b/py-fake-service/app/adapter/mail.py
@@ -18,7 +18,7 @@ class Mail:
mail.draft_reply_for = mail_json.get('draft_reply_for', 0)
return mail
-
+
def __init__(self, mbox_mail=None, ident=None):
if mbox_mail:
self.header = self._get_headers(mbox_mail)
@@ -31,11 +31,14 @@ class Mail:
def _get_body(self, message):
if message.is_multipart():
- boundary = message.get_boundary()
- start_boundary = '--'+boundary
- join_boundary = start_boundary+'\n'
+ boundary = '--{boundary}'.format(boundary= message.get_boundary().strip())
+ body_parts = [x.as_string() for x in message.get_payload()]
+
+ body = boundary + '\n'
+ body += '{boundary}\n'.format(boundary=boundary).join(body_parts)
+ body += '{boundary}--\n'.format(boundary=boundary)
- return join_boundary + join_boundary.join([x.as_string() for x in message.get_payload()]) + start_boundary+ '--'
+ return body
else:
return message.get_payload()
@@ -60,7 +63,7 @@ class Mail:
def _get_tags(self, mbox_mail):
return mbox_mail.get('X-TW-Pixelated-Tags').split(', ')
-
+
@property
def subject(self):
return self.header['subject']
diff --git a/py-fake-service/app/adapter/mail_service.py b/py-fake-service/app/adapter/mail_service.py
index 7c2570f9..41195c0a 100644
--- a/py-fake-service/app/adapter/mail_service.py
+++ b/py-fake-service/app/adapter/mail_service.py
@@ -16,12 +16,10 @@ class MailService:
def load_mailset(self):
mbox_filenames = [filename for filename in os.listdir(self.MAILSET_PATH) if filename.startswith('mbox')]
- boxes = (mailbox.mbox(os.path.join(self.MAILSET_PATH, mbox)) for mbox in mbox_filenames)
+ boxes = (mailbox.mbox(os.path.join(self.MAILSET_PATH, mbox)) for mbox in mbox_filenames)
for box in boxes:
message = box.popitem()[1]
- if message.is_multipart():
- continue
self.mailset.add(message)
self.tagsset.add(message)
self.contacts.add(message)
@@ -49,13 +47,13 @@ class MailService:
def update_tags_for(self, mail_id, new_tags):
mail = self.mail(mail_id)
-
+
new_tags_set = set(new_tags)
old_tags_set = set(mail.tags)
- increment_set = new_tags_set - old_tags_set
+ increment_set = new_tags_set - old_tags_set
decrement_set = old_tags_set - new_tags_set
-
+
map(lambda x : self.tagsset.increment_tag_total_count(x), increment_set)
map(lambda x : self.tagsset.decrement_tag_total_count(x), decrement_set)
@@ -71,8 +69,8 @@ class MailService:
def save_draft(self, mail):
mail = self.mailset.add_draft(Mail.from_json(mail))
return mail.ident
-
-
+
+
def update_draft(self, mail):
mail = Mail.from_json(mail)
self.mailset.update(mail)