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..debc3e2d7 --- /dev/null +++ b/k9mail-library/src/main/java/com/fsck/k9/mail/internet/FlowedMessageUtils.java @@ -0,0 +1,32 @@ +package com.fsck.k9.mail.internet; + + +import static com.fsck.k9.mail.internet.MimeUtility.getHeaderParameter; +import static com.fsck.k9.mail.internet.MimeUtility.isSameMimeType; + + +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); + return HEADER_DELSP_YES.equalsIgnoreCase(delSpParameter); + } + return false; + } +} 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 352b7be7a..009ecb9ba 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 @@ -25,7 +25,7 @@ import timber.log.Timber; 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; @@ -192,7 +192,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 17725a3cb..13ee30a27 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 @@ -26,9 +26,6 @@ import timber.log.Timber; 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 @@ -1142,13 +1139,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 772a2f4d5..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 @@ -42,8 +42,15 @@ public interface Viewable { } class Flowed extends Textual { - public Flowed(Part part) { + private boolean delSp; + + public Flowed(Part part, boolean delSp) { super(part); + this.delSp = delSp; + } + + 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..509273404 --- /dev/null +++ b/k9mail-library/src/test/java/com/fsck/k9/mail/internet/FlowedMessageUtilsTest.java @@ -0,0 +1,47 @@ +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 { + 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..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,19 +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")); - } } 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!"); }