mirror of https://github.com/M66B/FairEmail.git
Added semi automatic encryption
This commit is contained in:
parent
966e3ab20b
commit
a07bc15f38
File diff suppressed because it is too large
Load Diff
|
@ -49,7 +49,7 @@ import io.requery.android.database.sqlite.RequerySQLiteOpenHelperFactory;
|
|||
// https://developer.android.com/topic/libraries/architecture/room.html
|
||||
|
||||
@Database(
|
||||
version = 45,
|
||||
version = 46,
|
||||
entities = {
|
||||
EntityIdentity.class,
|
||||
EntityAccount.class,
|
||||
|
@ -519,6 +519,13 @@ public abstract class DB extends RoomDatabase {
|
|||
db.execSQL("ALTER TABLE `account` ADD COLUMN `ondemand` INTEGER NOT NULL DEFAULT 0");
|
||||
}
|
||||
})
|
||||
.addMigrations(new Migration(45, 46) {
|
||||
@Override
|
||||
public void migrate(SupportSQLiteDatabase db) {
|
||||
Log.i("DB migration from version " + startVersion + " to " + endVersion);
|
||||
db.execSQL("ALTER TABLE `identity` ADD COLUMN `encrypt` INTEGER NOT NULL DEFAULT 0");
|
||||
}
|
||||
})
|
||||
.build();
|
||||
}
|
||||
|
||||
|
|
|
@ -78,6 +78,8 @@ public class EntityIdentity {
|
|||
@NonNull
|
||||
public Boolean plain_only = false;
|
||||
@NonNull
|
||||
public Boolean encrypt = false;
|
||||
@NonNull
|
||||
public Boolean delivery_receipt = false;
|
||||
@NonNull
|
||||
public Boolean read_receipt = false;
|
||||
|
@ -120,6 +122,7 @@ public class EntityIdentity {
|
|||
json.put("bcc", bcc);
|
||||
|
||||
json.put("plain_only", plain_only);
|
||||
json.put("encrypt", encrypt);
|
||||
json.put("delivery_receipt", delivery_receipt);
|
||||
json.put("read_receipt", read_receipt);
|
||||
json.put("store_sent", store_sent);
|
||||
|
@ -160,6 +163,8 @@ public class EntityIdentity {
|
|||
|
||||
if (json.has("plain_only"))
|
||||
identity.plain_only = json.getBoolean("plain_only");
|
||||
if (json.has("encrypt"))
|
||||
identity.encrypt = json.getBoolean("encrypt");
|
||||
if (json.has("delivery_receipt"))
|
||||
identity.delivery_receipt = json.getBoolean("delivery_receipt");
|
||||
if (json.has("read_receipt"))
|
||||
|
@ -193,6 +198,8 @@ public class EntityIdentity {
|
|||
this.primary.equals(other.primary) &&
|
||||
(this.replyto == null ? other.replyto == null : this.replyto.equals(other.replyto)) &&
|
||||
(this.bcc == null ? other.bcc == null : this.bcc.equals(other.bcc)) &&
|
||||
this.plain_only.equals(other.plain_only) &&
|
||||
this.encrypt.equals(other.encrypt) &&
|
||||
this.delivery_receipt.equals(other.delivery_receipt) &&
|
||||
this.read_receipt.equals(other.read_receipt) &&
|
||||
this.store_sent.equals(other.store_sent) &&
|
||||
|
|
|
@ -174,6 +174,7 @@ public class FragmentCompose extends FragmentBase {
|
|||
private boolean autosave = false;
|
||||
private boolean busy = false;
|
||||
|
||||
private boolean encrypt = false;
|
||||
private OpenPgpServiceConnection pgpService;
|
||||
|
||||
private static final int REDUCED_IMAGE_SIZE = 1280;
|
||||
|
@ -225,9 +226,14 @@ public class FragmentCompose extends FragmentBase {
|
|||
@Override
|
||||
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
|
||||
EntityIdentity identity = (EntityIdentity) parent.getAdapter().getItem(position);
|
||||
|
||||
encrypt = (identity != null && identity.encrypt);
|
||||
getActivity().invalidateOptionsMenu();
|
||||
|
||||
int at = (identity == null ? -1 : identity.email.indexOf('@'));
|
||||
etExtra.setHint(at < 0 ? null : identity.email.substring(0, at));
|
||||
tvDomain.setText(at < 0 ? null : identity.email.substring(at));
|
||||
|
||||
Spanned signature = null;
|
||||
if (pro) {
|
||||
if (identity != null && !TextUtils.isEmpty(identity.signature))
|
||||
|
@ -248,8 +254,12 @@ public class FragmentCompose extends FragmentBase {
|
|||
|
||||
@Override
|
||||
public void onNothingSelected(AdapterView<?> parent) {
|
||||
encrypt = false;
|
||||
getActivity().invalidateOptionsMenu();
|
||||
|
||||
etExtra.setHint("");
|
||||
tvDomain.setText(null);
|
||||
|
||||
tvSignature.setText(null);
|
||||
grpSignature.setVisibility(View.GONE);
|
||||
}
|
||||
|
@ -717,6 +727,10 @@ public class FragmentCompose extends FragmentBase {
|
|||
menu.findItem(R.id.menu_clear).setEnabled(!busy);
|
||||
menu.findItem(R.id.menu_encrypt).setEnabled(!busy);
|
||||
menu.findItem(R.id.menu_send_after).setEnabled(!busy);
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -736,7 +750,8 @@ public class FragmentCompose extends FragmentBase {
|
|||
onMenuStyle(item.getItemId());
|
||||
return true;
|
||||
case R.id.menu_encrypt:
|
||||
onAction(R.id.menu_encrypt);
|
||||
encrypt = !encrypt;
|
||||
getActivity().invalidateOptionsMenu();
|
||||
return true;
|
||||
case R.id.menu_send_after:
|
||||
onMenuSendAfter();
|
||||
|
@ -910,7 +925,7 @@ public class FragmentCompose extends FragmentBase {
|
|||
final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getContext());
|
||||
boolean autosend = prefs.getBoolean("autosend", false);
|
||||
if (autosend) {
|
||||
onAction(R.id.action_send);
|
||||
onActionSendConfirmed();
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -938,16 +953,23 @@ public class FragmentCompose extends FragmentBase {
|
|||
public void onClick(DialogInterface dialog, int which) {
|
||||
if (cbNotAgain.isChecked())
|
||||
prefs.edit().putBoolean("autosend", true).apply();
|
||||
onAction(R.id.action_send);
|
||||
onActionSendConfirmed();
|
||||
}
|
||||
})
|
||||
.setNegativeButton(android.R.string.cancel, null)
|
||||
.show();
|
||||
} catch (Throwable ex) {
|
||||
onAction(R.id.action_send);
|
||||
onActionSendConfirmed();
|
||||
}
|
||||
}
|
||||
|
||||
private void onActionSendConfirmed() {
|
||||
if (encrypt)
|
||||
onAction(R.id.menu_encrypt);
|
||||
else
|
||||
onAction(R.id.action_send);
|
||||
}
|
||||
|
||||
private void onEncrypt() {
|
||||
if (Helper.isPro(getContext())) {
|
||||
if (pgpService.isBound())
|
||||
|
@ -1118,7 +1140,9 @@ public class FragmentCompose extends FragmentBase {
|
|||
|
||||
@Override
|
||||
protected void onExecuted(Bundle args, PendingIntent pi) {
|
||||
if (pi != null)
|
||||
if (pi == null)
|
||||
onAction(R.id.action_send);
|
||||
else
|
||||
try {
|
||||
startIntentSenderForResult(
|
||||
pi.getIntentSender(),
|
||||
|
|
|
@ -99,6 +99,7 @@ public class FragmentIdentity extends FragmentBase {
|
|||
private EditText etReplyTo;
|
||||
private EditText etBcc;
|
||||
private CheckBox cbPlainOnly;
|
||||
private CheckBox cbEncrypt;
|
||||
private CheckBox cbDeliveryReceipt;
|
||||
private CheckBox cbReadReceipt;
|
||||
|
||||
|
@ -166,6 +167,7 @@ public class FragmentIdentity extends FragmentBase {
|
|||
etReplyTo = view.findViewById(R.id.etReplyTo);
|
||||
etBcc = view.findViewById(R.id.etBcc);
|
||||
cbPlainOnly = view.findViewById(R.id.cbPlainOnly);
|
||||
cbEncrypt = view.findViewById(R.id.cbEncrypt);
|
||||
cbDeliveryReceipt = view.findViewById(R.id.cbDeliveryReceipt);
|
||||
cbReadReceipt = view.findViewById(R.id.cbReadReceipt);
|
||||
|
||||
|
@ -465,6 +467,7 @@ public class FragmentIdentity extends FragmentBase {
|
|||
args.putString("replyto", etReplyTo.getText().toString().trim());
|
||||
args.putString("bcc", etBcc.getText().toString().trim());
|
||||
args.putBoolean("plain_only", cbPlainOnly.isChecked());
|
||||
args.putBoolean("encrypt", cbEncrypt.isChecked());
|
||||
args.putBoolean("delivery_receipt", cbDeliveryReceipt.isChecked());
|
||||
args.putBoolean("read_receipt", cbReadReceipt.isChecked());
|
||||
args.putBoolean("store_sent", cbStoreSent.isChecked());
|
||||
|
@ -525,6 +528,7 @@ public class FragmentIdentity extends FragmentBase {
|
|||
String replyto = args.getString("replyto");
|
||||
String bcc = args.getString("bcc");
|
||||
boolean plain_only = args.getBoolean("plain_only");
|
||||
boolean encrypt = args.getBoolean("encrypt");
|
||||
boolean delivery_receipt = args.getBoolean("delivery_receipt");
|
||||
boolean read_receipt = args.getBoolean("read_receipt");
|
||||
boolean store_sent = args.getBoolean("store_sent");
|
||||
|
@ -630,6 +634,7 @@ public class FragmentIdentity extends FragmentBase {
|
|||
identity.replyto = replyto;
|
||||
identity.bcc = bcc;
|
||||
identity.plain_only = plain_only;
|
||||
identity.encrypt = encrypt;
|
||||
identity.delivery_receipt = delivery_receipt;
|
||||
identity.read_receipt = read_receipt;
|
||||
identity.store_sent = store_sent;
|
||||
|
@ -732,6 +737,7 @@ public class FragmentIdentity extends FragmentBase {
|
|||
etReplyTo.setText(identity == null ? null : identity.replyto);
|
||||
etBcc.setText(identity == null ? null : identity.bcc);
|
||||
cbPlainOnly.setChecked(identity == null ? false : identity.plain_only);
|
||||
cbEncrypt.setChecked(identity == null ? false : identity.encrypt);
|
||||
cbDeliveryReceipt.setChecked(identity == null ? false : identity.delivery_receipt);
|
||||
cbReadReceipt.setChecked(identity == null ? false : identity.read_receipt);
|
||||
cbStoreSent.setChecked(identity == null ? false : identity.store_sent);
|
||||
|
|
|
@ -457,6 +457,15 @@
|
|||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@id/etBcc" />
|
||||
|
||||
<CheckBox
|
||||
android:id="@+id/cbEncrypt"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="12dp"
|
||||
android:text="@string/title_identity_encrypt"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@id/cbPlainOnly" />
|
||||
|
||||
<CheckBox
|
||||
android:id="@+id/cbDeliveryReceipt"
|
||||
android:layout_width="wrap_content"
|
||||
|
@ -464,7 +473,7 @@
|
|||
android:layout_marginTop="12dp"
|
||||
android:text="@string/title_identity_delivery_receipt"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@id/cbPlainOnly" />
|
||||
app:layout_constraintTop_toBottomOf="@id/cbEncrypt" />
|
||||
|
||||
<CheckBox
|
||||
android:id="@+id/cbReadReceipt"
|
||||
|
@ -571,7 +580,7 @@
|
|||
tvRealm,etRealm,
|
||||
cbSynchronize,cbPrimary,
|
||||
tvReplyTo,etReplyTo,tvBcc,etBcc,
|
||||
cbPlainOnly,cbDeliveryReceipt,cbReadReceipt,tvReceipt,
|
||||
cbPlainOnly,cbEncrypt,cbDeliveryReceipt,cbReadReceipt,tvReceipt,
|
||||
cbStoreSent,tvStoreSent" />
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||
</ScrollView>
|
||||
|
|
|
@ -20,6 +20,7 @@
|
|||
|
||||
<item
|
||||
android:id="@+id/menu_encrypt"
|
||||
android:checkable="true"
|
||||
android:title="@string/title_encrypt"
|
||||
app:showAsAction="never" />
|
||||
|
||||
|
|
|
@ -200,6 +200,7 @@
|
|||
<string name="title_identity_email">Your email address</string>
|
||||
<string name="title_identity_reply_to">Reply to address</string>
|
||||
<string name="title_identity_plain_text">Send plain text only</string>
|
||||
<string name="title_identity_encrypt">Encrypt by default</string>
|
||||
<string name="title_identity_read_receipt">Request read receipt</string>
|
||||
<string name="title_identity_delivery_receipt">Request delivery receipt</string>
|
||||
<string name="title_identity_receipt_remark">Most providers ignore receipt requests</string>
|
||||
|
|
Loading…
Reference in New Issue