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