Page 2 of 2 FirstFirst 12
Results 11 to 14 of 14

Thread: Search Term Strategy - ImapMailReceiver 2.2.0.RC2

  1. #11
    Join Date
    Jan 2008
    Location
    Mohnton, PA USA (that's near Philadelphia)
    Posts
    2,148

    Default

    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?

  2. #12
    Join Date
    Oct 2012
    Posts
    5

    Default

    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();

  3. #13
    Join Date
    Dec 2011
    Posts
    15

    Default

    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

  4. #14
    Join Date
    Mar 2010
    Location
    Gtr Philadelphia, PA
    Posts
    2,036

    Default

    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.
    Gary P. Russell
    Spring Integration Team
    SpringSource, a division of VMware

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •