From dbc614769a9cdc21d36ce6d729d196afc79a46b8 Mon Sep 17 00:00:00 2001 From: yesalam Date: Mon, 6 Mar 2017 19:55:37 +0530 Subject: [PATCH 1/2] Support "delSp" for format=flowed #2237 --- .../k9/mail/internet/FlowedMessageUtils.java | 20 ++++++++++++ .../com/fsck/k9/mail/internet/Viewable.java | 6 ++++ .../mail/internet/FlowedMessageUtilsTest.java | 32 +++++++++++++++++++ .../k9/mail/internet/MimeUtilityTest.java | 2 ++ .../mailstore/MessageViewInfoExtractor.java | 7 ++-- 5 files changed, 65 insertions(+), 2 deletions(-) create mode 100644 k9mail-library/src/main/java/com/fsck/k9/mail/internet/FlowedMessageUtils.java create mode 100644 k9mail-library/src/test/java/com/fsck/k9/mail/internet/FlowedMessageUtilsTest.java diff --git a/k9mail-library/src/main/java/com/fsck/k9/mail/internet/FlowedMessageUtils.java b/k9mail-library/src/main/java/com/fsck/k9/mail/internet/FlowedMessageUtils.java new file mode 100644 index 000000000..7d152dd12 --- /dev/null +++ b/k9mail-library/src/main/java/com/fsck/k9/mail/internet/FlowedMessageUtils.java @@ -0,0 +1,20 @@ +package com.fsck.k9.mail.internet; + + +import static com.fsck.k9.mail.internet.MimeUtility.getHeaderParameter; +import static com.fsck.k9.mail.internet.MimeUtility.isFormatFlowed; + + +public class FlowedMessageUtils { + private static final String HEADER_PARAM_DELSP = "delsp"; + private static final String HEADER_DELSP_YES = "yes"; + + + static boolean isDelSp(String contentType) { + if (isFormatFlowed(contentType)) { + String delSpParameter = getHeaderParameter(contentType, HEADER_PARAM_DELSP); + return HEADER_DELSP_YES.equalsIgnoreCase(delSpParameter); + } + return false; + } +} diff --git a/k9mail-library/src/main/java/com/fsck/k9/mail/internet/Viewable.java b/k9mail-library/src/main/java/com/fsck/k9/mail/internet/Viewable.java index 772a2f4d5..ab8714f0b 100644 --- a/k9mail-library/src/main/java/com/fsck/k9/mail/internet/Viewable.java +++ b/k9mail-library/src/main/java/com/fsck/k9/mail/internet/Viewable.java @@ -42,8 +42,14 @@ public interface Viewable { } class Flowed extends Textual { + private boolean delSp; public Flowed(Part part) { super(part); + this.delSp = FlowedMessageUtils.isDelSp(part.getContentType()); + } + + public boolean isDelSp() { + return delSp; } } diff --git a/k9mail-library/src/test/java/com/fsck/k9/mail/internet/FlowedMessageUtilsTest.java b/k9mail-library/src/test/java/com/fsck/k9/mail/internet/FlowedMessageUtilsTest.java new file mode 100644 index 000000000..0140e97e2 --- /dev/null +++ b/k9mail-library/src/test/java/com/fsck/k9/mail/internet/FlowedMessageUtilsTest.java @@ -0,0 +1,32 @@ +package com.fsck.k9.mail.internet; + + +import org.junit.Test; + +import static com.fsck.k9.mail.internet.FlowedMessageUtils.isDelSp; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; + + +public class FlowedMessageUtilsTest { + + @Test + public void isDelSp_withFormatFlowed_shouldReturnTrue() throws Exception { + assertTrue(isDelSp("text/plain; format=flowed; delsp=yes")); + } + + @Test + public void isDelSp_withTextPlainFormatFlowed_shoulReturnFalse() throws Exception { + assertFalse(isDelSp("text/plain; format=flowed")); + } + + @Test + public void isDelSp_withoutFormatFlowed_shouldReturnFalse() throws Exception { + assertFalse(isDelSp("text/plain; delsp=yes")); + } + + @Test + public void idDelSp_withTextHtmlFormatFlowed_shouldReturnFalse() throws Exception { + assertFalse(isDelSp("text/html; format=flowed; delsp=yes")); + } +} diff --git a/k9mail-library/src/test/java/com/fsck/k9/mail/internet/MimeUtilityTest.java b/k9mail-library/src/test/java/com/fsck/k9/mail/internet/MimeUtilityTest.java index 849478f99..e2eb627de 100644 --- a/k9mail-library/src/test/java/com/fsck/k9/mail/internet/MimeUtilityTest.java +++ b/k9mail-library/src/test/java/com/fsck/k9/mail/internet/MimeUtilityTest.java @@ -148,4 +148,6 @@ public class MimeUtilityTest { public void isFormatFlowed_withTextHtmlFormatFlowed__shouldReturnFalse() throws Exception { assertFalse(MimeUtility.isFormatFlowed("text/html; format=flowed")); } + + } diff --git a/k9mail/src/main/java/com/fsck/k9/mailstore/MessageViewInfoExtractor.java b/k9mail/src/main/java/com/fsck/k9/mailstore/MessageViewInfoExtractor.java index ff72e52c8..d2df2a3fb 100644 --- a/k9mail/src/main/java/com/fsck/k9/mailstore/MessageViewInfoExtractor.java +++ b/k9mail/src/main/java/com/fsck/k9/mailstore/MessageViewInfoExtractor.java @@ -15,6 +15,7 @@ import timber.log.Timber; import com.fsck.k9.Globals; import com.fsck.k9.K9; import com.fsck.k9.R; +import com.fsck.k9.mail.internet.MimeUtility; import com.fsck.k9.message.html.HtmlConverter; import com.fsck.k9.message.html.HtmlSanitizer; import com.fsck.k9.mail.Address; @@ -233,7 +234,8 @@ public class MessageViewInfoExtractor { if (t == null) { t = ""; } else if (viewable instanceof Flowed) { - t = FlowedMessageUtils.deflow(t, false); + boolean delSp = ((Flowed) viewable).isDelSp(); + t = FlowedMessageUtils.deflow(t, delSp); t = HtmlConverter.textToHtml(t); } else if (viewable instanceof Text) { t = HtmlConverter.textToHtml(t); @@ -271,7 +273,8 @@ public class MessageViewInfoExtractor { } else if (viewable instanceof Html) { t = HtmlConverter.htmlToText(t); } else if (viewable instanceof Flowed) { - t = FlowedMessageUtils.deflow(t, false); + boolean delSp = ((Flowed) viewable).isDelSp(); + t = FlowedMessageUtils.deflow(t, delSp); } else if (!(viewable instanceof Text)) { throw new IllegalStateException("unhandled case!"); } From d22533b6d35290da5c3051d109154ee7c243200f Mon Sep 17 00:00:00 2001 From: cketti Date: Sun, 26 Mar 2017 05:46:38 +0200 Subject: [PATCH 2/2] Cleanup --- .../k9/mail/internet/FlowedMessageUtils.java | 16 ++++++++++++++-- .../fsck/k9/mail/internet/MessageExtractor.java | 5 +++-- .../com/fsck/k9/mail/internet/MimeUtility.java | 12 ------------ .../com/fsck/k9/mail/internet/Viewable.java | 5 +++-- .../mail/internet/FlowedMessageUtilsTest.java | 15 +++++++++++++++ .../fsck/k9/mail/internet/MimeUtilityTest.java | 17 ----------------- 6 files changed, 35 insertions(+), 35 deletions(-) diff --git a/k9mail-library/src/main/java/com/fsck/k9/mail/internet/FlowedMessageUtils.java b/k9mail-library/src/main/java/com/fsck/k9/mail/internet/FlowedMessageUtils.java index 7d152dd12..debc3e2d7 100644 --- a/k9mail-library/src/main/java/com/fsck/k9/mail/internet/FlowedMessageUtils.java +++ b/k9mail-library/src/main/java/com/fsck/k9/mail/internet/FlowedMessageUtils.java @@ -2,14 +2,26 @@ package com.fsck.k9.mail.internet; import static com.fsck.k9.mail.internet.MimeUtility.getHeaderParameter; -import static com.fsck.k9.mail.internet.MimeUtility.isFormatFlowed; +import static com.fsck.k9.mail.internet.MimeUtility.isSameMimeType; -public class FlowedMessageUtils { +class FlowedMessageUtils { + private static final String TEXT_PLAIN = "text/plain"; + private static final String HEADER_PARAM_FORMAT = "format"; + private static final String HEADER_FORMAT_FLOWED = "flowed"; private static final String HEADER_PARAM_DELSP = "delsp"; private static final String HEADER_DELSP_YES = "yes"; + static boolean isFormatFlowed(String contentType) { + String mimeType = getHeaderParameter(contentType, null); + if (isSameMimeType(TEXT_PLAIN, mimeType)) { + String formatParameter = getHeaderParameter(contentType, HEADER_PARAM_FORMAT); + return HEADER_FORMAT_FLOWED.equalsIgnoreCase(formatParameter); + } + return false; + } + static boolean isDelSp(String contentType) { if (isFormatFlowed(contentType)) { String delSpParameter = getHeaderParameter(contentType, HEADER_PARAM_DELSP); diff --git a/k9mail-library/src/main/java/com/fsck/k9/mail/internet/MessageExtractor.java b/k9mail-library/src/main/java/com/fsck/k9/mail/internet/MessageExtractor.java index 4842e6332..dcec8672c 100644 --- a/k9mail-library/src/main/java/com/fsck/k9/mail/internet/MessageExtractor.java +++ b/k9mail-library/src/main/java/com/fsck/k9/mail/internet/MessageExtractor.java @@ -26,7 +26,7 @@ import org.apache.commons.io.input.BoundedInputStream; import static com.fsck.k9.mail.K9MailLib.LOG_TAG; import static com.fsck.k9.mail.internet.CharsetSupport.fixupCharset; import static com.fsck.k9.mail.internet.MimeUtility.getHeaderParameter; -import static com.fsck.k9.mail.internet.MimeUtility.isFormatFlowed; +import static com.fsck.k9.mail.internet.FlowedMessageUtils.isFormatFlowed; import static com.fsck.k9.mail.internet.MimeUtility.isSameMimeType; import static com.fsck.k9.mail.internet.Viewable.Alternative; import static com.fsck.k9.mail.internet.Viewable.Html; @@ -193,7 +193,8 @@ public class MessageExtractor { Viewable viewable; if (isSameMimeType(mimeType, "text/plain")) { if (isFormatFlowed(part.getContentType())) { - viewable = new Flowed(part); + boolean delSp = FlowedMessageUtils.isDelSp(part.getContentType()); + viewable = new Flowed(part, delSp); } else { viewable = new Text(part); } diff --git a/k9mail-library/src/main/java/com/fsck/k9/mail/internet/MimeUtility.java b/k9mail-library/src/main/java/com/fsck/k9/mail/internet/MimeUtility.java index a966af987..c397f1275 100644 --- a/k9mail-library/src/main/java/com/fsck/k9/mail/internet/MimeUtility.java +++ b/k9mail-library/src/main/java/com/fsck/k9/mail/internet/MimeUtility.java @@ -28,9 +28,6 @@ import static com.fsck.k9.mail.K9MailLib.LOG_TAG; public class MimeUtility { public static final String DEFAULT_ATTACHMENT_MIME_TYPE = "application/octet-stream"; public static final String K9_SETTINGS_MIME_TYPE = "application/x-k9settings"; - private static final String TEXT_PLAIN = "text/plain"; - private static final String HEADER_PARAM_FORMAT = "format"; - private static final String HEADER_FORMAT_FLOWED = "flowed"; /* * http://www.w3schools.com/media/media_mimeref.asp @@ -1144,13 +1141,4 @@ public class MimeUtility { public static boolean isSameMimeType(String mimeType, String otherMimeType) { return mimeType != null && mimeType.equalsIgnoreCase(otherMimeType); } - - static boolean isFormatFlowed(String contentType) { - String mimeType = getHeaderParameter(contentType, null); - if (isSameMimeType(TEXT_PLAIN, mimeType)) { - String formatParameter = getHeaderParameter(contentType, HEADER_PARAM_FORMAT); - return HEADER_FORMAT_FLOWED.equalsIgnoreCase(formatParameter); - } - return false; - } } diff --git a/k9mail-library/src/main/java/com/fsck/k9/mail/internet/Viewable.java b/k9mail-library/src/main/java/com/fsck/k9/mail/internet/Viewable.java index ab8714f0b..40e6b6d3f 100644 --- a/k9mail-library/src/main/java/com/fsck/k9/mail/internet/Viewable.java +++ b/k9mail-library/src/main/java/com/fsck/k9/mail/internet/Viewable.java @@ -43,9 +43,10 @@ public interface Viewable { class Flowed extends Textual { private boolean delSp; - public Flowed(Part part) { + + public Flowed(Part part, boolean delSp) { super(part); - this.delSp = FlowedMessageUtils.isDelSp(part.getContentType()); + this.delSp = delSp; } public boolean isDelSp() { diff --git a/k9mail-library/src/test/java/com/fsck/k9/mail/internet/FlowedMessageUtilsTest.java b/k9mail-library/src/test/java/com/fsck/k9/mail/internet/FlowedMessageUtilsTest.java index 0140e97e2..509273404 100644 --- a/k9mail-library/src/test/java/com/fsck/k9/mail/internet/FlowedMessageUtilsTest.java +++ b/k9mail-library/src/test/java/com/fsck/k9/mail/internet/FlowedMessageUtilsTest.java @@ -4,11 +4,26 @@ package com.fsck.k9.mail.internet; import org.junit.Test; import static com.fsck.k9.mail.internet.FlowedMessageUtils.isDelSp; +import static com.fsck.k9.mail.internet.FlowedMessageUtils.isFormatFlowed; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; public class FlowedMessageUtilsTest { + @Test + public void isFormatFlowed_withTextPlainFormatFlowed_shouldReturnTrue() throws Exception { + assertTrue(isFormatFlowed("text/plain; format=flowed")); + } + + @Test + public void isFormatFlowed_withTextPlain_shouldReturnFalse() throws Exception { + assertFalse(isFormatFlowed("text/plain")); + } + + @Test + public void isFormatFlowed_withTextHtmlFormatFlowed_shouldReturnFalse() throws Exception { + assertFalse(isFormatFlowed("text/html; format=flowed")); + } @Test public void isDelSp_withFormatFlowed_shouldReturnTrue() throws Exception { diff --git a/k9mail-library/src/test/java/com/fsck/k9/mail/internet/MimeUtilityTest.java b/k9mail-library/src/test/java/com/fsck/k9/mail/internet/MimeUtilityTest.java index e2eb627de..df95df315 100644 --- a/k9mail-library/src/test/java/com/fsck/k9/mail/internet/MimeUtilityTest.java +++ b/k9mail-library/src/test/java/com/fsck/k9/mail/internet/MimeUtilityTest.java @@ -133,21 +133,4 @@ public class MimeUtilityTest { public void isSameMimeType_withSecondArgumentBeingNull_shouldReturnFalse() throws Exception { assertFalse(MimeUtility.isSameMimeType("text/html", null)); } - - @Test - public void isFormatFlowed_withTextPlainFormatFlowed__shouldReturnTrue() throws Exception { - assertTrue(MimeUtility.isFormatFlowed("text/plain; format=flowed")); - } - - @Test - public void isFormatFlowed_withTextPlain__shouldReturnFalse() throws Exception { - assertFalse(MimeUtility.isFormatFlowed("text/plain")); - } - - @Test - public void isFormatFlowed_withTextHtmlFormatFlowed__shouldReturnFalse() throws Exception { - assertFalse(MimeUtility.isFormatFlowed("text/html; format=flowed")); - } - - }