I want to use JavaMail to parse an .mbox file just like this one http://mail-archives.apache.org/mod_mbox/lucene-java-user/201210.mbox.
What I thought of doing was:
Session session = Session.getDefaultInstance(new Properties());
Store store = session.getStore("Here should go the .mbox file");
store.connect();
Folder folder = store.getFolder(server);
folder.open(Folder.READ_ONLY);
...
Which proved wrong. Any suggestions would be helpful.
Thank you in advance.
Update: Working example
public class MBoxFileReader implements MessageReader {
private final Path path; // Path to .mbox file
public MBoxFileReader(Path path) {
this.path = path;
}
@Override
public Message[] readMessages() {
Message[] messages = new Message[0];
URLName server = new URLName("mbox:" + path.toString());
Properties props = new Properties();
props.setProperty("mail.mime.address.strict", "false");
Session session = Session.getDefaultInstance(props);
try {
Folder folder = session.getFolder(server);
folder.open(Folder.READ_ONLY);
messages = folder.getMessages();
}
catch (Exception e) {
e.printStackTrace();
}
return messages;
}
}
You can use the JavaMail mbox Store, but you'll need to build it yourself.