I'm just trying to read the unread email's from Gmail using IMAP. So when I run my application is able to read all the unread email's. Even though those emails are already available in INBOX before I ran my application. Here is the problem let's say I have 120 emails my application started reading them, and it already read one of it and count reduced to 119, then if suppose my email got another email then my service started processing that, and the remaining 119 emails will be the unread state and my application is not processing them
I have tried with DefaultSearchTermStrategy which is coming from Spring
EmailReadTaskRunner<SampleMailMessage> emailTaskRunner = new
EmailReadTaskRunner<SampleMailMessage>();
for (MailConfig mailConfig : yamlConfig.getMailConfig()) {
if (mailConfig.isImapEnabled()) {
Properties properties = this.getImapProperties();
properties.put("mail.debug",
String.valueOf(mailConfig.isDebugEnabled()));
ImapMailReceiver receiver = new
ImapMailReceiver(mailConfig.getImageStoreUri() +
"/INBOX");
receiver.setShouldMarkMessagesAsRead(true);
receiver.setShouldDeleteMessages(false);
receiver.setJavaMailProperties(properties);
receiver.setJavaMailAuthenticator(
new MailAuthenticator(mailConfig.getUser(),
mailConfig.getPassword()));
StandardIntegrationFlow flow = IntegrationFlows
.from(Mail.imapIdleAdapter(receiver).shouldReconnectAutomatically(true)).handle(message -> {
emailTaskRunner.read(emailReadTask, message, mailConfig);
}).get();
this.getFlowContext().registration(flow).register();
}
}
I want to read all unread email's, which can be recent or old. Am Using SpringIntegration 5.0.3 version, And also using IMAP Protocol as I have mentioned in the code. I also want to know why it is showing this kind of behavior. Until new email comes to Gmail it is able to read them all, whenever a new email comes to Gmail it started reading new email's and ignoring previous unread email's