mirror of
https://github.com/moparisthebest/k-9
synced 2024-11-04 16:45:09 -05:00
parse MessageViewContainers from Parts (from dummy mime structure)
This commit is contained in:
parent
e513af9529
commit
cced35b3b8
@ -1,5 +1,6 @@
|
||||
package com.fsck.k9.mailstore;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.Locale;
|
||||
import java.util.TimeZone;
|
||||
@ -11,6 +12,8 @@ import com.fsck.k9.activity.K9ActivityCommon;
|
||||
import com.fsck.k9.mail.Address;
|
||||
import com.fsck.k9.mail.Message.RecipientType;
|
||||
import com.fsck.k9.mail.MessagingException;
|
||||
import com.fsck.k9.mail.Part;
|
||||
import com.fsck.k9.mail.internet.MessageExtractor;
|
||||
import com.fsck.k9.mail.internet.MimeBodyPart;
|
||||
import com.fsck.k9.mail.internet.MimeMessage;
|
||||
import com.fsck.k9.mail.internet.MimeMessageHelper;
|
||||
@ -38,7 +41,8 @@ public class LocalMessageExtractorTest {
|
||||
MimeMessageHelper.setBody(message, body);
|
||||
|
||||
// Extract text
|
||||
ViewableContainer container = extractTextAndAttachments(InstrumentationRegistry.getTargetContext(), message);
|
||||
ViewableContainer container = extractTextAndAttachments(InstrumentationRegistry.getTargetContext(),
|
||||
MessageExtractor.getViewables(message, attachments), new ArrayList<Part>());
|
||||
|
||||
String expectedText = bodyText;
|
||||
String expectedHtml =
|
||||
@ -63,7 +67,8 @@ public class LocalMessageExtractorTest {
|
||||
MimeMessageHelper.setBody(message, body);
|
||||
|
||||
// Extract text
|
||||
ViewableContainer container = extractTextAndAttachments(InstrumentationRegistry.getTargetContext(), message);
|
||||
ViewableContainer container = extractTextAndAttachments(InstrumentationRegistry.getTargetContext(),
|
||||
MessageExtractor.getViewables(message, attachments), new ArrayList<Part>());
|
||||
|
||||
String expectedText = "K-9 Mail rocks :>";
|
||||
String expectedHtml =
|
||||
@ -94,7 +99,8 @@ public class LocalMessageExtractorTest {
|
||||
MimeMessageHelper.setBody(message, multipart);
|
||||
|
||||
// Extract text
|
||||
ViewableContainer container = extractTextAndAttachments(InstrumentationRegistry.getTargetContext(), message);
|
||||
ViewableContainer container = extractTextAndAttachments(InstrumentationRegistry.getTargetContext(),
|
||||
MessageExtractor.getViewables(message, attachments), new ArrayList<Part>());
|
||||
|
||||
String expectedText =
|
||||
bodyText1 + "\r\n\r\n" +
|
||||
@ -151,7 +157,8 @@ public class LocalMessageExtractorTest {
|
||||
MimeMessageHelper.setBody(message, multipart);
|
||||
|
||||
// Extract text
|
||||
ViewableContainer container = extractTextAndAttachments(InstrumentationRegistry.getTargetContext(), message);
|
||||
ViewableContainer container = extractTextAndAttachments(InstrumentationRegistry.getTargetContext(),
|
||||
MessageExtractor.getViewables(message, attachments), new ArrayList<Part>());
|
||||
|
||||
String expectedText =
|
||||
bodyText +
|
||||
|
@ -13,7 +13,9 @@ import com.fsck.k9.mail.internet.MessageExtractor;
|
||||
import com.fsck.k9.mail.internet.MimeHeader;
|
||||
import com.fsck.k9.mail.internet.MimeUtility;
|
||||
import com.fsck.k9.mail.internet.Viewable;
|
||||
import com.fsck.k9.mailstore.MessageViewInfo.MessageViewContainer;
|
||||
import com.fsck.k9.provider.AttachmentProvider;
|
||||
import org.openintents.openpgp.OpenPgpSignatureResult;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
@ -40,18 +42,19 @@ public class LocalMessageExtractor {
|
||||
* Extract the viewable textual parts of a message and return the rest as attachments.
|
||||
*
|
||||
* @param context A {@link android.content.Context} instance that will be used to get localized strings.
|
||||
* @param viewables
|
||||
* @param attachments
|
||||
* @return A {@link ViewableContainer} instance containing the textual parts of the message as
|
||||
* plain text and HTML, and a list of message parts considered attachments.
|
||||
*
|
||||
* @throws com.fsck.k9.mail.MessagingException
|
||||
* In case of an error.
|
||||
*/
|
||||
public static ViewableContainer extractTextAndAttachments(Context context, Message message) throws MessagingException {
|
||||
public static ViewableContainer extractTextAndAttachments(Context context, List<Viewable> viewables,
|
||||
List<Part> attachments) throws MessagingException {
|
||||
try {
|
||||
List<Part> attachments = new ArrayList<Part>();
|
||||
|
||||
// Collect all viewable parts
|
||||
List<Viewable> viewables = MessageExtractor.getViewables(message, attachments);
|
||||
|
||||
/*
|
||||
* Convert the tree of viewable parts into text and HTML
|
||||
@ -412,10 +415,32 @@ public class LocalMessageExtractor {
|
||||
}
|
||||
|
||||
public static MessageViewInfo decodeMessageForView(Context context, Message message) throws MessagingException {
|
||||
//TODO: Modify extractTextAndAttachments() to only extract the text type (plain vs. HTML) we currently need.
|
||||
ViewableContainer viewable = LocalMessageExtractor.extractTextAndAttachments(context, message);
|
||||
List<AttachmentViewInfo> attachments = extractAttachmentInfos(viewable.attachments);
|
||||
return new MessageViewInfo(viewable.html, attachments, message);
|
||||
|
||||
// 1. break mime structure on encryption/signature boundaries
|
||||
ArrayList<Part> parts = new ArrayList<Part>();
|
||||
// TODO: actually break it down
|
||||
parts.add(message);
|
||||
// parts.add(message);
|
||||
|
||||
// 2. extract viewables/attachments of parts
|
||||
ArrayList<MessageViewContainer> containers = new ArrayList<MessageViewContainer>();
|
||||
for (Part part : parts) {
|
||||
ArrayList<Part> attachments = new ArrayList<Part>();
|
||||
List<Viewable> viewables = MessageExtractor.getViewables(part, attachments);
|
||||
|
||||
// 3. parse viewables into html string
|
||||
ViewableContainer viewable = LocalMessageExtractor.extractTextAndAttachments(context, viewables,
|
||||
attachments);
|
||||
List<AttachmentViewInfo> attachmentInfos = extractAttachmentInfos(attachments);
|
||||
|
||||
// TODO correctly extract OpenPgpSignatureResult and add to MessageViewContainer
|
||||
OpenPgpSignatureResult result = null;
|
||||
// result = new OpenPgpSignatureResult(OpenPgpSignatureResult.SIGNATURE_SUCCESS_CERTIFIED, "lul", false, 0x123);
|
||||
containers.add(new MessageViewContainer(viewable.html, attachmentInfos, result, true, null));
|
||||
|
||||
}
|
||||
|
||||
return new MessageViewInfo(containers, message);
|
||||
}
|
||||
|
||||
private static List<AttachmentViewInfo> extractAttachmentInfos(List<Part> attachmentParts)
|
||||
|
@ -13,14 +13,20 @@ import org.openintents.openpgp.OpenPgpSignatureResult;
|
||||
public class MessageViewInfo {
|
||||
|
||||
public final Message message;
|
||||
public final List<MessageViewContainer> containers = new ArrayList<MessageViewContainer>();
|
||||
public final List<MessageViewContainer> containers;
|
||||
|
||||
@Deprecated
|
||||
public MessageViewInfo(String text, List<AttachmentViewInfo> attachments, Message message) {
|
||||
containers = new ArrayList<MessageViewContainer>();
|
||||
containers.add(new MessageViewContainer(text, attachments));
|
||||
this.message = message;
|
||||
}
|
||||
|
||||
public MessageViewInfo(List<MessageViewContainer> containers, Message message) {
|
||||
this.containers = containers;
|
||||
this.message = message;
|
||||
}
|
||||
|
||||
public static class MessageViewContainer {
|
||||
|
||||
final public String text;
|
||||
|
Loading…
Reference in New Issue
Block a user