Improved demo account handling

master
M66B 2 weeks ago
parent d3b3adc42a
commit a6d70ce6f1

@ -425,7 +425,7 @@ public class BoundaryCallbackMessages extends PagedList.BoundaryCallback<TupleMe
} }
EntityAccount account = db.account().getAccount(browsable.account); EntityAccount account = db.account().getAccount(browsable.account);
if (account == null || account.protocol != EntityAccount.TYPE_IMAP) if (account == null || account.protocol != EntityAccount.TYPE_IMAP || account.isTestAccount())
return 0; return 0;
if (criteria == null) { if (criteria == null) {

@ -167,11 +167,6 @@ class Core {
State state, long serial) State state, long serial)
throws JSONException, FolderClosedException { throws JSONException, FolderClosedException {
try { try {
if (EntityAccount.isTestUser(account.user)) {
ops.clear();
return;
}
Log.i(folder.name + " start process"); Log.i(folder.name + " start process");
Store istore = iservice.getStore(); Store istore = iservice.getStore();

@ -908,49 +908,46 @@ 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);
if (!EntityAccount.isTestUser(user)) iservice.connect(address.getHostAddress(), port, user, null);
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);
if (!EntityAccount.isTestUser(user)) { iservice.connect(address.getHostAddress(), port, user, null);
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);
} }
} catch (MessagingException ex) { Log.breadcrumb("server", crumb);
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
@ -962,23 +959,22 @@ 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);
if (!EntityAccount.isTestUser(user)) try {
try { iservice.connect(address.getHostAddress(), port, user, null);
iservice.connect(address.getHostAddress(), port, user, null); } catch (MessagingException ex) {
} catch (MessagingException ex) { if (ehlo == null && ConnectionHelper.isSyntacticallyInvalid(ex)) {
if (ehlo == null && ConnectionHelper.isSyntacticallyInvalid(ex)) { properties.put("mail." + protocol + ".localhost", useip ? hdomain : haddr);
properties.put("mail." + protocol + ".localhost", useip ? hdomain : haddr); Log.i("Fallback localhost=" + properties.getProperty("mail." + protocol + ".localhost"));
Log.i("Fallback localhost=" + properties.getProperty("mail." + protocol + ".localhost")); try {
try { iservice.connect(address.getHostAddress(), port, user, null);
iservice.connect(address.getHostAddress(), port, user, null); } catch (MessagingException ex1) {
} catch (MessagingException ex1) { if (ConnectionHelper.isSyntacticallyInvalid(ex1))
if (ConnectionHelper.isSyntacticallyInvalid(ex1)) Log.e("Used localhost=" + haddr + "/" + hdomain);
Log.e("Used localhost=" + haddr + "/" + hdomain); throw ex1;
throw ex1; }
} } else
} else throw ex;
throw ex; }
}
} else } else
throw new NoSuchProviderException(protocol); throw new NoSuchProviderException(protocol);
} }

@ -565,6 +565,10 @@ public class EntityAccount extends EntityOrder implements Serializable {
}; };
} }
boolean isTestAccount() {
return isTestUser(this.user);
}
static boolean isTestUser(String user) { static boolean isTestUser(String user) {
return (user != null && user.endsWith("@demo.faircode.eu")); return (user != null && user.endsWith("@demo.faircode.eu"));
} }

