Spring Integration
  1. Spring Integration
  2. INT-1819

IMAP inbound channel adapters could allow move to folders for processed messages

    Details

    • Type: New Feature New Feature
    • Status: Closed
    • Priority: Critical Critical
    • Resolution: Complete
    • Affects Version/s: 2.0.3
    • Fix Version/s: 2.2 RC1
    • Component/s: Mail Support
    • Labels:
      None

      Description

      Looking at some of my own requirements around IMAP, this is something that I'm intending to implement and contribute as an extension to the existing IMAP channel adapter.

      Currently, for processed messages, we can either delete them or mark them as read.

      What I'd like to do (and I suspect is a use case for many mail scenarios) is to file successfully processed messages in a specified folder, and a different folder for messages that were attempted to be processed and failed (i.e. threw an SI MessagingException via a DirectChannel). This would work for scenarios where validation or transformation occur before any queues are involved.

      A luxury would be to provide a strategy interface for determining the destination folder based on the thrown exception.

        Activity

        Hide
        Oleg Zhurakousky added a comment -

        Also, based on the forum posts/requests I am upgrading it to Critical

        Show
        Oleg Zhurakousky added a comment - Also, based on the forum posts/requests I am upgrading it to Critical
        Hide
        Frik Strecker added a comment -

        We need to decide if we will use Spring for IMAP, but without this feature it is a not an option.

        Show
        Frik Strecker added a comment - We need to decide if we will use Spring for IMAP, but without this feature it is a not an option.
        Hide
        Oleg Zhurakousky added a comment -

        Moving it to 2.2.RC1

        Show
        Oleg Zhurakousky added a comment - Moving it to 2.2.RC1
        Hide
        Oleg Zhurakousky added a comment - - edited

        PR: https://github.com/SpringSource/spring-integration/pull/619

        Support for moving messages to other folders as well as other operations on the actual javax.mail.Message is now available as part of Transaction Synchronization strategy added to all inbound adapters including Mail
        For example:

        <int-mail:imap-idle-channel-adapter id="customAdapter"
        			store-uri="imaps://foo.com:password@imap.foo.com/INBOX"
        			channel="receiveChannel"
        			auto-startup="true"
        			should-delete-messages="false"		
        			java-mail-properties="javaMailProperties">
        	<int:transactional synchronization-factory="syncFactory"/>
        </int-mail:imap-idle-channel-adapter>
        
        <int:transaction-synchronization-factory id="syncFactory">
        		<int:before-commit expression="@syncProcessor.process(payload)"/>
        </int:transaction-synchronization-factory>
        
        <bean id="syncProcessor" class="foo.bar.Mover"/>
        
        public class Mover {
        
        	public void process(MimeMessage message) throws Exception{
        		Folder folder = message.getFolder();
        		Store store = null;
        		if (!folder.isOpen()){
        			folder.open(Folder.READ_WRITE);
        			store = folder.getStore();
        		}
        		message.setFlag(Flags.Flag.DELETED, true);
        		Folder fooFolder = store.getFolder("FOO"));
        		fooFolder.appendMessages(new MimeMessage[]{message});
        		folder.expunge();
        	}
        }
        

        The same could be done on Polling adapters where 'transactional' element is present on the poller.

        NOTE: that POP3 does not support such operations so adding TX synchronization will not have any affect.

        Show
        Oleg Zhurakousky added a comment - - edited PR: https://github.com/SpringSource/spring-integration/pull/619 Support for moving messages to other folders as well as other operations on the actual javax.mail.Message is now available as part of Transaction Synchronization strategy added to all inbound adapters including Mail For example: < int -mail:imap-idle-channel-adapter id= "customAdapter" store-uri= "imaps: //foo.com:password@imap.foo.com/INBOX" channel= "receiveChannel" auto-startup= " true " should-delete-messages= " false " java-mail-properties= "javaMailProperties" > < int :transactional synchronization-factory= "syncFactory" /> </ int -mail:imap-idle-channel-adapter> < int :transaction-synchronization-factory id= "syncFactory" > < int :before-commit expression= "@syncProcessor.process(payload)" /> </ int :transaction-synchronization-factory> <bean id= "syncProcessor" class= "foo.bar.Mover" /> public class Mover { public void process(MimeMessage message) throws Exception{ Folder folder = message.getFolder(); Store store = null ; if (!folder.isOpen()){ folder.open(Folder.READ_WRITE); store = folder.getStore(); } message.setFlag(Flags.Flag.DELETED, true ); Folder fooFolder = store.getFolder( "FOO" )); fooFolder.appendMessages( new MimeMessage[]{message}); folder.expunge(); } } The same could be done on Polling adapters where 'transactional' element is present on the poller. NOTE: that POP3 does not support such operations so adding TX synchronization will not have any affect.
        Hide
        Gary Russell added a comment -

        ... will not have any affect.

        They can still do afterCommit/afterRollback processing - such as sending the mail to a differen mailbox using an outbound adaper.

        Show
        Gary Russell added a comment - ... will not have any affect. They can still do afterCommit/afterRollback processing - such as sending the mail to a differen mailbox using an outbound adaper.

          People

          • Assignee:
            Oleg Zhurakousky
            Reporter:
            Neale Upstone
          • Votes:
            4 Vote for this issue
            Watchers:
            7 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: