Refactoring

This commit is contained in:
M66B 2020-01-29 21:06:45 +01:00
parent 35ebfa4f14
commit d0fca27e70
15 changed files with 59 additions and 59 deletions

View File

@ -415,7 +415,7 @@ public class ActivityEML extends ActivityBase {
Session isession = Session.getInstance(props, null);
MimeMessage imessage = new MimeMessage(isession, is);
try (MailService iservice = new MailService(context, account.getProtocol(), account.realm, account.insecure, false, true)) {
try (EmailService iservice = new EmailService(context, account.getProtocol(), account.realm, account.insecure, false, true)) {
iservice.setPartialFetch(account.partial_fetch);
iservice.setIgnoreBodyStructureSize(account.ignore_size);
iservice.connect(account);

View File

@ -143,7 +143,7 @@ public class AdapterAccount extends RecyclerView.Adapter<AdapterAccount.ViewHold
ivSync.setContentDescription(context.getString(account.synchronize ? R.string.title_legend_synchronize_on : R.string.title_legend_synchronize_off));
ivOAuth.setVisibility(
settings && account.auth_type != MailService.AUTH_TYPE_PASSWORD ? View.VISIBLE : View.GONE);
settings && account.auth_type != EmailService.AUTH_TYPE_PASSWORD ? View.VISIBLE : View.GONE);
ivPrimary.setVisibility(account.primary ? View.VISIBLE : View.GONE);
ivNotify.setVisibility(account.notify ? View.VISIBLE : View.GONE);

View File

@ -117,7 +117,7 @@ public class AdapterIdentity extends RecyclerView.Adapter<AdapterIdentity.ViewHo
ivSync.setImageResource(identity.synchronize ? R.drawable.baseline_sync_24 : R.drawable.baseline_sync_disabled_24);
ivSync.setContentDescription(context.getString(identity.synchronize ? R.string.title_legend_synchronize_on : R.string.title_legend_synchronize_off));
ivOAuth.setVisibility(identity.auth_type == MailService.AUTH_TYPE_PASSWORD ? View.GONE : View.VISIBLE);
ivOAuth.setVisibility(identity.auth_type == EmailService.AUTH_TYPE_PASSWORD ? View.GONE : View.VISIBLE);
ivPrimary.setVisibility(identity.primary ? View.VISIBLE : View.GONE);
tvName.setText(identity.getDisplayName());
tvUser.setText(identity.email);

View File

@ -301,7 +301,7 @@ public class BoundaryCallbackMessages extends PagedList.BoundaryCallback<TupleMe
throw new IllegalStateException(context.getString(R.string.title_no_internet));
Log.i("Boundary server connecting account=" + account.name);
state.iservice = new MailService(context, account.getProtocol(), account.realm, account.insecure, false, debug);
state.iservice = new EmailService(context, account.getProtocol(), account.realm, account.insecure, false, debug);
state.iservice.setPartialFetch(account.partial_fetch);
state.iservice.setIgnoreBodyStructureSize(account.ignore_size);
state.iservice.connect(account);
@ -576,7 +576,7 @@ public class BoundaryCallbackMessages extends PagedList.BoundaryCallback<TupleMe
List<Long> ids = null;
List<TupleMatch> matches = null;
MailService iservice = null;
EmailService iservice = null;
IMAPFolder ifolder = null;
Message[] imessages = null;
}

View File

@ -1238,8 +1238,8 @@ public abstract class DB extends RoomDatabase {
int previous_version = prefs.getInt("previous_version", -1);
if (previous_version <= 848 && Helper.isPlayStoreInstall()) {
// JavaMail didn't check server certificates
db.execSQL("UPDATE account SET insecure = 1 WHERE auth_type = " + MailService.AUTH_TYPE_PASSWORD);
db.execSQL("UPDATE identity SET insecure = 1 WHERE auth_type = " + MailService.AUTH_TYPE_PASSWORD);
db.execSQL("UPDATE account SET insecure = 1 WHERE auth_type = " + EmailService.AUTH_TYPE_PASSWORD);
db.execSQL("UPDATE identity SET insecure = 1 WHERE auth_type = " + EmailService.AUTH_TYPE_PASSWORD);
}
}
})

View File

