下面的代码使用javamail API来访问gmail,
String host = "pop.gmail.com";
int port = 995;
Properties properties = new Properties();
properties.put("mail.smtp.socketFactory.class", "javax.net.ssl.SSLSocketFactory");
final javax.mail.Session session = javax.mail.Session.getInstance(properties);
store = session.getStore("pop3s");
store.connect(host, port, mCredentialaNme, mCredentialApss);
// ***************************************************************
Folder personalFolders[] = store.getDefaultFolder().list( "*" );
// ***************************************************************
for (Folder object : personalFolders) {
// ***********************************
System.out.println( object.list("*") );
// ***********************************
if ((object.getType() & javax.mail.Folder.HOLDS_MESSAGES) != 0){
object.open(Folder.READ_ONLY);
Message messes[] = object.getMessages();
System.out.println(object.getFullName());
System.out.println("====================");
for (Message object1 : messes) {
System.out.println(object1.getFrom() + " - " + object1.getSubject());
}
object.close(false);
}
}
if (store.isConnected()) {
store.close();
}
问题是此代码仅列出INBOX文件夹,而定义的标签不少于20个.
如何让代码列出/访问这些嵌套的文件夹/标签应该怎么做?
解决方法:
如果您想要标签/文件夹,请不要使用POP,请使用IMAP.
如javamail docs所述,由于POP协议的性质,POP消息存储始终存在
Contains only one folder, “INBOX”.