Announcement Announcement Module
Collapse
No announcement yet.
Search Term Strategy - ImapMailReceiver 2.2.0.RC2 Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Search Term Strategy - ImapMailReceiver 2.2.0.RC2

    Hi everybody!

    I'm trying to use the new feature to create my own SearchTermStrategy, because I need to get all the mails which have not set the SEEN flag.

    I'm using the inbound-channel-adapter and not the imap-idle-channel-adapter for receiving mails by imap protocol. Somehow the schema validation tells me that it is not valid to use the "search-term-strategy" for an inbound-channel-adapter.

    My configuration is mainly the same as in your documentation:
    http://static.springsource.org/sprin...l#mail-inbound

    Is there any possibility to create my own SearchTermStrategy when not using imap-idle-channel-adapter?

    Cheers,
    Mikael

  • #2
    The search-term-strategy is currently only supported on the imap-idle adapter.

    However, the default strategy already includes the 'Not SEEN' rule (if supported by the server)...

    (RECENT and NOT ANSWERED and NOT DELETED and NOT SEEN)

    Comment


    • #3
      Thanks for your answer!

      My problem is that I would need to get every mail which is set as UNREAD, so that I get the mail again when the user marks it as unread. This does not work with the current SearchTerms, because as I think, the mail is not anymore flagged as RECENT.

      Is there any workaround?

      Thanks for your help!

      Comment


      • #4
        You can wire up the adapter using <bean/> definitions instead of using the namespace.

        You need a SourcePollingChannelAdapterFactoryBean; this needs properties

        source - a MailReceivingMessageSource
        outputChannel - ref to a <channel/>
        pollerMetadata - ref to a <poller/>


        The MailReceivingMessageSource needs a <constructor-arg/> which, in your case, would be an ImapMailReceiver.

        When defining your ImapMailReceiver, you can inject your custom SearchTermStrategy into it using the searchTermStrategy propery.


        Please go ahead and open a New Feature JIRA ticket; it seems reasonable to me that we should allow this to be configured using the namespace.

        https://jira.springsource.org/browse/INT

        Comment


        • #5
          Thank you for the description of the workaround, it's almost working

          My problem is now, that I can't access anymore the attachment in the mail which was working with version 2.1.4, I compared a bit the source of the ImapMailReceiver and I think it could have something to do that the messages aren't anymore copied before they're passed to the outputChannel. When accessing the attachment later I get a FolderClosedException.

          Thanks,
          Mikael

          Comment


          • #6
            I believe you are correct - that looks like a bug in 2.2 to me.

            However, you should be able to use the <bean/> technique using 2.1.4.

            Is there some other reason you are using the 2.2. RC?

            Comment


            • #7
              I'm using 2.2 because I need to define my own search term strategy. Version 2.1.4 does not yet provide this possibility, right?

              Comment


              • #8
                Duh - of course; sorry.

                Let me look into the copy problem; I'll get back to you.

                Comment


                • #9
                  I opened a ticket https://jira.springsource.org/browse/INT-2803

                  We expect to release RC3 shortly.

                  Comment


                  • #10
                    Given that we have to fix this problem, I have also scheduled to get INT-2800 into RC3 as well because it really was an omission.

                    Comment


                    • #11
                      Hmm, we were just testing it and its strange since it works for me but fails for Gary. . . all on 2.2.

                      Can you please paste the code you use to retrieve message attachement?

                      Comment


                      • #12
                        This is the part where I process the message. The same code works fine in version 2.1.4.

                        Code:
                        public void receive(MimeMessage message) {
                        	try {
                        		Object content = message.getContent();
                        		if (content instanceof Multipart) {
                        			handleMultipart((Multipart) content);
                        		}
                        	} catch (Exception e) { }
                        }
                         
                        private void handleMultipart(Multipart multipart)
                        		throws MessagingException, IOException {
                        	for (int i = 0, n = multipart.getCount(); i < n; i++) {
                        		handlePart(multipart.getBodyPart(i));
                        	}
                        }
                        
                        private void handlePart(Part part) throws MessagingException, IOException {
                        	try {
                                        String disposition = part.getDisposition();
                        		if (disposition != null
                        			&& disposition.equalsIgnoreCase(Part.ATTACHMENT)) {
                        			String fileName = part.getFileName();
                        			String[] splitted = fileName.split("\\.");
                        			if (splitted.length > 0 && this.fileEndingFilter
                        						.contains(splitted[splitted.length - 1])) {
                        				InputStream is = part.getInputStream();
                        				File file = saveFile(fileName, is);
                        				List<String> caseIds = this.etl.extractPatientData(file);
                        				notifyChange(caseIds);
                        			}
                        		}
                        	} catch (Exception e) { 	}
                        }
                        
                        private File saveFile(String filename, InputStream input)
                        		throws IOException {
                        	String filePrefix = new Long(System.currentTimeMillis()).toString();
                        
                        	File file = new File(this.archiveDirectory + "/" + filePrefix + "-"
                        				+ filename);
                        
                        	FileOutputStream fos = new FileOutputStream(file);
                        	BufferedOutputStream bos = new BufferedOutputStream(fos);
                        
                        	BufferedInputStream bis = new BufferedInputStream(input);
                        	int aByte;
                        	while ((aByte = bis.read()) != -1) {
                        		bos.write(aByte);
                        	}
                        	bos.flush();
                        	bos.close();
                        	bis.close();
                        	return file;
                        }
                        It always throws an exception when accessing the input stream of the attachment.

                        InputStream is = part.getInputStream();

                        Comment


                        • #13
                          Hi folks,

                          have u integrated the feature to search for old but unread messages already. If yes are there any examples where i could look up for a solution because if have exactly the same problem as described above. I could go with the proposed workaround but configuring it via XML would be the easiest way ;-)

                          Cheers Peter

                          Comment


                          • #14
                            Simply implement your own SearchTermStrategy. Take a look at DefaultSearchTermStrategy in ImapMailReceiver to see how the default strategy is implemented.

                            Then, provide a reference to your custom strategy to the adapter.

                            Comment

                            Working...
                            X