diff --git a/k9mail/src/main/java/com/fsck/k9/Account.java b/k9mail/src/main/java/com/fsck/k9/Account.java
index 73f280ec5..13c47c9ed 100644
--- a/k9mail/src/main/java/com/fsck/k9/Account.java
+++ b/k9mail/src/main/java/com/fsck/k9/Account.java
@@ -220,6 +220,7 @@ public class Account implements BaseAccount, StoreConfig {
private boolean mStripSignature;
private boolean mSyncRemoteDeletions;
private String mCryptoApp;
+ private long mCryptoKey;
private boolean mMarkMessageAsReadOnView;
private boolean mAlwaysShowCcBcc;
private boolean mAllowRemoteSearch;
@@ -314,6 +315,7 @@ public class Account implements BaseAccount, StoreConfig {
mStripSignature = DEFAULT_STRIP_SIGNATURE;
mSyncRemoteDeletions = true;
mCryptoApp = NO_OPENPGP_PROVIDER;
+ mCryptoKey = 0;
mAllowRemoteSearch = false;
mRemoteSearchFullText = false;
mRemoteSearchNumResults = DEFAULT_REMOTE_SEARCH_NUM_RESULTS;
@@ -724,6 +726,7 @@ public class Account implements BaseAccount, StoreConfig {
editor.putBoolean(mUuid + ".replyAfterQuote", mReplyAfterQuote);
editor.putBoolean(mUuid + ".stripSignature", mStripSignature);
editor.putString(mUuid + ".cryptoApp", mCryptoApp);
+ editor.putLong(mUuid + ".cryptoKey", mCryptoKey);
editor.putBoolean(mUuid + ".allowRemoteSearch", mAllowRemoteSearch);
editor.putBoolean(mUuid + ".remoteSearchFullText", mRemoteSearchFullText);
editor.putInt(mUuid + ".remoteSearchNumResults", mRemoteSearchNumResults);
@@ -1605,6 +1608,14 @@ public class Account implements BaseAccount, StoreConfig {
}
}
+ public long getCryptoKey() {
+ return mCryptoKey;
+ }
+
+ public void setCryptoKey(long keyId) {
+ mCryptoKey = keyId;
+ }
+
public boolean allowRemoteSearch() {
return mAllowRemoteSearch;
}
diff --git a/k9mail/src/main/java/com/fsck/k9/activity/MessageCompose.java b/k9mail/src/main/java/com/fsck/k9/activity/MessageCompose.java
index 2bc8a0932..09153ea76 100644
--- a/k9mail/src/main/java/com/fsck/k9/activity/MessageCompose.java
+++ b/k9mail/src/main/java/com/fsck/k9/activity/MessageCompose.java
@@ -1298,9 +1298,11 @@ public class MessageCompose extends K9Activity implements OnClickListener,
if (mEncryptCheckbox.isChecked() && mCryptoSignatureCheckbox.isChecked()) {
Intent intent = new Intent(OpenPgpApi.ACTION_SIGN_AND_ENCRYPT);
intent.putExtra(OpenPgpApi.EXTRA_USER_IDS, emailsArray);
+ intent.putExtra(OpenPgpApi.EXTRA_SIGN_KEY_ID, mAccount.getCryptoKey());
executeOpenPgpMethod(intent);
} else if (mCryptoSignatureCheckbox.isChecked()) {
Intent intent = new Intent(OpenPgpApi.ACTION_SIGN);
+ intent.putExtra(OpenPgpApi.EXTRA_SIGN_KEY_ID, mAccount.getCryptoKey());
executeOpenPgpMethod(intent);
} else if (mEncryptCheckbox.isChecked()) {
Intent intent = new Intent(OpenPgpApi.ACTION_ENCRYPT);
@@ -1338,10 +1340,6 @@ public class MessageCompose extends K9Activity implements OnClickListener,
private void executeOpenPgpMethod(Intent intent) {
intent.putExtra(OpenPgpApi.EXTRA_REQUEST_ASCII_ARMOR, true);
- // this follows user id format of OpenPGP to allow key generation based on it
- // includes account number to make it unique
- String accName = OpenPgpApiHelper.buildAccountName(mIdentity);
- intent.putExtra(OpenPgpApi.EXTRA_ACCOUNT_NAME, accName);
final InputStream is = getOpenPgpInputStream();
final ByteArrayOutputStream os = new ByteArrayOutputStream();
diff --git a/k9mail/src/main/java/com/fsck/k9/activity/setup/AccountSettings.java b/k9mail/src/main/java/com/fsck/k9/activity/setup/AccountSettings.java
index 19a718bf0..8a1c629bc 100644
--- a/k9mail/src/main/java/com/fsck/k9/activity/setup/AccountSettings.java
+++ b/k9mail/src/main/java/com/fsck/k9/activity/setup/AccountSettings.java
@@ -39,6 +39,7 @@ import com.fsck.k9.activity.ChooseIdentity;
import com.fsck.k9.activity.ColorPickerDialog;
import com.fsck.k9.activity.K9PreferenceActivity;
import com.fsck.k9.activity.ManageIdentities;
+import com.fsck.k9.crypto.OpenPgpApiHelper;
import com.fsck.k9.mail.Folder;
import com.fsck.k9.mail.Store;
import com.fsck.k9.mailstore.LocalFolder;
@@ -46,6 +47,7 @@ import com.fsck.k9.mailstore.StorageManager;
import com.fsck.k9.service.MailService;
import org.openintents.openpgp.util.OpenPgpAppPreference;
+import org.openintents.openpgp.util.OpenPgpKeyPreference;
import org.openintents.openpgp.util.OpenPgpUtils;
@@ -110,6 +112,7 @@ public class AccountSettings extends K9PreferenceActivity {
private static final String PREFERENCE_SYNC_REMOTE_DELETIONS = "account_sync_remote_deletetions";
private static final String PREFERENCE_CRYPTO = "crypto";
private static final String PREFERENCE_CRYPTO_APP = "crypto_app";
+ private static final String PREFERENCE_CRYPTO_KEY = "crypto_key";
private static final String PREFERENCE_CLOUD_SEARCH_ENABLED = "remote_search_enabled";
private static final String PREFERENCE_REMOTE_SEARCH_NUM_RESULTS = "account_remote_search_num_results";
private static final String PREFERENCE_REMOTE_SEARCH_FULL_TEXT = "account_remote_search_full_text";
@@ -175,6 +178,7 @@ public class AccountSettings extends K9PreferenceActivity {
private ListPreference mMaxPushFolders;
private boolean mHasCrypto = false;
private OpenPgpAppPreference mCryptoApp;
+ private OpenPgpKeyPreference mCryptoKey;
private PreferenceScreen mSearchScreen;
private CheckBoxPreference mCloudSearchEnabled;
@@ -688,14 +692,27 @@ public class AccountSettings extends K9PreferenceActivity {
mHasCrypto = OpenPgpUtils.isAvailable(this);
if (mHasCrypto) {
mCryptoApp = (OpenPgpAppPreference) findPreference(PREFERENCE_CRYPTO_APP);
+ mCryptoKey = (OpenPgpKeyPreference) findPreference(PREFERENCE_CRYPTO_KEY);
mCryptoApp.setValue(String.valueOf(mAccount.getCryptoApp()));
- mCryptoApp.setSummary(mCryptoApp.getEntry());
mCryptoApp.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
public boolean onPreferenceChange(Preference preference, Object newValue) {
String value = newValue.toString();
- mCryptoApp.setSummary(mCryptoApp.getEntryByValue(value));
mCryptoApp.setValue(value);
+
+ mCryptoKey.setOpenPgpProvider(value);
+ return false;
+ }
+ });
+
+ mCryptoKey.setValue(mAccount.getCryptoKey());
+ mCryptoKey.setOpenPgpProvider(mCryptoApp.getValue());
+ // TODO: other identities?
+ mCryptoKey.setDefaultUserId(OpenPgpApiHelper.buildUserId(mAccount.getIdentity(0)));
+ mCryptoKey.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
+ public boolean onPreferenceChange(Preference preference, Object newValue) {
+ long value = (Long) newValue;
+ mCryptoKey.setValue(value);
return false;
}
});
@@ -765,6 +782,7 @@ public class AccountSettings extends K9PreferenceActivity {
mAccount.setLocalStorageProviderId(mLocalStorageProvider.getValue());
if (mHasCrypto) {
mAccount.setCryptoApp(mCryptoApp.getValue());
+ mAccount.setCryptoKey(mCryptoKey.getValue());
}
// In webdav account we use the exact folder name also for inbox,
@@ -832,6 +850,9 @@ public class AccountSettings extends K9PreferenceActivity {
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
+ if (mCryptoKey != null && mCryptoKey.handleOnActivityResult(requestCode, resultCode, data)) {
+ return;
+ }
if (resultCode == RESULT_OK) {
switch (requestCode) {
case SELECT_AUTO_EXPAND_FOLDER:
diff --git a/k9mail/src/main/java/com/fsck/k9/crypto/OpenPgpApiHelper.java b/k9mail/src/main/java/com/fsck/k9/crypto/OpenPgpApiHelper.java
index f69e61472..f9d71ed3d 100644
--- a/k9mail/src/main/java/com/fsck/k9/crypto/OpenPgpApiHelper.java
+++ b/k9mail/src/main/java/com/fsck/k9/crypto/OpenPgpApiHelper.java
@@ -16,7 +16,7 @@ public class OpenPgpApiHelper {
*
* @see org.openintents.openpgp.util.OpenPgpApi#EXTRA_ACCOUNT_NAME
*/
- public static String buildAccountName(Identity identity) {
+ public static String buildUserId(Identity identity) {
StringBuilder sb = new StringBuilder();
String name = identity.getName();
diff --git a/k9mail/src/main/java/com/fsck/k9/ui/crypto/MessageCryptoHelper.java b/k9mail/src/main/java/com/fsck/k9/ui/crypto/MessageCryptoHelper.java
index 695785fce..4a8792cb6 100644
--- a/k9mail/src/main/java/com/fsck/k9/ui/crypto/MessageCryptoHelper.java
+++ b/k9mail/src/main/java/com/fsck/k9/ui/crypto/MessageCryptoHelper.java
@@ -170,10 +170,6 @@ public class MessageCryptoHelper {
private void decryptVerify(Intent intent) {
intent.setAction(OpenPgpApi.ACTION_DECRYPT_VERIFY);
- Identity identity = IdentityHelper.getRecipientIdentityFromMessage(account, message);
- String accountName = OpenPgpApiHelper.buildAccountName(identity);
- intent.putExtra(OpenPgpApi.EXTRA_ACCOUNT_NAME, accountName);
-
try {
CryptoPartType cryptoPartType = currentCryptoPart.type;
switch (cryptoPartType) {
diff --git a/k9mail/src/main/res/values/strings.xml b/k9mail/src/main/res/values/strings.xml
index 61c314837..5d977423d 100644
--- a/k9mail/src/main/res/values/strings.xml
+++ b/k9mail/src/main/res/values/strings.xml
@@ -569,8 +569,9 @@ Please submit bug reports, contribute new features and ask questions at
Folders
Quoted text prefix
Cryptography
- OpenPGP Provider
- No OpenPGP Provider installed
+ OpenPGP app
+ My Key
+ No OpenPGP app installed
Folder poll frequency
diff --git a/k9mail/src/main/res/xml/account_settings_preferences.xml b/k9mail/src/main/res/xml/account_settings_preferences.xml
index d55c87ec1..be644c511 100644
--- a/k9mail/src/main/res/xml/account_settings_preferences.xml
+++ b/k9mail/src/main/res/xml/account_settings_preferences.xml
@@ -471,6 +471,11 @@
android:key="crypto_app"
android:title="@string/account_settings_crypto_app" />
+
+
diff --git a/plugins/openpgp-api-library/src/main/java/org/openintents/openpgp/util/OpenPgpAppPreference.java b/plugins/openpgp-api-library/src/main/java/org/openintents/openpgp/util/OpenPgpAppPreference.java
index 6e8ddad84..4bf4cec43 100644
--- a/plugins/openpgp-api-library/src/main/java/org/openintents/openpgp/util/OpenPgpAppPreference.java
+++ b/plugins/openpgp-api-library/src/main/java/org/openintents/openpgp/util/OpenPgpAppPreference.java
@@ -201,14 +201,23 @@ public class OpenPgpAppPreference extends DialogPreference {
return 0;
}
+ /**
+ * Public API
+ */
public String getEntry() {
return getEntryByValue(mSelectedPackage);
}
+ /**
+ * Public API
+ */
public String getValue() {
return mSelectedPackage;
}
+ /**
+ * Public API
+ */
public void setValue(String packageName) {
setAndPersist(packageName);
}
diff --git a/plugins/openpgp-api-library/src/main/java/org/openintents/openpgp/util/OpenPgpKeyPreference.java b/plugins/openpgp-api-library/src/main/java/org/openintents/openpgp/util/OpenPgpKeyPreference.java
index e5bd8ea03..634328569 100644
--- a/plugins/openpgp-api-library/src/main/java/org/openintents/openpgp/util/OpenPgpKeyPreference.java
+++ b/plugins/openpgp-api-library/src/main/java/org/openintents/openpgp/util/OpenPgpKeyPreference.java
@@ -145,6 +145,20 @@ public class OpenPgpKeyPreference extends Preference {
setAndPersist(newValue);
}
+ /**
+ * Public API
+ */
+ public void setValue(long keyId) {
+ setAndPersist(keyId);
+ }
+
+ /**
+ * Public API
+ */
+ public long getValue() {
+ return mKeyId;
+ }
+
private void setAndPersist(long newValue) {
mKeyId = newValue;