I found this example online. See if this helps you move forward. Take note of
folder.open(Folder.READ_ONLY);
public static void main(String[] args) throws Exception {
URLName server = new URLName("protocol://username:password@host/foldername");
Session session = Session.getDefaultInstance(new Properties(), null);
Folder folder = session.getFolder(server);
if (folder == null) {
System.out.println("Folder " + server.getFile() + " not found.");
System.exit(1);
}
folder.open(Folder.READ_ONLY);
// Get the messages from the server
Message[] messages = folder.getMessages();
for (int i = 0; i < messages.length; i++) {
System.out.println("------------ Message " + (i + 1) + " ------------");
messages[i].writeTo(System.out);
}
folder.close(false);
}