Added default sign/encrypt to identity

pull/194/head
M66B 4 years ago
parent a7041978c5
commit 7db5656037

File diff suppressed because it is too large Load Diff

@ -65,7 +65,7 @@ import static eu.faircode.email.ServiceAuthenticator.AUTH_TYPE_PASSWORD;
// https://developer.android.com/topic/libraries/architecture/room.html // https://developer.android.com/topic/libraries/architecture/room.html
@Database( @Database(
version = 188, version = 189,
entities = { entities = {
EntityIdentity.class, EntityIdentity.class,
EntityAccount.class, EntityAccount.class,
@ -1854,6 +1854,14 @@ public abstract class DB extends RoomDatabase {
Log.i("DB migration from version " + startVersion + " to " + endVersion); Log.i("DB migration from version " + startVersion + " to " + endVersion);
db.execSQL("ALTER TABLE `message` ADD COLUMN `ui_silent` INTEGER NOT NULL DEFAULT 0"); db.execSQL("ALTER TABLE `message` ADD COLUMN `ui_silent` INTEGER NOT NULL DEFAULT 0");
} }
})
.addMigrations(new Migration(188, 189) {
@Override
public void migrate(@NonNull SupportSQLiteDatabase db) {
Log.i("DB migration from version " + startVersion + " to " + endVersion);
db.execSQL("ALTER TABLE `identity` ADD COLUMN `sign_default` INTEGER NOT NULL DEFAULT 0");
db.execSQL("ALTER TABLE `identity` ADD COLUMN `encrypt_default` INTEGER NOT NULL DEFAULT 0");
}
}); });
} }

