|
1 | 1 | /* |
2 | | - * Copyright 2002-2020 the original author or authors. |
| 2 | + * Copyright 2002-2021 the original author or authors. |
3 | 3 | * |
4 | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
5 | 5 | * you may not use this file except in compliance with the License. |
|
27 | 27 | import javax.mail.Folder; |
28 | 28 | import javax.mail.Message; |
29 | 29 | import javax.mail.MessagingException; |
30 | | -import javax.mail.event.MessageCountAdapter; |
31 | | -import javax.mail.event.MessageCountEvent; |
32 | | -import javax.mail.event.MessageCountListener; |
33 | 30 | import javax.mail.search.AndTerm; |
34 | 31 | import javax.mail.search.FlagTerm; |
35 | 32 | import javax.mail.search.NotTerm; |
|
54 | 51 | * @author Oleg Zhurakousky |
55 | 52 | * @author Gary Russell |
56 | 53 | * @author Artem Bilan |
| 54 | + * @author Alexander Pinske |
57 | 55 | */ |
58 | 56 | public class ImapMailReceiver extends AbstractMailReceiver { |
59 | 57 |
|
60 | 58 | private static final int DEFAULT_CANCEL_IDLE_INTERVAL = 120000; |
61 | 59 |
|
62 | 60 | private static final String PROTOCOL = "imap"; |
63 | 61 |
|
64 | | - private final MessageCountListener messageCountListener = new SimpleMessageCountListener(); |
65 | | - |
66 | 62 | private final IdleCanceler idleCanceler = new IdleCanceler(); |
67 | 63 |
|
68 | 64 | private boolean shouldMarkMessagesAsRead = true; |
@@ -188,16 +184,14 @@ public void waitForNewMessages() throws MessagingException { |
188 | 184 | else if (!folder.getPermanentFlags().contains(Flags.Flag.RECENT) && searchForNewMessages().length > 0) { |
189 | 185 | return; |
190 | 186 | } |
191 | | - imapFolder.addMessageCountListener(this.messageCountListener); |
192 | 187 | try { |
193 | 188 | this.pingTask = this.scheduler.schedule(this.idleCanceler, |
194 | 189 | new Date(System.currentTimeMillis() + this.cancelIdleInterval)); |
195 | 190 | if (imapFolder.isOpen()) { |
196 | | - imapFolder.idle(); |
| 191 | + imapFolder.idle(true); |
197 | 192 | } |
198 | 193 | } |
199 | 194 | finally { |
200 | | - imapFolder.removeMessageCountListener(this.messageCountListener); |
201 | 195 | if (this.pingTask != null) { |
202 | 196 | this.pingTask.cancel(true); |
203 | 197 | } |
@@ -276,25 +270,6 @@ public void run() { |
276 | 270 |
|
277 | 271 | } |
278 | 272 |
|
279 | | - /** |
280 | | - * Callback used for handling the event-driven idle response. |
281 | | - */ |
282 | | - private static class SimpleMessageCountListener extends MessageCountAdapter { |
283 | | - |
284 | | - SimpleMessageCountListener() { |
285 | | - } |
286 | | - |
287 | | - @Override |
288 | | - public void messagesAdded(MessageCountEvent event) { |
289 | | - Message[] messages = event.getMessages(); |
290 | | - if (messages.length > 0) { |
291 | | - // this will return the flow to the idle call |
292 | | - messages[0].getFolder().isOpen(); |
293 | | - } |
294 | | - } |
295 | | - |
296 | | - } |
297 | | - |
298 | 273 | private class DefaultSearchTermStrategy implements SearchTermStrategy { |
299 | 274 |
|
300 | 275 | DefaultSearchTermStrategy() { |
|
0 commit comments