Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9305811
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 19, 20262026-06-19T00:01:00+00:00 2026-06-19T00:01:00+00:00

I am trying to create a folder if it does not exist and then

  • 0

I am trying to create a folder if it does not exist and then copy a message from another folder to the destination folder. I am finding some strange behaviour that I can not understand. Given the following excerpt:

// messages is an array of Message instances.
// Source is the source folder
// destination is a string of the destination folder.
Folder dest = null;
try {
    dest = store.getFolder(destination);
    if (!dest.exists()) {
        dest.create(Folder.HOLDS_MESSAGES | Folder.HOLDS_FOLDERS);
        // Since folder's are not meant to cache I thought I'd get it again
        // though this does not work either.
        //dest.close(false);
        //dest = store.getFolder(destination);
    }
    dest.open(Folder.READ_WRITE);
    // Fails here
    source.copyMessages(messages, dest);
    source.setFlags(messages, new Flags(Flags.Flag.DELETED), true);
} catch (MessagingException ex) {
    throw new MailProcessorException(ex.getMessage(), ex);
} finally {
    if (dest != null) {
        try {
            dest.close(false);
        } catch (MessagingException ex) {
            System.err.println("Couldn't close destination folder.");
        }
    }
}

The following behaviour is examined:

  • If the folder does not exist:
    1. The folder gets created
    2. An exception is thrown at source.copyMessages.
  • If the folder does exist:
    1. The messages are copied as expected.
    2. Messages are marked for deletion.

I am using JavaMail 1.4.6, also tried with 1.6.5.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-19T00:01:01+00:00Added an answer on June 19, 2026 at 12:01 am

    This is really strange. Looking at your code and reading the docs, there should be no way that this is happening…

    Could it be some problem with the mail server? Some databases use consistency models (see http://en.wikipedia.org/wiki/Eventual_consistency for example) that don’t always act the way you’d naively expect. Is there a chance you can try your code on a different mail server? Or, try to put a really long (30 seconds?) Thread.sleep(...) before your copyMessages(...) call and see if that fixes it.

    If it does, what is happening is that your server creates the folder in one request, but this creation takes a while to reach the part of the server code that is handling the message copying. Then, unfortunately, I’m not sure if there is much you can do other than a retry if the copying fails or the artificial delay (which sucks).

    Aside: The docs seem to say, that you can skip the dest.open(Folder.READ_WRITE); if you like.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to create cookie from one folder that will also work in another.
I am trying to create a folder in launcher application from the settings application.
I'm trying to use Node.js to create a zip file from an existing folder,
I'm trying to copy resources (IFile) from an eclipse project to another location. The
For some reason the following code does not work for me... I'm trying to
I'm trying to create a folder and create a file within it. Whenever i
I am trying to create a small assembly program to create a folder. I
So I'm trying to dynamically create a folder inside the web pages folder. I'm
I am trying to create a program similar to Folder Lock which prevents users
I'm trying to create a Python script that would : Look into the folder

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.