获取“已看到”标志似乎不起作用

pst*_*ton 4 java email pop3 jakarta-mail

我正在使用 java 的默认 pop3 实现,但无法让它读取标志的实际状态(我认为)。

这是(缩写)代码:

Store store = null;
Folder folder = null;
try
{
    Session mailSession = Session.getInstance(new Properties(), null);
    store = mailSession.getStore("pop3");
    store.connect(host, addr, pwd);
    folder = store.getFolder("INBOX");
    folder.open(Folder.READ_WRITE);

    for (Message msg : folder.getMessages())
    {
        if (msg.isSet(Flag.SEEN))
            continue;

        LOG.debug("processing email titled '" + msg.getSubject()
                + "' from '" + msg.getFrom()[0] + "'");

        ... do some stuff

        msg.setFlag(Flag.SEEN, true);
    }
}
finally
{
        if (folder != null)
            folder.close(true);
        if (store != null)
            store.close();
}
Run Code Online (Sandbox Code Playgroud)

问题是,每次执行上述代码时,都会处理相同的消息(所有消息),因为对的调用msg.isSet(Flag.SEEN)始终返回 false,即使我在上一次迭代中将其设置为 true。

网络邮件客户端甚至反映了正在设置的标志(标题从粗体更改为正常字体)。

有谁知道我做错了什么?

谢谢,p。

pst*_*ton 5

进一步阅读告诉我 pop3 不支持设置/获取这些标志,只支持删除消息。

pop3 似乎确实支持设置标志(因为我可以看到该标志已在网络邮件程序中成功设置),但随后无法读取标志状态。

幸运的是,我的邮件服务器支持 imap,它可以按预期完成所有操作。我只需要将我的代码从 更改mailSession.getStore("pop3")mailSession.getStore("imap").