Page 3 of 3 FirstFirst 123
Results 21 to 27 of 27

Thread: Transactional POP3 Mailbox access with Spring Integration

  1. #21
    Join Date
    Oct 2012
    Location
    Staffordshire, England
    Posts
    10

    Default

    I'm struggling to get this to work. Basically, the plan was to for the poller to get each POP3 email message, write its attachment to the database as a BLOB, send a JMS message and delete the email if all goes well - so all in a transaction like the M4 version did (with should-delete-messages set to true however). This code is done within the service-activator method called by the poller - but leaving the email deletion to the transaction (in the M4 version).

    Now with the RC2 version, I can get all but the deletion working as should-delete-messages was advised to be set to false, which I understand the reasons for. In the trans-sync method, I have copied the examples mentioned by setting the message's flag to DELETED but it has no effect. It still does not work if I move the deletion code to the end of the service-activator method and remove the trans-sync stuff.

    Here is what I had in the trans-sync method:
    Code:
    Folder folder = message.getFolder();
    if (!folder.isOpen()) {
    	folder.open(Folder.READ_WRITE);
    }
    
    message.setFlag(Flags.Flag.DELETED, true);
    folder.close(true);  // True means do expunge.
    This method is being called as I can see my println output appearing in the console. Crucially though, there is no "C: DELE 1" being output by the mail debugger anywhere.

    I'm still investigating but your input would be appreciated.

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

    Default

    Ok, let me look at this again, i'll let you know

  3. #23
    Join Date
    Oct 2012
    Location
    Staffordshire, England
    Posts
    10

    Default

    Hi Oleg.

    Have you been able to find out anything on this recently? I'll come back to the problem and look at it further but I'd run out of ideas before. If I do find anything, or indeed the reason for the problem then I'll let you know.

  4. #24
    Join Date
    Mar 2010
    Location
    Gtr Philadelphia, PA
    Posts
    2,015

    Default

    Hi, the JavaDocs for the Folder indicate once the folder is closed you can't use it again with the same message.

    Message objects from a Folder are only valid while a Folder is open and should not be accessed after the Folder is closed, even if the Folder is subsequently reopened. Instead, new Message objects must be fetched from the Folder after the Folder is reopened.
    I just got this to work (with IMAP) ...

    Code:
    		Folder folder = message.getFolder();
    		folder.open(Folder.READ_WRITE);
    		String messageId = message.getMessageID();
    		Message[] messages = folder.getMessages();
    		FetchProfile contentsProfile = new FetchProfile();
    		contentsProfile.add(FetchProfile.Item.ENVELOPE);
    		contentsProfile.add(FetchProfile.Item.CONTENT_INFO);
    		contentsProfile.add(FetchProfile.Item.FLAGS);
    		folder.fetch(messages, contentsProfile);
    
    		for (int i = 0; i < messages.length; i++) {
    			if (((MimeMessage) messages[i]).getMessageID().equals(messageId)) {
    				messages[i].setFlag(Flags.Flag.DELETED, true);
    				break;
    			}
    		}
    		folder.expunge();
    		folder.close(true);
    That said, I am working on a fix (INT-2803) because, right now, the folder in the message is the same instance as that in the MailReceiver so you could get collisions. So, until RC3 comes out, it would be safer to use

    Code:
    ...
    
    		URLName url = new URLName("INBOX");
    		Folder folder = message.getFolder().getStore().getFolder(url);
    ...
    instead of message.getFolder();
    Gary P. Russell
    Spring Integration Team
    SpringSource, a division of VMware

  5. #25
    Join Date
    Mar 2010
    Location
    Gtr Philadelphia, PA
    Posts
    2,015

    Default

    FYI, I just tested with POP3 (Apache James) and it worked fine (had to remove the call to folder.expunge() because it's not supported by POP3)...

    Code:
    Subject: Test SI Delete
    Content-Type: text/plain; charset=ISO-8859-1; format=flowed
    Content-Transfer-Encoding: 7bit
    
    Test SI Delete
    .
    DEBUG POP3: got message size 662
    C: DELE 1
    S: +OK Message deleted
    C: QUIT
    S: +OK Apache James POP3 Server signing off.
    Gary P. Russell
    Spring Integration Team
    SpringSource, a division of VMware

  6. #26
    Join Date
    Oct 2012
    Location
    Staffordshire, England
    Posts
    10

    Default

    OK, thanks for that. I'll look into it again in more detail to see what I might be doing wrong.

  7. #27
    Join Date
    Oct 2012
    Location
    Staffordshire, England
    Posts
    10

    Default

    Thanks Gary,

    Your code example has worked. I have put it in the syncProcessor before-commit (for now) and it does delete the message.

    Thank you both very much for your help Gary and Oleg.

Tags for this Thread

Posting Permissions

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