@ -65,7 +65,7 @@ import javax.net.ssl.TrustManager;
import javax.net.ssl.TrustManagerFactory;
import javax.net.ssl.X509TrustManager;
public class MailService implements AutoCloseable {
public class EmailService implements AutoCloseable {
private Context context;
private String protocol;
private boolean insecure;
@ -96,11 +96,11 @@ public class MailService implements AutoCloseable {
"SSLv2", "SSLv3", "TLSv1", "TLSv1.1"
));
private MailService() {
private EmailService() {
// Prevent instantiation
}
MailService(Context context, String protocol, String realm, boolean insecure, boolean check, boolean debug) throws NoSuchProviderException {
EmailService(Context context, String protocol, String realm, boolean insecure, boolean check, boolean debug) throws NoSuchProviderException {
this.context = context.getApplicationContext();
this.protocol = protocol;
this.insecure = insecure;

View File

@ -149,7 +149,7 @@ public class FragmentAccount extends FragmentBase {
private long id = -1;
private long copy = -1;
private int auth = MailService.AUTH_TYPE_PASSWORD;
private int auth = EmailService.AUTH_TYPE_PASSWORD;
private String provider = null;
private boolean saving = false;
@ -610,7 +610,7 @@ public class FragmentAccount extends FragmentBase {
// Check IMAP server / get folders
String protocol = "imap" + (starttls ? "" : "s");
try (MailService iservice = new MailService(context, protocol, realm, insecure, true, true)) {
try (EmailService iservice = new EmailService(context, protocol, realm, insecure, true, true)) {
iservice.connect(host, Integer.parseInt(port), auth, provider, user, password, fingerprint);
result.idle = iservice.hasCapability("IDLE");
@ -977,7 +977,7 @@ public class FragmentAccount extends FragmentBase {
EntityFolder inbox = null;
if (check) {
String protocol = "imap" + (starttls ? "" : "s");
try (MailService iservice = new MailService(context, protocol, realm, insecure, true, true)) {
try (EmailService iservice = new EmailService(context, protocol, realm, insecure, true, true)) {
iservice.connect(host, Integer.parseInt(port), auth, provider, user, password, fingerprint);
for (Folder ifolder : iservice.getStore().getDefaultFolder().list("*")) {
@ -1236,7 +1236,7 @@ public class FragmentAccount extends FragmentBase {
if (account.user.equals(google.name))
return am.blockingGetAuthToken(
google,
MailService.getAuthTokenType("com.google"),
EmailService.getAuthTokenType("com.google"),
true);
return null;
@ -1259,8 +1259,8 @@ public class FragmentAccount extends FragmentBase {
tvError.setText(Log.formatThrowable(ex, false));
grpError.setVisibility(View.VISIBLE);
if (ex instanceof MailService.UntrustedException) {
MailService.UntrustedException e = (MailService.UntrustedException) ex;
if (ex instanceof EmailService.UntrustedException) {
EmailService.UntrustedException e = (EmailService.UntrustedException) ex;
cbTrust.setTag(e.getFingerprint());
cbTrust.setText(getString(R.string.title_trust, e.getFingerprint()));
cbTrust.setVisibility(View.VISIBLE);
@ -1384,7 +1384,7 @@ public class FragmentAccount extends FragmentBase {
cbIgnoreSize.setChecked(account == null ? false : account.ignore_size);
cbUseDate.setChecked(account == null ? false : account.use_date);
auth = (account == null ? MailService.AUTH_TYPE_PASSWORD : account.auth_type);
auth = (account == null ? EmailService.AUTH_TYPE_PASSWORD : account.auth_type);
provider = (account == null ? null : account.provider);
new SimpleTask<EntityAccount>() {
@ -1417,12 +1417,12 @@ public class FragmentAccount extends FragmentBase {
Helper.setViewsEnabled(view, true);
if (auth != MailService.AUTH_TYPE_PASSWORD) {
if (auth != EmailService.AUTH_TYPE_PASSWORD) {
etUser.setEnabled(false);
tilPassword.setEnabled(false);
}
if (account == null || account.auth_type != MailService.AUTH_TYPE_GMAIL)
if (account == null || account.auth_type != EmailService.AUTH_TYPE_GMAIL)
Helper.hide((btnOAuth));
cbOnDemand.setEnabled(cbSynchronize.isChecked());

View File

@ -270,7 +270,7 @@ public class FragmentAccounts extends FragmentBase {
boolean authorized = true;
for (TupleAccountEx account : accounts)
if (account.auth_type != MailService.AUTH_TYPE_PASSWORD &&
if (account.auth_type != EmailService.AUTH_TYPE_PASSWORD &&
!Helper.hasPermissions(getContext(), Helper.getOAuthPermissions())) {
authorized = false;
}

View File

@ -229,7 +229,7 @@ public class FragmentGmail extends FragmentBase {
if (name.equals(account.name)) {
am.getAuthToken(
account,
MailService.getAuthTokenType(type),
EmailService.getAuthTokenType(type),
new Bundle(),
getActivity(),
new AccountManagerCallback<Bundle>() {
@ -300,8 +300,8 @@ public class FragmentGmail extends FragmentBase {
List<EntityFolder> folders;
String aprotocol = provider.imap.starttls ? "imap" : "imaps";
try (MailService iservice = new MailService(context, aprotocol, null, false, true, true)) {
iservice.connect(provider.imap.host, provider.imap.port, MailService.AUTH_TYPE_GMAIL, null, user, password, null);
try (EmailService iservice = new EmailService(context, aprotocol, null, false, true, true)) {
iservice.connect(provider.imap.host, provider.imap.port, EmailService.AUTH_TYPE_GMAIL, null, user, password, null);
folders = iservice.getFolders();
@ -310,8 +310,8 @@ public class FragmentGmail extends FragmentBase {
}
String iprotocol = provider.smtp.starttls ? "smtp" : "smtps";
try (MailService iservice = new MailService(context, iprotocol, null, false, true, true)) {
iservice.connect(provider.smtp.host, provider.smtp.port, MailService.AUTH_TYPE_GMAIL, null, user, password, null);
try (EmailService iservice = new EmailService(context, iprotocol, null, false, true, true)) {
iservice.connect(provider.smtp.host, provider.smtp.port, EmailService.AUTH_TYPE_GMAIL, null, user, password, null);
}
DB db = DB.getInstance(context);
@ -326,7 +326,7 @@ public class FragmentGmail extends FragmentBase {
account.host = provider.imap.host;
account.starttls = provider.imap.starttls;
account.port = provider.imap.port;
account.auth_type = MailService.AUTH_TYPE_GMAIL;
account.auth_type = EmailService.AUTH_TYPE_GMAIL;
account.user = user;
account.password = password;
@ -370,7 +370,7 @@ public class FragmentGmail extends FragmentBase {
identity.host = provider.smtp.host;
identity.starttls = provider.smtp.starttls;
identity.port = provider.smtp.port;
identity.auth_type = MailService.AUTH_TYPE_GMAIL;
identity.auth_type = EmailService.AUTH_TYPE_GMAIL;
identity.user = user;
identity.password = password;
identity.synchronize = true;

View File

@ -129,7 +129,7 @@ public class FragmentIdentity extends FragmentBase {
private long id = -1;
private long copy = -1;
private long account = -1;
private int auth = MailService.AUTH_TYPE_PASSWORD;
private int auth = EmailService.AUTH_TYPE_PASSWORD;
private String provider = null;
private boolean saving = false;
@ -268,8 +268,8 @@ public class FragmentIdentity extends FragmentBase {
tilPassword.getEditText().setText(account.password);
etRealm.setText(account.realm);
etUser.setEnabled(auth == MailService.AUTH_TYPE_PASSWORD);
tilPassword.setEnabled(auth == MailService.AUTH_TYPE_PASSWORD);
etUser.setEnabled(auth == EmailService.AUTH_TYPE_PASSWORD);
tilPassword.setEnabled(auth == EmailService.AUTH_TYPE_PASSWORD);
cbTrust.setChecked(false);
}
@ -396,12 +396,12 @@ public class FragmentIdentity extends FragmentBase {
EntityAccount account = (EntityAccount) spAccount.getSelectedItem();
if (account == null ||
provider.imap.host == null || !provider.imap.host.equals(account.host))
auth = MailService.AUTH_TYPE_PASSWORD;
auth = EmailService.AUTH_TYPE_PASSWORD;
else
auth = account.auth_type;
etUser.setEnabled(auth == MailService.AUTH_TYPE_PASSWORD);
tilPassword.setEnabled(auth == MailService.AUTH_TYPE_PASSWORD);
etUser.setEnabled(auth == EmailService.AUTH_TYPE_PASSWORD);
tilPassword.setEnabled(auth == EmailService.AUTH_TYPE_PASSWORD);
}
@Override
@ -771,7 +771,7 @@ public class FragmentIdentity extends FragmentBase {
if (check) {
// Create transport
String protocol = (starttls ? "smtp" : "smtps");
try (MailService iservice = new MailService(context, protocol, realm, insecure, true, true)) {
try (EmailService iservice = new EmailService(context, protocol, realm, insecure, true, true)) {
iservice.setUseIp(use_ip);
iservice.connect(host, Integer.parseInt(port), auth, provider, user, password, fingerprint);
}
@ -900,7 +900,7 @@ public class FragmentIdentity extends FragmentBase {
if (identity.user.equals(google.name))
return am.blockingGetAuthToken(
google,
MailService.getAuthTokenType("com.google"),
EmailService.getAuthTokenType("com.google"),
true);
return null;
@ -923,8 +923,8 @@ public class FragmentIdentity extends FragmentBase {
tvError.setText(Log.formatThrowable(ex, false));
grpError.setVisibility(View.VISIBLE);
if (ex instanceof MailService.UntrustedException) {
MailService.UntrustedException e = (MailService.UntrustedException) ex;
if (ex instanceof EmailService.UntrustedException) {
EmailService.UntrustedException e = (EmailService.UntrustedException) ex;
cbTrust.setTag(e.getFingerprint());
cbTrust.setText(getString(R.string.title_trust, e.getFingerprint()));
cbTrust.setVisibility(View.VISIBLE);
@ -1022,7 +1022,7 @@ public class FragmentIdentity extends FragmentBase {
etReplyTo.setText(identity == null ? null : identity.replyto);
etBcc.setText(identity == null ? null : identity.bcc);
auth = (identity == null ? MailService.AUTH_TYPE_PASSWORD : identity.auth_type);
auth = (identity == null ? EmailService.AUTH_TYPE_PASSWORD : identity.auth_type);
provider = (identity == null ? null : identity.provider);
if (identity == null || copy > 0)
@ -1052,12 +1052,12 @@ public class FragmentIdentity extends FragmentBase {
Helper.setViewsEnabled(view, true);
if (auth != MailService.AUTH_TYPE_PASSWORD) {
if (auth != EmailService.AUTH_TYPE_PASSWORD) {
etUser.setEnabled(false);
tilPassword.setEnabled(false);
}
if (identity == null || identity.auth_type != MailService.AUTH_TYPE_GMAIL)
if (identity == null || identity.auth_type != EmailService.AUTH_TYPE_GMAIL)
Helper.hide(btnOAuth);
cbPrimary.setEnabled(cbSynchronize.isChecked());
@ -1077,7 +1077,7 @@ public class FragmentIdentity extends FragmentBase {
EntityAccount unselected = new EntityAccount();
unselected.id = -1L;
unselected.auth_type = MailService.AUTH_TYPE_PASSWORD;
unselected.auth_type = EmailService.AUTH_TYPE_PASSWORD;
unselected.name = getString(R.string.title_select);
unselected.primary = false;
accounts.add(0, unselected);

View File

@ -469,8 +469,8 @@ public class FragmentOAuth extends FragmentBase {
Log.i("OAuth checking IMAP provider=" + provider.id);
String aprotocol = provider.imap.starttls ? "imap" : "imaps";
try (MailService iservice = new MailService(context, aprotocol, null, false, true, true)) {
iservice.connect(provider.imap.host, provider.imap.port, MailService.AUTH_TYPE_OAUTH, provider.id, primaryEmail, state, null);
try (EmailService iservice = new EmailService(context, aprotocol, null, false, true, true)) {
iservice.connect(provider.imap.host, provider.imap.port, EmailService.AUTH_TYPE_OAUTH, provider.id, primaryEmail, state, null);
folders = iservice.getFolders();
@ -480,8 +480,8 @@ public class FragmentOAuth extends FragmentBase {
Log.i("OAuth checking SMTP provider=" + provider.id);
String iprotocol = provider.smtp.starttls ? "smtp" : "smtps";
try (MailService iservice = new MailService(context, iprotocol, null, false, true, true)) {
iservice.connect(provider.smtp.host, provider.smtp.port, MailService.AUTH_TYPE_OAUTH, provider.id, primaryEmail, state, null);
try (EmailService iservice = new EmailService(context, iprotocol, null, false, true, true)) {
iservice.connect(provider.smtp.host, provider.smtp.port, EmailService.AUTH_TYPE_OAUTH, provider.id, primaryEmail, state, null);
}
Log.i("OAuth passed provider=" + provider.id);
@ -498,7 +498,7 @@ public class FragmentOAuth extends FragmentBase {
account.host = provider.imap.host;
account.starttls = provider.imap.starttls;
account.port = provider.imap.port;
account.auth_type = MailService.AUTH_TYPE_OAUTH;
account.auth_type = EmailService.AUTH_TYPE_OAUTH;
account.provider = provider.id;
account.user = primaryEmail;
account.password = state;
@ -541,7 +541,7 @@ public class FragmentOAuth extends FragmentBase {
ident.host = provider.smtp.host;
ident.starttls = provider.smtp.starttls;
ident.port = provider.smtp.port;
ident.auth_type = MailService.AUTH_TYPE_OAUTH;
ident.auth_type = EmailService.AUTH_TYPE_OAUTH;
ident.provider = provider.id;
ident.user = primaryEmail;
ident.password = state;

View File

@ -309,8 +309,8 @@ public class FragmentPop extends FragmentBase {
// Check POP3 server
if (check) {
String protocol = "pop3" + (starttls ? "" : "s");
try (MailService iservice = new MailService(context, protocol, null, insecure, true, true)) {
iservice.connect(host, Integer.parseInt(port), MailService.AUTH_TYPE_PASSWORD, null, user, password, null);
try (EmailService iservice = new EmailService(context, protocol, null, insecure, true, true)) {
iservice.connect(host, Integer.parseInt(port), EmailService.AUTH_TYPE_PASSWORD, null, user, password, null);
}
}
@ -333,7 +333,7 @@ public class FragmentPop extends FragmentBase {
account.starttls = starttls;
account.insecure = insecure;
account.port = Integer.parseInt(port);
account.auth_type = MailService.AUTH_TYPE_PASSWORD;
account.auth_type = EmailService.AUTH_TYPE_PASSWORD;
account.user = user;
account.password = password;

View File

@ -275,15 +275,15 @@ public class FragmentQuickSetup extends FragmentBase {
List<EntityFolder> folders;
String aprotocol = provider.imap.starttls ? "imap" : "imaps";
try (MailService iservice = new MailService(context, aprotocol, null, false, true, true)) {
try (EmailService iservice = new EmailService(context, aprotocol, null, false, true, true)) {
try {
iservice.connect(provider.imap.host, provider.imap.port, MailService.AUTH_TYPE_PASSWORD, null, user, password, null);
iservice.connect(provider.imap.host, provider.imap.port, EmailService.AUTH_TYPE_PASSWORD, null, user, password, null);
} catch (AuthenticationFailedException ex) {
if (!user.equals(username)) {
Log.w(ex);
user = username;
Log.i("Retry with user=" + user);
iservice.connect(provider.imap.host, provider.imap.port, MailService.AUTH_TYPE_PASSWORD, null, user, password, null);
iservice.connect(provider.imap.host, provider.imap.port, EmailService.AUTH_TYPE_PASSWORD, null, user, password, null);
} else
throw ex;
}
@ -295,9 +295,9 @@ public class FragmentQuickSetup extends FragmentBase {
}
String iprotocol = provider.smtp.starttls ? "smtp" : "smtps";
try (MailService iservice = new MailService(context, iprotocol, null, false, true, true)) {
try (EmailService iservice = new EmailService(context, iprotocol, null, false, true, true)) {
iservice.setUseIp(provider.useip);
iservice.connect(provider.smtp.host, provider.smtp.port, MailService.AUTH_TYPE_PASSWORD, null, user, password, null);
iservice.connect(provider.smtp.host, provider.smtp.port, EmailService.AUTH_TYPE_PASSWORD, null, user, password, null);
}
if (check)
@ -315,7 +315,7 @@ public class FragmentQuickSetup extends FragmentBase {
account.host = provider.imap.host;
account.starttls = provider.imap.starttls;
account.port = provider.imap.port;
account.auth_type = MailService.AUTH_TYPE_PASSWORD;
account.auth_type = EmailService.AUTH_TYPE_PASSWORD;
account.user = user;
account.password = password;
@ -361,7 +361,7 @@ public class FragmentQuickSetup extends FragmentBase {
identity.host = provider.smtp.host;
identity.starttls = provider.smtp.starttls;
identity.port = provider.smtp.port;
identity.auth_type = MailService.AUTH_TYPE_PASSWORD;
identity.auth_type = EmailService.AUTH_TYPE_PASSWORD;
identity.user = user;
identity.password = password;
identity.use_ip = provider.useip;

View File

@ -418,7 +418,7 @@ public class ServiceSend extends ServiceBase {
}
// Create transport
try (MailService iservice = new MailService(
try (EmailService iservice = new EmailService(
this, ident.getProtocol(), ident.realm, ident.insecure, false, debug)) {
iservice.setUseIp(ident.use_ip);

View File

@ -793,7 +793,7 @@ public class ServiceSynchronize extends ServiceBase implements SharedPreferences
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
boolean debug = (prefs.getBoolean("debug", false) || BuildConfig.DEBUG);
final MailService iservice = new MailService(
final EmailService iservice = new EmailService(
this, account.getProtocol(), account.realm, account.insecure, false, debug);
iservice.setPartialFetch(account.partial_fetch);
iservice.setIgnoreBodyStructureSize(account.ignore_size);