|
|
|
@ -78,7 +78,6 @@ 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,8 +92,6 @@ public class FragmentAccount extends FragmentBase {
|
|
|
|
|
private Button btnAutoConfig;
|
|
|
|
|
|
|
|
|
|
private Button btnAuthorize;
|
|
|
|
|
private SwitchCompat swPop;
|
|
|
|
|
private TextView tvPopHint;
|
|
|
|
|
private EditText etHost;
|
|
|
|
|
private CheckBox cbStartTls;
|
|
|
|
|
private CheckBox cbInsecure;
|
|
|
|
@ -171,8 +168,6 @@ public class FragmentAccount extends FragmentBase {
|
|
|
|
|
btnAutoConfig = view.findViewById(R.id.btnAutoConfig);
|
|
|
|
|
|
|
|
|
|
btnAuthorize = view.findViewById(R.id.btnAuthorize);
|
|
|
|
|
swPop = view.findViewById(R.id.swPop);
|
|
|
|
|
tvPopHint = view.findViewById(R.id.tvPopHint);
|
|
|
|
|
etHost = view.findViewById(R.id.etHost);
|
|
|
|
|
etPort = view.findViewById(R.id.etPort);
|
|
|
|
|
cbStartTls = view.findViewById(R.id.cbStartTls);
|
|
|
|
@ -247,7 +242,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);
|
|
|
|
@ -293,38 +287,9 @@ public class FragmentAccount extends FragmentBase {
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
swPop.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
|
|
|
|
|
@Override
|
|
|
|
|
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
|
|
|
|
|
boolean starttls = cbStartTls.isChecked();
|
|
|
|
|
if (isChecked) {
|
|
|
|
|
tvPopHint.setVisibility(View.VISIBLE);
|
|
|
|
|
etHost.setHint("pop.domain.tld");
|
|
|
|
|
etPort.setHint(starttls ? "110" : "995");
|
|
|
|
|
etRealm.setText(null);
|
|
|
|
|
cbBrowse.setChecked(false);
|
|
|
|
|
etPrefix.setText(null);
|
|
|
|
|
btnCheck.setVisibility(View.GONE);
|
|
|
|
|
btnSave.setVisibility(View.VISIBLE);
|
|
|
|
|
} else {
|
|
|
|
|
tvPopHint.setVisibility(View.GONE);
|
|
|
|
|
etHost.setHint("imap.domain.tld");
|
|
|
|
|
etPort.setHint(starttls ? "143" : "993");
|
|
|
|
|
btnCheck.setVisibility(View.VISIBLE);
|
|
|
|
|
btnSave.setVisibility(View.GONE);
|
|
|
|
|
}
|
|
|
|
|
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");
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
@ -465,8 +430,6 @@ public class FragmentAccount extends FragmentBase {
|
|
|
|
|
|
|
|
|
|
btnAutoConfig.setEnabled(false);
|
|
|
|
|
|
|
|
|
|
tvPopHint.setVisibility(View.GONE);
|
|
|
|
|
|
|
|
|
|
btnAuthorize.setVisibility(View.GONE);
|
|
|
|
|
cbStartTls.setVisibility(View.GONE);
|
|
|
|
|
cbInsecure.setVisibility(View.GONE);
|
|
|
|
@ -518,7 +481,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);
|
|
|
|
@ -538,7 +500,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());
|
|
|
|
@ -573,7 +534,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");
|
|
|
|
@ -585,9 +545,6 @@ 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");
|
|
|
|
|
if (TextUtils.isEmpty(user))
|
|
|
|
|
throw new IllegalArgumentException(context.getString(R.string.title_no_user));
|
|
|
|
@ -609,7 +566,7 @@ public class FragmentAccount extends FragmentBase {
|
|
|
|
|
isession.setDebug(true);
|
|
|
|
|
Store istore = null;
|
|
|
|
|
try {
|
|
|
|
|
istore = isession.getStore((pop ? "pop3" : "imap") + (starttls ? "" : "s"));
|
|
|
|
|
istore = isession.getStore("imap" + (starttls ? "" : "s"));
|
|
|
|
|
try {
|
|
|
|
|
istore.connect(host, Integer.parseInt(port), user, password);
|
|
|
|
|
} catch (AuthenticationFailedException ex) {
|
|
|
|
@ -620,11 +577,9 @@ public class FragmentAccount extends FragmentBase {
|
|
|
|
|
throw ex;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (istore instanceof IMAPStore) {
|
|
|
|
|
result.idle = ((IMAPStore) istore).hasCapability("IDLE");
|
|
|
|
|
result.move = ((IMAPStore) istore).hasCapability("MOVE");
|
|
|
|
|
result.uidplus = ((IMAPStore) istore).hasCapability("UIDPLUS");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
boolean inbox = false;
|
|
|
|
|
boolean archive = false;
|
|
|
|
@ -718,16 +673,10 @@ 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);
|
|
|
|
|
tvMove.setVisibility(result.move ? View.GONE : View.VISIBLE);
|
|
|
|
|
tvUidPlus.setVisibility(result.uidplus ? View.GONE : View.VISIBLE);
|
|
|
|
|
|
|
|
|
|
tvIdle.setVisibility(result.idle || pop ? View.GONE : View.VISIBLE);
|
|
|
|
|
tvMove.setVisibility(result.move || pop ? View.GONE : View.VISIBLE);
|
|
|
|
|
tvUidPlus.setVisibility(result.uidplus || pop ? View.GONE : View.VISIBLE);
|
|
|
|
|
|
|
|
|
|
if (pop) {
|
|
|
|
|
grpFolders.setVisibility(View.GONE);
|
|
|
|
|
btnSave.setVisibility(View.VISIBLE);
|
|
|
|
|
} else
|
|
|
|
|
setFolders(result.folders, result.account);
|
|
|
|
|
|
|
|
|
|
new Handler().post(new Runnable() {
|
|
|
|
@ -787,7 +736,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());
|
|
|
|
@ -837,7 +785,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");
|
|
|
|
@ -864,28 +811,9 @@ public class FragmentAccount extends FragmentBase {
|
|
|
|
|
EntityFolder left = (EntityFolder) args.getSerializable("left");
|
|
|
|
|
EntityFolder right = (EntityFolder) args.getSerializable("right");
|
|
|
|
|
|
|
|
|
|
if (pop) {
|
|
|
|
|
drafts = new EntityFolder();
|
|
|
|
|
drafts.name = context.getString(R.string.title_folder_drafts);
|
|
|
|
|
drafts.synchronize = false;
|
|
|
|
|
drafts.initialize = false;
|
|
|
|
|
drafts.sync_days = 0;
|
|
|
|
|
drafts.keep_days = 0;
|
|
|
|
|
|
|
|
|
|
sent = new EntityFolder();
|
|
|
|
|
sent.name = context.getString(R.string.title_folder_sent);
|
|
|
|
|
sent.synchronize = false;
|
|
|
|
|
sent.initialize = false;
|
|
|
|
|
sent.sync_days = 0;
|
|
|
|
|
sent.keep_days = 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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");
|
|
|
|
|
if (TextUtils.isEmpty(user))
|
|
|
|
|
throw new IllegalArgumentException(context.getString(R.string.title_no_user));
|
|
|
|
@ -912,7 +840,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))));
|
|
|
|
@ -934,7 +861,7 @@ public class FragmentAccount extends FragmentBase {
|
|
|
|
|
|
|
|
|
|
Store istore = null;
|
|
|
|
|
try {
|
|
|
|
|
istore = isession.getStore((pop ? "pop3" : "imap") + (starttls ? "" : "s"));
|
|
|
|
|
istore = isession.getStore("imap" + (starttls ? "" : "s"));
|
|
|
|
|
try {
|
|
|
|
|
istore.connect(host, Integer.parseInt(port), user, password);
|
|
|
|
|
} catch (AuthenticationFailedException ex) {
|
|
|
|
@ -949,11 +876,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);
|
|
|
|
|
|
|
|
|
@ -964,9 +887,9 @@ public class FragmentAccount extends FragmentBase {
|
|
|
|
|
inbox.synchronize = true;
|
|
|
|
|
inbox.unified = true;
|
|
|
|
|
inbox.notify = true;
|
|
|
|
|
inbox.initialize = !pop;
|
|
|
|
|
inbox.sync_days = (pop ? 0 : EntityFolder.DEFAULT_SYNC);
|
|
|
|
|
inbox.keep_days = (pop ? 0 : EntityFolder.DEFAULT_KEEP);
|
|
|
|
|
inbox.initialize = true;
|
|
|
|
|
inbox.sync_days = EntityFolder.DEFAULT_SYNC;
|
|
|
|
|
inbox.keep_days = EntityFolder.DEFAULT_KEEP;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -987,7 +910,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;
|
|
|
|
@ -1205,7 +1127,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));
|
|
|
|
|
}
|
|
|
|
@ -1268,15 +1189,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>>() {
|
|
|
|
|