Announcement Announcement Module
Collapse
No announcement yet.
Spring Integration + Mail - unable to access Folder Object Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Spring Integration + Mail - unable to access Folder Object

    Hi everybody,

    I'm having some trouble using Imap IDLE and mail integration. Everything is working fine so far, as long as I'm only dealing with messages and their contents.

    Code:
    	public void pushMimeMessage(MimeMailMessage incomingMessage){
    		//TODO: Do something useful here and postprocess messages,
    		//not to mention get them off the server :)
    		StrippedMessage strippedMessage = null;
    		MimeMessage mimeMsg = incomingMessage.getMimeMessage();
    		try {
    			InternetAddress[] from = (InternetAddress[])mimeMsg.getFrom();
    			String fromAddress = from[0].getAddress();
    			log.debug("Content-Type: "+mimeMsg.getContentType());
    			log.debug("Received: "+incomingMessage.getMimeMessage().getSubject());
    			
    			/*if (mimeMsg.getFolder().isOpen()){
    				//do nothing
    			}else {
    				log.debug("Trying to open folder in RW mode...");
    				mimeMsg.getFolder().open(Folder.READ_WRITE);
    				
    			}
    			log.debug("Current Folder: "+mimeMsg.getFolder().getFullName());*/
    			
    			//FIXME: Figure out how to access folders...
    			//We need this to delete any leftover mail...
    I commented out what is not working right now. But an NPE is thrown when I try to access anything on the Folder Object. Problem is, that this takes away most of the control we have over messages. I'd want to 'rollback' anything that didn't get processed properly and have it double-checked by something else, moved somewhere else in the Imap tree, and so on.

    Another issue for me is that the push-method is the only thing working right now. Meaning, it doesn't care about any new messages on the server (after a certain downtime for instance), it only processes messages the moment they're received. I planned on doing some clean-up in the constructor, when Spring creates the object, but there's no way to re-use the configuration I already made when I can't access the folders.

    Using Spring 3.0.2 with SI + Mail 2.0.3 - Maven doesn't complain about any incompatibilities, but I read somewhere in the forum that 3.0.5 is needed for SI 2+.

    My question is: Does it work as designed? Am I not supposed to access the folders or do any rollback or post-processing on the messages or is this a bug or an incompatibility?

    I'd be glad about any sort of help.

    Cheers from germany.

    Andreas

    Edit: Totally forgot: Using javamail 1.4.4 of course, read about the issues with earlier versions, so that should not be the problem.
    Last edited by azeller; Sep 7th, 2011, 08:02 PM.

  • #2
    Andreas

    I am a bit confused as to what you are trying to accomplish since in your code I don't see any usage of Spring Integration project or its API (unless you are posting a question about general integration with Spring and mail)
    Could you please instead just formulate your use case?

    Comment


    • #3
      Hi Oleg, sorry about that. To make more sense of it:

      Code:
      <?xml version="1.0" encoding="UTF-8"?>
      <beans xmlns="http://www.springframework.org/schema/beans"
      	   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      	   xmlns:mail="http://www.springframework.org/schema/integration/mail"
             xmlns:int="http://www.springframework.org/schema/integration"
             xmlns:util="http://www.springframework.org/schema/util"
             
             xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd 
                  http://www.springframework.org/schema/integration/mail http://www.springframework.org/schema/integration/mail/spring-integration-mail-2.0.xsd 
                  http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-2.0.xsd">
      	
      	<mail:imap-idle-channel-adapter id="customAdapter"
            store-uri="imaps://that.is%[email protected]/INBOX"
            channel="receiveChannel"
            auto-startup="true"
            should-delete-messages="false"
            should-mark-messages-as-read="true"
            java-mail-properties="javaMailProperties"
            />
            
          <util:properties id="javaMailProperties">
        		<prop key="mail.imap.socketFactory.class">javax.net.ssl.SSLSocketFactory</prop>
        		<prop key="mail.imap.socketFactory.fallback">false</prop>
        		<prop key="mail.store.protocol">imaps</prop>
        		<prop key="mail.debug">false</prop>
      	</util:properties>
      	
          <int:channel id="receiveChannel">        
              <int:interceptors>
                  <int:wire-tap channel="logger"/>
              </int:interceptors>
          </int:channel>
      		
          <int:logging-channel-adapter id="logger" level="DEBUG"/>
      
          <int:service-activator input-channel="receiveChannel" ref="emailReceiverService" method="pushMimeMessage"/>
      
          <bean id="emailReceiverService" class="our.namespace.backend.mail.GoogleMailService">
          </bean>
      </beans>
      I think my post makes a lot more sense when you add the above

      Andreas

      Comment


      • #4
        Not sure what you are doing up at 03:00, but I guess it is what it is

        Of the top of my head the fact that you are getting the exception is perfectly fine since you are in Service Activator which is downstream from IMAP adapter and at that point there is no connection to the mail server. All you get is a MimeMessage as a payload.
        That is why I asked you to explain your use case. Just because things work the way they are now doesn't mean they have to but as a community driven framework we need to understand you issue, so please explain what you are trying to do once you receive a Message.

        Also, I am picking up from your explanation that you are trying to do something with moving messages around etc., so look at this issue and see if it is relevant https://jira.springsource.org/browse/INT-1819
        Also, (although it most definitely wil not help your use case), the current release of SI is 2.1.M1 and although it targets Spring 3.0.6, it has been tested with 3.2.M2 and 3.0.*

        Comment


        • #5
          https://jira.springsource.org/browse/INT-1819 is more or less exactly what I need.

          But it's just as I suspected. The transaction is done and there's no reference to the Imap folder in any way any more. I was just wondering, because there's a reference to the Folder in the MimeMessage Object. I just doublechecked and realized that the MimeMailMessage Object belongs to Spring, whereas the MimeMessage is a native java mail object. So the exception makes sense.

          Neales idea is great. Providing an interface for that or dealing with a callback handler along with the mail object would be a very useful thing for me. For now, I'm going to handle failure and/or success by dispatching a custom manager that moves messages around the way I want to.

          Just to explain what I'm doing:

          We're processing messages that are forwarded to us by users. We need to validate contents, attachments, do some internal validation and parsing. If anything goes wrong, I might still need the message, because it might not have been the users fault but some parsing mistake. It would be hard for me to find the messages by logfile, unless I serialize them and save them somewhere. But we're dealing with thousands of messages so I'd be really happy if I could just sort them somewhere else for a scheduled re-processing, after parsers have been updated, etc.

          The whole MimeMessage concept is kind of tricky, so it's very likely that things get messed up at some point, with hundreds of MUAs around, not to mention human failure, or mine

          About 3am: Most software developers I know prefer working in the middle of the night

          Comment


          • #6
            Ok, i've added this forum post to that JIRA issue, add yourself as a follower and please provide a feedback as it evolves. Should be shortly since its scheduled for M2

            Comment


            • #7
              Done. I'll let you know and I'll definitely give you guys some feedback, because I _will_ be using this feature.

              Thank you for the quick reply. Proving my point... Good things happen when working nights...

              Just to let you know: Due do other dependencies, we are stuck with Spring 3.0.2 for now, so we can't upgrade to anything above that in the near future. So if you want feedback on that matter, I need to be able to use it with 3.0.2 - if at all possible.

              Off to sleep now, I'll keep an eye on JIRA.

              Andreas

              Comment


              • #8
                Good evening again,

                I finally had a chance to check out https://jira.springsource.org/secure...dBoardId=12200

                Seems like we're quite some time away from the milestone. 80 Issues, more than half of them being improvements and new features. This sounds like a lot of work and I don't really see this particular feature happening any time in the next two weeks. Correct me, if I'm wrong, it just seems like there's a lot more to do than just a few missing fixes

                We're about to launch a closed beta of our project by the end of september. I should probably work on my own message handling system until M2 is released, right?

                Just let me know and thanks again for bumping this up.

                Andreas

                Comment


                • #9
                  Well, although we are planning for 2.1.M2 for the end of next week, you probably right. . . that issue might not make it in that release. We basically need to re-prioritize things. But here is the interesting question. Would you like to contribute? You seem to know thing or two about mail API so why not? I am definitely more than willing to help you get started and give you some pointers as to what it should look like. All you need to do is fork a repository, implement and issue a pull request. Here are the details: https://github.com/SpringSource/spri...tor-Guidelines
                  Let me know if you are interested.
                  Cheers

                  Comment


                  • #10
                    Sorry for taking to long to reply...

                    My project is keeping me kind of busy, but I don't see why I shouldn't make a contribution to the spring framework. I might still need a few things to get me started, because some of the stuff is still "magic" to me, that I merely use instead of checking out how it works

                    So, if you like, just send me whatever I need to get started and I'll see what I can do. We're also on a tough schedule here, so I might not be able to take the first look at it in the next two weeks.

                    Andreas

                    Comment


                    • #11
                      Hey again.

                      It's working for now. I built something by hand, nothing fancy, but moving messags should not be too hard.

                      I built a [Google]MailPostProcessor class that handles as in handleSuccess(), handleFailure(). I also built in methods like moveMessage(MimeMessage msg, folder from, folder to) - which is pretty much all one needs to get the stuff working within spring? Or so I hope. It's not much, but if you fix me up with everything I need, I would be willing to contribute that (and of course use it myself then ) - right now I have two classes connecting to the imap directory. One is defined in Spring, the other is my own that does the post-processing.

                      If I can built this into Spring myself, I would be happy to do so.

                      Andreas

                      Comment

                      Working...
                      X