Move format=flowed decoding to MessageExtractor
This commit is contained in:
parent
6c2f4b6354
commit
9ee3a76ef1
5 changed files with 18 additions and 33 deletions
|
@ -20,9 +20,7 @@ import com.fsck.k9.mail.Part;
|
|||
import com.fsck.k9.mail.internet.MessageExtractor;
|
||||
import com.fsck.k9.mail.internet.MimeUtility;
|
||||
import com.fsck.k9.mail.internet.Viewable;
|
||||
import com.fsck.k9.mail.internet.Viewable.Flowed;
|
||||
import com.fsck.k9.mailstore.CryptoResultAnnotation.CryptoError;
|
||||
import com.fsck.k9.mailstore.util.FlowedMessageUtils;
|
||||
import com.fsck.k9.message.extractors.AttachmentInfoExtractor;
|
||||
import com.fsck.k9.message.html.HtmlConverter;
|
||||
import com.fsck.k9.message.html.HtmlProcessor;
|
||||
|
@ -271,10 +269,6 @@ public class MessageViewInfoExtractor {
|
|||
String t = getTextFromPart(part);
|
||||
if (t == null) {
|
||||
t = "";
|
||||
} else if (viewable instanceof Flowed) {
|
||||
boolean delSp = ((Flowed) viewable).isDelSp();
|
||||
t = FlowedMessageUtils.deflow(t, delSp);
|
||||
t = HtmlConverter.textToHtml(t);
|
||||
} else if (viewable instanceof Text) {
|
||||
t = HtmlConverter.textToHtml(t);
|
||||
} else if (!(viewable instanceof Html)) {
|
||||
|
@ -310,9 +304,6 @@ public class MessageViewInfoExtractor {
|
|||
t = "";
|
||||
} else if (viewable instanceof Html) {
|
||||
t = HtmlConverter.htmlToText(t);
|
||||
} else if (viewable instanceof Flowed) {
|
||||
boolean delSp = ((Flowed) viewable).isDelSp();
|
||||
t = FlowedMessageUtils.deflow(t, delSp);
|
||||
} else if (!(viewable instanceof Text)) {
|
||||
throw new IllegalStateException("unhandled case!");
|
||||
}
|
||||
|
|
|
@ -2,6 +2,7 @@ package com.fsck.k9.mailstore;
|
|||
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
@ -17,6 +18,7 @@ import com.fsck.k9.DI;
|
|||
import com.fsck.k9.K9RobolectricTest;
|
||||
import com.fsck.k9.TestCoreResourceProvider;
|
||||
import com.fsck.k9.mail.Address;
|
||||
import com.fsck.k9.mail.Body;
|
||||
import com.fsck.k9.mail.BodyPart;
|
||||
import com.fsck.k9.mail.Message;
|
||||
import com.fsck.k9.mail.MessagingException;
|
||||
|
@ -135,7 +137,7 @@ public class MessageViewInfoExtractorTest extends K9RobolectricTest {
|
|||
@Test
|
||||
public void testTextPlainFormatFlowed() throws MessagingException {
|
||||
// Create text/plain body
|
||||
TextBody body = new TextBody(BODY_TEXT_FLOWED);
|
||||
Body body = new BinaryMemoryBody(BODY_TEXT_FLOWED.getBytes(StandardCharsets.UTF_8), "utf-8");
|
||||
|
||||
// Create message
|
||||
MimeMessage message = new MimeMessage();
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
package com.fsck.k9.mailstore.util;
|
||||
package com.fsck.k9.mail.internet;
|
||||
|
||||
|
||||
/**
|
|
@ -19,13 +19,11 @@ import com.fsck.k9.mail.Message;
|
|||
import com.fsck.k9.mail.MessagingException;
|
||||
import com.fsck.k9.mail.Multipart;
|
||||
import com.fsck.k9.mail.Part;
|
||||
import com.fsck.k9.mail.internet.Viewable.Flowed;
|
||||
import org.apache.commons.io.input.BoundedInputStream;
|
||||
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.FormatFlowedHelper.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;
|
||||
|
@ -112,13 +110,25 @@ public class MessageExtractor {
|
|||
InputStream in = MimeUtility.decodeBody(body);
|
||||
InputStream possiblyLimitedIn =
|
||||
textSizeLimit != NO_TEXT_SIZE_LIMIT ? new BoundedInputStream(in, textSizeLimit) : in;
|
||||
|
||||
String text;
|
||||
try {
|
||||
return CharsetSupport.readToString(possiblyLimitedIn, charset);
|
||||
text = CharsetSupport.readToString(possiblyLimitedIn, charset);
|
||||
} finally {
|
||||
try {
|
||||
MimeUtility.closeInputStreamWithoutDeletingTemporaryFiles(in);
|
||||
} catch (IOException e) { /* Ignore */ }
|
||||
}
|
||||
|
||||
if (isSameMimeType(mimeType, "text/plain")) {
|
||||
String contentType = part.getContentType();
|
||||
if (FormatFlowedHelper.isFormatFlowed(contentType)) {
|
||||
boolean delSp = FormatFlowedHelper.isDelSp(contentType);
|
||||
return FlowedMessageUtils.deflow(text, delSp);
|
||||
}
|
||||
}
|
||||
|
||||
return text;
|
||||
}
|
||||
|
||||
public static boolean hasMissingParts(Part part) {
|
||||
|
@ -202,12 +212,7 @@ public class MessageExtractor {
|
|||
String mimeType = part.getMimeType();
|
||||
Viewable viewable;
|
||||
if (isSameMimeType(mimeType, "text/plain")) {
|
||||
if (isFormatFlowed(part.getContentType())) {
|
||||
boolean delSp = FormatFlowedHelper.isDelSp(part.getContentType());
|
||||
viewable = new Flowed(part, delSp);
|
||||
} else {
|
||||
viewable = new Text(part);
|
||||
}
|
||||
viewable = new Text(part);
|
||||
} else {
|
||||
viewable = new Html(part);
|
||||
}
|
||||
|
|
|
@ -41,19 +41,6 @@ public interface Viewable {
|
|||
}
|
||||
}
|
||||
|
||||
class Flowed extends Textual {
|
||||
private boolean delSp;
|
||||
|
||||
public Flowed(Part part, boolean delSp) {
|
||||
super(part);
|
||||
this.delSp = delSp;
|
||||
}
|
||||
|
||||
public boolean isDelSp() {
|
||||
return delSp;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Class representing a {@code text/html} part of a message.
|
||||
*/
|
||||
|
|
Loading…
Reference in a new issue