简体   繁体   English

获得'看到'标志似乎不起作用

[英]getting the 'seen' flag doesn't seem to work

I'm playing around with java's default pop3 implementation and having trouble getting it to read the actual state of flags (i think). 我正在玩java的默认pop3实现,并且无法让它读取标志的实际状态(我认为)。

Here's the (abbreviated) code: 这是(缩写)代码:

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();
}

The problem is that each time the above code is executed, the same messages (all of them) are processed because the call to msg.isSet(Flag.SEEN) always returns false, even though I have set it to true in the previous iteration. 问题是,每次执行上面的代码时,都会处理相同的消息(所有这些消息),因为对msg.isSet(Flag.SEEN)的调用总是返回false,即使我在上一次迭代中将其设置为true 。

The webmail client even reflects the flag being set (title changes from bold to normal font). Webmail客户端甚至反映了正在设置的标志(标题从粗体更改为普通字体)。

Does anyone know what I'm doing wrong? 有谁知道我做错了什么?

thanks, p. 谢谢,p。

further reading tells me that pop3 doesn't support setting/getting these flags, only deleting messages. 进一步阅读告诉我pop3不支持设置/获取这些标志,只删除消息。

it does seem that pop3 supports setting the flag (since i could see the flag had been set successfully in the webmail program) but could not subsequently read the flags state. 似乎pop3支持设置标志(因为我可以看到该标志已在webmail程序中成功设置),但随后无法读取标志状态。

thankfully my mail server supports imap which does everything as expected. 谢天谢地,我的邮件服务器支持imap,它按预期完成所有操作。 I just had to change my code from mailSession.getStore("pop3") to mailSession.getStore("imap") . 我只需要将我的代码从mailSession.getStore("pop3")更改为mailSession.getStore("imap")

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM