From 4e6f9b9bbf8fe52d054c507a3daf4c12ab433344 Mon Sep 17 00:00:00 2001 From: Tankred Hase Date: Tue, 5 Nov 2013 22:33:19 +0100 Subject: [PATCH] [WO-64] fix newline in reader and text parser in writer --- src/js/controller/mail-list.js | 33 ++++++++++++++++++++------------- src/js/controller/write.js | 25 +++++++------------------ src/tpl/read.html | 6 +----- 3 files changed, 28 insertions(+), 36 deletions(-) diff --git a/src/js/controller/mail-list.js b/src/js/controller/mail-list.js index 133baaa..66a3a4c 100644 --- a/src/js/controller/mail-list.js +++ b/src/js/controller/mail-list.js @@ -15,18 +15,20 @@ define(function(require) { firstSelect = true; emailDao = appController._emailDao; + if (emailDao) { + emailDao.onIncomingMessage = function(email) { + if (email.subject.indexOf(str.subjectPrefix) === -1) { + return; + } - emailDao.onIncomingMessage = function(email) { - if (email.subject.indexOf(str.subjectPrefix) === -1) { - return; - } - - // sync - $scope.synchronize(function() { - // show notification - notificationForEmail(email); - }); - }; + // sync + $scope.synchronize(function() { + // show notification + notificationForEmail(email); + }); + }; + chrome.notifications.onClicked.addListener(notificationClicked); + } function notificationClicked(uidString) { var email, uid = parseInt(uidString, 10); @@ -43,7 +45,6 @@ define(function(require) { $scope.select(email); } } - chrome.notifications.onClicked.addListener(notificationClicked); // // scope functions @@ -55,7 +56,13 @@ define(function(require) { } // split text only emails into parts for easier rendering if (!email.html && typeof email.body === 'string') { - email.bodyDisplayParts = email.body.split('\n'); + email.bodyDisplayParts = []; + var parts = email.body.split('\n'); + parts.forEach(function(part) { + if (part.trim().length > 0) { + email.bodyDisplayParts.push(part); + } + }); } $scope.selected = email; // set selected in parent scope ro it can be displayed in the read view diff --git a/src/js/controller/write.js b/src/js/controller/write.js index 57428f9..7a2086a 100644 --- a/src/js/controller/write.js +++ b/src/js/controller/write.js @@ -6,6 +6,7 @@ define(function(require) { aes = require('cryptoLib/aes-cbc'), util = require('cryptoLib/util'), str = require('js/app-config').string, + $ = require('jquery'), emailDao; // @@ -129,9 +130,8 @@ define(function(require) { return; } - body = $scope.body; // remove generated html from body - body = parseBody(body); + body = parseBody($scope.body); email = { to: [], // list of receivers @@ -165,23 +165,12 @@ define(function(require) { }; function parseBody(body) { - function has(substr) { - return (body.indexOf(substr) !== -1); - } - while (has('

')) { - body = body.replace('

', '\n'); - } - while (has('
')) { - body = body.replace('
', '\n'); - } - while (has('
')) { - body = body.replace('
', '\n'); - } - while (has('
')) { - body = body.replace('
', ''); - } + var regex = /(\r\n|\n|\r)/gm; - return body; + var text = body.replace(regex, '').split('

').join('\n').split('
').join('\n').split('
').join('\n'); + var html = '

' + text + '

'; + + return $(html).text(); } // diff --git a/src/tpl/read.html b/src/tpl/read.html index 61f741b..4a30410 100644 --- a/src/tpl/read.html +++ b/src/tpl/read.html @@ -24,10 +24,6 @@ -

- - {{part}} - -

+

{{part}}

\ No newline at end of file