if (mListeners != null && mListeners.isEmpty() == false) {
List<MailboxListener> closedListener = new ArrayList<MailboxListener>();
int sz = mListeners.size();
for (int i = 0; i < sz; i++) {
MailboxListener l = mListeners.get(i);
if (l.isClosed()) {
closedListener.add(l);
} else {
l.event(event);
}
}
if (event instanceof MailboxDeletion) {
// remove listeners if the mailbox was deleted
listeners.remove(path);
} else if (event instanceof MailboxRenamed) {
// handle rename events
MailboxRenamed renamed = (MailboxRenamed) event;
List<MailboxListener> l = listeners.remove(path);
if (l != null) {
listeners.put(renamed.getNewPath(), l);
}
}
if (closedListener.isEmpty() == false) {
mListeners.removeAll(closedListener);
if (mListeners.isEmpty()) {
listeners.remove(path);
}
}
}
}
List<MailboxListener> globalListeners = getGlobalListeners();
synchronized (globalListeners) {
if (globalListeners != null && globalListeners.isEmpty() == false) {
List<MailboxListener> closedListener = new ArrayList<MailboxListener>();
int sz = globalListeners.size();
for (int i = 0; i < sz; i++) {
MailboxListener l = globalListeners.get(i);
if (l.isClosed()) {
closedListener.add(l);
} else {
l.event(event);
}
}
if (closedListener.isEmpty() == false) {