classpathx-javamail
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Classpathx-javamail] Re: Maildir is not visible


From: Chris Burdess
Subject: Re: [Classpathx-javamail] Re: Maildir is not visible
Date: Wed, 23 May 2007 10:30:22 +0100

Matej Cepl wrote:
So, with help from people on comp.lang.java.help I found a solution which at least compiles and works somehow. However, not correctly. This is the
source:

   import java.util.*;
   import javax.mail.*;

   public class CopyFolder {

      /**
       * @param args
       * @throws MessagingException
       */
      public static void main(String[] args) throws \
            MessagingException {
         String urlStr = "/home/matej/.eclipse/workspace"+
            "/kmail2tbfolders/examples/";
         Session session = Session.getInstance(new \
            Properties());
         session.setDebug(true);
URLName storeURL = new URLName("mbox://"+urlStr); Store mboxStore
         = session.getStore(storeURL); mboxStore.connect();
Folder mboxFolder = mboxStore.getDefaultFolder(); mboxFolder = mboxStore.getFolder("test"); mboxFolder.open (Folder.READ_ONLY);

         URLName store2URL = new URLName("maildir://"+
            urlStr+"/output/");
         Store maildirStore = session.getStore(store2URL); Folder
targetFolder = maildirStore.getDefaultFolder(); targetFolder = targetFolder.getFolder("target"); if (!targetFolder.exists ()) {
            try {
               targetFolder.create (Folder.HOLDS_MESSAGES);
            }
            catch(Exception e) {
               System.err.println("Cannot create target foldr: "+
                     e.getLocalizedMessage());
               throw new RuntimeException(e);
            }
         }
         System.out.println("name of the folder is "+
            targetFolder.getName());
         targetFolder.open(Folder.READ_WRITE);

         Message[] messages = mboxFolder.getMessages();
         System.out.println("There are "+mboxFolder.getMessageCount()+
               " messages in the source folder");
         System.out.println("There are "+messages.length+
                " messages in the selection");
targetFolder.appendMessages(messages); System.out.println ("There
         are "+targetFolder.getMessageCount()+
               " messages in the target folder");

         mboxStore.close();
         maildirStore.close();
      }

   }

However, when I run it I don't get expected results:

address@hidden kmail2tbfolders]$ rm -rf examples/output/ address@hidden
kmail2tbfolders]$ ls -lh examples/ celkem 2,0M
-rw-rw-rw- 1 matej matej 2,0M kvÄ›  2 20:23 test address@hidden
kmail2tbfolders]$ java CopyFolder name of the folder is target
There are 40 messages in the source folder There are 40 messages in the
selection There are 0 messages in the target folder address@hidden
kmail2tbfolders]$ find examples/output/target/* -type f | wc -l
6
address@hidden kmail2tbfolders]$

And truly there are only 6 messages in the create maildir folder. Any
ideas why this doesn't work as expected? I feel so close, and yet I am
still not there!

Thanks for any reply,

There shouldn't be any actual files in the maildir folder. There should just be 3 directories: cur, new, and tmp. The messages should have been created in the tmp dir, and then renamed to its final location in either cur or new, depending on whether they contain the SEEN flag. What patform are you using, perhaps it doesn't implement File.renameTo correctly? We could add some validation after the renameTo to ensure that the target file was created properly in each instance, and bail with an appropriate error message if not.

You should also register a MessageCountListener on the target folder to see which messages were actually added. For instance, only MimeMessages can be appended to a MaildirFolder.





reply via email to

[Prev in Thread] Current Thread [Next in Thread]