Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using spring integration IMAP adapter, how to fetch an email which was marked "unread" manually?

I have a piece of code which uses spring integration's IMAP adapter to poll an inbox to read all incoming emails which are unread and that works perfectly. But if I open any email message and and then mark it as "unread" in my outlook inbox the poller doesn't fetch the marked email. I can use the pop3 adapter which fetches all the email, but deletes them afterwords, but I want to keep the emails in my inbox and I want the poller to fetch all the email which are unseen.

Any suggestions to handle this problem? I been searching and reading articles on email adapters but didn't find anything useful.

Thanks in advance.

like image 214
Sonu Avatar asked Oct 04 '22 00:10

Sonu


1 Answers

Looks like you need custom 'search-term-strategy'. From Spring Integration (SI) documentation:

By default, the ImapMailReceiver will search for Messages based on the default SearchTerm which is All mails that are RECENT (if supported), that are NOT ANSWERED, that are NOT DELETED, that are NOT SEEN and have not been processed by this mail receiver (enabled by the use of the custom USER flag or simply NOT FLAGGED if not supported). Since version 2.2, the SearchTerm used by the ImapMailReceiver is fully configurable via the SearchTermStrategy which you can inject via the search-term-strategy attribute. SearchTermStrategy is a simple strategy interface with a single method that allows you to create an instance of the SearchTerm that will be used by the ImapMailReceiver.

And here is a post from SI forum with funtastic Oleg's explanation: Server does not support RECENT or USER flags

And here you can find SI DefaultSearchTermStrategy: it's a place to determine how you should implement your own strategy. I guess, you case is:

This email server does not support RECENT flag, but it does support USER flags which will be used to prevent duplicates during email fetch.

Switch SI-mail logging level to DEBUG and take a look, which flag supports your email server.

like image 188
Artem Bilan Avatar answered Oct 12 '22 11:10

Artem Bilan