deliver the user id as well for secret key selection, so k9mail can use it to display the signature key

This commit is contained in:
Thialfihar 2010-06-01 14:59:06 +00:00
parent 4229b94270
commit 5547f61e4f
4 changed files with 54 additions and 13 deletions

View File

@ -81,6 +81,8 @@ import org.bouncycastle2.openpgp.PGPSignatureSubpacketVector;
import org.bouncycastle2.openpgp.PGPUtil;
import org.thialfihar.android.apg.provider.Database;
import org.thialfihar.android.apg.provider.KeyRings;
import org.thialfihar.android.apg.provider.Keys;
import org.thialfihar.android.apg.provider.UserIds;
import org.thialfihar.android.apg.ui.widget.KeyEditor;
import org.thialfihar.android.apg.ui.widget.SectionView;
import org.thialfihar.android.apg.ui.widget.UserIdEditor;
@ -116,6 +118,7 @@ public class Apg {
public static final String EXTRA_SIGNATURE_USER_ID = "signatureUserId";
public static final String EXTRA_SIGNATURE_SUCCESS = "signatureSuccess";
public static final String EXTRA_SIGNATURE_UNKNOWN = "signatureUnknown";
public static final String EXTRA_USER_ID = "userId";
public static final String EXTRA_KEY_ID = "keyId";
public static final String EXTRA_REPLY_TO = "replyTo";
public static final String EXTRA_SEND_TO = "sendTo";
@ -1042,6 +1045,41 @@ public class Apg {
return keyIds;
}
public static String getMainUserId(long keyId, int type) {
SQLiteDatabase db = mDatabase.db();
Cursor c = db.query(Keys.TABLE_NAME + " INNER JOIN " + KeyRings.TABLE_NAME + " ON (" +
KeyRings.TABLE_NAME + "." + KeyRings._ID + " = " +
Keys.TABLE_NAME + "." + Keys.KEY_RING_ID + ") " +
" INNER JOIN " + Keys.TABLE_NAME + " AS masterKey ON (" +
KeyRings.TABLE_NAME + "." + KeyRings._ID + " = " +
"masterKey." + Keys.KEY_RING_ID + " AND " +
"masterKey." + Keys.IS_MASTER_KEY + " = '1') " +
" INNER JOIN " + UserIds.TABLE_NAME + " ON (" +
UserIds.TABLE_NAME + "." + UserIds.KEY_ID + " = " +
"masterKey." + Keys._ID + " AND " +
UserIds.TABLE_NAME + "." + UserIds.RANK + " = '0')",
new String[] { UserIds.USER_ID },
Keys.TABLE_NAME + "." + Keys.KEY_ID + " = ? AND " +
KeyRings.TABLE_NAME + "." + KeyRings.TYPE + " = ?",
new String[] {
"" + keyId,
"" + type,
},
null, null, null);
String userId = "";
if (c != null && c.moveToFirst()) {
do {
userId = c.getString(0);
} while (c.moveToNext());
}
if (c != null) {
c.close();
}
return userId;
}
public static void encrypt(Context context,
InputStream inStream, OutputStream outStream,
long dataLength,

View File

@ -346,7 +346,7 @@ public class EncryptActivity extends BaseActivity {
if (mMessage.getText().length() > 0 &&
((mEncryptionKeyIds != null &&
mEncryptionKeyIds.length > 0) ||
getSecretKeyId() > 0)) {
getSecretKeyId() != 0)) {
encryptClicked();
}
}
@ -467,7 +467,7 @@ public class EncryptActivity extends BaseActivity {
return;
}
} else {
boolean encryptIt = mEncryptionKeyIds != null && mEncryptionKeyIds.length > 0;
boolean encryptIt = (mEncryptionKeyIds != null && mEncryptionKeyIds.length > 0);
// for now require at least one form of encryption for files
if (!encryptIt && mEncryptTarget == Id.target.file) {
Toast.makeText(this, R.string.selectEncryptionKey, Toast.LENGTH_SHORT).show();
@ -537,7 +537,7 @@ public class EncryptActivity extends BaseActivity {
} else {
encryptionKeyIds = mEncryptionKeyIds;
signatureKeyId = getSecretKeyId();
signOnly = mEncryptionKeyIds == null || mEncryptionKeyIds.length == 0;
signOnly = (mEncryptionKeyIds == null || mEncryptionKeyIds.length == 0);
}
if (mEncryptTarget == Id.target.file) {
@ -558,7 +558,9 @@ public class EncryptActivity extends BaseActivity {
} else {
String message = mMessage.getText().toString();
if (signOnly) {
if (signOnly &&
!(mIntent != null &&
mIntent.getAction().equals(Apg.Intent.ENCRYPT_AND_RETURN))) {
// fix the message a bit, trailing spaces and newlines break stuff,
// because GMail sends as HTML and such things fuck up the signature,
// TODO: things like "<" and ">" also fuck up the signature

View File

@ -44,6 +44,7 @@ public class SelectSecretKeyListActivity extends BaseActivity {
public void onItemClick(AdapterView<?> adapterView, View view, int position, long id) {
Intent data = new Intent();
data.putExtra(Apg.EXTRA_KEY_ID, id);
data.putExtra(Apg.EXTRA_USER_ID, Apg.getMainUserId(id, Id.database.type_secret));
setResult(RESULT_OK, data);
finish();
}