From b06b794de750d972a9dff9165e203815b79c5b62 Mon Sep 17 00:00:00 2001 From: Alexandre Pretto Date: Thu, 8 Jan 2015 18:48:48 -0200 Subject: #157: mail api to return htmlBody and textPlainBody so the UI doesnt have to parse the multipart mails anymore --- web-ui/app/js/helpers/view_helper.js | 49 ++++++------------------------------ 1 file changed, 7 insertions(+), 42 deletions(-) (limited to 'web-ui/app/js/helpers') diff --git a/web-ui/app/js/helpers/view_helper.js b/web-ui/app/js/helpers/view_helper.js index 72ced4af..48d9a9c7 100644 --- a/web-ui/app/js/helpers/view_helper.js +++ b/web-ui/app/js/helpers/view_helper.js @@ -31,52 +31,17 @@ define( }).join(' '); } - function addParagraphsToPlainText(plainTextBodyPart) { - return _.map(plainTextBodyPart.split('\n'), function (paragraph) { + function addParagraphsToPlainText(textPlainBody) { + return _.map(textPlainBody.split('\n'), function (paragraph) { return '

' + paragraph + '

'; }).join(''); } - function isQuotedPrintableBodyPart (bodyPart) { - return bodyPart.headers && - bodyPart.headers['Content-Transfer-Encoding'] && - bodyPart.headers['Content-Transfer-Encoding'] === 'quoted-printable'; - } - - function getHtmlContentType (mail) { - return _.find(mail.availableBodyPartsContentType(), function (contentType) { - return contentType.indexOf('text/html') >= 0; - }); - } - - function getSanitizedAndDecodedMailBody (bodyPart) { - var body; - - if (isQuotedPrintableBodyPart(bodyPart)) { - body = utf8.decode(quotedPrintable.decode(bodyPart.body)); - } else if (bodyPart.body) { - body = bodyPart.body; - } else { - body = bodyPart; - } - - return htmlWhitelister.sanitize(body, htmlWhitelister.tagPolicy); - } - function formatMailBody (mail) { - if (mail.isMailMultipartAlternative()) { - var htmlContentType; - - htmlContentType = getHtmlContentType(mail); - - if (htmlContentType) { - return $(getSanitizedAndDecodedMailBody(mail.getMailPartByContentType(htmlContentType))); - } - - return $(getSanitizedAndDecodedMailBody(addParagraphsToPlainText(mail.getMailMultiParts[0]))); - } - - return $(getSanitizedAndDecodedMailBody(addParagraphsToPlainText(mail.body))); + var body = mail.htmlBodyPart ? + htmlWhitelister.sanitize(mail.htmlBody, htmlWhitelister.tagPolicy) : + addParagraphsToPlainText(mail.textPlainBody) + return $(body) } function moveCaretToEnd(el) { @@ -125,7 +90,7 @@ define( } function quoteMail(mail) { - var quotedLines = _.map(mail.body.split('\n'), function (line) { + var quotedLines = _.map(mail.textPlainBody.split('\n'), function (line) { return '> ' + line; }); -- cgit v1.2.3