mirror of
https://github.com/M66B/FairEmail.git
synced 2025-02-28 08:46:01 +00:00
Check S/MIME sender/signature address
This commit is contained in:
parent
ff6237d690
commit
ff919d0350
4 changed files with 155 additions and 33 deletions
|
@ -3971,7 +3971,7 @@ public class FragmentCompose extends FragmentBase {
|
|||
public Dialog onCreateDialog(@Nullable Bundle savedInstanceState) {
|
||||
email = getArguments().getString("email");
|
||||
|
||||
View dview = LayoutInflater.from(getContext()).inflate(R.layout.dialog_certificate, null);
|
||||
View dview = LayoutInflater.from(getContext()).inflate(R.layout.dialog_select_certificate, null);
|
||||
final RecyclerView rvCertificate = dview.findViewById(R.id.rvCertificate);
|
||||
final ProgressBar pbWait = dview.findViewById(R.id.pbWait);
|
||||
|
||||
|
|
|
@ -163,6 +163,7 @@ import java.util.Properties;
|
|||
|
||||
import javax.mail.FolderClosedException;
|
||||
import javax.mail.Session;
|
||||
import javax.mail.internet.InternetAddress;
|
||||
import javax.mail.internet.MimeMessage;
|
||||
|
||||
import static android.app.Activity.RESULT_OK;
|
||||
|
@ -4391,6 +4392,11 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences.
|
|||
String email = Helper.getAltSubjectName(cert);
|
||||
EntityCertificate record = db.certificate().getCertificate(fingerprint, email);
|
||||
|
||||
String sender = null;
|
||||
if (message.from != null && message.from.length == 1)
|
||||
sender = ((InternetAddress) message.from[0]).getAddress();
|
||||
|
||||
args.putString("sender", sender);
|
||||
args.putString("fingerprint", fingerprint);
|
||||
args.putString("email", email);
|
||||
args.putString("subject", Helper.getSubject(cert));
|
||||
|
@ -4515,16 +4521,38 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences.
|
|||
@Override
|
||||
protected void onExecuted(final Bundle args, Boolean valid) {
|
||||
int type = args.getInt("type");
|
||||
if (EntityMessage.SMIME_SIGNONLY.equals(type))
|
||||
if (EntityMessage.SMIME_SIGNONLY.equals(type)) {
|
||||
String sender = args.getString("sender");
|
||||
String fingerprint = args.getString("fingerprint");
|
||||
String email = args.getString("email");
|
||||
String subject = args.getString("subject");
|
||||
byte[] encoded = args.getByteArray("encoded");
|
||||
boolean known = args.getBoolean("known");
|
||||
boolean match = Objects.equals(sender, email);
|
||||
|
||||
if (valid == null || !valid)
|
||||
Snackbar.make(view, R.string.title_signature_invalid, Snackbar.LENGTH_LONG).show();
|
||||
else if (args.getBoolean("known"))
|
||||
else if (known && match)
|
||||
Snackbar.make(view, R.string.title_signature_valid, Snackbar.LENGTH_LONG).show();
|
||||
else {
|
||||
new AlertDialog.Builder(getContext())
|
||||
.setTitle(R.string.title_signature_valid)
|
||||
.setMessage(args.getString("email") + ": " + args.getString("subject"))
|
||||
.setPositiveButton(R.string.title_signature_store, new DialogInterface.OnClickListener() {
|
||||
LayoutInflater inflator = LayoutInflater.from(getContext());
|
||||
View dview = inflator.inflate(R.layout.dialog_certificate, null);
|
||||
TextView tvSender = dview.findViewById(R.id.tvSender);
|
||||
TextView tvEmail = dview.findViewById(R.id.tvEmail);
|
||||
TextView tvEmailInvalid = dview.findViewById(R.id.tvEmailInvalid);
|
||||
TextView tvSubject = dview.findViewById(R.id.tvSubject);
|
||||
|
||||
tvSender.setText(sender);
|
||||
tvEmail.setText(email);
|
||||
tvEmailInvalid.setVisibility(match ? View.GONE : View.VISIBLE);
|
||||
tvSubject.setText(subject);
|
||||
|
||||
AlertDialog.Builder builder = new AlertDialog.Builder(getContext())
|
||||
.setView(dview)
|
||||
.setNegativeButton(android.R.string.cancel, null);
|
||||
|
||||
if (!TextUtils.isEmpty(sender) && !known)
|
||||
builder.setPositiveButton(R.string.title_signature_store, new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
new SimpleTask<Void>() {
|
||||
|
@ -4539,10 +4567,10 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences.
|
|||
return null;
|
||||
|
||||
EntityCertificate record = new EntityCertificate();
|
||||
record.fingerprint = args.getString("fingerprint");
|
||||
record.email = args.getString("email");
|
||||
record.subject = args.getString("subject");
|
||||
record.setEncoded(args.getByteArray("encoded"));
|
||||
record.fingerprint = fingerprint;
|
||||
record.email = email;
|
||||
record.subject = subject;
|
||||
record.setEncoded(encoded);
|
||||
record.id = db.certificate().insertCertificate(record);
|
||||
|
||||
return null;
|
||||
|
@ -4554,9 +4582,10 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences.
|
|||
}
|
||||
}.execute(FragmentMessages.this, args, "certificate:store");
|
||||
}
|
||||
})
|
||||
.setNegativeButton(android.R.string.cancel, null)
|
||||
.show();
|
||||
});
|
||||
|
||||
builder.show();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
89
app/src/main/res/layout/dialog_certificate.xml
Normal file
89
app/src/main/res/layout/dialog_certificate.xml
Normal file
|
@ -0,0 +1,89 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:padding="24dp">
|
||||
|
||||
<androidx.constraintlayout.widget.ConstraintLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/tvCaption"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/title_signature_valid"
|
||||
android:textAppearance="@style/TextAppearance.AppCompat.Large"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/tvSenderTitle"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="24dp"
|
||||
android:text="@string/title_signature_sender"
|
||||
android:textAppearance="@style/TextAppearance.AppCompat.Small"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@id/tvCaption" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/tvSender"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="test@example.com"
|
||||
android:textAppearance="@style/TextAppearance.AppCompat.Medium"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@id/tvSenderTitle" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/tvEmailTitle"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="24dp"
|
||||
android:text="@string/title_signature_email"
|
||||
android:textAppearance="@style/TextAppearance.AppCompat.Small"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@id/tvSender" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/tvEmail"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="test@example.com"
|
||||
android:textAppearance="@style/TextAppearance.AppCompat.Medium"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@id/tvEmailTitle" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/tvEmailInvalid"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="24dp"
|
||||
android:text="@string/title_signature_mismatch"
|
||||
android:textAppearance="@style/TextAppearance.AppCompat.Small"
|
||||
android:textColor="?attr/colorWarning"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@id/tvEmail" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/tvSubjectTitle"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="24dp"
|
||||
android:text="@string/title_signature_subject"
|
||||
android:textAppearance="@style/TextAppearance.AppCompat.Small"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@id/tvEmailInvalid" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/tvSubject"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="CN=test@example.com"
|
||||
android:textAppearance="@style/TextAppearance.AppCompat.Medium"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@id/tvSubjectTitle" />
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||
</ScrollView>
|
|
@ -709,6 +709,10 @@
|
|||
<string name="title_signature_valid">Message signature valid</string>
|
||||
<string name="title_signature_unconfirmed">Message signature valid but not confirmed</string>
|
||||
<string name="title_signature_invalid">Message signature invalid</string>
|
||||
<string name="title_signature_sender">Sender\'s address</string>
|
||||
<string name="title_signature_email">Signature\'s address</string>
|
||||
<string name="title_signature_mismatch">The email address of the sender and signature do not match</string>
|
||||
<string name="title_signature_subject">Subject</string>
|
||||
<string name="title_signature_store">Store</string>
|
||||
|
||||
<string name="title_search">Search</string>
|
||||
|
|
Loading…
Reference in a new issue