Реагировать на изменения настройки пользователей < /li>
< /ol>
позвольте мне объяснить: < /h3>
Я в настоящее время подключаюсь с помощью хоста и порта, а также пароль электронной почты пользователей и почтового ящика. Если пользователь, например, меняет пароль почтового ящика или настройки IMAP (например, переход на другой поставщик почты), я хочу отключить их сеанс и восстановить их. Рабочий поток, заканчивающий соединение: < /p>
Код: Выделить всё
void triggerDisconnect(AtomicBoolean listenerActive, IMAPFolder inbox, long userId) throws MailboxConnectionException {
LOG.debug("Triggering disconnect of user {}...", userId);
listenerActive.set(false);
// Any operation performed on the open inbox will cause the inbox to exit IDLE mode,
// resulting in the .idle() method returning.
if (inbox.isOpen()) {
try {
inbox.getMessageCount();
} catch (MessagingException e) {
throw new MailboxConnectionException(
String.format("Failed to get message count for user %d", userId), e, false);
}
}
}
< /code>
Worker Thread < /h3>
while (listenerActive.get() && !Thread.currentThread().isInterrupted()) {
try {
// Check if inbox open if not open it if yes issue IDLE command
} catch (FolderClosedException e) {
// LOG
} catch (MessagingException e) {
// Thrown an exception to be handled upstream
}
}
LOG.info(
"Mailbox listener for user {} is stopping. Listener active: {},"
+ " Thread interrupted: {}",
userId,
listenerActive.get(),
Thread.currentThread().isInterrupted());
disconnect(inbox, userId);
}
< /code>
void disconnect(IMAPFolder inbox, long userId) throws MailboxConnectionException {
LOG.debug("Disconnecting mailbox listener of user {}...", userId);
try {
if (inbox.isOpen()) {
inbox.close(false);
}
Store store = inbox.getStore();
store.close();
} catch (MessagingException e) {
throw new MailboxConnectionException(
String.format("Failed to disconnect user %d", userId), e, false);
}
}
< /code>
Проблема: < /h3>
После того, как я успешно закрыл магазин: < /p>
B7 LOGOUT
* BYE Server logging out
B7 OK LOGOUT completed
DEBUG IMAP: IMAPStore cleanup done
< /code>
Я пытаюсь восстановить подключение (в настоящее время используя тот же хост, порт, имя пользователя и пароль), используя этот метод: < /p>
private Store connectToStore(Properties properties, User user)
throws MailboxConnectionException {
LOG.debug("Connecting to store for user {}", user.getId());
try {
Session session = Session.getInstance(properties);
session.setDebug(isDebug);
Store store = session.getStore("imap");
Settings settings = user.getSettings();
store.connect(
settings.getImapHost(),
user.getEmailAddress(),
settings.getMailboxPassword());
return store;
} catch (MessagingException e) {
throw new MailboxConnectionException(
String.format("Failed to create store session for user %d", user.getId()),
e,
true);
}
}
Отладочная отладка отладки imap: Попытка подключиться к хозяину «myhost», порт 993, ISSSL True никогда не печатается.>
Подробнее здесь: https://stackoverflow.com/questions/796 ... karta-mail