|
|
|
@ -908,46 +908,49 @@ public class EmailService implements AutoCloseable {
|
|
|
|
|
|
|
|
|
|
|
|
if ("pop3".equals(protocol) || "pop3s".equals(protocol)) {
|
|
|
|
if ("pop3".equals(protocol) || "pop3s".equals(protocol)) {
|
|
|
|
iservice = isession.getStore(protocol);
|
|
|
|
iservice = isession.getStore(protocol);
|
|
|
|
iservice.connect(address.getHostAddress(), port, user, null);
|
|
|
|
if (!EntityAccount.isTestAccount(user))
|
|
|
|
|
|
|
|
iservice.connect(address.getHostAddress(), port, user, null);
|
|
|
|
|
|
|
|
|
|
|
|
} else if ("imap".equals(protocol) || "imaps".equals(protocol) || "gimaps".equals(protocol)) {
|
|
|
|
} else if ("imap".equals(protocol) || "imaps".equals(protocol) || "gimaps".equals(protocol)) {
|
|
|
|
iservice = isession.getStore(protocol);
|
|
|
|
iservice = isession.getStore(protocol);
|
|
|
|
if (listener != null)
|
|
|
|
if (listener != null)
|
|
|
|
((IMAPStore) iservice).addStoreListener(listener);
|
|
|
|
((IMAPStore) iservice).addStoreListener(listener);
|
|
|
|
iservice.connect(address.getHostAddress(), port, user, null);
|
|
|
|
if (!EntityAccount.isTestAccount(user)) {
|
|
|
|
|
|
|
|
iservice.connect(address.getHostAddress(), port, user, null);
|
|
|
|
|
|
|
|
|
|
|
|
// https://www.ietf.org/rfc/rfc2971.txt
|
|
|
|
// https://www.ietf.org/rfc/rfc2971.txt
|
|
|
|
IMAPStore istore = (IMAPStore) getStore();
|
|
|
|
IMAPStore istore = (IMAPStore) getStore();
|
|
|
|
if (istore.hasCapability("ID"))
|
|
|
|
if (istore.hasCapability("ID"))
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
|
|
|
|
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
|
|
|
|
boolean client_id = prefs.getBoolean("client_id", true);
|
|
|
|
boolean client_id = prefs.getBoolean("client_id", true);
|
|
|
|
Map<String, String> sid = istore.id(client_id ? getId(context) : null);
|
|
|
|
Map<String, String> sid = istore.id(client_id ? getId(context) : null);
|
|
|
|
if (sid != null) {
|
|
|
|
if (sid != null) {
|
|
|
|
Map<String, String> crumb = new HashMap<>();
|
|
|
|
Map<String, String> crumb = new HashMap<>();
|
|
|
|
for (String key : sid.keySet()) {
|
|
|
|
for (String key : sid.keySet()) {
|
|
|
|
crumb.put(key, sid.get(key));
|
|
|
|
crumb.put(key, sid.get(key));
|
|
|
|
EntityLog.log(context, EntityLog.Type.Protocol, "Server " + key + "=" + sid.get(key));
|
|
|
|
EntityLog.log(context, EntityLog.Type.Protocol, "Server " + key + "=" + sid.get(key));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
Log.breadcrumb("server", crumb);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
Log.breadcrumb("server", crumb);
|
|
|
|
} catch (MessagingException ex) {
|
|
|
|
|
|
|
|
Log.w(ex);
|
|
|
|
|
|
|
|
// Check for 'User is authenticated but not connected'
|
|
|
|
|
|
|
|
if (require_id)
|
|
|
|
|
|
|
|
throw ex;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} catch (MessagingException ex) {
|
|
|
|
|
|
|
|
Log.w(ex);
|
|
|
|
|
|
|
|
// Check for 'User is authenticated but not connected'
|
|
|
|
|
|
|
|
if (require_id)
|
|
|
|
|
|
|
|
throw ex;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Verizon
|
|
|
|
// Verizon
|
|
|
|
// https://senders.yahooinc.com/developer/documentation/#imap-modes-limited
|
|
|
|
// https://senders.yahooinc.com/developer/documentation/#imap-modes-limited
|
|
|
|
// https://www.ietf.org/archive/id/draft-melnikov-imap-uidonly-00.html
|
|
|
|
// https://www.ietf.org/archive/id/draft-melnikov-imap-uidonly-00.html
|
|
|
|
// https://answers.microsoft.com/en-us/outlook_com/forum/all/why-is-an-imap-inbox-only-displaying-10000-items/6d15de5f-9047-4b41-9b58-1d8345bbd002
|
|
|
|
// https://answers.microsoft.com/en-us/outlook_com/forum/all/why-is-an-imap-inbox-only-displaying-10000-items/6d15de5f-9047-4b41-9b58-1d8345bbd002
|
|
|
|
if (false && istore.hasCapability("X-UIDONLY") && istore.hasCapability("ENABLE"))
|
|
|
|
if (false && istore.hasCapability("X-UIDONLY") && istore.hasCapability("ENABLE"))
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
istore.enable("X-UIDONLY");
|
|
|
|
istore.enable("X-UIDONLY");
|
|
|
|
} catch (ProtocolException ex) {
|
|
|
|
} catch (ProtocolException ex) {
|
|
|
|
Log.e(ex);
|
|
|
|
Log.e(ex);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
} else if ("smtp".equals(protocol) || "smtps".equals(protocol)) {
|
|
|
|
} else if ("smtp".equals(protocol) || "smtps".equals(protocol)) {
|
|
|
|
// https://tools.ietf.org/html/rfc5321#section-4.1.3
|
|
|
|
// https://tools.ietf.org/html/rfc5321#section-4.1.3
|
|
|
|
@ -959,22 +962,23 @@ public class EmailService implements AutoCloseable {
|
|
|
|
Log.i("Using localhost=" + properties.getProperty("mail." + protocol + ".localhost"));
|
|
|
|
Log.i("Using localhost=" + properties.getProperty("mail." + protocol + ".localhost"));
|
|
|
|
|
|
|
|
|
|
|
|
iservice = isession.getTransport(protocol);
|
|
|
|
iservice = isession.getTransport(protocol);
|
|
|
|
try {
|
|
|
|
if (!EntityAccount.isTestAccount(user))
|
|
|
|
iservice.connect(address.getHostAddress(), port, user, null);
|
|
|
|
try {
|
|
|
|
} catch (MessagingException ex) {
|
|
|
|
iservice.connect(address.getHostAddress(), port, user, null);
|
|
|
|
if (ehlo == null && ConnectionHelper.isSyntacticallyInvalid(ex)) {
|
|
|
|
} catch (MessagingException ex) {
|
|
|
|
properties.put("mail." + protocol + ".localhost", useip ? hdomain : haddr);
|
|
|
|
if (ehlo == null && ConnectionHelper.isSyntacticallyInvalid(ex)) {
|
|
|
|
Log.i("Fallback localhost=" + properties.getProperty("mail." + protocol + ".localhost"));
|
|
|
|
properties.put("mail." + protocol + ".localhost", useip ? hdomain : haddr);
|
|
|
|
try {
|
|
|
|
Log.i("Fallback localhost=" + properties.getProperty("mail." + protocol + ".localhost"));
|
|
|
|
iservice.connect(address.getHostAddress(), port, user, null);
|
|
|
|
try {
|
|
|
|
} catch (MessagingException ex1) {
|
|
|
|
iservice.connect(address.getHostAddress(), port, user, null);
|
|
|
|
if (ConnectionHelper.isSyntacticallyInvalid(ex1))
|
|
|
|
} catch (MessagingException ex1) {
|
|
|
|
Log.e("Used localhost=" + haddr + "/" + hdomain);
|
|
|
|
if (ConnectionHelper.isSyntacticallyInvalid(ex1))
|
|
|
|
throw ex1;
|
|
|
|
Log.e("Used localhost=" + haddr + "/" + hdomain);
|
|
|
|
}
|
|
|
|
throw ex1;
|
|
|
|
} else
|
|
|
|
}
|
|
|
|
throw ex;
|
|
|
|
} else
|
|
|
|
}
|
|
|
|
throw ex;
|
|
|
|
|
|
|
|
}
|
|
|
|
} else
|
|
|
|
} else
|
|
|
|
throw new NoSuchProviderException(protocol);
|
|
|
|
throw new NoSuchProviderException(protocol);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|