|
|
|
@ -74,11 +74,9 @@ import java.util.Properties;
|
|
|
|
|
import javax.mail.AuthenticationFailedException;
|
|
|
|
|
import javax.mail.Folder;
|
|
|
|
|
import javax.mail.Session;
|
|
|
|
|
import javax.mail.Store;
|
|
|
|
|
|
|
|
|
|
import androidx.annotation.NonNull;
|
|
|
|
|
import androidx.annotation.Nullable;
|
|
|
|
|
import androidx.appcompat.widget.SwitchCompat;
|
|
|
|
|
import androidx.constraintlayout.widget.Group;
|
|
|
|
|
import androidx.fragment.app.FragmentTransaction;
|
|
|
|
|
|
|
|
|
@ -93,7 +91,6 @@ public class FragmentAccount extends FragmentBase {
|
|
|
|
|
private Button btnAutoConfig;
|
|
|
|
|
|
|
|
|
|
private Button btnAuthorize;
|
|
|
|
|
private SwitchCompat swPop;
|
|
|
|
|
private EditText etHost;
|
|
|
|
|
private CheckBox cbStartTls;
|
|
|
|
|
private CheckBox cbInsecure;
|
|
|
|
@ -168,7 +165,6 @@ public class FragmentAccount extends FragmentBase {
|
|
|
|
|
btnAutoConfig = view.findViewById(R.id.btnAutoConfig);
|
|
|
|
|
|
|
|
|
|
btnAuthorize = view.findViewById(R.id.btnAuthorize);
|
|
|
|
|
swPop = view.findViewById(R.id.swPop);
|
|
|
|
|
etHost = view.findViewById(R.id.etHost);
|
|
|
|
|
etPort = view.findViewById(R.id.etPort);
|
|
|
|
|
cbStartTls = view.findViewById(R.id.cbStartTls);
|
|
|
|
@ -239,7 +235,6 @@ public class FragmentAccount extends FragmentBase {
|
|
|
|
|
|
|
|
|
|
auth_type = Helper.AUTH_TYPE_PASSWORD;
|
|
|
|
|
|
|
|
|
|
swPop.setChecked(false);
|
|
|
|
|
etHost.setText(provider.imap_host);
|
|
|
|
|
etPort.setText(provider.imap_host == null ? null : Integer.toString(provider.imap_port));
|
|
|
|
|
cbStartTls.setChecked(provider.imap_starttls);
|
|
|
|
@ -285,33 +280,10 @@ public class FragmentAccount extends FragmentBase {
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
swPop.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
|
|
|
|
|
@Override
|
|
|
|
|
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
|
|
|
|
|
boolean starttls = cbStartTls.isChecked();
|
|
|
|
|
if (isChecked) {
|
|
|
|
|
etHost.setHint("pop.domain.tld");
|
|
|
|
|
etPort.setHint(starttls ? "110" : "995");
|
|
|
|
|
etRealm.setText(null);
|
|
|
|
|
cbBrowse.setChecked(false);
|
|
|
|
|
etPrefix.setText(null);
|
|
|
|
|
} else {
|
|
|
|
|
etHost.setHint("imap.domain.tld");
|
|
|
|
|
etPort.setHint(starttls ? "143" : "993");
|
|
|
|
|
}
|
|
|
|
|
etRealm.setEnabled(!isChecked);
|
|
|
|
|
cbBrowse.setEnabled(!isChecked);
|
|
|
|
|
etPrefix.setEnabled(!isChecked);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
cbStartTls.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
|
|
|
|
|
@Override
|
|
|
|
|
public void onCheckedChanged(CompoundButton compoundButton, boolean checked) {
|
|
|
|
|
if (swPop.isChecked())
|
|
|
|
|
etPort.setHint(checked ? "110" : "995");
|
|
|
|
|
else
|
|
|
|
|
etPort.setHint(checked ? "143" : "993");
|
|
|
|
|
etPort.setHint(checked ? "143" : "993");
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
@ -500,7 +472,6 @@ public class FragmentAccount extends FragmentBase {
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
protected void onExecuted(Bundle args, EmailProvider provider) {
|
|
|
|
|
swPop.setChecked(false);
|
|
|
|
|
etHost.setText(provider.imap_host);
|
|
|
|
|
etPort.setText(Integer.toString(provider.imap_port));
|
|
|
|
|
cbStartTls.setChecked(provider.imap_starttls);
|
|
|
|
@ -520,7 +491,6 @@ public class FragmentAccount extends FragmentBase {
|
|
|
|
|
Bundle args = new Bundle();
|
|
|
|
|
args.putLong("id", id);
|
|
|
|
|
args.putInt("auth_type", auth_type);
|
|
|
|
|
args.putBoolean("pop", swPop.isChecked());
|
|
|
|
|
args.putString("host", etHost.getText().toString());
|
|
|
|
|
args.putBoolean("starttls", cbStartTls.isChecked());
|
|
|
|
|
args.putBoolean("insecure", cbInsecure.isChecked());
|
|
|
|
@ -553,7 +523,6 @@ public class FragmentAccount extends FragmentBase {
|
|
|
|
|
protected CheckResult onExecute(Context context, Bundle args) throws Throwable {
|
|
|
|
|
long id = args.getLong("id");
|
|
|
|
|
int auth_type = args.getInt("auth_type");
|
|
|
|
|
boolean pop = args.getBoolean("pop");
|
|
|
|
|
String host = args.getString("host");
|
|
|
|
|
boolean starttls = args.getBoolean("starttls");
|
|
|
|
|
boolean insecure = args.getBoolean("insecure");
|
|
|
|
@ -565,10 +534,7 @@ public class FragmentAccount extends FragmentBase {
|
|
|
|
|
if (TextUtils.isEmpty(host))
|
|
|
|
|
throw new IllegalArgumentException(context.getString(R.string.title_no_host));
|
|
|
|
|
if (TextUtils.isEmpty(port))
|
|
|
|
|
if (pop)
|
|
|
|
|
port = (starttls ? "110" : "995");
|
|
|
|
|
else
|
|
|
|
|
port = (starttls ? "143" : "993");
|
|
|
|
|
port = (starttls ? "143" : "993");
|
|
|
|
|
if (TextUtils.isEmpty(user))
|
|
|
|
|
throw new IllegalArgumentException(context.getString(R.string.title_no_user));
|
|
|
|
|
if (TextUtils.isEmpty(password) && !insecure)
|
|
|
|
@ -587,9 +553,9 @@ public class FragmentAccount extends FragmentBase {
|
|
|
|
|
Properties props = MessageHelper.getSessionProperties(auth_type, realm, insecure);
|
|
|
|
|
Session isession = Session.getInstance(props, null);
|
|
|
|
|
isession.setDebug(true);
|
|
|
|
|
Store istore = null;
|
|
|
|
|
IMAPStore istore = null;
|
|
|
|
|
try {
|
|
|
|
|
istore = isession.getStore((pop ? "pop3" : "imap") + (starttls ? "" : "s"));
|
|
|
|
|
istore = (IMAPStore) isession.getStore(starttls ? "imap" : "imaps");
|
|
|
|
|
try {
|
|
|
|
|
istore.connect(host, Integer.parseInt(port), user, password);
|
|
|
|
|
} catch (AuthenticationFailedException ex) {
|
|
|
|
@ -600,8 +566,7 @@ public class FragmentAccount extends FragmentBase {
|
|
|
|
|
throw ex;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (istore instanceof IMAPStore)
|
|
|
|
|
result.idle = ((IMAPStore) istore).hasCapability("IDLE");
|
|
|
|
|
result.idle = istore.hasCapability("IDLE");
|
|
|
|
|
|
|
|
|
|
boolean inbox = false;
|
|
|
|
|
boolean archive = false;
|
|
|
|
@ -618,11 +583,7 @@ public class FragmentAccount extends FragmentBase {
|
|
|
|
|
for (Folder ifolder : istore.getDefaultFolder().list("*")) {
|
|
|
|
|
// Check folder attributes
|
|
|
|
|
String fullName = ifolder.getFullName();
|
|
|
|
|
String[] attrs;
|
|
|
|
|
if (ifolder instanceof IMAPFolder)
|
|
|
|
|
attrs = ((IMAPFolder) ifolder).getAttributes();
|
|
|
|
|
else
|
|
|
|
|
attrs = new String[0];
|
|
|
|
|
String[] attrs = ((IMAPFolder) ifolder).getAttributes();
|
|
|
|
|
Log.i(fullName + " attrs=" + TextUtils.join(" ", attrs));
|
|
|
|
|
String type = EntityFolder.getType(attrs, fullName);
|
|
|
|
|
|
|
|
|
@ -699,15 +660,9 @@ public class FragmentAccount extends FragmentBase {
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
protected void onExecuted(Bundle args, CheckResult result) {
|
|
|
|
|
boolean pop = args.getBoolean("pop");
|
|
|
|
|
tvIdle.setVisibility(result.idle ? View.GONE : View.VISIBLE);
|
|
|
|
|
|
|
|
|
|
tvIdle.setVisibility(result.idle || pop ? View.GONE : View.VISIBLE);
|
|
|
|
|
|
|
|
|
|
if (pop) {
|
|
|
|
|
grpFolders.setVisibility(View.GONE);
|
|
|
|
|
btnSave.setVisibility(View.VISIBLE);
|
|
|
|
|
} else
|
|
|
|
|
setFolders(result.folders, result.account);
|
|
|
|
|
setFolders(result.folders, result.account);
|
|
|
|
|
|
|
|
|
|
new Handler().post(new Runnable() {
|
|
|
|
|
@Override
|
|
|
|
@ -766,7 +721,6 @@ public class FragmentAccount extends FragmentBase {
|
|
|
|
|
args.putLong("id", id);
|
|
|
|
|
|
|
|
|
|
args.putInt("auth_type", auth_type);
|
|
|
|
|
args.putBoolean("pop", swPop.isChecked());
|
|
|
|
|
args.putString("host", etHost.getText().toString());
|
|
|
|
|
args.putBoolean("starttls", cbStartTls.isChecked());
|
|
|
|
|
args.putBoolean("insecure", cbInsecure.isChecked());
|
|
|
|
@ -816,7 +770,6 @@ public class FragmentAccount extends FragmentBase {
|
|
|
|
|
long id = args.getLong("id");
|
|
|
|
|
|
|
|
|
|
int auth_type = args.getInt("auth_type");
|
|
|
|
|
boolean pop = args.getBoolean("pop");
|
|
|
|
|
String host = args.getString("host");
|
|
|
|
|
boolean starttls = args.getBoolean("starttls");
|
|
|
|
|
boolean insecure = args.getBoolean("insecure");
|
|
|
|
@ -846,10 +799,7 @@ public class FragmentAccount extends FragmentBase {
|
|
|
|
|
if (TextUtils.isEmpty(host))
|
|
|
|
|
throw new IllegalArgumentException(context.getString(R.string.title_no_host));
|
|
|
|
|
if (TextUtils.isEmpty(port))
|
|
|
|
|
if (pop)
|
|
|
|
|
port = (starttls ? "110" : "995");
|
|
|
|
|
else
|
|
|
|
|
port = (starttls ? "143" : "993");
|
|
|
|
|
port = (starttls ? "143" : "993");
|
|
|
|
|
if (TextUtils.isEmpty(user))
|
|
|
|
|
throw new IllegalArgumentException(context.getString(R.string.title_no_user));
|
|
|
|
|
if (synchronize && TextUtils.isEmpty(password) && !insecure)
|
|
|
|
@ -875,7 +825,6 @@ public class FragmentAccount extends FragmentBase {
|
|
|
|
|
|
|
|
|
|
boolean check = (synchronize && (account == null ||
|
|
|
|
|
auth_type != account.auth_type ||
|
|
|
|
|
pop != account.pop ||
|
|
|
|
|
!host.equals(account.host) || Integer.parseInt(port) != account.port ||
|
|
|
|
|
!user.equals(account.user) || !password.equals(account.password) ||
|
|
|
|
|
(realm == null ? accountRealm != null : !realm.equals(accountRealm))));
|
|
|
|
@ -895,9 +844,9 @@ public class FragmentAccount extends FragmentBase {
|
|
|
|
|
Session isession = Session.getInstance(props, null);
|
|
|
|
|
isession.setDebug(true);
|
|
|
|
|
|
|
|
|
|
Store istore = null;
|
|
|
|
|
IMAPStore istore = null;
|
|
|
|
|
try {
|
|
|
|
|
istore = isession.getStore((pop ? "pop3" : "imap") + (starttls ? "" : "s"));
|
|
|
|
|
istore = (IMAPStore) isession.getStore(starttls ? "imap" : "imaps");
|
|
|
|
|
try {
|
|
|
|
|
istore.connect(host, Integer.parseInt(port), user, password);
|
|
|
|
|
} catch (AuthenticationFailedException ex) {
|
|
|
|
@ -912,11 +861,7 @@ public class FragmentAccount extends FragmentBase {
|
|
|
|
|
for (Folder ifolder : istore.getDefaultFolder().list("*")) {
|
|
|
|
|
// Check folder attributes
|
|
|
|
|
String fullName = ifolder.getFullName();
|
|
|
|
|
String[] attrs;
|
|
|
|
|
if (ifolder instanceof IMAPFolder)
|
|
|
|
|
attrs = ((IMAPFolder) ifolder).getAttributes();
|
|
|
|
|
else
|
|
|
|
|
attrs = new String[0];
|
|
|
|
|
String[] attrs = ((IMAPFolder) ifolder).getAttributes();
|
|
|
|
|
Log.i(fullName + " attrs=" + TextUtils.join(" ", attrs));
|
|
|
|
|
String type = EntityFolder.getType(attrs, fullName);
|
|
|
|
|
|
|
|
|
@ -949,7 +894,6 @@ public class FragmentAccount extends FragmentBase {
|
|
|
|
|
account = new EntityAccount();
|
|
|
|
|
|
|
|
|
|
account.auth_type = auth_type;
|
|
|
|
|
account.pop = pop;
|
|
|
|
|
account.host = host;
|
|
|
|
|
account.starttls = starttls;
|
|
|
|
|
account.insecure = insecure;
|
|
|
|
@ -1167,7 +1111,6 @@ public class FragmentAccount extends FragmentBase {
|
|
|
|
|
spProvider.setTag(1);
|
|
|
|
|
spProvider.setSelection(1);
|
|
|
|
|
}
|
|
|
|
|
swPop.setChecked(account.pop);
|
|
|
|
|
etHost.setText(account.host);
|
|
|
|
|
etPort.setText(Long.toString(account.port));
|
|
|
|
|
}
|
|
|
|
@ -1230,15 +1173,6 @@ public class FragmentAccount extends FragmentBase {
|
|
|
|
|
// Consider previous check/save/delete as cancelled
|
|
|
|
|
pbWait.setVisibility(View.GONE);
|
|
|
|
|
|
|
|
|
|
if (account != null && account.pop) {
|
|
|
|
|
etRealm.setEnabled(false);
|
|
|
|
|
cbBrowse.setEnabled(false);
|
|
|
|
|
etPrefix.setEnabled(false);
|
|
|
|
|
grpFolders.setVisibility(View.GONE);
|
|
|
|
|
btnSave.setVisibility(View.VISIBLE);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
args.putLong("account", account == null ? -1 : account.id);
|
|
|
|
|
|
|
|
|
|
new SimpleTask<List<EntityFolder>>() {
|
|
|
|
|