[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Classpathx-javamail] Re: Maildir is not visible
From: |
Matej Cepl |
Subject: |
[Classpathx-javamail] Re: Maildir is not visible |
Date: |
Tue, 22 May 2007 15:03:12 +0200 |
User-agent: |
Pan/0.129 (Benson & Hedges Moscow Gold) |
On Mon, 21 May 2007 23:40:46 +0200, Matej Cepl scripst:
> OK, this is probably another newbie question, but let me try. I have
> this testing program to copy all messages from one mbox folder to
> another maildir one:
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,
Matej
- [Classpathx-javamail] Re: Maildir is not visible,
Matej Cepl <=