|
|
@ -34,6 +34,7 @@ import javax.mail.NoSuchProviderException;
|
|
|
|
import javax.mail.Service;
|
|
|
|
import javax.mail.Service;
|
|
|
|
import javax.mail.Session;
|
|
|
|
import javax.mail.Session;
|
|
|
|
import javax.mail.Store;
|
|
|
|
import javax.mail.Store;
|
|
|
|
|
|
|
|
import javax.mail.event.StoreListener;
|
|
|
|
|
|
|
|
|
|
|
|
public class MailService implements AutoCloseable {
|
|
|
|
public class MailService implements AutoCloseable {
|
|
|
|
private Context context;
|
|
|
|
private Context context;
|
|
|
@ -43,6 +44,7 @@ public class MailService implements AutoCloseable {
|
|
|
|
private Properties properties;
|
|
|
|
private Properties properties;
|
|
|
|
private Session isession;
|
|
|
|
private Session isession;
|
|
|
|
private Service iservice;
|
|
|
|
private Service iservice;
|
|
|
|
|
|
|
|
private StoreListener listener;
|
|
|
|
|
|
|
|
|
|
|
|
private ExecutorService executor = Helper.getBackgroundExecutor(0, "mail");
|
|
|
|
private ExecutorService executor = Helper.getBackgroundExecutor(0, "mail");
|
|
|
|
|
|
|
|
|
|
|
@ -123,6 +125,7 @@ public class MailService implements AutoCloseable {
|
|
|
|
properties.put("mail.imap.starttls.enable", "true");
|
|
|
|
properties.put("mail.imap.starttls.enable", "true");
|
|
|
|
properties.put("mail.imap.starttls.required", Boolean.toString(!insecure));
|
|
|
|
properties.put("mail.imap.starttls.required", Boolean.toString(!insecure));
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
properties.put("mail." + protocol + ".separatestoreconnection", "true");
|
|
|
|
properties.put("mail." + protocol + ".connectionpool.debug", "true");
|
|
|
|
properties.put("mail." + protocol + ".connectionpool.debug", "true");
|
|
|
|
properties.put("mail." + protocol + ".connectionpoolsize", "1");
|
|
|
|
properties.put("mail." + protocol + ".connectionpoolsize", "1");
|
|
|
|
properties.put("mail." + protocol + ".connectionpooltimeout", Integer.toString(POOL_TIMEOUT));
|
|
|
|
properties.put("mail." + protocol + ".connectionpooltimeout", Integer.toString(POOL_TIMEOUT));
|
|
|
@ -169,14 +172,14 @@ public class MailService implements AutoCloseable {
|
|
|
|
useip = enabled;
|
|
|
|
useip = enabled;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void setSeparateStoreConnection() {
|
|
|
|
|
|
|
|
properties.put("mail." + protocol + ".separatestoreconnection", "true");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void setLeaveOnServer(boolean keep) {
|
|
|
|
void setLeaveOnServer(boolean keep) {
|
|
|
|
properties.put("mail." + protocol + ".rsetbeforequit", Boolean.toString(keep));
|
|
|
|
properties.put("mail." + protocol + ".rsetbeforequit", Boolean.toString(keep));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void setListener(StoreListener listener) {
|
|
|
|
|
|
|
|
this.listener = listener;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void connect(EntityAccount account) throws MessagingException {
|
|
|
|
public void connect(EntityAccount account) throws MessagingException {
|
|
|
|
String password = connect(account.host, account.port, account.auth_type, account.user, account.password);
|
|
|
|
String password = connect(account.host, account.port, account.auth_type, account.user, account.password);
|
|
|
|
if (password != null) {
|
|
|
|
if (password != null) {
|
|
|
@ -265,6 +268,8 @@ public class MailService implements AutoCloseable {
|
|
|
|
|
|
|
|
|
|
|
|
} else if ("imap".equals(protocol) || "imaps".equals(protocol)) {
|
|
|
|
} else if ("imap".equals(protocol) || "imaps".equals(protocol)) {
|
|
|
|
iservice = isession.getStore(protocol);
|
|
|
|
iservice = isession.getStore(protocol);
|
|
|
|
|
|
|
|
if (listener != null)
|
|
|
|
|
|
|
|
((IMAPStore) iservice).addStoreListener(listener);
|
|
|
|
iservice.connect(host, port, user, password);
|
|
|
|
iservice.connect(host, port, user, password);
|
|
|
|
|
|
|
|
|
|
|
|
// https://www.ietf.org/rfc/rfc2971.txt
|
|
|
|
// https://www.ietf.org/rfc/rfc2971.txt
|
|
|
|