mirror of
https://github.com/M66B/FairEmail.git
synced 2025-03-19 02:15:28 +00:00
Added default sign/encrypt to identity
This commit is contained in:
parent
a7041978c5
commit
7db5656037
6 changed files with 2484 additions and 23 deletions
2394
app/schemas/eu.faircode.email.DB/189.json
Normal file
2394
app/schemas/eu.faircode.email.DB/189.json
Normal file
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
|
||||
|
||||
@Database(
|
||||
version = 188,
|
||||
version = 189,
|
||||
entities = {
|
||||
EntityIdentity.class,
|
||||
EntityAccount.class,
|
||||
|
@ -1854,6 +1854,14 @@ public abstract class DB extends RoomDatabase {
|
|||
Log.i("DB migration from version " + startVersion + " to " + endVersion);
|
||||
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
|
||||
public Boolean plain_only = false; // obsolete
|
||||
@NonNull
|
||||
public Boolean sign_default = false;
|
||||
@NonNull
|
||||
public Boolean encrypt_default = false;
|
||||
@NonNull
|
||||
public Integer encrypt = 0; // Default method 0=PGP 1=S/MIME
|
||||
@NonNull
|
||||
public Boolean delivery_receipt = false; // obsolete
|
||||
|
|
|
@ -3559,12 +3559,12 @@ public class FragmentCompose extends FragmentBase {
|
|||
if (plain_only)
|
||||
data.draft.plain_only = true;
|
||||
|
||||
if (encrypt_default)
|
||||
if (encrypt_default || selected.encrypt_default)
|
||||
if (selected.encrypt == 0)
|
||||
data.draft.ui_encrypt = EntityMessage.PGP_SIGNENCRYPT;
|
||||
else
|
||||
data.draft.ui_encrypt = EntityMessage.SMIME_SIGNENCRYPT;
|
||||
else if (sign_default)
|
||||
else if (sign_default || selected.sign_default)
|
||||
if (selected.encrypt == 0)
|
||||
data.draft.ui_encrypt = EntityMessage.PGP_SIGNONLY;
|
||||
else
|
||||
|
@ -4176,6 +4176,7 @@ public class FragmentCompose extends FragmentBase {
|
|||
if (data.draft.identity != null)
|
||||
for (int pos = 0; pos < data.identities.size(); pos++) {
|
||||
if (data.identities.get(pos).id.equals(data.draft.identity)) {
|
||||
spIdentity.setTag(pos);
|
||||
spIdentity.setSelection(pos);
|
||||
break;
|
||||
}
|
||||
|
@ -5356,7 +5357,10 @@ public class FragmentCompose extends FragmentBase {
|
|||
|
||||
setBodyPadding();
|
||||
|
||||
updateEncryption();
|
||||
if (!Objects.equals(spIdentity.getTag(), position)) {
|
||||
spIdentity.setTag(position);
|
||||
updateEncryption(identity);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -5369,11 +5373,10 @@ public class FragmentCompose extends FragmentBase {
|
|||
|
||||
setBodyPadding();
|
||||
|
||||
updateEncryption();
|
||||
updateEncryption(null);
|
||||
}
|
||||
|
||||
private void updateEncryption() {
|
||||
EntityIdentity identity = (EntityIdentity) spIdentity.getSelectedItem();
|
||||
private void updateEncryption(EntityIdentity identity) {
|
||||
if (identity == null)
|
||||
return;
|
||||
|
||||
|
@ -5388,35 +5391,37 @@ public class FragmentCompose extends FragmentBase {
|
|||
long iid = args.getLong("identity");
|
||||
|
||||
DB db = DB.getInstance(context);
|
||||
EntityMessage draft = db.message().getMessage(id);
|
||||
if (draft == null ||
|
||||
draft.ui_encrypt == null || EntityMessage.ENCRYPT_NONE.equals(draft.ui_encrypt))
|
||||
return null;
|
||||
|
||||
if (draft.identity != null && draft.identity.equals(iid))
|
||||
return draft.ui_encrypt;
|
||||
EntityMessage draft = db.message().getMessage(id);
|
||||
if (draft == null)
|
||||
return null;
|
||||
|
||||
EntityIdentity identity = db.identity().getIdentity(iid);
|
||||
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 (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))
|
||||
encrypt = EntityMessage.PGP_SIGNENCRYPT;
|
||||
draft.ui_encrypt = EntityMessage.PGP_SIGNENCRYPT;
|
||||
} else {
|
||||
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))
|
||||
encrypt = EntityMessage.SMIME_SIGNENCRYPT;
|
||||
draft.ui_encrypt = EntityMessage.SMIME_SIGNENCRYPT;
|
||||
}
|
||||
|
||||
if (draft.ui_encrypt != encrypt)
|
||||
db.message().setMessageUiEncrypt(draft.id, encrypt);
|
||||
db.message().setMessageUiEncrypt(draft.id, draft.ui_encrypt);
|
||||
|
||||
return encrypt;
|
||||
return draft.ui_encrypt;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -21,6 +21,7 @@ package eu.faircode.email;
|
|||
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.SharedPreferences;
|
||||
import android.graphics.Color;
|
||||
import android.net.Uri;
|
||||
import android.os.Bundle;
|
||||
|
@ -51,6 +52,7 @@ import androidx.annotation.NonNull;
|
|||
import androidx.annotation.Nullable;
|
||||
import androidx.constraintlayout.widget.Group;
|
||||
import androidx.lifecycle.Lifecycle;
|
||||
import androidx.preference.PreferenceManager;
|
||||
|
||||
import com.google.android.material.snackbar.Snackbar;
|
||||
import com.google.android.material.textfield.TextInputLayout;
|
||||
|
@ -111,6 +113,8 @@ public class FragmentIdentity extends FragmentBase {
|
|||
private EditText etReplyTo;
|
||||
private EditText etCc;
|
||||
private EditText etBcc;
|
||||
private CheckBox cbSignDefault;
|
||||
private CheckBox cbEncryptDefault;
|
||||
private CheckBox cbUnicode;
|
||||
private EditText etMaxSize;
|
||||
|
||||
|
@ -204,6 +208,8 @@ public class FragmentIdentity extends FragmentBase {
|
|||
etReplyTo = view.findViewById(R.id.etReplyTo);
|
||||
etCc = view.findViewById(R.id.etCc);
|
||||
etBcc = view.findViewById(R.id.etBcc);
|
||||
cbSignDefault = view.findViewById(R.id.cbSignDefault);
|
||||
cbEncryptDefault = view.findViewById(R.id.cbEncryptDefault);
|
||||
cbUnicode = view.findViewById(R.id.cbUnicode);
|
||||
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() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
|
@ -597,6 +610,8 @@ public class FragmentIdentity extends FragmentBase {
|
|||
args.putString("replyto", etReplyTo.getText().toString().trim());
|
||||
args.putString("cc", etCc.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.putString("max_size", etMaxSize.getText().toString());
|
||||
args.putLong("account", account == null ? -1 : account.id);
|
||||
|
@ -679,6 +694,8 @@ public class FragmentIdentity extends FragmentBase {
|
|||
String replyto = args.getString("replyto");
|
||||
String cc = args.getString("cc");
|
||||
String bcc = args.getString("bcc");
|
||||
boolean sign_default = args.getBoolean("sign_default");
|
||||
boolean encrypt_default = args.getBoolean("encrypt_default");
|
||||
boolean unicode = args.getBoolean("unicode");
|
||||
String max_size = args.getString("max_size");
|
||||
|
||||
|
@ -823,6 +840,10 @@ public class FragmentIdentity extends FragmentBase {
|
|||
return true;
|
||||
if (!Objects.equals(identity.bcc, bcc))
|
||||
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))
|
||||
return true;
|
||||
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.cc = cc;
|
||||
identity.bcc = bcc;
|
||||
identity.sign_default = sign_default;
|
||||
identity.encrypt_default = encrypt_default;
|
||||
identity.unicode = unicode;
|
||||
identity.sent_folder = null;
|
||||
identity.sign_key = null;
|
||||
|
@ -1090,6 +1113,8 @@ public class FragmentIdentity extends FragmentBase {
|
|||
etReplyTo.setText(identity == null ? null : identity.replyto);
|
||||
etCc.setText(identity == null ? null : identity.cc);
|
||||
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);
|
||||
|
||||
auth = (identity == null ? AUTH_TYPE_PASSWORD : identity.auth_type);
|
||||
|
@ -1134,6 +1159,12 @@ public class FragmentIdentity extends FragmentBase {
|
|||
|
||||
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
|
||||
List<EmailProvider> providers = EmailProvider.loadProfiles(getContext());
|
||||
providers.add(0, new EmailProvider(getString(R.string.title_custom)));
|
||||
|
|
|
@ -707,6 +707,24 @@
|
|||
app:layout_constraintStart_toStartOf="parent"
|
||||
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
|
||||
android:id="@+id/cbUnicode"
|
||||
android:layout_width="wrap_content"
|
||||
|
@ -714,7 +732,7 @@
|
|||
android:layout_marginTop="12dp"
|
||||
android:text="@string/title_identity_unicode"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@id/tvBccHint" />
|
||||
app:layout_constraintTop_toBottomOf="@id/cbEncryptDefault" />
|
||||
|
||||
<eu.faircode.email.FixedTextView
|
||||
android:id="@+id/tvUnicodeHint"
|
||||
|
@ -869,6 +887,7 @@
|
|||
cbSynchronize,cbPrimary,cbSelf,tvSelfHint,
|
||||
cbSenderExtra,tvSenderExtra,etSenderExtra,ibSenderExtra,tvSenderExtraHint,
|
||||
tvReplyTo,etReplyTo,tvCc,etCc,tvCcHint,tvBcc,etBcc,tvBccHint,
|
||||
cbSignDefault,cbEncryptDefault,
|
||||
cbUnicode,tvUnicodeHint,tvMaxSize,etMaxSize" />
|
||||
|
||||
<androidx.constraintlayout.widget.Group
|
||||
|
|
Loading…
Add table
Reference in a new issue