@ -104,6 +104,10 @@ public class EntityIdentity {
@NonNull @NonNull
public Boolean plain_only = false; // obsolete public Boolean plain_only = false; // obsolete
@NonNull @NonNull
public Boolean sign_default = false;
@NonNull
public Boolean encrypt_default = false;
@NonNull
public Integer encrypt = 0; // Default method 0=PGP 1=S/MIME public Integer encrypt = 0; // Default method 0=PGP 1=S/MIME
@NonNull @NonNull
public Boolean delivery_receipt = false; // obsolete public Boolean delivery_receipt = false; // obsolete

@ -3559,12 +3559,12 @@ public class FragmentCompose extends FragmentBase {
if (plain_only) if (plain_only)
data.draft.plain_only = true; data.draft.plain_only = true;
if (encrypt_default) if (encrypt_default || selected.encrypt_default)
if (selected.encrypt == 0) if (selected.encrypt == 0)
data.draft.ui_encrypt = EntityMessage.PGP_SIGNENCRYPT; data.draft.ui_encrypt = EntityMessage.PGP_SIGNENCRYPT;
else else
data.draft.ui_encrypt = EntityMessage.SMIME_SIGNENCRYPT; data.draft.ui_encrypt = EntityMessage.SMIME_SIGNENCRYPT;
else if (sign_default) else if (sign_default || selected.sign_default)
if (selected.encrypt == 0) if (selected.encrypt == 0)
data.draft.ui_encrypt = EntityMessage.PGP_SIGNONLY; data.draft.ui_encrypt = EntityMessage.PGP_SIGNONLY;
else else
@ -4176,6 +4176,7 @@ public class FragmentCompose extends FragmentBase {
if (data.draft.identity != null) if (data.draft.identity != null)
for (int pos = 0; pos < data.identities.size(); pos++) { for (int pos = 0; pos < data.identities.size(); pos++) {
if (data.identities.get(pos).id.equals(data.draft.identity)) { if (data.identities.get(pos).id.equals(data.draft.identity)) {
spIdentity.setTag(pos);
spIdentity.setSelection(pos); spIdentity.setSelection(pos);
break; break;
} }
@ -5356,7 +5357,10 @@ public class FragmentCompose extends FragmentBase {
setBodyPadding(); setBodyPadding();
updateEncryption(); if (!Objects.equals(spIdentity.getTag(), position)) {
spIdentity.setTag(position);
updateEncryption(identity);
}
} }
@Override @Override
@ -5369,11 +5373,10 @@ public class FragmentCompose extends FragmentBase {
setBodyPadding(); setBodyPadding();
updateEncryption(); updateEncryption(null);
} }
private void updateEncryption() { private void updateEncryption(EntityIdentity identity) {
EntityIdentity identity = (EntityIdentity) spIdentity.getSelectedItem();
if (identity == null) if (identity == null)
return; return;
@ -5388,35 +5391,37 @@ public class FragmentCompose extends FragmentBase {
long iid = args.getLong("identity"); long iid = args.getLong("identity");
DB db = DB.getInstance(context); DB db = DB.getInstance(context);
EntityMessage draft = db.message().getMessage(id); EntityMessage draft = db.message().getMessage(id);
if (draft == null || if (draft == null)
draft.ui_encrypt == null || EntityMessage.ENCRYPT_NONE.equals(draft.ui_encrypt))
return null; return null;
if (draft.identity != null && draft.identity.equals(iid))
return draft.ui_encrypt;
EntityIdentity identity = db.identity().getIdentity(iid); EntityIdentity identity = db.identity().getIdentity(iid);
if (identity == null) if (identity == null)
return null; return draft.ui_encrypt;
if (identity.encrypt_default)
draft.ui_encrypt = EntityMessage.PGP_SIGNENCRYPT;
else if (identity.sign_default)
draft.ui_encrypt = EntityMessage.PGP_SIGNONLY;
else
draft.ui_encrypt = null;
int encrypt = draft.ui_encrypt;
if (identity.encrypt == 0) { if (identity.encrypt == 0) {
if (EntityMessage.SMIME_SIGNONLY.equals(draft.ui_encrypt)) if (EntityMessage.SMIME_SIGNONLY.equals(draft.ui_encrypt))
encrypt = EntityMessage.PGP_SIGNONLY; draft.ui_encrypt = EntityMessage.PGP_SIGNONLY;
else if (EntityMessage.SMIME_SIGNENCRYPT.equals(draft.ui_encrypt)) else if (EntityMessage.SMIME_SIGNENCRYPT.equals(draft.ui_encrypt))
encrypt = EntityMessage.PGP_SIGNENCRYPT; draft.ui_encrypt = EntityMessage.PGP_SIGNENCRYPT;
} else { } else {
if (EntityMessage.PGP_SIGNONLY.equals(draft.ui_encrypt)) if (EntityMessage.PGP_SIGNONLY.equals(draft.ui_encrypt))
encrypt = EntityMessage.SMIME_SIGNONLY; draft.ui_encrypt = EntityMessage.SMIME_SIGNONLY;
else if (EntityMessage.PGP_SIGNENCRYPT.equals(draft.ui_encrypt)) else if (EntityMessage.PGP_SIGNENCRYPT.equals(draft.ui_encrypt))
encrypt = EntityMessage.SMIME_SIGNENCRYPT; draft.ui_encrypt = EntityMessage.SMIME_SIGNENCRYPT;
} }
if (draft.ui_encrypt != encrypt) db.message().setMessageUiEncrypt(draft.id, draft.ui_encrypt);
db.message().setMessageUiEncrypt(draft.id, encrypt);
return encrypt; return draft.ui_encrypt;
} }
@Override @Override

@ -21,6 +21,7 @@ package eu.faircode.email;
import android.content.Context; import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.content.SharedPreferences;
import android.graphics.Color; import android.graphics.Color;
import android.net.Uri; import android.net.Uri;
import android.os.Bundle; import android.os.Bundle;
@ -51,6 +52,7 @@ import androidx.annotation.NonNull;
import androidx.annotation.Nullable; import androidx.annotation.Nullable;
import androidx.constraintlayout.widget.Group; import androidx.constraintlayout.widget.Group;
import androidx.lifecycle.Lifecycle; import androidx.lifecycle.Lifecycle;
import androidx.preference.PreferenceManager;
import com.google.android.material.snackbar.Snackbar; import com.google.android.material.snackbar.Snackbar;
import com.google.android.material.textfield.TextInputLayout; import com.google.android.material.textfield.TextInputLayout;
@ -111,6 +113,8 @@ public class FragmentIdentity extends FragmentBase {
private EditText etReplyTo; private EditText etReplyTo;
private EditText etCc; private EditText etCc;
private EditText etBcc; private EditText etBcc;
private CheckBox cbSignDefault;
private CheckBox cbEncryptDefault;
private CheckBox cbUnicode; private CheckBox cbUnicode;
private EditText etMaxSize; private EditText etMaxSize;
@ -204,6 +208,8 @@ public class FragmentIdentity extends FragmentBase {
etReplyTo = view.findViewById(R.id.etReplyTo); etReplyTo = view.findViewById(R.id.etReplyTo);
etCc = view.findViewById(R.id.etCc); etCc = view.findViewById(R.id.etCc);
etBcc = view.findViewById(R.id.etBcc); etBcc = view.findViewById(R.id.etBcc);
cbSignDefault = view.findViewById(R.id.cbSignDefault);
cbEncryptDefault = view.findViewById(R.id.cbEncryptDefault);
cbUnicode = view.findViewById(R.id.cbUnicode); cbUnicode = view.findViewById(R.id.cbUnicode);
etMaxSize = view.findViewById(R.id.etMaxSize); etMaxSize = view.findViewById(R.id.etMaxSize);
@ -423,6 +429,13 @@ public class FragmentIdentity extends FragmentBase {
} }
}); });
cbEncryptDefault.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
cbSignDefault.setEnabled(!isChecked);
}
});
btnSave.setOnClickListener(new View.OnClickListener() { btnSave.setOnClickListener(new View.OnClickListener() {
@Override @Override
public void onClick(View v) { public void onClick(View v) {
@ -597,6 +610,8 @@ public class FragmentIdentity extends FragmentBase {
args.putString("replyto", etReplyTo.getText().toString().trim()); args.putString("replyto", etReplyTo.getText().toString().trim());
args.putString("cc", etCc.getText().toString().trim()); args.putString("cc", etCc.getText().toString().trim());
args.putString("bcc", etBcc.getText().toString().trim()); args.putString("bcc", etBcc.getText().toString().trim());
args.putBoolean("sign_default", cbSignDefault.isChecked());
args.putBoolean("encrypt_default", cbEncryptDefault.isChecked());
args.putBoolean("unicode", cbUnicode.isChecked()); args.putBoolean("unicode", cbUnicode.isChecked());
args.putString("max_size", etMaxSize.getText().toString()); args.putString("max_size", etMaxSize.getText().toString());
args.putLong("account", account == null ? -1 : account.id); args.putLong("account", account == null ? -1 : account.id);
@ -679,6 +694,8 @@ public class FragmentIdentity extends FragmentBase {
String replyto = args.getString("replyto"); String replyto = args.getString("replyto");
String cc = args.getString("cc"); String cc = args.getString("cc");
String bcc = args.getString("bcc"); String bcc = args.getString("bcc");
boolean sign_default = args.getBoolean("sign_default");
boolean encrypt_default = args.getBoolean("encrypt_default");
boolean unicode = args.getBoolean("unicode"); boolean unicode = args.getBoolean("unicode");
String max_size = args.getString("max_size"); String max_size = args.getString("max_size");
@ -823,6 +840,10 @@ public class FragmentIdentity extends FragmentBase {
return true; return true;
if (!Objects.equals(identity.bcc, bcc)) if (!Objects.equals(identity.bcc, bcc))
return true; return true;
if (!Objects.equals(identity.sign_default, sign_default))
return true;
if (!Objects.equals(identity.encrypt_default, encrypt_default))
return true;
if (!Objects.equals(identity.unicode, unicode)) if (!Objects.equals(identity.unicode, unicode))
return true; return true;
if (user_max_size != null && !Objects.equals(identity.max_size, user_max_size)) if (user_max_size != null && !Objects.equals(identity.max_size, user_max_size))
@ -915,6 +936,8 @@ public class FragmentIdentity extends FragmentBase {
identity.replyto = replyto; identity.replyto = replyto;
identity.cc = cc; identity.cc = cc;
identity.bcc = bcc; identity.bcc = bcc;
identity.sign_default = sign_default;
identity.encrypt_default = encrypt_default;
identity.unicode = unicode; identity.unicode = unicode;
identity.sent_folder = null; identity.sent_folder = null;
identity.sign_key = null; identity.sign_key = null;
@ -1090,6 +1113,8 @@ public class FragmentIdentity extends FragmentBase {
etReplyTo.setText(identity == null ? null : identity.replyto); etReplyTo.setText(identity == null ? null : identity.replyto);
etCc.setText(identity == null ? null : identity.cc); etCc.setText(identity == null ? null : identity.cc);
etBcc.setText(identity == null ? null : identity.bcc); etBcc.setText(identity == null ? null : identity.bcc);
cbSignDefault.setChecked(identity != null && identity.sign_default);
cbEncryptDefault.setChecked(identity != null && identity.encrypt_default);
cbUnicode.setChecked(identity != null && identity.unicode); cbUnicode.setChecked(identity != null && identity.unicode);
auth = (identity == null ? AUTH_TYPE_PASSWORD : identity.auth_type); auth = (identity == null ? AUTH_TYPE_PASSWORD : identity.auth_type);
@ -1134,6 +1159,12 @@ public class FragmentIdentity extends FragmentBase {
cbPrimary.setEnabled(cbSynchronize.isChecked()); cbPrimary.setEnabled(cbSynchronize.isChecked());
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getContext());
boolean sign_default = prefs.getBoolean("sign_default", false);
boolean encrypt_default = prefs.getBoolean("encrypt_default", false);
cbSignDefault.setEnabled(!sign_default && !cbEncryptDefault.isChecked());
cbEncryptDefault.setEnabled(!encrypt_default);
// Get providers // Get providers
List<EmailProvider> providers = EmailProvider.loadProfiles(getContext()); List<EmailProvider> providers = EmailProvider.loadProfiles(getContext());
providers.add(0, new EmailProvider(getString(R.string.title_custom))); providers.add(0, new EmailProvider(getString(R.string.title_custom)));

@ -707,6 +707,24 @@
app:layout_constraintStart_toStartOf="parent" app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/etBcc" /> app:layout_constraintTop_toBottomOf="@id/etBcc" />
<CheckBox
android:id="@+id/cbSignDefault"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="12dp"
android:text="@string/title_advanced_sign_default"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/tvBccHint" />
<CheckBox
android:id="@+id/cbEncryptDefault"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="12dp"
android:text="@string/title_advanced_encrypt_default"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/cbSignDefault" />
<CheckBox <CheckBox
android:id="@+id/cbUnicode" android:id="@+id/cbUnicode"
android:layout_width="wrap_content" android:layout_width="wrap_content"
@ -714,7 +732,7 @@
android:layout_marginTop="12dp" android:layout_marginTop="12dp"
android:text="@string/title_identity_unicode" android:text="@string/title_identity_unicode"
app:layout_constraintStart_toStartOf="parent" app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/tvBccHint" /> app:layout_constraintTop_toBottomOf="@id/cbEncryptDefault" />
<eu.faircode.email.FixedTextView <eu.faircode.email.FixedTextView
android:id="@+id/tvUnicodeHint" android:id="@+id/tvUnicodeHint"
@ -869,6 +887,7 @@
cbSynchronize,cbPrimary,cbSelf,tvSelfHint, cbSynchronize,cbPrimary,cbSelf,tvSelfHint,
cbSenderExtra,tvSenderExtra,etSenderExtra,ibSenderExtra,tvSenderExtraHint, cbSenderExtra,tvSenderExtra,etSenderExtra,ibSenderExtra,tvSenderExtraHint,
tvReplyTo,etReplyTo,tvCc,etCc,tvCcHint,tvBcc,etBcc,tvBccHint, tvReplyTo,etReplyTo,tvCc,etCc,tvCcHint,tvBcc,etBcc,tvBccHint,
cbSignDefault,cbEncryptDefault,
cbUnicode,tvUnicodeHint,tvMaxSize,etMaxSize" /> cbUnicode,tvUnicodeHint,tvMaxSize,etMaxSize" />
<androidx.constraintlayout.widget.Group <androidx.constraintlayout.widget.Group

Loading…
Cancel
Save