mirror of
https://github.com/moparisthebest/k-9
synced 2024-11-27 11:42:16 -05:00
Pass OpenPgpSignatureResult to LocalMessageExtractor
This commit is contained in:
parent
9e47686277
commit
fbfa6d146f
@ -24,6 +24,8 @@ import org.apache.james.mime4j.parser.MimeStreamParser;
|
|||||||
import org.apache.james.mime4j.stream.BodyDescriptor;
|
import org.apache.james.mime4j.stream.BodyDescriptor;
|
||||||
import org.apache.james.mime4j.stream.Field;
|
import org.apache.james.mime4j.stream.Field;
|
||||||
import org.apache.james.mime4j.stream.MimeConfig;
|
import org.apache.james.mime4j.stream.MimeConfig;
|
||||||
|
import org.openintents.openpgp.OpenPgpError;
|
||||||
|
import org.openintents.openpgp.OpenPgpSignatureResult;
|
||||||
|
|
||||||
|
|
||||||
public class DecryptStreamParser {
|
public class DecryptStreamParser {
|
||||||
@ -181,8 +183,27 @@ public class DecryptStreamParser {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static class DecryptedBodyPart extends MimeBodyPart {
|
public static class DecryptedBodyPart extends MimeBodyPart {
|
||||||
|
private OpenPgpSignatureResult signatureResult;
|
||||||
|
private OpenPgpError error;
|
||||||
|
|
||||||
public DecryptedBodyPart() throws MessagingException {
|
public DecryptedBodyPart() throws MessagingException {
|
||||||
// Do nothing
|
// Do nothing
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public OpenPgpSignatureResult getSignatureResult() {
|
||||||
|
return signatureResult;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setSignatureResult(OpenPgpSignatureResult signatureResult) {
|
||||||
|
this.signatureResult = signatureResult;
|
||||||
|
}
|
||||||
|
|
||||||
|
public OpenPgpError getError() {
|
||||||
|
return error;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setError(OpenPgpError error) {
|
||||||
|
this.error = error;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -4,15 +4,20 @@ import android.content.Context;
|
|||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
|
|
||||||
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;
|
||||||
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.DecryptStreamParser.DecryptedBodyPart;
|
||||||
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.OpenPgpSignatureResult;
|
import org.openintents.openpgp.OpenPgpSignatureResult;
|
||||||
@ -36,6 +41,7 @@ public class LocalMessageExtractor {
|
|||||||
private static final int FILENAME_PREFIX_LENGTH = FILENAME_PREFIX.length();
|
private static final int FILENAME_PREFIX_LENGTH = FILENAME_PREFIX.length();
|
||||||
private static final String FILENAME_SUFFIX = " ";
|
private static final String FILENAME_SUFFIX = " ";
|
||||||
private static final int FILENAME_SUFFIX_LENGTH = FILENAME_SUFFIX.length();
|
private static final int FILENAME_SUFFIX_LENGTH = FILENAME_SUFFIX.length();
|
||||||
|
private static final OpenPgpSignatureResult NO_SIGNATURE_RESULT = null;
|
||||||
|
|
||||||
private LocalMessageExtractor() {}
|
private LocalMessageExtractor() {}
|
||||||
/**
|
/**
|
||||||
@ -433,8 +439,7 @@ public class LocalMessageExtractor {
|
|||||||
attachments);
|
attachments);
|
||||||
List<AttachmentViewInfo> attachmentInfos = extractAttachmentInfos(attachments);
|
List<AttachmentViewInfo> attachmentInfos = extractAttachmentInfos(attachments);
|
||||||
|
|
||||||
// TODO correctly extract OpenPgpSignatureResult and add to MessageViewContainer
|
OpenPgpSignatureResult result = getSignatureResultForPart(part);
|
||||||
OpenPgpSignatureResult result = null;
|
|
||||||
containers.add(new MessageViewContainer(viewable.html, attachmentInfos, result, false, null));
|
containers.add(new MessageViewContainer(viewable.html, attachmentInfos, result, false, null));
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -442,6 +447,30 @@ public class LocalMessageExtractor {
|
|||||||
return new MessageViewInfo(containers, message);
|
return new MessageViewInfo(containers, message);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static OpenPgpSignatureResult getSignatureResultForPart(Part part) {
|
||||||
|
if (!MessageDecryptor.isPgpMimeEncryptedPart(part)) {
|
||||||
|
return NO_SIGNATURE_RESULT;
|
||||||
|
}
|
||||||
|
|
||||||
|
Body body = part.getBody();
|
||||||
|
if (!(body instanceof Multipart)) {
|
||||||
|
return NO_SIGNATURE_RESULT;
|
||||||
|
}
|
||||||
|
|
||||||
|
Multipart multipart = (Multipart) body;
|
||||||
|
if (multipart.getCount() < 3) {
|
||||||
|
return NO_SIGNATURE_RESULT;
|
||||||
|
}
|
||||||
|
|
||||||
|
BodyPart bodyPart = multipart.getBodyPart(2);
|
||||||
|
if (!(bodyPart instanceof DecryptedBodyPart)) {
|
||||||
|
return NO_SIGNATURE_RESULT;
|
||||||
|
}
|
||||||
|
|
||||||
|
DecryptedBodyPart decryptedBodyPart = (DecryptedBodyPart) bodyPart;
|
||||||
|
return decryptedBodyPart.getSignatureResult();
|
||||||
|
}
|
||||||
|
|
||||||
private static List<AttachmentViewInfo> extractAttachmentInfos(List<Part> attachmentParts)
|
private static List<AttachmentViewInfo> extractAttachmentInfos(List<Part> attachmentParts)
|
||||||
throws MessagingException {
|
throws MessagingException {
|
||||||
|
|
||||||
|
@ -71,6 +71,8 @@ import com.fsck.k9.ui.message.DecodeMessageLoader;
|
|||||||
import com.fsck.k9.ui.message.LocalMessageLoader;
|
import com.fsck.k9.ui.message.LocalMessageLoader;
|
||||||
import com.fsck.k9.view.MessageHeader;
|
import com.fsck.k9.view.MessageHeader;
|
||||||
import org.openintents.openpgp.IOpenPgpService;
|
import org.openintents.openpgp.IOpenPgpService;
|
||||||
|
import org.openintents.openpgp.OpenPgpError;
|
||||||
|
import org.openintents.openpgp.OpenPgpSignatureResult;
|
||||||
import org.openintents.openpgp.util.OpenPgpApi;
|
import org.openintents.openpgp.util.OpenPgpApi;
|
||||||
import org.openintents.openpgp.util.OpenPgpApi.IOpenPgpCallback;
|
import org.openintents.openpgp.util.OpenPgpApi.IOpenPgpCallback;
|
||||||
import org.openintents.openpgp.util.OpenPgpServiceConnection;
|
import org.openintents.openpgp.util.OpenPgpServiceConnection;
|
||||||
@ -433,14 +435,20 @@ public class MessageViewFragment extends Fragment implements ConfirmationDialogF
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case OpenPgpApi.RESULT_CODE_ERROR: {
|
case OpenPgpApi.RESULT_CODE_ERROR: {
|
||||||
|
OpenPgpError error = currentDecryptingResult.getParcelableExtra(OpenPgpApi.RESULT_ERROR);
|
||||||
|
|
||||||
if (K9.DEBUG) {
|
if (K9.DEBUG) {
|
||||||
String errorMessage = currentDecryptingResult.getStringExtra(OpenPgpApi.RESULT_ERROR);
|
Log.w(K9.LOG_TAG, "OpenPGP API error: " + error.getMessage());
|
||||||
Log.w(K9.LOG_TAG, "OpenPGP API error: " + errorMessage);
|
|
||||||
}
|
}
|
||||||
onDecryptionFailed();
|
|
||||||
|
onDecryptionFailed(error);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case OpenPgpApi.RESULT_CODE_SUCCESS: {
|
case OpenPgpApi.RESULT_CODE_SUCCESS: {
|
||||||
|
OpenPgpSignatureResult signatureResult =
|
||||||
|
currentDecryptingResult.getParcelableExtra(OpenPgpApi.RESULT_SIGNATURE);
|
||||||
|
decryptedPart.setSignatureResult(signatureResult);
|
||||||
|
|
||||||
onDecryptionSuccess(decryptedPart);
|
onDecryptionSuccess(decryptedPart);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -454,7 +462,8 @@ public class MessageViewFragment extends Fragment implements ConfirmationDialogF
|
|||||||
if (resultCode == Activity.RESULT_OK) {
|
if (resultCode == Activity.RESULT_OK) {
|
||||||
decryptNextPartOrStartExtractingTextAndAttachments();
|
decryptNextPartOrStartExtractingTextAndAttachments();
|
||||||
} else {
|
} else {
|
||||||
onDecryptionFailed();
|
//FIXME: don't pass null
|
||||||
|
onDecryptionFailed(null);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -468,8 +477,14 @@ public class MessageViewFragment extends Fragment implements ConfirmationDialogF
|
|||||||
multipart.addBodyPart(decryptedPart);
|
multipart.addBodyPart(decryptedPart);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void onDecryptionFailed() {
|
private void onDecryptionFailed(OpenPgpError error) {
|
||||||
// TODO: display error to user?
|
try {
|
||||||
|
DecryptedBodyPart errorPart = new DecryptedBodyPart();
|
||||||
|
errorPart.setError(error);
|
||||||
|
addDecryptedPartToMessage(errorPart);
|
||||||
|
} catch (MessagingException e) {
|
||||||
|
Log.e(K9.LOG_TAG, "This shouldn't happen", e);
|
||||||
|
}
|
||||||
onDecryptionFinished();
|
onDecryptionFinished();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user