From de70ee5f7868ede7a738fbeb8ba9f9fe3558aefb Mon Sep 17 00:00:00 2001 From: Todd Kennedy Date: Fri, 25 Mar 2011 14:22:19 -0700 Subject: [PATCH] Don't duplicate HTML in reply / forward On exchange servers that support "smart reply", the original message is actually appended by the server. In this situation, we should not append the original HTML text on the client. but 4177192 Change-Id: I6fad74ac761e2abfe7cb0f536df4db30f7d5ca9a --- .../android/emailcommon/internet/Rfc822Output.java | 10 ++++++---- .../emailcommon/internet/Rfc822OutputTests.java | 13 +++++++++---- 2 files changed, 15 insertions(+), 8 deletions(-) diff --git a/emailcommon/src/com/android/emailcommon/internet/Rfc822Output.java b/emailcommon/src/com/android/emailcommon/internet/Rfc822Output.java index 00de12681..c9eb5893d 100644 --- a/emailcommon/src/com/android/emailcommon/internet/Rfc822Output.java +++ b/emailcommon/src/com/android/emailcommon/internet/Rfc822Output.java @@ -98,7 +98,7 @@ public class Rfc822Output { /** * Returns an HTML encoded message alternate */ - /*package*/ static String getHtmlAlternate(Body body) { + /*package*/ static String getHtmlAlternate(Body body, boolean useSmartReply) { if (body.mHtmlReply == null) { return null; } @@ -111,8 +111,10 @@ public class Rfc822Output { htmlIntro = NEWLINE_PATTERN.matcher(htmlIntro).replaceAll(NEWLINE_HTML); altMessage.append(htmlIntro); } - String htmlBody = getHtmlBody(body.mHtmlReply); - altMessage.append(htmlBody); + if (!useSmartReply) { + String htmlBody = getHtmlBody(body.mHtmlReply); + altMessage.append(htmlBody); + } return altMessage.toString(); } @@ -161,7 +163,7 @@ public class Rfc822Output { } } messageBody[INDEX_BODY_TEXT] = text; - messageBody[INDEX_BODY_HTML] = getHtmlAlternate(body); + messageBody[INDEX_BODY_HTML] = getHtmlAlternate(body, useSmartReply); return messageBody; } diff --git a/tests/src/com/android/emailcommon/internet/Rfc822OutputTests.java b/tests/src/com/android/emailcommon/internet/Rfc822OutputTests.java index 51684d513..0369e18b9 100644 --- a/tests/src/com/android/emailcommon/internet/Rfc822OutputTests.java +++ b/tests/src/com/android/emailcommon/internet/Rfc822OutputTests.java @@ -350,16 +350,21 @@ public class Rfc822OutputTests extends ProviderTestCase2 { Body body = createTestBody(message); String html; - html = Rfc822Output.getHtmlAlternate(body); + // Generic case + html = Rfc822Output.getHtmlAlternate(body, false); assertEquals(TEXT + REPLY_INTRO_HTML + BODY_HTML_REPLY, html); + // "smart reply" enabled; html body should not be added + html = Rfc822Output.getHtmlAlternate(body, true); + assertEquals(TEXT + REPLY_INTRO_HTML, html); + // HTML special characters; dependent upon TextUtils#htmlEncode() message.mId = -1; // Changing the message; need to reset the id message.mText = "<>&'\""; message.save(mMockContext); body = createTestBody(message); - html = Rfc822Output.getHtmlAlternate(body); + html = Rfc822Output.getHtmlAlternate(body, false); assertEquals("<>&'"" + REPLY_INTRO_HTML + BODY_HTML_REPLY, html); // Newlines in user text @@ -368,7 +373,7 @@ public class Rfc822OutputTests extends ProviderTestCase2 { message.save(mMockContext); body = createTestBody(message); - html = Rfc822Output.getHtmlAlternate(body); + html = Rfc822Output.getHtmlAlternate(body, false); assertEquals("dos
unix
three


" + REPLY_INTRO_HTML + BODY_HTML_REPLY, html); // Null HTML reply @@ -377,7 +382,7 @@ public class Rfc822OutputTests extends ProviderTestCase2 { message.save(mMockContext); body = createTestBody(message); - html = Rfc822Output.getHtmlAlternate(body); + html = Rfc822Output.getHtmlAlternate(body, false); assertNull(html); }