Support "delSp" for format=flowed #2237
This commit is contained in:
parent
05df114eb1
commit
dbc614769a
5 changed files with 65 additions and 2 deletions
|
@ -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;
|
||||||
|
}
|
||||||
|
}
|
|
@ -42,8 +42,14 @@ public interface Viewable {
|
||||||
}
|
}
|
||||||
|
|
||||||
class Flowed extends Textual {
|
class Flowed extends Textual {
|
||||||
|
private boolean delSp;
|
||||||
public Flowed(Part part) {
|
public Flowed(Part part) {
|
||||||
super(part);
|
super(part);
|
||||||
|
this.delSp = FlowedMessageUtils.isDelSp(part.getContentType());
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isDelSp() {
|
||||||
|
return delSp;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -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"));
|
||||||
|
}
|
||||||
|
}
|
|
@ -148,4 +148,6 @@ public class MimeUtilityTest {
|
||||||
public void isFormatFlowed_withTextHtmlFormatFlowed__shouldReturnFalse() throws Exception {
|
public void isFormatFlowed_withTextHtmlFormatFlowed__shouldReturnFalse() throws Exception {
|
||||||
assertFalse(MimeUtility.isFormatFlowed("text/html; format=flowed"));
|
assertFalse(MimeUtility.isFormatFlowed("text/html; format=flowed"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,6 +15,7 @@ import timber.log.Timber;
|
||||||
import com.fsck.k9.Globals;
|
import com.fsck.k9.Globals;
|
||||||
import com.fsck.k9.K9;
|
import com.fsck.k9.K9;
|
||||||
import com.fsck.k9.R;
|
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.HtmlConverter;
|
||||||
import com.fsck.k9.message.html.HtmlSanitizer;
|
import com.fsck.k9.message.html.HtmlSanitizer;
|
||||||
import com.fsck.k9.mail.Address;
|
import com.fsck.k9.mail.Address;
|
||||||
|
@ -233,7 +234,8 @@ public class MessageViewInfoExtractor {
|
||||||
if (t == null) {
|
if (t == null) {
|
||||||
t = "";
|
t = "";
|
||||||
} else if (viewable instanceof Flowed) {
|
} else if (viewable instanceof Flowed) {
|
||||||
t = FlowedMessageUtils.deflow(t, false);
|
boolean delSp = ((Flowed) viewable).isDelSp();
|
||||||
|
t = FlowedMessageUtils.deflow(t, delSp);
|
||||||
t = HtmlConverter.textToHtml(t);
|
t = HtmlConverter.textToHtml(t);
|
||||||
} else if (viewable instanceof Text) {
|
} else if (viewable instanceof Text) {
|
||||||
t = HtmlConverter.textToHtml(t);
|
t = HtmlConverter.textToHtml(t);
|
||||||
|
@ -271,7 +273,8 @@ public class MessageViewInfoExtractor {
|
||||||
} else if (viewable instanceof Html) {
|
} else if (viewable instanceof Html) {
|
||||||
t = HtmlConverter.htmlToText(t);
|
t = HtmlConverter.htmlToText(t);
|
||||||
} else if (viewable instanceof Flowed) {
|
} 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)) {
|
} else if (!(viewable instanceof Text)) {
|
||||||
throw new IllegalStateException("unhandled case!");
|
throw new IllegalStateException("unhandled case!");
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue