1
0
mirror of https://github.com/moparisthebest/k-9 synced 2024-11-27 11:42:16 -05:00

Merge remote-tracking branch 'vincent/pgp_mime_preparations' into pgp_mime_preparations_view

This commit is contained in:
Dominik Schürmann 2015-01-28 14:55:51 +01:00
commit 28e9c2a8ec
3 changed files with 50 additions and 12 deletions

View File

@ -1,5 +1,6 @@
package com.fsck.k9.mailstore; package com.fsck.k9.mailstore;
import java.util.ArrayList;
import java.util.Date; import java.util.Date;
import java.util.Locale; import java.util.Locale;
import java.util.TimeZone; 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.Address;
import com.fsck.k9.mail.Message.RecipientType; import com.fsck.k9.mail.Message.RecipientType;
import com.fsck.k9.mail.MessagingException; 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.MimeBodyPart;
import com.fsck.k9.mail.internet.MimeMessage; import com.fsck.k9.mail.internet.MimeMessage;
import com.fsck.k9.mail.internet.MimeMessageHelper; import com.fsck.k9.mail.internet.MimeMessageHelper;
@ -38,7 +41,8 @@ public class LocalMessageExtractorTest {
MimeMessageHelper.setBody(message, body); MimeMessageHelper.setBody(message, body);
// Extract text // Extract text
ViewableContainer container = extractTextAndAttachments(InstrumentationRegistry.getTargetContext(), message); ViewableContainer container = extractTextAndAttachments(InstrumentationRegistry.getTargetContext(),
MessageExtractor.getViewables(message, attachments), new ArrayList<Part>());
String expectedText = bodyText; String expectedText = bodyText;
String expectedHtml = String expectedHtml =
@ -63,7 +67,8 @@ public class LocalMessageExtractorTest {
MimeMessageHelper.setBody(message, body); MimeMessageHelper.setBody(message, body);
// Extract text // 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 expectedText = "K-9 Mail rocks :>";
String expectedHtml = String expectedHtml =
@ -94,7 +99,8 @@ public class LocalMessageExtractorTest {
MimeMessageHelper.setBody(message, multipart); MimeMessageHelper.setBody(message, multipart);
// Extract text // Extract text
ViewableContainer container = extractTextAndAttachments(InstrumentationRegistry.getTargetContext(), message); ViewableContainer container = extractTextAndAttachments(InstrumentationRegistry.getTargetContext(),
MessageExtractor.getViewables(message, attachments), new ArrayList<Part>());
String expectedText = String expectedText =
bodyText1 + "\r\n\r\n" + bodyText1 + "\r\n\r\n" +
@ -151,7 +157,8 @@ public class LocalMessageExtractorTest {
MimeMessageHelper.setBody(message, multipart); MimeMessageHelper.setBody(message, multipart);
// Extract text // Extract text
ViewableContainer container = extractTextAndAttachments(InstrumentationRegistry.getTargetContext(), message); ViewableContainer container = extractTextAndAttachments(InstrumentationRegistry.getTargetContext(),
MessageExtractor.getViewables(message, attachments), new ArrayList<Part>());
String expectedText = String expectedText =
bodyText + bodyText +

View File

@ -13,7 +13,9 @@ import com.fsck.k9.mail.internet.MessageExtractor;
import com.fsck.k9.mail.internet.MimeHeader; import com.fsck.k9.mail.internet.MimeHeader;
import com.fsck.k9.mail.internet.MimeUtility; import com.fsck.k9.mail.internet.MimeUtility;
import com.fsck.k9.mail.internet.Viewable; import com.fsck.k9.mail.internet.Viewable;
import com.fsck.k9.mailstore.MessageViewInfo.MessageViewContainer;
import com.fsck.k9.provider.AttachmentProvider; import com.fsck.k9.provider.AttachmentProvider;
import org.openintents.openpgp.OpenPgpSignatureResult;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Date; 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. * 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 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 * @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. * plain text and HTML, and a list of message parts considered attachments.
* *
* @throws com.fsck.k9.mail.MessagingException * @throws com.fsck.k9.mail.MessagingException
* In case of an error. * 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 { try {
List<Part> attachments = new ArrayList<Part>();
// Collect all viewable parts // Collect all viewable parts
List<Viewable> viewables = MessageExtractor.getViewables(message, attachments);
/* /*
* Convert the tree of viewable parts into text and HTML * 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 { 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); // 1. break mime structure on encryption/signature boundaries
List<AttachmentViewInfo> attachments = extractAttachmentInfos(viewable.attachments); ArrayList<Part> parts = new ArrayList<Part>();
return new MessageViewInfo(viewable.html, attachments, message); // 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) private static List<AttachmentViewInfo> extractAttachmentInfos(List<Part> attachmentParts)

View File

@ -13,14 +13,20 @@ import org.openintents.openpgp.OpenPgpSignatureResult;
public class MessageViewInfo { public class MessageViewInfo {
public final Message message; public final Message message;
public final List<MessageViewContainer> containers = new ArrayList<MessageViewContainer>(); public final List<MessageViewContainer> containers;
@Deprecated @Deprecated
public MessageViewInfo(String text, List<AttachmentViewInfo> attachments, Message message) { public MessageViewInfo(String text, List<AttachmentViewInfo> attachments, Message message) {
containers = new ArrayList<MessageViewContainer>();
containers.add(new MessageViewContainer(text, attachments)); containers.add(new MessageViewContainer(text, attachments));
this.message = message; this.message = message;
} }
public MessageViewInfo(List<MessageViewContainer> containers, Message message) {
this.containers = containers;
this.message = message;
}
public static class MessageViewContainer { public static class MessageViewContainer {
final public String text; final public String text;