gpt4 book ai didi

JavaMail : Folder. hasNewMessages() 和 .getMessageCount() 似乎无法正常工作

转载 作者:行者123 更新时间:2023-12-02 07:29:52 24 4
gpt4 key购买 nike

我有这个简单的代码来定期访问 pop3 服务器并检查收件箱文件夹中是否有新邮件

public static void main(String[] args) {


try {

String storeType = "pop3";

String host = "...";
int port = ...;
String user = "...";
String psw = "...";

//
int delay = 1;
long mins = 200 * 60 * delay;
firstAccess = true;


Properties properties = new Properties();
properties.put("mail.pop3.host", host);
properties.put("mail.pop3.user", user);
properties.put("mail.pop3.socketFactory.class", "javax.net.ssl.SSLSocketFactory");
properties.put("mail.pop3.port", port);


RomasAuthenticator r = new RomasAuthenticator(user, psw);

Session session = Session.getDefaultInstance(properties, r);

POP3Store emailStore = (POP3Store) session.getStore(storeType);
emailStore.connect(host, port, user, psw);

Folder emailFolder = emailStore.getFolder("INBOX");
emailFolder.open(Folder.READ_ONLY);

while (true) {
if (checkInbox(emailFolder)) {
//prepara la notifica per il voice_service
System.out.println("mes!");
}
firstAccess = false;
Thread.sleep(mins);
}




} catch (Exception ex) {
//return null;
}
}


private static boolean checkInbox(Folder inbox_folder) throws MessagingException, IOException {
System.out.println("checking");
boolean res = false;

try {

int email_actual_count = inbox_folder.getMessageCount();

if (email_actual_count > email_prev_count /*or hasNewMessages()*/) {
if (!firstAccess) {
res = true;
}
}

//bisogna aggiornare comunque email_count in caso siano stati cancellati messaggi
email_prev_count = email_actual_count;

}

catch (Exception e) {
e.printStackTrace();
}

return res;

}

getMessageCount() 和 hasNewMessages() 都不起作用,因为第一个总是返回相同数量的消息,而第二个总是返回 false。我做错了什么?我不想使用消息监听器,因为此代码将在性能非常低的机器人上运行。谢谢大家

最佳答案

关于JavaMail : Folder. hasNewMessages() 和 .getMessageCount() 似乎无法正常工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13058245/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com