mirror of https://github.com/M66B/FairEmail.git
Allow untrusted /quick setup wizard
This commit is contained in:
parent
59d3428c2e
commit
3fa68990d2
|
@ -71,7 +71,9 @@ public class FragmentQuickSetup extends FragmentBase {
|
|||
private TextView tvInstructions;
|
||||
|
||||
private TextView tvImap;
|
||||
private TextView tvImapFingerprint;
|
||||
private TextView tvSmtp;
|
||||
private TextView tvSmtpFingerprint;
|
||||
private Button btnSave;
|
||||
private ContentLoadingProgressBar pbSave;
|
||||
|
||||
|
@ -102,7 +104,9 @@ public class FragmentQuickSetup extends FragmentBase {
|
|||
tvInstructions = view.findViewById(R.id.tvInstructions);
|
||||
|
||||
tvImap = view.findViewById(R.id.tvImap);
|
||||
tvImapFingerprint = view.findViewById(R.id.tvImapFingerprint);
|
||||
tvSmtp = view.findViewById(R.id.tvSmtp);
|
||||
tvSmtpFingerprint = view.findViewById(R.id.tvSmtpFingerprint);
|
||||
btnSave = view.findViewById(R.id.btnSave);
|
||||
pbSave = view.findViewById(R.id.pbSave);
|
||||
|
||||
|
@ -177,6 +181,8 @@ public class FragmentQuickSetup extends FragmentBase {
|
|||
|
||||
// Initialize
|
||||
tvCharacters.setVisibility(View.GONE);
|
||||
tvImapFingerprint.setText(null);
|
||||
tvSmtpFingerprint.setText(null);
|
||||
pbCheck.setVisibility(View.GONE);
|
||||
pbSave.setVisibility(View.GONE);
|
||||
btnHelp.setVisibility(View.GONE);
|
||||
|
@ -220,6 +226,8 @@ public class FragmentQuickSetup extends FragmentBase {
|
|||
args.putString("name", etName.getText().toString().trim());
|
||||
args.putString("email", etEmail.getText().toString().trim());
|
||||
args.putString("password", tilPassword.getEditText().getText().toString());
|
||||
args.putString("imap_fingerprint", tvImapFingerprint.getText().toString());
|
||||
args.putString("smtp_fingerprint", tvSmtpFingerprint.getText().toString());
|
||||
args.putBoolean("check", check);
|
||||
|
||||
new SimpleTask<EmailProvider>() {
|
||||
|
@ -250,6 +258,8 @@ public class FragmentQuickSetup extends FragmentBase {
|
|||
String email = args.getString("email");
|
||||
String password = args.getString("password");
|
||||
boolean check = args.getBoolean("check");
|
||||
String imap_fingerprint = args.getString("imap_fingerprint");
|
||||
String smtp_fingerprint = args.getString("smtp_fingerprint");
|
||||
|
||||
if (TextUtils.isEmpty(name))
|
||||
throw new IllegalArgumentException(context.getString(R.string.title_no_name));
|
||||
|
@ -259,6 +269,10 @@ public class FragmentQuickSetup extends FragmentBase {
|
|||
throw new IllegalArgumentException(context.getString(R.string.title_email_invalid, email));
|
||||
if (TextUtils.isEmpty(password))
|
||||
throw new IllegalArgumentException(context.getString(R.string.title_no_password));
|
||||
if (TextUtils.isEmpty(imap_fingerprint))
|
||||
imap_fingerprint = null;
|
||||
if (TextUtils.isEmpty(smtp_fingerprint))
|
||||
smtp_fingerprint = null;
|
||||
|
||||
EmailProvider provider = EmailProvider.fromEmail(context, email, EmailProvider.Discover.ALL);
|
||||
args.putBoolean("appPassword", provider.appPassword);
|
||||
|
@ -274,17 +288,24 @@ public class FragmentQuickSetup extends FragmentBase {
|
|||
String user = (provider.user == EmailProvider.UserType.EMAIL ? email : username);
|
||||
Log.i("User type=" + provider.user + " name=" + user);
|
||||
|
||||
List<EntityFolder> folders;
|
||||
List<EntityFolder> folders = null;
|
||||
|
||||
String aprotocol = provider.imap.starttls ? "imap" : "imaps";
|
||||
try (EmailService iservice = new EmailService(
|
||||
context, aprotocol, null, false, EmailService.PURPOSE_CHECK, true)) {
|
||||
boolean check_folders = false;
|
||||
try {
|
||||
iservice.connect(
|
||||
provider.imap.host, provider.imap.port,
|
||||
EmailService.AUTH_TYPE_PASSWORD, null,
|
||||
user, password,
|
||||
null, null);
|
||||
null, imap_fingerprint);
|
||||
check_folders = true;
|
||||
} catch (EmailService.UntrustedException ex) {
|
||||
if (check)
|
||||
imap_fingerprint = ex.getFingerprint();
|
||||
else
|
||||
throw ex;
|
||||
} catch (AuthenticationFailedException ex) {
|
||||
if (!user.equals(username)) {
|
||||
Log.w(ex);
|
||||
|
@ -299,10 +320,12 @@ public class FragmentQuickSetup extends FragmentBase {
|
|||
throw ex;
|
||||
}
|
||||
|
||||
folders = iservice.getFolders();
|
||||
if (check_folders) {
|
||||
folders = iservice.getFolders();
|
||||
|
||||
if (folders == null)
|
||||
throw new IllegalArgumentException(context.getString(R.string.title_setup_no_system_folders));
|
||||
if (folders == null)
|
||||
throw new IllegalArgumentException(context.getString(R.string.title_setup_no_system_folders));
|
||||
}
|
||||
}
|
||||
|
||||
String iprotocol = provider.smtp.starttls ? "smtp" : "smtps";
|
||||
|
@ -313,11 +336,19 @@ public class FragmentQuickSetup extends FragmentBase {
|
|||
provider.smtp.host, provider.smtp.port,
|
||||
EmailService.AUTH_TYPE_PASSWORD, null,
|
||||
user, password,
|
||||
null, null);
|
||||
null, smtp_fingerprint);
|
||||
} catch (EmailService.UntrustedException ex) {
|
||||
if (check)
|
||||
smtp_fingerprint = ex.getFingerprint();
|
||||
else
|
||||
throw ex;
|
||||
}
|
||||
|
||||
if (check)
|
||||
if (check) {
|
||||
args.putString("imap_fingerprint", imap_fingerprint);
|
||||
args.putString("smtp_fingerprint", smtp_fingerprint);
|
||||
return provider;
|
||||
}
|
||||
|
||||
DB db = DB.getInstance(context);
|
||||
try {
|
||||
|
@ -334,6 +365,7 @@ public class FragmentQuickSetup extends FragmentBase {
|
|||
account.auth_type = EmailService.AUTH_TYPE_PASSWORD;
|
||||
account.user = user;
|
||||
account.password = password;
|
||||
account.fingerprint = imap_fingerprint;
|
||||
|
||||
account.name = provider.name;
|
||||
|
||||
|
@ -383,6 +415,7 @@ public class FragmentQuickSetup extends FragmentBase {
|
|||
identity.auth_type = EmailService.AUTH_TYPE_PASSWORD;
|
||||
identity.user = user;
|
||||
identity.password = password;
|
||||
identity.fingerprint = smtp_fingerprint;
|
||||
identity.use_ip = provider.useip;
|
||||
identity.synchronize = true;
|
||||
identity.primary = true;
|
||||
|
@ -406,8 +439,10 @@ public class FragmentQuickSetup extends FragmentBase {
|
|||
if (check) {
|
||||
tvImap.setText(result == null ? null
|
||||
: result.imap.host + ":" + result.imap.port + (result.imap.starttls ? " starttls" : " ssl"));
|
||||
tvImapFingerprint.setText(args.getString("imap_fingerprint"));
|
||||
tvSmtp.setText(result == null ? null
|
||||
: result.smtp.host + ":" + result.smtp.port + (result.smtp.starttls ? " starttls" : " ssl"));
|
||||
tvSmtpFingerprint.setText(args.getString("smtp_fingerprint"));
|
||||
grpSetup.setVisibility(result == null ? View.GONE : View.VISIBLE);
|
||||
} else {
|
||||
FragmentReview fragment = new FragmentReview();
|
||||
|
|
|
@ -193,6 +193,16 @@
|
|||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@id/tvImapTitle" />
|
||||
|
||||
<eu.faircode.email.FixedTextView
|
||||
android:id="@+id/tvImapFingerprint"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="fingerprint"
|
||||
android:textAppearance="@style/TextAppearance.AppCompat.Medium"
|
||||
android:textColor="?attr/colorWarning"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@id/tvImap" />
|
||||
|
||||
<eu.faircode.email.FixedTextView
|
||||
android:id="@+id/tvSmtpTitle"
|
||||
android:layout_width="wrap_content"
|
||||
|
@ -201,7 +211,7 @@
|
|||
android:text="@string/title_setup_quick_smtp"
|
||||
android:textAppearance="@style/TextAppearance.AppCompat.Small"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@id/tvImap" />
|
||||
app:layout_constraintTop_toBottomOf="@id/tvImapFingerprint" />
|
||||
|
||||
<eu.faircode.email.FixedTextView
|
||||
android:id="@+id/tvSmtp"
|
||||
|
@ -213,6 +223,16 @@
|
|||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@id/tvSmtpTitle" />
|
||||
|
||||
<eu.faircode.email.FixedTextView
|
||||
android:id="@+id/tvSmtpFingerprint"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="fingerprint"
|
||||
android:textAppearance="@style/TextAppearance.AppCompat.Medium"
|
||||
android:textColor="?attr/colorWarning"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@id/tvSmtp" />
|
||||
|
||||
<Button
|
||||
android:id="@+id/btnSave"
|
||||
android:layout_width="wrap_content"
|
||||
|
@ -221,7 +241,7 @@
|
|||
android:tag="disable"
|
||||
android:text="@string/title_save"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@id/tvSmtp" />
|
||||
app:layout_constraintTop_toBottomOf="@id/tvSmtpFingerprint" />
|
||||
|
||||
<eu.faircode.email.ContentLoadingProgressBar
|
||||
android:id="@+id/pbSave"
|
||||
|
@ -238,7 +258,10 @@
|
|||
android:id="@+id/grpSetup"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="0dp"
|
||||
app:constraint_referenced_ids="tvImapTitle,tvImap,tvSmtpTitle,tvSmtp,btnSave" />
|
||||
app:constraint_referenced_ids="
|
||||
tvImapTitle,tvImap,tvImapFingerprint,tvSmtpTitle,
|
||||
tvSmtp,tvSmtpFingerprint,
|
||||
btnSave" />
|
||||
|
||||
<androidx.constraintlayout.widget.Group
|
||||
android:id="@+id/grpError"
|
||||
|
|
Loading…
Reference in New Issue