mirror of
https://github.com/moparisthebest/k-9
synced 2024-11-23 09:52:16 -05:00
pass pendingIntent, and some refactoring
This commit is contained in:
parent
712acf4481
commit
00b7b74878
@ -42,7 +42,7 @@ public class LocalMessageExtractor {
|
||||
private static final int FILENAME_PREFIX_LENGTH = FILENAME_PREFIX.length();
|
||||
private static final String FILENAME_SUFFIX = " ";
|
||||
private static final int FILENAME_SUFFIX_LENGTH = FILENAME_SUFFIX.length();
|
||||
private static final OpenPgpSignatureResult NO_SIGNATURE_RESULT = null;
|
||||
private static final OpenPgpResultBodyPart NO_SIGNATURE_RESULT = null;
|
||||
|
||||
private LocalMessageExtractor() {}
|
||||
/**
|
||||
@ -437,24 +437,24 @@ public class LocalMessageExtractor {
|
||||
attachments);
|
||||
List<AttachmentViewInfo> attachmentInfos = extractAttachmentInfos(attachments);
|
||||
|
||||
// TODO fill from part
|
||||
OpenPgpSignatureResult pgpResult = getSignatureResultForPart(part);
|
||||
OpenPgpError pgpError = null;
|
||||
boolean wasEncrypted = getPartWasEncrypted(part);
|
||||
PendingIntent pendingIntent = null;
|
||||
OpenPgpResultBodyPart resultBodyPart = getSignatureResultForPart(part);
|
||||
if (resultBodyPart != NO_SIGNATURE_RESULT) {
|
||||
OpenPgpSignatureResult pgpResult = resultBodyPart.getSignatureResult();
|
||||
OpenPgpError pgpError = null;
|
||||
boolean wasEncrypted = resultBodyPart.wasEncrypted();
|
||||
PendingIntent pendingIntent = resultBodyPart.getPendingIntent();
|
||||
|
||||
containers.add(new MessageViewContainer(
|
||||
viewable.html, attachmentInfos, pgpResult, pgpError, wasEncrypted, pendingIntent));
|
||||
containers.add(new MessageViewContainer(
|
||||
viewable.html, attachmentInfos, pgpResult, pgpError, wasEncrypted, pendingIntent));
|
||||
} else {
|
||||
containers.add(new MessageViewContainer(viewable.html, attachmentInfos));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return new MessageViewInfo(containers, message);
|
||||
}
|
||||
|
||||
private static boolean getPartWasEncrypted(Part part) {
|
||||
return (part instanceof OpenPgpResultBodyPart) && ((OpenPgpResultBodyPart) part).wasEncrypted();
|
||||
}
|
||||
|
||||
public static List<Part> getCryptPieces(Part part) throws MessagingException {
|
||||
ArrayList<Part> parts = new ArrayList<Part>();
|
||||
if (!getCryptSubPieces(part, parts)) {
|
||||
@ -496,16 +496,16 @@ public class LocalMessageExtractor {
|
||||
&& ((Multipart) part.getBody()).getCount() == 3;
|
||||
}
|
||||
|
||||
private static OpenPgpSignatureResult getSignatureResultForPart(Part part) {
|
||||
private static OpenPgpResultBodyPart getSignatureResultForPart(Part part) {
|
||||
if (part instanceof OpenPgpResultBodyPart) {
|
||||
OpenPgpResultBodyPart openPgpResultBodyPart = (OpenPgpResultBodyPart) part;
|
||||
return openPgpResultBodyPart.getSignatureResult();
|
||||
return openPgpResultBodyPart;
|
||||
}
|
||||
if (MessageDecryptVerifyer.isPgpMimeSignedPart(part)) {
|
||||
Multipart multi = (Multipart) part.getBody();
|
||||
if (multi.getCount() == 3 && multi.getBodyPart(2) instanceof OpenPgpResultBodyPart) {
|
||||
OpenPgpResultBodyPart openPgpResultBodyPart = (OpenPgpResultBodyPart) multi.getBodyPart(2);
|
||||
return openPgpResultBodyPart.getSignatureResult();
|
||||
return openPgpResultBodyPart;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,6 +1,8 @@
|
||||
package com.fsck.k9.mailstore;
|
||||
|
||||
|
||||
import android.app.PendingIntent;
|
||||
|
||||
import com.fsck.k9.mail.MessagingException;
|
||||
import com.fsck.k9.mail.internet.MimeBodyPart;
|
||||
import org.openintents.openpgp.OpenPgpError;
|
||||
@ -11,6 +13,7 @@ public class OpenPgpResultBodyPart extends MimeBodyPart {
|
||||
private boolean wasEncrypted;
|
||||
private OpenPgpSignatureResult signatureResult;
|
||||
private OpenPgpError error;
|
||||
private PendingIntent pendingIntent;
|
||||
|
||||
public OpenPgpResultBodyPart(boolean wasEncrypted) throws MessagingException {
|
||||
this.wasEncrypted = wasEncrypted;
|
||||
@ -20,10 +23,18 @@ public class OpenPgpResultBodyPart extends MimeBodyPart {
|
||||
return signatureResult;
|
||||
}
|
||||
|
||||
public PendingIntent getPendingIntent() {
|
||||
return pendingIntent;
|
||||
}
|
||||
|
||||
public void setSignatureResult(OpenPgpSignatureResult signatureResult) {
|
||||
this.signatureResult = signatureResult;
|
||||
}
|
||||
|
||||
public void setPendingIntent(PendingIntent pendingIntent) {
|
||||
this.pendingIntent = pendingIntent;
|
||||
}
|
||||
|
||||
public OpenPgpError getError() {
|
||||
return error;
|
||||
}
|
||||
|
@ -340,38 +340,11 @@ public class MessageViewFragment extends Fragment implements ConfirmationDialogF
|
||||
intent.putExtra(OpenPgpApi.EXTRA_ACCOUNT_NAME, accountName);
|
||||
|
||||
try {
|
||||
|
||||
PipedInputStream pipedInputStream;
|
||||
PipedOutputStream decryptedOutputStream;
|
||||
final CountDownLatch latch;
|
||||
|
||||
if (MessageDecryptVerifyer.isPgpMimeSignedPart(currentlyDecrypringOrVerifyingPart)) {
|
||||
pipedInputStream = getPipedInputStreamForSignedData();
|
||||
|
||||
byte[] signatureData = MessageDecryptVerifyer.getSignatureData(currentlyDecrypringOrVerifyingPart);
|
||||
intent.putExtra(OpenPgpApi.EXTRA_DETACHED_SIGNATURE, signatureData);
|
||||
decryptedOutputStream = null;
|
||||
latch = null;
|
||||
callAsyncDetachedVerify(intent);
|
||||
} else {
|
||||
pipedInputStream = getPipedInputStreamForEncryptedData();
|
||||
latch = new CountDownLatch(1);
|
||||
decryptedOutputStream = getPipedOutputStreamForDecryptedData(latch);
|
||||
callAsyncDecrypt(intent);
|
||||
}
|
||||
|
||||
openPgpApi.executeApiAsync(intent, pipedInputStream, decryptedOutputStream, new IOpenPgpCallback() {
|
||||
@Override
|
||||
public void onReturn(Intent result) {
|
||||
currentCryptoResult = result;
|
||||
|
||||
if (latch != null) {
|
||||
Log.d(K9.LOG_TAG, "on result!");
|
||||
latch.countDown();
|
||||
return;
|
||||
}
|
||||
|
||||
onCryptoConverge(null);
|
||||
}
|
||||
});
|
||||
} catch (IOException e) {
|
||||
Log.e(K9.LOG_TAG, "IOException", e);
|
||||
} catch (MessagingException e) {
|
||||
@ -379,6 +352,35 @@ public class MessageViewFragment extends Fragment implements ConfirmationDialogF
|
||||
}
|
||||
}
|
||||
|
||||
private void callAsyncDecrypt(Intent intent) throws IOException {
|
||||
final CountDownLatch latch = new CountDownLatch(1);
|
||||
PipedInputStream pipedInputStream = getPipedInputStreamForEncryptedData();
|
||||
PipedOutputStream decryptedOutputStream = getPipedOutputStreamForDecryptedData(latch);
|
||||
|
||||
openPgpApi.executeApiAsync(intent, pipedInputStream, decryptedOutputStream, new IOpenPgpCallback() {
|
||||
@Override
|
||||
public void onReturn(Intent result) {
|
||||
currentCryptoResult = result;
|
||||
latch.countDown();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void callAsyncDetachedVerify(Intent intent) throws IOException, MessagingException {
|
||||
PipedInputStream pipedInputStream = getPipedInputStreamForSignedData();
|
||||
|
||||
byte[] signatureData = MessageDecryptVerifyer.getSignatureData(currentlyDecrypringOrVerifyingPart);
|
||||
intent.putExtra(OpenPgpApi.EXTRA_DETACHED_SIGNATURE, signatureData);
|
||||
|
||||
openPgpApi.executeApiAsync(intent, pipedInputStream, null, new IOpenPgpCallback() {
|
||||
@Override
|
||||
public void onReturn(Intent result) {
|
||||
currentCryptoResult = result;
|
||||
onCryptoConverge(null);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private PipedInputStream getPipedInputStreamForSignedData() throws IOException {
|
||||
PipedInputStream pipedInputStream = new PipedInputStream();
|
||||
|
||||
@ -498,6 +500,10 @@ public class MessageViewFragment extends Fragment implements ConfirmationDialogF
|
||||
currentCryptoResult.getParcelableExtra(OpenPgpApi.RESULT_SIGNATURE);
|
||||
openPgpResultBodyPart.setSignatureResult(signatureResult);
|
||||
|
||||
PendingIntent pendingIntent =
|
||||
currentCryptoResult.getParcelableExtra(OpenPgpApi.RESULT_INTENT);
|
||||
openPgpResultBodyPart.setPendingIntent(pendingIntent);
|
||||
|
||||
onCryptoSuccess(openPgpResultBodyPart);
|
||||
break;
|
||||
}
|
||||
@ -514,7 +520,7 @@ public class MessageViewFragment extends Fragment implements ConfirmationDialogF
|
||||
if (resultCode == Activity.RESULT_OK) {
|
||||
decryptOrVerifyNextPartOrStartExtractingTextAndAttachments();
|
||||
} else {
|
||||
//FIXME: don't pass null
|
||||
// FIXME: don't pass null
|
||||
onCryptoFailed(null);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user