Fixed IMAP event listener

This commit is contained in:
M66B
2019-12-09 16:32:37 +01:00
parent f8a7c1f42f
commit 1a596ea511
4 changed files with 38 additions and 37 deletions

View File

@@ -714,6 +714,35 @@ public class ServiceSynchronize extends ServiceBase implements SharedPreferences
iservice.setIgnoreBodyStructureSize(account.ignore_size);
if (account.protocol != EntityAccount.TYPE_IMAP)
iservice.setLeaveOnServer(account.browse);
iservice.setListener(new StoreListener() {
@Override
public void notification(StoreEvent e) {
if (e.getMessageType() == StoreEvent.NOTICE)
EntityLog.log(ServiceSynchronize.this, account.name + " notice: " + e.getMessage());
else
try {
wlFolder.acquire();
String message = e.getMessage();
Log.w(account.name + " alert: " + message);
EntityLog.log(
ServiceSynchronize.this, account.name + " " +
Log.formatThrowable(new Core.AlertException(message), false));
db.account().setAccountError(account.id, message);
NotificationManager nm = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
nm.notify("alert:" + account.id, 1,
Core.getNotificationError(
ServiceSynchronize.this, "warning", account.name,
new Core.AlertException(message))
.build());
state.error(null);
} finally {
wlFolder.release();
}
}
});
final Map<EntityFolder, IMAPFolder> mapFolders = new HashMap<>();
List<Thread> idlers = new ArrayList<>();
@@ -766,37 +795,6 @@ public class ServiceSynchronize extends ServiceBase implements SharedPreferences
db.account().setAccountWarning(account.id, null);
EntityLog.log(this, account.name + " connected");
// Listen for store events
iservice.getStore().addStoreListener(new StoreListener() {
@Override
public void notification(StoreEvent e) {
if (e.getMessageType() == StoreEvent.NOTICE)
EntityLog.log(ServiceSynchronize.this, account.name + " notice: " + e.getMessage());
else
try {
wlFolder.acquire();
String message = e.getMessage();
Log.w(account.name + " alert: " + message);
EntityLog.log(
ServiceSynchronize.this, account.name + " " +
Log.formatThrowable(new Core.AlertException(message), false));
db.account().setAccountError(account.id, message);
NotificationManager nm = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
nm.notify("alert:" + account.id, 1,
Core.getNotificationError(
ServiceSynchronize.this, "warning", account.name,
new Core.AlertException(message))
.build());
state.error(null);
} finally {
wlFolder.release();
}
}
});
// Listen for folder events
iservice.getStore().addFolderListener(new FolderAdapter() {
@Override