break message into multiple MessageViewContainers

This commit is contained in:
Vincent Breitmoser 2015-01-29 16:10:03 +01:00
parent 1046308a38
commit ba79779758
2 changed files with 61 additions and 9 deletions

View File

@ -1,12 +1,19 @@
package com.fsck.k9.mailstore;
import android.app.PendingIntent;
import android.content.Context;
import android.net.Uri;
import android.util.Log;
import com.fsck.k9.K9;
import com.fsck.k9.R;
import com.fsck.k9.crypto.MessageDecryptor;
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;
import com.fsck.k9.mail.Multipart;
import com.fsck.k9.mail.Part;
import com.fsck.k9.helper.HtmlConverter;
import com.fsck.k9.mail.internet.MessageExtractor;
@ -15,6 +22,7 @@ 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.OpenPgpError;
import org.openintents.openpgp.OpenPgpSignatureResult;
import java.util.ArrayList;
@ -417,10 +425,7 @@ public class LocalMessageExtractor {
public static MessageViewInfo decodeMessageForView(Context context, Message message) throws MessagingException {
// 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);
List<Part> parts = getCryptPieces(message);
// 2. extract viewables/attachments of parts
ArrayList<MessageViewContainer> containers = new ArrayList<MessageViewContainer>();
@ -433,15 +438,58 @@ public class LocalMessageExtractor {
attachments);
List<AttachmentViewInfo> attachmentInfos = extractAttachmentInfos(attachments);
// TODO correctly extract OpenPgpSignatureResult and add to MessageViewContainer
OpenPgpSignatureResult result = null;
containers.add(new MessageViewContainer(viewable.html, attachmentInfos, result, false, null));
// TODO fill from part
OpenPgpSignatureResult pgpResult = null;
OpenPgpError pgpError = null;
boolean wasEncrypted = false;
PendingIntent pendingIntent = null;
containers.add(new MessageViewContainer(
viewable.html, attachmentInfos, pgpResult, pgpError, wasEncrypted, pendingIntent));
}
return new MessageViewInfo(containers, message);
}
public static List<Part> getCryptPieces(Part part) throws MessagingException {
ArrayList<Part> parts = new ArrayList<Part>();
if (!getCryptSubPieces(part, parts)) {
parts.add(part);
}
return parts;
}
public static boolean getCryptSubPieces(Part part, ArrayList<Part> parts) throws MessagingException {
Body body = part.getBody();
if (body instanceof Multipart) {
Multipart multi = (Multipart) body;
if ("multipart/mixed".equals(part.getMimeType())) {
boolean foundSome = false;
for (BodyPart sub : multi.getBodyParts()) {
foundSome |= getCryptSubPieces(sub, parts);
}
if (!foundSome) {
parts.add(part);
return true;
}
} else if (isPgpMimeDecryptedPart(part)) {
parts.add(multi.getBodyPart(2));
return true;
}
}
return false;
}
public static boolean isPgpMimeDecryptedPart (Part part) {
Body body = part.getBody();
return (body instanceof Multipart)
&& MessageDecryptor.isPgpMimeEncryptedPart(part)
&& ((Multipart) part.getBody()).getBodyParts().size() == 3;
}
private static List<AttachmentViewInfo> extractAttachmentInfos(List<Part> attachmentParts)
throws MessagingException {

View File

@ -7,6 +7,7 @@ import java.util.ArrayList;
import java.util.List;
import com.fsck.k9.mail.Message;
import org.openintents.openpgp.OpenPgpError;
import org.openintents.openpgp.OpenPgpSignatureResult;
@ -33,22 +34,25 @@ public class MessageViewInfo {
final public List<AttachmentViewInfo> attachments;
final public boolean encrypted;
final public OpenPgpSignatureResult signatureResult;
final public OpenPgpError pgpError;
final public PendingIntent pgpPendingIntent;
MessageViewContainer(String text, List<AttachmentViewInfo> attachments) {
this.text = text;
this.attachments = attachments;
this.signatureResult = null;
this.pgpError = null;
this.encrypted = false;
this.pgpPendingIntent = null;
}
MessageViewContainer(String text, List<AttachmentViewInfo> attachments,
OpenPgpSignatureResult signatureResult, boolean encrypted,
PendingIntent pgpPendingIntent) {
OpenPgpSignatureResult signatureResult, OpenPgpError pgpError,
boolean encrypted, PendingIntent pgpPendingIntent) {
this.text = text;
this.attachments = attachments;
this.signatureResult = signatureResult;
this.pgpError = pgpError;
this.encrypted = encrypted;
this.pgpPendingIntent = pgpPendingIntent;
}