compose: extract putEncryptionIntentExtras method in PgpMessageBuilder
This commit is contained in:
parent
fe4429416a
commit
029b04a1db
1 changed files with 19 additions and 33 deletions
|
@ -167,23 +167,7 @@ public class PgpMessageBuilder extends MessageBuilder {
|
|||
Intent pgpApiIntent;
|
||||
if (shouldEncrypt) {
|
||||
pgpApiIntent = new Intent(OpenPgpApi.ACTION_ENCRYPT);
|
||||
|
||||
long[] encryptKeyIds = cryptoStatus.getEncryptKeyIds();
|
||||
if (encryptKeyIds != null) {
|
||||
pgpApiIntent.putExtra(OpenPgpApi.EXTRA_KEY_IDS, encryptKeyIds);
|
||||
}
|
||||
|
||||
if(!isDraft()) {
|
||||
String[] encryptRecipientAddresses = cryptoStatus.getRecipientAddresses();
|
||||
boolean hasRecipientAddresses = encryptRecipientAddresses != null && encryptRecipientAddresses.length > 0;
|
||||
if (!hasRecipientAddresses) {
|
||||
// TODO safeguard here once this is better handled by the caller?
|
||||
// throw new MessagingException("Encryption is enabled, but no encryption key specified!");
|
||||
return;
|
||||
}
|
||||
pgpApiIntent.putExtra(OpenPgpApi.EXTRA_USER_IDS, encryptRecipientAddresses);
|
||||
pgpApiIntent.putExtra(OpenPgpApi.EXTRA_ENCRYPT_OPPORTUNISTIC, cryptoStatus.isEncryptionOpportunistic());
|
||||
}
|
||||
putEncryptionIntentExtras(pgpApiIntent);
|
||||
} else {
|
||||
pgpApiIntent = new Intent(OpenPgpApi.ACTION_SIGN);
|
||||
}
|
||||
|
@ -212,22 +196,7 @@ public class PgpMessageBuilder extends MessageBuilder {
|
|||
Intent encryptIntent = new Intent(OpenPgpApi.ACTION_ENCRYPT);
|
||||
encryptIntent.putExtra(OpenPgpApi.EXTRA_REQUEST_ASCII_ARMOR, true);
|
||||
|
||||
long[] encryptKeyIds = cryptoStatus.getEncryptKeyIds();
|
||||
if (encryptKeyIds != null) {
|
||||
encryptIntent.putExtra(OpenPgpApi.EXTRA_KEY_IDS, encryptKeyIds);
|
||||
}
|
||||
|
||||
if(!isDraft()) {
|
||||
String[] encryptRecipientAddresses = cryptoStatus.getRecipientAddresses();
|
||||
boolean hasRecipientAddresses = encryptRecipientAddresses != null && encryptRecipientAddresses.length > 0;
|
||||
if (!hasRecipientAddresses) {
|
||||
// TODO safeguard here once this is better handled by the caller?
|
||||
// throw new MessagingException("Encryption is enabled, but no encryption key specified!");
|
||||
return;
|
||||
}
|
||||
encryptIntent.putExtra(OpenPgpApi.EXTRA_USER_IDS, encryptRecipientAddresses);
|
||||
encryptIntent.putExtra(OpenPgpApi.EXTRA_ENCRYPT_OPPORTUNISTIC, cryptoStatus.isEncryptionOpportunistic());
|
||||
}
|
||||
putEncryptionIntentExtras(encryptIntent);
|
||||
|
||||
currentState = State.OPENPGP_ENCRYPT;
|
||||
mimeIntentLaunch(encryptIntent);
|
||||
|
@ -254,6 +223,23 @@ public class PgpMessageBuilder extends MessageBuilder {
|
|||
mimeIntentLaunch(signIntent);
|
||||
}
|
||||
|
||||
private void putEncryptionIntentExtras(Intent pgpApiIntent) throws MessagingException {
|
||||
long[] encryptKeyIds = cryptoStatus.getEncryptKeyIds();
|
||||
if (encryptKeyIds != null) {
|
||||
pgpApiIntent.putExtra(OpenPgpApi.EXTRA_KEY_IDS, encryptKeyIds);
|
||||
}
|
||||
|
||||
if(!isDraft()) {
|
||||
String[] encryptRecipientAddresses = cryptoStatus.getRecipientAddresses();
|
||||
boolean hasRecipientAddresses = encryptRecipientAddresses != null && encryptRecipientAddresses.length > 0;
|
||||
if (!hasRecipientAddresses) {
|
||||
throw new MessagingException("Encryption is enabled, but no encryption key specified!");
|
||||
}
|
||||
pgpApiIntent.putExtra(OpenPgpApi.EXTRA_USER_IDS, encryptRecipientAddresses);
|
||||
pgpApiIntent.putExtra(OpenPgpApi.EXTRA_ENCRYPT_OPPORTUNISTIC, cryptoStatus.isEncryptionOpportunistic());
|
||||
}
|
||||
}
|
||||
|
||||
/** This method executes the given Intent with the OpenPGP Api. It will pass the
|
||||
* entire current message as input. On success, either mimeBuildSignedMessage() or
|
||||
* mimeBuildEncryptedMessage() will be called with their appropriate inputs. If an
|
||||
|
|
Loading…
Reference in a new issue