mirror of
https://github.com/M66B/FairEmail.git
synced 2025-12-29 00:51:44 +01:00
Simplification
This commit is contained in:
@@ -46,65 +46,65 @@ public class MailService implements AutoCloseable {
|
||||
this.context = context.getApplicationContext();
|
||||
this.protocol = protocol;
|
||||
this.debug = debug;
|
||||
this.properties = MessageHelper.getSessionProperties();
|
||||
properties = MessageHelper.getSessionProperties();
|
||||
|
||||
this.properties.put("mail.event.scope", "folder");
|
||||
properties.put("mail.event.scope", "folder");
|
||||
|
||||
String checkserveridentity = Boolean.toString(!insecure).toLowerCase();
|
||||
|
||||
if ("imap".equals(protocol) || "imaps".equals(protocol)) {
|
||||
// https://javaee.github.io/javamail/docs/api/com/sun/mail/imap/package-summary.html#properties
|
||||
this.properties.put("mail." + this.protocol + ".ssl.checkserveridentity", checkserveridentity);
|
||||
this.properties.put("mail." + this.protocol + ".ssl.trust", "*");
|
||||
properties.put("mail." + protocol + ".ssl.checkserveridentity", checkserveridentity);
|
||||
properties.put("mail." + protocol + ".ssl.trust", "*");
|
||||
|
||||
this.properties.put("mail.imaps.starttls.enable", "false");
|
||||
properties.put("mail.imaps.starttls.enable", "false");
|
||||
|
||||
this.properties.put("mail.imap.starttls.enable", "true");
|
||||
this.properties.put("mail.imap.starttls.required", "true");
|
||||
properties.put("mail.imap.starttls.enable", "true");
|
||||
properties.put("mail.imap.starttls.required", "true");
|
||||
|
||||
if (realm != null)
|
||||
this.properties.put("mail." + this.protocol + ".auth.ntlm.domain", realm);
|
||||
properties.put("mail." + protocol + ".auth.ntlm.domain", realm);
|
||||
|
||||
// TODO: make timeouts configurable?
|
||||
this.properties.put("mail." + this.protocol + ".connectiontimeout", Integer.toString(CONNECT_TIMEOUT));
|
||||
this.properties.put("mail." + this.protocol + ".writetimeout", Integer.toString(WRITE_TIMEOUT)); // one thread overhead
|
||||
this.properties.put("mail." + this.protocol + ".timeout", Integer.toString(READ_TIMEOUT));
|
||||
properties.put("mail." + protocol + ".connectiontimeout", Integer.toString(CONNECT_TIMEOUT));
|
||||
properties.put("mail." + protocol + ".writetimeout", Integer.toString(WRITE_TIMEOUT)); // one thread overhead
|
||||
properties.put("mail." + protocol + ".timeout", Integer.toString(READ_TIMEOUT));
|
||||
|
||||
this.properties.put("mail." + this.protocol + ".connectionpool.debug", "true");
|
||||
this.properties.put("mail." + this.protocol + ".connectionpoolsize", "2");
|
||||
this.properties.put("mail." + this.protocol + ".connectionpooltimeout", Integer.toString(POOL_TIMEOUT));
|
||||
properties.put("mail." + protocol + ".connectionpool.debug", "true");
|
||||
properties.put("mail." + protocol + ".connectionpoolsize", "2");
|
||||
properties.put("mail." + protocol + ".connectionpooltimeout", Integer.toString(POOL_TIMEOUT));
|
||||
|
||||
this.properties.put("mail." + this.protocol + ".finalizecleanclose", "false");
|
||||
properties.put("mail." + protocol + ".finalizecleanclose", "false");
|
||||
|
||||
// https://tools.ietf.org/html/rfc4978
|
||||
// https://docs.oracle.com/javase/8/docs/api/java/util/zip/Deflater.html
|
||||
this.properties.put("mail." + this.protocol + ".compress.enable", "true");
|
||||
//this.properties.put("mail.imaps.compress.level", "-1");
|
||||
//this.properties.put("mail.imaps.compress.strategy", "0");
|
||||
properties.put("mail." + protocol + ".compress.enable", "true");
|
||||
//properties.put("mail.imaps.compress.level", "-1");
|
||||
//properties.put("mail.imaps.compress.strategy", "0");
|
||||
|
||||
this.properties.put("mail." + this.protocol + ".throwsearchexception", "true");
|
||||
this.properties.put("mail." + this.protocol + ".fetchsize", Integer.toString(FETCH_SIZE));
|
||||
this.properties.put("mail." + this.protocol + ".peek", "true");
|
||||
this.properties.put("mail." + this.protocol + ".appendbuffersize", Integer.toString(APPEND_BUFFER_SIZE));
|
||||
properties.put("mail." + protocol + ".throwsearchexception", "true");
|
||||
properties.put("mail." + protocol + ".fetchsize", Integer.toString(FETCH_SIZE));
|
||||
properties.put("mail." + protocol + ".peek", "true");
|
||||
properties.put("mail." + protocol + ".appendbuffersize", Integer.toString(APPEND_BUFFER_SIZE));
|
||||
|
||||
} else if ("smtp".equals(protocol) || "smtps".equals(protocol)) {
|
||||
// https://javaee.github.io/javamail/docs/api/com/sun/mail/smtp/package-summary.html#properties
|
||||
this.properties.put("mail." + this.protocol + ".ssl.checkserveridentity", checkserveridentity);
|
||||
this.properties.put("mail." + this.protocol + ".ssl.trust", "*");
|
||||
properties.put("mail." + protocol + ".ssl.checkserveridentity", checkserveridentity);
|
||||
properties.put("mail." + protocol + ".ssl.trust", "*");
|
||||
|
||||
this.properties.put("mail.smtps.starttls.enable", "false");
|
||||
properties.put("mail.smtps.starttls.enable", "false");
|
||||
|
||||
this.properties.put("mail.smtp.starttls.enable", "true");
|
||||
this.properties.put("mail.smtp.starttls.required", "true");
|
||||
properties.put("mail.smtp.starttls.enable", "true");
|
||||
properties.put("mail.smtp.starttls.required", "true");
|
||||
|
||||
this.properties.put("mail." + this.protocol + ".auth", "true");
|
||||
properties.put("mail." + protocol + ".auth", "true");
|
||||
|
||||
if (realm != null)
|
||||
this.properties.put("mail." + this.protocol + ".auth.ntlm.domain", realm);
|
||||
properties.put("mail." + protocol + ".auth.ntlm.domain", realm);
|
||||
|
||||
this.properties.put("mail." + this.protocol + ".connectiontimeout", Integer.toString(CONNECT_TIMEOUT));
|
||||
this.properties.put("mail." + this.protocol + ".writetimeout", Integer.toString(WRITE_TIMEOUT)); // one thread overhead
|
||||
this.properties.put("mail." + this.protocol + ".timeout", Integer.toString(READ_TIMEOUT));
|
||||
properties.put("mail." + protocol + ".connectiontimeout", Integer.toString(CONNECT_TIMEOUT));
|
||||
properties.put("mail." + protocol + ".writetimeout", Integer.toString(WRITE_TIMEOUT)); // one thread overhead
|
||||
properties.put("mail." + protocol + ".timeout", Integer.toString(READ_TIMEOUT));
|
||||
|
||||
} else
|
||||
throw new NoSuchProviderException(protocol);
|
||||
@@ -112,15 +112,15 @@ public class MailService implements AutoCloseable {
|
||||
|
||||
void setPartialFetch(boolean enabled) {
|
||||
if (!enabled)
|
||||
this.properties.put("mail." + this.protocol + ".partialfetch", "false");
|
||||
properties.put("mail." + protocol + ".partialfetch", "false");
|
||||
}
|
||||
|
||||
void setUseIp(boolean enabled) {
|
||||
this.useip = enabled;
|
||||
useip = enabled;
|
||||
}
|
||||
|
||||
void setSeparateStoreConnection() {
|
||||
this.properties.put("mail." + this.protocol + ".separatestoreconnection", "true");
|
||||
properties.put("mail." + protocol + ".separatestoreconnection", "true");
|
||||
}
|
||||
|
||||
public void connect(EntityAccount account) throws MessagingException {
|
||||
@@ -139,7 +139,7 @@ public class MailService implements AutoCloseable {
|
||||
} catch (MailConnectException ex) {
|
||||
try {
|
||||
// Some devices resolve IPv6 addresses while not having IPv6 connectivity
|
||||
this.properties.put("mail." + this.protocol + ".ssl.checkserveridentity", "false");
|
||||
properties.put("mail." + protocol + ".ssl.checkserveridentity", "false");
|
||||
InetAddress[] iaddrs = InetAddress.getAllByName(host);
|
||||
if (iaddrs.length > 1)
|
||||
for (InetAddress iaddr : iaddrs)
|
||||
@@ -202,7 +202,7 @@ public class MailService implements AutoCloseable {
|
||||
}
|
||||
|
||||
Log.i("Using localhost=" + haddr);
|
||||
this.properties.put("mail." + this.protocol + ".localhost", haddr);
|
||||
properties.put("mail." + protocol + ".localhost", haddr);
|
||||
|
||||
iservice = isession.getTransport(protocol);
|
||||
iservice.connect(host, port, user, password);
|
||||
@@ -211,11 +211,11 @@ public class MailService implements AutoCloseable {
|
||||
}
|
||||
|
||||
IMAPStore getStore() {
|
||||
return (IMAPStore) this.iservice;
|
||||
return (IMAPStore) iservice;
|
||||
}
|
||||
|
||||
SMTPTransport getTransport() {
|
||||
return (SMTPTransport) this.iservice;
|
||||
return (SMTPTransport) iservice;
|
||||
}
|
||||
|
||||
public void close() throws MessagingException {
|
||||
@@ -223,7 +223,7 @@ public class MailService implements AutoCloseable {
|
||||
if (iservice != null)
|
||||
iservice.close();
|
||||
} finally {
|
||||
this.context = null;
|
||||
context = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user