mirror of
https://github.com/moparisthebest/k-9
synced 2024-11-23 18:02:15 -05:00
break message into multiple MessageViewContainers
This commit is contained in:
parent
1046308a38
commit
ba79779758
@ -1,12 +1,19 @@
|
|||||||
package com.fsck.k9.mailstore;
|
package com.fsck.k9.mailstore;
|
||||||
|
|
||||||
|
import android.app.PendingIntent;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
|
import android.util.Log;
|
||||||
|
|
||||||
|
import com.fsck.k9.K9;
|
||||||
import com.fsck.k9.R;
|
import com.fsck.k9.R;
|
||||||
|
import com.fsck.k9.crypto.MessageDecryptor;
|
||||||
import com.fsck.k9.mail.Address;
|
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.Message;
|
||||||
import com.fsck.k9.mail.MessagingException;
|
import com.fsck.k9.mail.MessagingException;
|
||||||
|
import com.fsck.k9.mail.Multipart;
|
||||||
import com.fsck.k9.mail.Part;
|
import com.fsck.k9.mail.Part;
|
||||||
import com.fsck.k9.helper.HtmlConverter;
|
import com.fsck.k9.helper.HtmlConverter;
|
||||||
import com.fsck.k9.mail.internet.MessageExtractor;
|
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.mail.internet.Viewable;
|
||||||
import com.fsck.k9.mailstore.MessageViewInfo.MessageViewContainer;
|
import com.fsck.k9.mailstore.MessageViewInfo.MessageViewContainer;
|
||||||
import com.fsck.k9.provider.AttachmentProvider;
|
import com.fsck.k9.provider.AttachmentProvider;
|
||||||
|
import org.openintents.openpgp.OpenPgpError;
|
||||||
import org.openintents.openpgp.OpenPgpSignatureResult;
|
import org.openintents.openpgp.OpenPgpSignatureResult;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
@ -417,10 +425,7 @@ public class LocalMessageExtractor {
|
|||||||
public static MessageViewInfo decodeMessageForView(Context context, Message message) throws MessagingException {
|
public static MessageViewInfo decodeMessageForView(Context context, Message message) throws MessagingException {
|
||||||
|
|
||||||
// 1. break mime structure on encryption/signature boundaries
|
// 1. break mime structure on encryption/signature boundaries
|
||||||
ArrayList<Part> parts = new ArrayList<Part>();
|
List<Part> parts = getCryptPieces(message);
|
||||||
// TODO: actually break it down
|
|
||||||
parts.add(message);
|
|
||||||
// parts.add(message);
|
|
||||||
|
|
||||||
// 2. extract viewables/attachments of parts
|
// 2. extract viewables/attachments of parts
|
||||||
ArrayList<MessageViewContainer> containers = new ArrayList<MessageViewContainer>();
|
ArrayList<MessageViewContainer> containers = new ArrayList<MessageViewContainer>();
|
||||||
@ -433,15 +438,58 @@ public class LocalMessageExtractor {
|
|||||||
attachments);
|
attachments);
|
||||||
List<AttachmentViewInfo> attachmentInfos = extractAttachmentInfos(attachments);
|
List<AttachmentViewInfo> attachmentInfos = extractAttachmentInfos(attachments);
|
||||||
|
|
||||||
// TODO correctly extract OpenPgpSignatureResult and add to MessageViewContainer
|
// TODO fill from part
|
||||||
OpenPgpSignatureResult result = null;
|
OpenPgpSignatureResult pgpResult = null;
|
||||||
containers.add(new MessageViewContainer(viewable.html, attachmentInfos, result, false, 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);
|
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)
|
private static List<AttachmentViewInfo> extractAttachmentInfos(List<Part> attachmentParts)
|
||||||
throws MessagingException {
|
throws MessagingException {
|
||||||
|
|
||||||
|
@ -7,6 +7,7 @@ import java.util.ArrayList;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import com.fsck.k9.mail.Message;
|
import com.fsck.k9.mail.Message;
|
||||||
|
import org.openintents.openpgp.OpenPgpError;
|
||||||
import org.openintents.openpgp.OpenPgpSignatureResult;
|
import org.openintents.openpgp.OpenPgpSignatureResult;
|
||||||
|
|
||||||
|
|
||||||
@ -33,22 +34,25 @@ public class MessageViewInfo {
|
|||||||
final public List<AttachmentViewInfo> attachments;
|
final public List<AttachmentViewInfo> attachments;
|
||||||
final public boolean encrypted;
|
final public boolean encrypted;
|
||||||
final public OpenPgpSignatureResult signatureResult;
|
final public OpenPgpSignatureResult signatureResult;
|
||||||
|
final public OpenPgpError pgpError;
|
||||||
final public PendingIntent pgpPendingIntent;
|
final public PendingIntent pgpPendingIntent;
|
||||||
|
|
||||||
MessageViewContainer(String text, List<AttachmentViewInfo> attachments) {
|
MessageViewContainer(String text, List<AttachmentViewInfo> attachments) {
|
||||||
this.text = text;
|
this.text = text;
|
||||||
this.attachments = attachments;
|
this.attachments = attachments;
|
||||||
this.signatureResult = null;
|
this.signatureResult = null;
|
||||||
|
this.pgpError = null;
|
||||||
this.encrypted = false;
|
this.encrypted = false;
|
||||||
this.pgpPendingIntent = null;
|
this.pgpPendingIntent = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
MessageViewContainer(String text, List<AttachmentViewInfo> attachments,
|
MessageViewContainer(String text, List<AttachmentViewInfo> attachments,
|
||||||
OpenPgpSignatureResult signatureResult, boolean encrypted,
|
OpenPgpSignatureResult signatureResult, OpenPgpError pgpError,
|
||||||
PendingIntent pgpPendingIntent) {
|
boolean encrypted, PendingIntent pgpPendingIntent) {
|
||||||
this.text = text;
|
this.text = text;
|
||||||
this.attachments = attachments;
|
this.attachments = attachments;
|
||||||
this.signatureResult = signatureResult;
|
this.signatureResult = signatureResult;
|
||||||
|
this.pgpError = pgpError;
|
||||||
this.encrypted = encrypted;
|
this.encrypted = encrypted;
|
||||||
this.pgpPendingIntent = pgpPendingIntent;
|
this.pgpPendingIntent = pgpPendingIntent;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user