Added option for inbound OAuth only

pull/208/head
M66B 3 years ago
parent 528d60fae8
commit 49a68dc1a8

@ -112,6 +112,7 @@ public class FragmentOAuth extends FragmentBase {
private EditText etName; private EditText etName;
private EditText etEmail; private EditText etEmail;
private EditText etTenant; private EditText etTenant;
private CheckBox cbInboundOnly;
private CheckBox cbPop; private CheckBox cbPop;
private CheckBox cbUpdate; private CheckBox cbUpdate;
private Button btnOAuth; private Button btnOAuth;
@ -162,6 +163,7 @@ public class FragmentOAuth extends FragmentBase {
etName = view.findViewById(R.id.etName); etName = view.findViewById(R.id.etName);
etEmail = view.findViewById(R.id.etEmail); etEmail = view.findViewById(R.id.etEmail);
etTenant = view.findViewById(R.id.etTenant); etTenant = view.findViewById(R.id.etTenant);
cbInboundOnly = view.findViewById(R.id.cbInboundOnly);
cbPop = view.findViewById(R.id.cbPop); cbPop = view.findViewById(R.id.cbPop);
cbUpdate = view.findViewById(R.id.cbUpdate); cbUpdate = view.findViewById(R.id.cbUpdate);
btnOAuth = view.findViewById(R.id.btnOAuth); btnOAuth = view.findViewById(R.id.btnOAuth);
@ -229,6 +231,7 @@ public class FragmentOAuth extends FragmentBase {
etName.setText(personal); etName.setText(personal);
etEmail.setText(address); etEmail.setText(address);
etTenant.setText(null); etTenant.setText(null);
cbInboundOnly.setChecked(false);
cbPop.setChecked(false); cbPop.setChecked(false);
cbUpdate.setChecked(update); cbUpdate.setChecked(update);
@ -284,6 +287,7 @@ public class FragmentOAuth extends FragmentBase {
etName.setEnabled(false); etName.setEnabled(false);
etEmail.setEnabled(false); etEmail.setEnabled(false);
etTenant.setEnabled(false); etTenant.setEnabled(false);
cbInboundOnly.setEnabled(false);
cbPop.setEnabled(false); cbPop.setEnabled(false);
cbUpdate.setEnabled(false); cbUpdate.setEnabled(false);
btnOAuth.setEnabled(false); btnOAuth.setEnabled(false);
@ -426,6 +430,7 @@ public class FragmentOAuth extends FragmentBase {
etName.setEnabled(true); etName.setEnabled(true);
etEmail.setEnabled(true); etEmail.setEnabled(true);
etTenant.setEnabled(true); etTenant.setEnabled(true);
cbInboundOnly.setEnabled(true);
cbPop.setEnabled(true); cbPop.setEnabled(true);
cbUpdate.setEnabled(true); cbUpdate.setEnabled(true);
@ -513,6 +518,7 @@ public class FragmentOAuth extends FragmentBase {
args.putBoolean("askAccount", askAccount); args.putBoolean("askAccount", askAccount);
args.putString("personal", etName.getText().toString().trim()); args.putString("personal", etName.getText().toString().trim());
args.putString("address", etEmail.getText().toString().trim()); args.putString("address", etEmail.getText().toString().trim());
args.putBoolean("inbound_only", cbInboundOnly.isChecked());
args.putBoolean("pop", cbPop.isChecked()); args.putBoolean("pop", cbPop.isChecked());
args.putBoolean("update", cbUpdate.isChecked()); args.putBoolean("update", cbUpdate.isChecked());
@ -537,6 +543,7 @@ public class FragmentOAuth extends FragmentBase {
boolean askAccount = args.getBoolean("askAccount", false); boolean askAccount = args.getBoolean("askAccount", false);
String personal = args.getString("personal"); String personal = args.getString("personal");
String address = args.getString("address"); String address = args.getString("address");
boolean inbound_only = args.getBoolean("inbound_only");
boolean pop = args.getBoolean("pop"); boolean pop = args.getBoolean("pop");
EmailProvider provider = EmailProvider.getProvider(context, id); EmailProvider provider = EmailProvider.getProvider(context, id);
@ -742,18 +749,20 @@ public class FragmentOAuth extends FragmentBase {
folders = aservice.getFolders(); folders = aservice.getFolders();
} }
Log.i("OAuth checking SMTP provider=" + provider.id); Long max_size = null;
Long max_size; if (!inbound_only) {
Log.i("OAuth checking SMTP provider=" + provider.id);
try (EmailService iservice = new EmailService(
context, iprotocol, null, iencryption, false, try (EmailService iservice = new EmailService(
EmailService.PURPOSE_CHECK, true)) { context, iprotocol, null, iencryption, false,
iservice.connect( EmailService.PURPOSE_CHECK, true)) {
provider.smtp.host, provider.smtp.port, iservice.connect(
AUTH_TYPE_OAUTH, provider.id, provider.smtp.host, provider.smtp.port,
username, state, AUTH_TYPE_OAUTH, provider.id,
null, null); username, state,
max_size = iservice.getMaxSize(); null, null);
max_size = iservice.getMaxSize();
}
} }
Log.i("OAuth passed provider=" + provider.id); Log.i("OAuth passed provider=" + provider.id);
@ -839,27 +848,28 @@ public class FragmentOAuth extends FragmentBase {
db.account().updateAccount(account); db.account().updateAccount(account);
// Create identities // Create identities
for (Pair<String, String> identity : identities) { if (!inbound_only)
EntityIdentity ident = new EntityIdentity(); for (Pair<String, String> identity : identities) {
ident.name = identity.second; EntityIdentity ident = new EntityIdentity();
ident.email = identity.first; ident.name = identity.second;
ident.account = account.id; ident.email = identity.first;
ident.account = account.id;
ident.host = provider.smtp.host;
ident.encryption = iencryption; ident.host = provider.smtp.host;
ident.port = provider.smtp.port; ident.encryption = iencryption;
ident.auth_type = AUTH_TYPE_OAUTH; ident.port = provider.smtp.port;
ident.provider = provider.id; ident.auth_type = AUTH_TYPE_OAUTH;
ident.user = username; ident.provider = provider.id;
ident.password = state; ident.user = username;
ident.use_ip = provider.useip; ident.password = state;
ident.synchronize = true; ident.use_ip = provider.useip;
ident.primary = ident.user.equals(ident.email); ident.synchronize = true;
ident.max_size = max_size; ident.primary = ident.user.equals(ident.email);
ident.max_size = max_size;
ident.id = db.identity().insertIdentity(ident);
EntityLog.log(context, "OAuth identity=" + ident.name + " email=" + ident.email); ident.id = db.identity().insertIdentity(ident);
} EntityLog.log(context, "OAuth identity=" + ident.name + " email=" + ident.email);
}
args.putBoolean("pop", pop); args.putBoolean("pop", pop);
} else { } else {
@ -912,6 +922,7 @@ public class FragmentOAuth extends FragmentBase {
etName.setEnabled(true); etName.setEnabled(true);
etEmail.setEnabled(true); etEmail.setEnabled(true);
etTenant.setEnabled(true); etTenant.setEnabled(true);
cbInboundOnly.setEnabled(true);
cbPop.setEnabled(true); cbPop.setEnabled(true);
cbUpdate.setEnabled(true); cbUpdate.setEnabled(true);
btnOAuth.setEnabled(true); btnOAuth.setEnabled(true);
@ -952,6 +963,7 @@ public class FragmentOAuth extends FragmentBase {
etName.setEnabled(true); etName.setEnabled(true);
etEmail.setEnabled(true); etEmail.setEnabled(true);
etTenant.setEnabled(true); etTenant.setEnabled(true);
cbInboundOnly.setEnabled(true);
cbPop.setEnabled(true); cbPop.setEnabled(true);
cbUpdate.setEnabled(true); cbUpdate.setEnabled(true);
btnOAuth.setEnabled(true); btnOAuth.setEnabled(true);

@ -90,6 +90,16 @@
app:layout_constraintStart_toStartOf="parent" app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/etTenant" /> app:layout_constraintTop_toBottomOf="@id/etTenant" />
<CheckBox
android:id="@+id/cbInboundOnly"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="12dp"
android:text="@string/title_setup_inbound"
android:textAppearance="@style/TextAppearance.AppCompat.Small"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/tvTenantHint" />
<CheckBox <CheckBox
android:id="@+id/cbPop" android:id="@+id/cbPop"
android:layout_width="wrap_content" android:layout_width="wrap_content"
@ -98,7 +108,7 @@
android:text="@string/title_setup_pop" android:text="@string/title_setup_pop"
android:textAppearance="@style/TextAppearance.AppCompat.Small" android:textAppearance="@style/TextAppearance.AppCompat.Small"
app:layout_constraintStart_toStartOf="parent" app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/tvTenantHint" /> app:layout_constraintTop_toBottomOf="@id/cbInboundOnly" />
<CheckBox <CheckBox
android:id="@+id/cbUpdate" android:id="@+id/cbUpdate"

@ -200,6 +200,7 @@
<string name="title_setup_gmail" translatable="false">Gmail</string> <string name="title_setup_gmail" translatable="false">Gmail</string>
<string name="title_setup_oauth" translatable="false">%1$s (OAuth)</string> <string name="title_setup_oauth" translatable="false">%1$s (OAuth)</string>
<string name="title_setup_other">Other provider</string> <string name="title_setup_other">Other provider</string>
<string name="title_setup_inbound">Incoming email only (email cannot be sent!)</string>
<string name="title_setup_pop3">POP3 account</string> <string name="title_setup_pop3">POP3 account</string>
<string name="title_setup_oauth_permission">The email provider has approved OAuth only for the Play Store and GitHub version</string> <string name="title_setup_oauth_permission">The email provider has approved OAuth only for the Play Store and GitHub version</string>
<string name="title_setup_gmail_support">Authorizing Google accounts will work in the Play Store and GitHub version only because Android checks the digital app signature</string> <string name="title_setup_gmail_support">Authorizing Google accounts will work in the Play Store and GitHub version only because Android checks the digital app signature</string>

Loading…
Cancel
Save