@ -458,6 +458,10 @@ public class EntityIdentity {
return (display == null ? name : display); return (display == null ? name : display);
} }
boolean isTestIdentity() {
return EntityAccount.isTestUser(this.user);
}
static EntityIdentity getTestIdentity(Long account, String user) { static EntityIdentity getTestIdentity(Long account, String user) {
EntityIdentity identity = new EntityIdentity(); EntityIdentity identity = new EntityIdentity();
identity.account = account; identity.account = account;

@ -116,6 +116,13 @@ public class EntityOperation {
static void queue(Context context, EntityMessage message, String name, Object... values) { static void queue(Context context, EntityMessage message, String name, Object... values) {
DB db = DB.getInstance(context); DB db = DB.getInstance(context);
EntityAccount account = db.account().getAccount(message.account);
if (account != null && account.isTestAccount()) {
if (DELETE.equals(name) || SEND.equals(name))
db.message().deleteMessage(message.id);
return;
}
try { try {
JSONArray jargs = new JSONArray(); JSONArray jargs = new JSONArray();
for (Object value : values) for (Object value : values)
@ -124,7 +131,6 @@ public class EntityOperation {
if (SEEN.equals(name)) { if (SEEN.equals(name)) {
boolean seen = jargs.getBoolean(0); boolean seen = jargs.getBoolean(0);
boolean ignore = jargs.optBoolean(1, true); boolean ignore = jargs.optBoolean(1, true);
EntityAccount account = db.account().getAccount(message.account);
for (EntityMessage similar : db.message().getMessagesBySimilarity(message.account, message.id, message.msgid, message.hash)) { for (EntityMessage similar : db.message().getMessagesBySimilarity(message.account, message.id, message.msgid, message.hash)) {
if ((account != null && !account.isGmail() && !account.isWebDe()) && if ((account != null && !account.isGmail() && !account.isWebDe()) &&
!Objects.equals(message.id, similar.id) && !Objects.equals(message.id, similar.id) &&
@ -141,7 +147,6 @@ public class EntityOperation {
} else if (FLAG.equals(name)) { } else if (FLAG.equals(name)) {
boolean flagged = jargs.getBoolean(0); boolean flagged = jargs.getBoolean(0);
Integer color = (jargs.length() > 1 && !jargs.isNull(1) ? jargs.getInt(1) : null); Integer color = (jargs.length() > 1 && !jargs.isNull(1) ? jargs.getInt(1) : null);
EntityAccount account = db.account().getAccount(message.id);
for (EntityMessage similar : db.message().getMessagesBySimilarity(message.account, message.id, message.msgid, message.hash)) { for (EntityMessage similar : db.message().getMessagesBySimilarity(message.account, message.id, message.msgid, message.hash)) {
if ((account != null && !account.isGmail()) && if ((account != null && !account.isGmail()) &&
!Objects.equals(message.id, similar.id) && !Objects.equals(message.id, similar.id) &&
@ -164,7 +169,6 @@ public class EntityOperation {
return; return;
} else if (ANSWERED.equals(name)) { } else if (ANSWERED.equals(name)) {
EntityAccount account = db.account().getAccount(message.id);
for (EntityMessage similar : db.message().getMessagesBySimilarity(message.account, message.id, message.msgid, message.hash)) { for (EntityMessage similar : db.message().getMessagesBySimilarity(message.account, message.id, message.msgid, message.hash)) {
if ((account != null && !account.isGmail()) && if ((account != null && !account.isGmail()) &&
!Objects.equals(message.id, similar.id) && !Objects.equals(message.id, similar.id) &&
@ -206,7 +210,6 @@ public class EntityOperation {
DB.Converters.fromStringArray(fkeywords.toArray(new String[0]))); DB.Converters.fromStringArray(fkeywords.toArray(new String[0])));
} }
} else { } else {
EntityAccount account = db.account().getAccount(message.account);
if (account != null && account.protocol == EntityAccount.TYPE_POP) { if (account != null && account.protocol == EntityAccount.TYPE_POP) {
EntityFolder folder = db.folder().getFolder(message.folder); EntityFolder folder = db.folder().getFolder(message.folder);
if (folder != null) { if (folder != null) {
@ -320,7 +323,6 @@ public class EntityOperation {
" auto read=" + autoread + " flag=" + autounflag + " importance=" + reset_importance); " auto read=" + autoread + " flag=" + autounflag + " importance=" + reset_importance);
if (autoread || autounflag || reset_importance) { if (autoread || autounflag || reset_importance) {
EntityAccount account = db.account().getAccount(message.account);
for (EntityMessage similar : db.message().getMessagesBySimilarity(message.account, message.id, message.msgid, message.hash)) { for (EntityMessage similar : db.message().getMessagesBySimilarity(message.account, message.id, message.msgid, message.hash)) {
if ((account != null && !account.isGmail()) && if ((account != null && !account.isGmail()) &&
!Objects.equals(message.id, similar.id) && !Objects.equals(message.id, similar.id) &&
@ -343,7 +345,6 @@ public class EntityOperation {
boolean premove = true; boolean premove = true;
if (source.account.equals(target.account)) { if (source.account.equals(target.account)) {
EntityAccount account = db.account().getAccount(message.account);
if (account != null && account.isGmail()) { if (account != null && account.isGmail()) {
if (EntityFolder.ARCHIVE.equals(source.type) && if (EntityFolder.ARCHIVE.equals(source.type) &&
!(EntityFolder.SENT.equals(target.type) || !(EntityFolder.SENT.equals(target.type) ||
@ -540,8 +541,6 @@ public class EntityOperation {
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context); SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
boolean perform_expunge = prefs.getBoolean("perform_expunge", true); boolean perform_expunge = prefs.getBoolean("perform_expunge", true);
EntityAccount account = db.account().getAccount(message.account);
if (perform_expunge || if (perform_expunge ||
account == null || account == null ||
account.protocol != EntityAccount.TYPE_IMAP) { account.protocol != EntityAccount.TYPE_IMAP) {

@ -672,11 +672,6 @@ public class ServiceSend extends ServiceBase implements SharedPreferences.OnShar
throw new IllegalArgumentException("Message body missing"); throw new IllegalArgumentException("Message body missing");
EntityAccount account = db.account().getAccount(message.account); EntityAccount account = db.account().getAccount(message.account);
if (EntityAccount.isTestUser(account.user)){
db.operation().deleteOperation(operation.id);
db.message().deleteMessage(message.id);
return;
}
EntityIdentity ident = db.identity().getIdentity(message.identity); EntityIdentity ident = db.identity().getIdentity(message.identity);
if (ident == null) if (ident == null)

@ -1631,6 +1631,9 @@ public class ServiceSynchronize extends ServiceBase implements SharedPreferences
final PowerManager.WakeLock wlMessage = pm.newWakeLock( final PowerManager.WakeLock wlMessage = pm.newWakeLock(
PowerManager.PARTIAL_WAKE_LOCK, BuildConfig.APPLICATION_ID + ":account." + account.id + ".message"); PowerManager.PARTIAL_WAKE_LOCK, BuildConfig.APPLICATION_ID + ":account." + account.id + ".message");
if (account != null && account.isTestAccount())
return;
long start = new Date().getTime(); long start = new Date().getTime();
try { try {
wlAccount.acquire(Helper.WAKELOCK_MAX); wlAccount.acquire(Helper.WAKELOCK_MAX);

Loading…
Cancel
Save