issues@javamail.java.net

[Bug 5822] New: Folder.create(int) followed by Folder.copyMessages(Message[],Folder) throws javax.mail.FolderNotFoundException

From: <bugzilla-daemon_at_kenai.com>
Date: Mon, 11 Feb 2013 04:10:15 +0000

http://kenai.com/bugzilla/show_bug.cgi?id=5822

             Bug #: 5822
           Summary: Folder.create(int) followed by
                    Folder.copyMessages(Message[],Folder) throws
                    javax.mail.FolderNotFoundException
    Classification: Unclassified
           Product: javamail
           Version: 1.4.5
          Platform: PC
        OS/Version: Mac OS
            Status: NEW
          Severity: normal
          Priority: P5
         Component: imap
        AssignedTo: shannon_at_kenai.com
        ReportedBy: bryan_at_kenai.com
                CC: issues_at_javamail.kenai.com


In an attempt to copy/(move) messages from one folder to another I am first
testing the existance of the folder, if it does not exist I create it and then
use copyMessages(...) to perform the copy, however; this raises
javax.mail.FolderNotFoundException.

If I set a delay of 10 seconds between the calls the process completes
successfully.

This issue is being exhibited on Microsoft Exchange 2007.

Test code follows:


public void copyTest(
        final Session session,
        final Store store,
        final Message[] messages,
        final String destination)
        throws MessagingException,
               InterruptedException {
    if (messages == null || messages.length == 0) {
        return;
    }

    Folder dest = null;
    Folder source = messages[0].getFolder();
    try {
        dest = store.getFolder(destination);
        while (!dest.exists()) {
            dest.create(Folder.HOLDS_MESSAGES | Folder.HOLDS_FOLDERS);
            //System.err.println("Sleeping while folder creates...");
            //FIX: Uncommenting makes the process work.
            //Thread.sleep(10000);
        }

        dest.open(Folder.READ_WRITE);

        source.copyMessages(messages, dest);
        source.setFlags(messages, new Flags(Flags.Flag.DELETED), true);
    } catch (MessagingException | InterruptedException ex) {
        ex.printStackTrace();
        throw ex;
    } finally {
        if (dest != null) {
            try {
                dest.close(false);
            } catch (MessagingException ex) {
                System.err.println("Couldn't close destination folder.");
            }
        }
    }
}


This also occurs in 1.4.6.

-- 
Configure bugmail: http://kenai.com/bugzilla/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are on the CC list for the bug.