diff options
author | Alexandre Pretto <anunes@thoughtworks.com> | 2015-01-08 18:48:48 -0200 |
---|---|---|
committer | Pixpoa pairing <pixpoapairing@pixelated-project.org> | 2015-01-08 18:53:40 -0200 |
commit | b06b794de750d972a9dff9165e203815b79c5b62 (patch) | |
tree | b34414d27dff67ce94c7c15f419f25b9dcfae0d1 /web-ui/app/js | |
parent | 266b2f10f848902b31e0dfd05696dc2f5618bf2e (diff) |
#157: mail api to return htmlBody and textPlainBody so the UI doesnt have to parse the multipart mails anymore
Diffstat (limited to 'web-ui/app/js')
-rw-r--r-- | web-ui/app/js/helpers/view_helper.js | 49 |
1 files changed, 7 insertions, 42 deletions
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 '<p>' + paragraph + '</p>'; }).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; }); |