javax.mail.event.MessageCountAdapter Java Examples

The following examples show how to use javax.mail.event.MessageCountAdapter. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: MailNotificationService.java    From camunda-bpm-mail with Apache License 2.0 6 votes vote down vote up
public void start(String folderName) throws Exception {
	executorService = Executors.newSingleThreadExecutor();

	Folder folder = mailService.ensureOpenFolder(folderName);

	folder.addMessageCountListener(new MessageCountAdapter() {
		@Override
		public void messagesAdded(MessageCountEvent event) {
			List<Message> messages = Arrays.asList(event.getMessages());

			handlers.forEach(handler -> handler.accept(messages));
		}
	});

	if (supportsIdle(folder)) {
		notificationWorker = new IdleNotificationWorker(mailService, (IMAPFolder) folder);
	} else {
		notificationWorker = new PollNotificationWorker(mailService, folder,
				configuration.getNotificationLookupTime());
	}

	LOGGER.debug("start notification service: {}", notificationWorker);

	executorService.submit(notificationWorker);
}