Merge pull request #2352 from YESALAM/2237
Support "delSp" for format=flowed Fixes issue #2237
This commit is contained in:
commit
ba21aaf412
7 changed files with 95 additions and 32 deletions
|
@ -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;
|
||||
}
|
||||
}
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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"));
|
||||
}
|
||||
}
|
|
@ -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"));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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!");
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue