mirror of
https://github.com/M66B/FairEmail.git
synced 2025-02-21 13:47:04 +00:00
Sign-only fixes
This commit is contained in:
parent
8b8c3b539b
commit
ec365a4a9b
8 changed files with 89 additions and 80 deletions
|
@ -2182,8 +2182,10 @@ class Core {
|
|||
attachment.message = message.id;
|
||||
attachment.sequence = sequence++;
|
||||
attachment.id = db.attachment().insertAttachment(attachment);
|
||||
if (EntityAttachment.PGP_MESSAGE.equals(attachment.encryption))
|
||||
db.message().setMessageEncrypt(message.id, EntityMessage.ENCRYPTION_SIGNENCRYPT);
|
||||
if (EntityAttachment.PGP_SIGNATURE.equals(attachment.encryption))
|
||||
db.message().setMessageEncrypt(message.id, EntityMessage.PGP_SIGNONLY);
|
||||
else if (EntityAttachment.PGP_MESSAGE.equals(attachment.encryption))
|
||||
db.message().setMessageEncrypt(message.id, EntityMessage.PGP_SIGNENCRYPT);
|
||||
}
|
||||
|
||||
runRules(context, imessage, message, rules);
|
||||
|
|
|
@ -80,9 +80,9 @@ import static androidx.room.ForeignKey.SET_NULL;
|
|||
public class EntityMessage implements Serializable {
|
||||
static final String TABLE_NAME = "message";
|
||||
|
||||
static final Integer ENCRYPTION_NONE = 0;
|
||||
static final Integer ENCRYPTION_SIGNENCRYPT = 1;
|
||||
static final Integer ENCRYPTION_SIGNONLY = 2;
|
||||
static final Integer ENCRYPT_NONE = 0;
|
||||
static final Integer PGP_SIGNENCRYPT = 1;
|
||||
static final Integer PGP_SIGNONLY = 2;
|
||||
|
||||
static final Integer PRIORITIY_LOW = 0;
|
||||
static final Integer PRIORITIY_NORMAL = 1;
|
||||
|
|
|
@ -121,7 +121,7 @@ public class EntityOperation {
|
|||
for (Object value : values)
|
||||
jargs.put(value);
|
||||
|
||||
if (MOVE.equals(name) && EntityMessage.ENCRYPTION_SIGNENCRYPT.equals(message.encrypt)) {
|
||||
if (MOVE.equals(name) && EntityMessage.PGP_SIGNENCRYPT.equals(message.encrypt)) {
|
||||
EntityFolder folder = db.folder().getFolder(message.folder);
|
||||
if (folder != null && EntityFolder.DRAFTS.equals(folder.type))
|
||||
name = DELETE;
|
||||
|
|
|
@ -936,17 +936,17 @@ public class FragmentCompose extends FragmentBase {
|
|||
int colorEncrypt = Helper.resolveColor(getContext(), R.attr.colorEncrypt);
|
||||
ImageButton ib = (ImageButton) menu.findItem(R.id.menu_encrypt).getActionView();
|
||||
ib.setEnabled(!busy);
|
||||
ib.setImageResource(EntityMessage.ENCRYPTION_SIGNENCRYPT.equals(encrypt)
|
||||
ib.setImageResource(EntityMessage.PGP_SIGNENCRYPT.equals(encrypt)
|
||||
? R.drawable.baseline_lock_24 : R.drawable.baseline_lock_open_24);
|
||||
ib.setImageTintList(EntityMessage.ENCRYPTION_SIGNENCRYPT.equals(encrypt)
|
||||
ib.setImageTintList(EntityMessage.PGP_SIGNENCRYPT.equals(encrypt)
|
||||
? ColorStateList.valueOf(colorEncrypt) : null);
|
||||
|
||||
menu.findItem(R.id.menu_media).setChecked(media);
|
||||
menu.findItem(R.id.menu_compact).setChecked(compact);
|
||||
|
||||
if (EntityMessage.ENCRYPTION_SIGNONLY.equals(encrypt))
|
||||
if (EntityMessage.PGP_SIGNONLY.equals(encrypt))
|
||||
bottom_navigation.getMenu().findItem(R.id.action_send).setTitle(R.string.title_sign);
|
||||
else if (EntityMessage.ENCRYPTION_SIGNENCRYPT.equals(encrypt))
|
||||
else if (EntityMessage.PGP_SIGNENCRYPT.equals(encrypt))
|
||||
bottom_navigation.getMenu().findItem(R.id.action_send).setTitle(R.string.title_encrypt);
|
||||
else
|
||||
bottom_navigation.getMenu().findItem(R.id.action_send).setTitle(R.string.title_send);
|
||||
|
@ -999,8 +999,8 @@ public class FragmentCompose extends FragmentBase {
|
|||
}
|
||||
|
||||
private void onMenuEncrypt() {
|
||||
encrypt = (EntityMessage.ENCRYPTION_SIGNENCRYPT.equals(encrypt)
|
||||
? EntityMessage.ENCRYPTION_NONE : EntityMessage.ENCRYPTION_SIGNENCRYPT);
|
||||
encrypt = (EntityMessage.PGP_SIGNENCRYPT.equals(encrypt)
|
||||
? EntityMessage.ENCRYPT_NONE : EntityMessage.PGP_SIGNENCRYPT);
|
||||
getActivity().invalidateOptionsMenu();
|
||||
|
||||
Bundle args = new Bundle();
|
||||
|
@ -1014,7 +1014,7 @@ public class FragmentCompose extends FragmentBase {
|
|||
int encrypt = args.getInt("encrypt");
|
||||
|
||||
DB db = DB.getInstance(context);
|
||||
if (EntityMessage.ENCRYPTION_NONE.equals(encrypt))
|
||||
if (EntityMessage.ENCRYPT_NONE.equals(encrypt))
|
||||
db.message().setMessageEncrypt(id, null);
|
||||
else
|
||||
db.message().setMessageEncrypt(id, encrypt);
|
||||
|
@ -1217,10 +1217,10 @@ public class FragmentCompose extends FragmentBase {
|
|||
}
|
||||
|
||||
Intent intent;
|
||||
if (EntityMessage.ENCRYPTION_SIGNONLY.equals(draft.encrypt)) {
|
||||
if (EntityMessage.PGP_SIGNONLY.equals(draft.encrypt)) {
|
||||
intent = new Intent(OpenPgpApi.ACTION_GET_SIGN_KEY_ID);
|
||||
intent.putExtra(BuildConfig.APPLICATION_ID, working);
|
||||
} else if (EntityMessage.ENCRYPTION_SIGNENCRYPT.equals(draft.encrypt)) {
|
||||
} else if (EntityMessage.PGP_SIGNENCRYPT.equals(draft.encrypt)) {
|
||||
intent = new Intent(OpenPgpApi.ACTION_GET_KEY_IDS);
|
||||
intent.putExtra(OpenPgpApi.EXTRA_USER_IDS, pgpUserIds);
|
||||
intent.putExtra(BuildConfig.APPLICATION_ID, working);
|
||||
|
@ -1515,9 +1515,9 @@ public class FragmentCompose extends FragmentBase {
|
|||
File output = new File(context.getCacheDir(), "output." + id);
|
||||
|
||||
// Serializing messages is NOT reproducible
|
||||
if ((EntityMessage.ENCRYPTION_SIGNONLY.equals(draft.encrypt) &&
|
||||
if ((EntityMessage.PGP_SIGNONLY.equals(draft.encrypt) &&
|
||||
OpenPgpApi.ACTION_GET_SIGN_KEY_ID.equals(data.getAction())) ||
|
||||
(EntityMessage.ENCRYPTION_SIGNENCRYPT.equals(draft.encrypt) &&
|
||||
(EntityMessage.PGP_SIGNENCRYPT.equals(draft.encrypt) &&
|
||||
OpenPgpApi.ACTION_GET_KEY_IDS.equals(data.getAction()))) {
|
||||
// Get attachments
|
||||
List<EntityAttachment> attachments = db.attachment().getAttachments(id);
|
||||
|
@ -1654,7 +1654,7 @@ public class FragmentCompose extends FragmentBase {
|
|||
|
||||
if (OpenPgpApi.ACTION_GET_KEY.equals(data.getAction()) ||
|
||||
(OpenPgpApi.ACTION_GET_KEY_IDS.equals(data.getAction()) && pgpKeyIds.length > 1)) {
|
||||
if (EntityMessage.ENCRYPTION_SIGNONLY.equals(draft.encrypt)) {
|
||||
if (EntityMessage.PGP_SIGNONLY.equals(draft.encrypt)) {
|
||||
// Sign message
|
||||
Intent intent = new Intent(OpenPgpApi.ACTION_DETACHED_SIGN);
|
||||
intent.putExtra(OpenPgpApi.EXTRA_SIGN_KEY_ID, pgpSignKeyId);
|
||||
|
@ -1682,14 +1682,14 @@ public class FragmentCompose extends FragmentBase {
|
|||
pgpSignKeyId = result.getLongExtra(OpenPgpApi.EXTRA_SIGN_KEY_ID, -1);
|
||||
db.identity().setIdentitySignKey(identity.id, pgpSignKeyId);
|
||||
|
||||
if (EntityMessage.ENCRYPTION_SIGNONLY.equals(draft.encrypt)) {
|
||||
if (EntityMessage.PGP_SIGNONLY.equals(draft.encrypt)) {
|
||||
// Get sign key
|
||||
Intent intent = new Intent(OpenPgpApi.ACTION_GET_KEY);
|
||||
intent.putExtra(OpenPgpApi.EXTRA_KEY_ID, pgpSignKeyId);
|
||||
intent.putExtra(OpenPgpApi.EXTRA_REQUEST_ASCII_ARMOR, true);
|
||||
intent.putExtra(BuildConfig.APPLICATION_ID, id);
|
||||
return intent;
|
||||
} else if (EntityMessage.ENCRYPTION_SIGNENCRYPT.equals(draft.encrypt)) {
|
||||
} else if (EntityMessage.PGP_SIGNENCRYPT.equals(draft.encrypt)) {
|
||||
// Encrypt message
|
||||
Intent intent = new Intent(OpenPgpApi.ACTION_SIGN_AND_ENCRYPT);
|
||||
intent.putExtra(OpenPgpApi.EXTRA_KEY_IDS, pgpKeyIds);
|
||||
|
@ -2232,7 +2232,7 @@ public class FragmentCompose extends FragmentBase {
|
|||
if (plain_only)
|
||||
data.draft.plain_only = true;
|
||||
if (encrypt_default)
|
||||
data.draft.encrypt = EntityMessage.ENCRYPTION_SIGNENCRYPT;
|
||||
data.draft.encrypt = EntityMessage.PGP_SIGNENCRYPT;
|
||||
if (receipt_default)
|
||||
data.draft.receipt_request = true;
|
||||
|
||||
|
@ -3916,7 +3916,7 @@ public class FragmentCompose extends FragmentBase {
|
|||
cbPlainOnly.setVisibility(draft.receipt != null && draft.receipt ? View.GONE : View.VISIBLE);
|
||||
cbReceipt.setVisibility(draft.receipt != null && draft.receipt ? View.GONE : View.VISIBLE);
|
||||
|
||||
int encrypt = (draft.encrypt == null ? EntityMessage.ENCRYPTION_NONE : draft.encrypt);
|
||||
int encrypt = (draft.encrypt == null ? EntityMessage.ENCRYPT_NONE : draft.encrypt);
|
||||
for (int i = 0; i < encryptValues.length; i++)
|
||||
if (encryptValues[i] == encrypt) {
|
||||
spEncrypt.setTag(i);
|
||||
|
|
|
@ -4112,12 +4112,14 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences.
|
|||
return null;
|
||||
|
||||
InputStream in = null;
|
||||
OutputStream out = null;
|
||||
boolean inline = false;
|
||||
File plain = File.createTempFile("plain", "." + message.id, context.getCacheDir());
|
||||
|
||||
// Find encrypted data
|
||||
for (EntityAttachment attachment : attachments)
|
||||
if (EntityAttachment.PGP_MESSAGE.equals(attachment.encryption) ||
|
||||
EntityAttachment.PGP_CONTENT.equals(attachment.encryption)) {
|
||||
if (EntityAttachment.PGP_CONTENT.equals(attachment.encryption) ||
|
||||
EntityAttachment.PGP_MESSAGE.equals(attachment.encryption)) {
|
||||
if (!attachment.available)
|
||||
if (auto)
|
||||
return null;
|
||||
|
@ -4126,14 +4128,17 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences.
|
|||
|
||||
File file = attachment.getFile(context);
|
||||
in = new FileInputStream(file);
|
||||
break;
|
||||
|
||||
if (EntityAttachment.PGP_MESSAGE.equals(attachment.encryption))
|
||||
out = new FileOutputStream(plain);
|
||||
|
||||
} else if (EntityAttachment.PGP_SIGNATURE.equals(attachment.encryption)) {
|
||||
File file = attachment.getFile(context);
|
||||
byte[] signature = new byte[(int) file.length()];
|
||||
try (FileInputStream fis = new FileInputStream(file)) {
|
||||
fis.read(signature);
|
||||
}
|
||||
data.putExtra(OpenPgpApi.ACTION_DETACHED_SIGN, signature);
|
||||
data.putExtra(OpenPgpApi.EXTRA_DETACHED_SIGNATURE, signature);
|
||||
}
|
||||
|
||||
if (in == null) {
|
||||
|
@ -4167,74 +4172,74 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences.
|
|||
throw new IllegalArgumentException(context.getString(R.string.title_not_encrypted));
|
||||
|
||||
Intent result;
|
||||
File plain = File.createTempFile("plain", "." + message.id, context.getCacheDir());
|
||||
try {
|
||||
// Decrypt message
|
||||
Log.i("Executing " + data.getAction());
|
||||
Log.logExtras(data);
|
||||
OpenPgpApi api = new OpenPgpApi(context, pgpService.getService());
|
||||
result = api.executeApi(data, in, new FileOutputStream(plain));
|
||||
result = api.executeApi(data, in, out);
|
||||
|
||||
int resultCode = result.getIntExtra(OpenPgpApi.RESULT_CODE, OpenPgpApi.RESULT_CODE_ERROR);
|
||||
Log.i("Result action=" + data.getAction() + " code=" + resultCode);
|
||||
Log.logExtras(data);
|
||||
switch (resultCode) {
|
||||
case OpenPgpApi.RESULT_CODE_SUCCESS:
|
||||
if (inline) {
|
||||
try {
|
||||
db.beginTransaction();
|
||||
if (out != null)
|
||||
if (inline) {
|
||||
try {
|
||||
db.beginTransaction();
|
||||
|
||||
// Write decrypted body
|
||||
Helper.copy(plain, message.getFile(context));
|
||||
db.message().setMessageStored(message.id, new Date().getTime());
|
||||
// Write decrypted body
|
||||
Helper.copy(plain, message.getFile(context));
|
||||
db.message().setMessageStored(message.id, new Date().getTime());
|
||||
|
||||
db.setTransactionSuccessful();
|
||||
} finally {
|
||||
db.endTransaction();
|
||||
}
|
||||
|
||||
} else {
|
||||
// Decode message
|
||||
MessageHelper.MessageParts parts;
|
||||
Properties props = MessageHelper.getSessionProperties();
|
||||
Session isession = Session.getInstance(props, null);
|
||||
try (InputStream fis = new FileInputStream(plain)) {
|
||||
MimeMessage imessage = new MimeMessage(isession, fis);
|
||||
MessageHelper helper = new MessageHelper(imessage);
|
||||
parts = helper.getMessageParts();
|
||||
}
|
||||
|
||||
try {
|
||||
db.beginTransaction();
|
||||
|
||||
// Write decrypted body
|
||||
String html = parts.getHtml(context);
|
||||
Helper.writeText(message.getFile(context), html);
|
||||
|
||||
// Remove existing attachments
|
||||
db.attachment().deleteAttachments(message.id);
|
||||
|
||||
// Add decrypted attachments
|
||||
List<EntityAttachment> remotes = parts.getAttachments();
|
||||
for (int index = 0; index < remotes.size(); index++) {
|
||||
EntityAttachment remote = remotes.get(index);
|
||||
remote.message = message.id;
|
||||
remote.sequence = index + 1;
|
||||
remote.id = db.attachment().insertAttachment(remote);
|
||||
try {
|
||||
parts.downloadAttachment(context, index, remote);
|
||||
} catch (Throwable ex) {
|
||||
Log.e(ex);
|
||||
}
|
||||
db.setTransactionSuccessful();
|
||||
} finally {
|
||||
db.endTransaction();
|
||||
}
|
||||
|
||||
db.message().setMessageStored(message.id, new Date().getTime());
|
||||
} else {
|
||||
// Decode message
|
||||
MessageHelper.MessageParts parts;
|
||||
Properties props = MessageHelper.getSessionProperties();
|
||||
Session isession = Session.getInstance(props, null);
|
||||
try (InputStream fis = new FileInputStream(plain)) {
|
||||
MimeMessage imessage = new MimeMessage(isession, fis);
|
||||
MessageHelper helper = new MessageHelper(imessage);
|
||||
parts = helper.getMessageParts();
|
||||
}
|
||||
|
||||
db.setTransactionSuccessful();
|
||||
} finally {
|
||||
db.endTransaction();
|
||||
try {
|
||||
db.beginTransaction();
|
||||
|
||||
// Write decrypted body
|
||||
String html = parts.getHtml(context);
|
||||
Helper.writeText(message.getFile(context), html);
|
||||
|
||||
// Remove existing attachments
|
||||
db.attachment().deleteAttachments(message.id);
|
||||
|
||||
// Add decrypted attachments
|
||||
List<EntityAttachment> remotes = parts.getAttachments();
|
||||
for (int index = 0; index < remotes.size(); index++) {
|
||||
EntityAttachment remote = remotes.get(index);
|
||||
remote.message = message.id;
|
||||
remote.sequence = index + 1;
|
||||
remote.id = db.attachment().insertAttachment(remote);
|
||||
try {
|
||||
parts.downloadAttachment(context, index, remote);
|
||||
} catch (Throwable ex) {
|
||||
Log.e(ex);
|
||||
}
|
||||
}
|
||||
|
||||
db.message().setMessageStored(message.id, new Date().getTime());
|
||||
|
||||
db.setTransactionSuccessful();
|
||||
} finally {
|
||||
db.endTransaction();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Check signature status
|
||||
OpenPgpSignatureResult sigResult = result.getParcelableExtra(OpenPgpApi.RESULT_SIGNATURE);
|
||||
|
|
|
@ -345,7 +345,8 @@ public class Log {
|
|||
elements[i] = (element == null ? null : element.toString());
|
||||
}
|
||||
value = TextUtils.join(",", elements);
|
||||
}
|
||||
} else
|
||||
value = "[" + length + "]";
|
||||
} else if (v instanceof Long)
|
||||
value = "0x" + Long.toHexString((Long) v);
|
||||
|
||||
|
|
|
@ -1243,7 +1243,7 @@ public class MessageHelper {
|
|||
|
||||
AttachmentPart apart = new AttachmentPart();
|
||||
apart.disposition = Part.INLINE;
|
||||
apart.filename = "content.txt";
|
||||
apart.filename = "content.asc";
|
||||
apart.encrypt = EntityAttachment.PGP_CONTENT;
|
||||
apart.part = multipart.getBodyPart(0);
|
||||
|
||||
|
@ -1253,6 +1253,7 @@ public class MessageHelper {
|
|||
apart.attachment.disposition = apart.disposition;
|
||||
apart.attachment.name = apart.filename;
|
||||
apart.attachment.type = ct.getBaseType().toLowerCase(Locale.ROOT);
|
||||
apart.attachment.size = (long) apart.part.getSize();
|
||||
apart.attachment.encryption = apart.encrypt;
|
||||
|
||||
parts.attachments.add(apart);
|
||||
|
|
|
@ -694,7 +694,7 @@
|
|||
<string name="title_decrypt">Decrypt</string>
|
||||
<string name="title_resync">Resync</string>
|
||||
<string name="title_no_openpgp">OpenKeychain not found</string>
|
||||
<string name="title_not_encrypted">Message is not encrypted</string>
|
||||
<string name="title_not_encrypted">Message is not signed or encrypted</string>
|
||||
<string name="title_reset_sign_key">Reset sign key</string>
|
||||
<string name="title_import_encrypt_key">Import encryption key</string>
|
||||
|
||||
|
|
Loading…
Reference in a new issue