Folder[] folders = store.getPersonalNamespaces();
System.out.println("Folders:");
for (Folder folder : folders) {
System.out.println("- " + folder.getName() + " // " + folder.getFullName());
}
Folder folder = store.getFolder("INBOX");
System.out.println("Folder (Name, FullName):" + folder.getName() + ", " + folder.getFullName());
folder.open(Folder.READ_ONLY);
// folder.getUnreadMessageCount();
Message messages[] = folder.getMessages();
System.out.println(messages.length + " Messages.");
System.out.println("");
int k = messages.length > 8 ? 8 : messages.length;
for (int i = 0; i < messages.length; i++) {
// Nur ein paar anlisten.
if (i == k) {
i = messages.length - k / 2;
}
Message message = messages[i];
System.out.println(i + ": " + message.getFrom()[0] + " - \"" + message.getSubject() + "\"");
Object content = message.getContent();
System.out.println("Content-Klasse: " + content.getClass().toString() + " / Content-Type: "
+ message.getContentType());
@SuppressWarnings("unchecked")
Enumeration<Header> s = message.getAllHeaders();
while (s.hasMoreElements()) {
Header h = s.nextElement();
System.out.println("H: " + h.getName() + " := " + h.getValue());
}
System.out.println(" ");
if (content instanceof String) {
System.out.println("String-CONTENT ::: " + (String) content);
}
else {
System.out.println("NO String-CONTENT ::: " + content.getClass());
}
}
folder.close(false);
store.close();
}
catch (MessagingException exception) {
throw new RuntimeException(exception);
}