Default encrypt on replying to encrypted message

This commit is contained in:
M66B
2019-07-16 18:46:25 +02:00
parent 369a476513
commit a8215cd7bd
8 changed files with 1867 additions and 7 deletions

View File

@@ -54,7 +54,7 @@ import io.requery.android.database.sqlite.RequerySQLiteOpenHelperFactory;
// https://developer.android.com/topic/libraries/architecture/room.html
@Database(
version = 93,
version = 94,
entities = {
EntityIdentity.class,
EntityAccount.class,
@@ -911,6 +911,13 @@ public abstract class DB extends RoomDatabase {
db.execSQL("ALTER TABLE `message` ADD COLUMN `mx` INTEGER");
}
})
.addMigrations(new Migration(93, 94) {
@Override
public void migrate(SupportSQLiteDatabase db) {
Log.i("DB migration from version " + startVersion + " to " + endVersion);
db.execSQL("ALTER TABLE `message` ADD COLUMN `encrypt` INTEGER");
}
})
.build();
}

View File

@@ -410,6 +410,9 @@ public interface DaoMessage {
@Query("UPDATE message SET plain_only = :plain_only WHERE id = :id")
int setMessagePlainOnly(long id, boolean plain_only);
@Query("UPDATE message SET encrypt = :encrypt WHERE id = :id")
int setMessageEncrypt(long id, boolean encrypt);
@Query("UPDATE message SET last_attempt = :last_attempt WHERE id = :id")
int setMessageLastAttempt(long id, long last_attempt);

View File

@@ -115,6 +115,7 @@ public class EntityMessage implements Serializable {
@NonNull
public Boolean content = false;
public Boolean plain_only = null;
public Boolean encrypt = null;
public String preview;
public Long sent; // compose = null
@NonNull

View File

@@ -796,6 +796,7 @@ public class FragmentCompose extends FragmentBase {
menu.findItem(R.id.menu_plain_only).setChecked(plain_only);
menu.findItem(R.id.menu_encrypt).setChecked(encrypt);
bottom_navigation.getMenu().findItem(R.id.action_send)
.setTitle(encrypt ? R.string.title_encrypt : R.string.title_send);
}
@@ -918,6 +919,7 @@ public class FragmentCompose extends FragmentBase {
private void onMenuEncrypt() {
encrypt = !encrypt;
getActivity().invalidateOptionsMenu();
onAction(R.id.action_save);
}
private void onMenuSendAfter() {
@@ -1744,6 +1746,7 @@ public class FragmentCompose extends FragmentBase {
args.putString("subject", etSubject.getText().toString().trim());
args.putString("body", HtmlHelper.toHtml(etBody.getText()));
args.putBoolean("plain_only", plain_only);
args.putBoolean("encrypt", encrypt);
args.putBoolean("empty", isEmpty());
Log.i("Run execute id=" + working);
@@ -2174,7 +2177,12 @@ public class FragmentCompose extends FragmentBase {
int sequence = 0;
List<EntityAttachment> attachments = db.attachment().getAttachments(ref.id);
for (EntityAttachment attachment : attachments)
if (attachment.encryption == null &&
if (attachment.encryption != null &&
attachment.encryption.equals(EntityAttachment.PGP_MESSAGE)) {
draft.encrypt = true;
db.message().setMessageEncrypt(draft.id, true);
} else if (attachment.encryption == null &&
("forward".equals(action) ||
(attachment.isInline() && attachment.isImage()))) {
if (attachment.available) {
@@ -2241,6 +2249,7 @@ public class FragmentCompose extends FragmentBase {
bottom_navigation.getMenu().findItem(R.id.action_redo).setVisible(draft.revision != null && !draft.revision.equals(draft.revisions));
plain_only = (draft.plain_only != null && draft.plain_only);
encrypt = (draft.encrypt != null && draft.encrypt);
getActivity().invalidateOptionsMenu();
if (args.getBoolean("incomplete"))
@@ -2402,6 +2411,7 @@ public class FragmentCompose extends FragmentBase {
String subject = args.getString("subject");
String body = args.getString("body");
boolean plain_only = args.getBoolean("plain_only");
boolean encrypt = args.getBoolean("encrypt");
boolean empty = args.getBoolean("empty");
EntityMessage draft;
@@ -2520,6 +2530,7 @@ public class FragmentCompose extends FragmentBase {
!MessageHelper.equal(draft.cc, acc) ||
!MessageHelper.equal(draft.bcc, abcc) ||
!Objects.equals(draft.subject, subject) ||
((draft.encrypt != null && draft.encrypt) != encrypt) ||
last_available != available);
last_available = available;
@@ -2533,6 +2544,7 @@ public class FragmentCompose extends FragmentBase {
draft.cc = acc;
draft.bcc = abcc;
draft.subject = subject;
draft.encrypt = encrypt;
draft.received = new Date().getTime();
draft.sender = MessageHelper.getSortKey(draft.from);
Uri lookupUri = ContactInfo.getLookupUri(context, draft.from);
@@ -3069,8 +3081,10 @@ public class FragmentCompose extends FragmentBase {
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
EntityIdentity identity = (EntityIdentity) parent.getAdapter().getItem(position);
encrypt = (identity != null && identity.encrypt && Helper.isPro(getContext()));
getActivity().invalidateOptionsMenu();
if (identity != null && identity.encrypt) {
encrypt = true;
getActivity().invalidateOptionsMenu();
}
int at = (identity == null ? -1 : identity.email.indexOf('@'));
etExtra.setHint(at < 0 ? null : identity.email.substring(0, at));

View File

@@ -116,6 +116,7 @@ public class FragmentIdentity extends FragmentBase {
private CheckBox cbSenderExtra;
private EditText etReplyTo;
private EditText etBcc;
private TextView tvEncryptPro;
private CheckBox cbEncrypt;
private CheckBox cbDeliveryReceipt;
private CheckBox cbReadReceipt;
@@ -193,6 +194,7 @@ public class FragmentIdentity extends FragmentBase {
cbSenderExtra = view.findViewById(R.id.cbSenderExtra);
etReplyTo = view.findViewById(R.id.etReplyTo);
etBcc = view.findViewById(R.id.etBcc);
tvEncryptPro = view.findViewById(R.id.tvEncryptPro);
cbEncrypt = view.findViewById(R.id.cbEncrypt);
cbDeliveryReceipt = view.findViewById(R.id.cbDeliveryReceipt);
cbReadReceipt = view.findViewById(R.id.cbReadReceipt);
@@ -423,6 +425,8 @@ public class FragmentIdentity extends FragmentBase {
cbInsecure.setVisibility(View.GONE);
tilPassword.setEndIconMode(id < 0 ? END_ICON_PASSWORD_TOGGLE : END_ICON_NONE);
Helper.linkPro(tvEncryptPro);
btnAdvanced.setVisibility(View.GONE);
btnSave.setVisibility(View.GONE);

View File

@@ -824,7 +824,7 @@ public class Helper {
}
static void linkPro(final TextView tv) {
if (isPro(tv.getContext()))
if (isPro(tv.getContext()) && !BuildConfig.DEBUG)
hide(tv);
else {
final Intent pro = new Intent(Intent.ACTION_VIEW, Uri.parse(BuildConfig.PRO_FEATURES_URI));