public static void selectUserAttr(Call callBack) {
try {
Session session = getSendSession();
if (session != null) {// 注意:这里一定要做一个判断 每个方法内都要
IMAPStore store = EMailUtils.getStore(session, recvHost, userName, passWord, "imap");
Folder rootSend = EMailUtils.getFolderWrite(store, "草稿箱");//起始的时候打开一次文件夹
if(rootSend.getMessageCount() > 0) { //一定要判断一下是不是大于0 如果小于0 说明文件夹被关闭 错误:java Failed to load IMAP envelope
EMailUtils.getEmailData(rootSend, store, new CallBack() {
@Override
public void data(Message[] messages, Folder folder, Store store) throws Exception {
if (messages.length > 0) {
for (Message message : messages) {
InputStream inputStream = EMailUtils.downLoadFileInputStream(message);
if (inputStream != null) {
String json = EMailUtils.getJson(inputStream);
boolean isValidJson = JSON.isValid(message.getSubject());
if (isValidJson) {
RootGetUserInfo ri = JSON.parseObject(json, RootGetUserInfo.class);
callBack.call(ri);
}
}
}
}
}
});
}else {
//在一次重新打开文件夹
rootSend = EMailUtils.getFolderWrite(store, "草稿箱");
}
}
} catch (Exception e) {
e.printStackTrace();
}
}
只需要判断一下 if(rootSend.getMessageCount() > 0) 这个地方的值就能解决这个问题