关闭IMAP文件夹时,JavaMail API如何清除消息

时间:2021-10-07 18:18:21

I wonder, how JavaMail API expunges IMAP messages when Folder.close(true) is being called? According to the docs, the only parameter "expunge" of method "close" determines whether to expunge all messages that have been previously marked with a \Deleted flag. In the source code (V. 1.4.7), however, I cannot see any piece of code in the method close (class IMAPFolder), that expunges anything or does anything even going into that direction. Can anyone help me understand the effect of the expunge parameter?

我想知道,当调用Folder.close(true)时,JavaMail API如何清除IMAP消息?根据文档,方法“close”的唯一参数“expunge”确定是否要删除之前用\ Deleted标记标记的所有消息。但是,在源代码(V. 1.4.7)中,我看不到方法close(类IMAPFolder)中的任何代码片段,它会删除任何内容或者甚至进入该方向。任何人都可以帮我理解expunge参数的效果吗?

Thank you very much in advance and have a nice day.

非常感谢您提前和美好的一天。

1 个解决方案

#1


IMAPFolder.class, line 1310 :

IMAPFolder.class,第1310行:

 // If the expunge flag is set, close the folder first.
 if (expunge && protocol != null)
    protocol.close();

IMAPProtocol.class, line 1201 :

IMAPProtocol.class,第1201行:

 /**
 * CLOSE Command.
 *
 * @see "RFC2060, section 6.4.2"
 */
public void close() throws ProtocolException {
   simpleCommand("CLOSE", null);
}

https://tools.ietf.org/html/rfc2060#section-6.4.2 :

The CLOSE command permanently removes from the currently selected mailbox all messages that have the \Deleted flag set, and returns to authenticated state from selected state. No untagged EXPUNGE responses are sent.

CLOSE命令从当前选定的邮箱中永久删除所有设置了\ Deleted标志的邮件,并从选定状态返回到身份验证状态。没有发送未标记的EXPUNGE响应。

No messages are removed, and no error is given, if the mailbox is selected by an EXAMINE command or is otherwise selected read-only.

如果邮箱由EXAMINE命令选择或以其他方式选择为只读,则不会删除任何邮件,也不会给出错误。

Even if a mailbox is selected, a SELECT, EXAMINE, or LOGOUT command MAY be issued without previously issuing a CLOSE command. The SELECT, EXAMINE, and LOGOUT commands implicitly close the currently selected mailbox without doing an expunge. However, when many messages are deleted, a CLOSE-LOGOUT or CLOSE-SELECT

即使选择了邮箱,也可以在不事先发出CLOSE命令的情况下发出SELECT,EXAMINE或LOGOUT命令。 SELECT,EXAMINE和LOGOUT命令隐式关闭当前选定的邮箱而不进行清除。但是,当删除许多消息时,会发生CLOSE-LOGOUT或CLOSE-SELECT

#1


IMAPFolder.class, line 1310 :

IMAPFolder.class,第1310行:

 // If the expunge flag is set, close the folder first.
 if (expunge && protocol != null)
    protocol.close();

IMAPProtocol.class, line 1201 :

IMAPProtocol.class,第1201行:

 /**
 * CLOSE Command.
 *
 * @see "RFC2060, section 6.4.2"
 */
public void close() throws ProtocolException {
   simpleCommand("CLOSE", null);
}

https://tools.ietf.org/html/rfc2060#section-6.4.2 :

The CLOSE command permanently removes from the currently selected mailbox all messages that have the \Deleted flag set, and returns to authenticated state from selected state. No untagged EXPUNGE responses are sent.

CLOSE命令从当前选定的邮箱中永久删除所有设置了\ Deleted标志的邮件,并从选定状态返回到身份验证状态。没有发送未标记的EXPUNGE响应。

No messages are removed, and no error is given, if the mailbox is selected by an EXAMINE command or is otherwise selected read-only.

如果邮箱由EXAMINE命令选择或以其他方式选择为只读,则不会删除任何邮件,也不会给出错误。

Even if a mailbox is selected, a SELECT, EXAMINE, or LOGOUT command MAY be issued without previously issuing a CLOSE command. The SELECT, EXAMINE, and LOGOUT commands implicitly close the currently selected mailbox without doing an expunge. However, when many messages are deleted, a CLOSE-LOGOUT or CLOSE-SELECT

即使选择了邮箱,也可以在不事先发出CLOSE命令的情况下发出SELECT,EXAMINE或LOGOUT命令。 SELECT,EXAMINE和LOGOUT命令隐式关闭当前选定的邮箱而不进行清除。但是,当删除许多消息时,会发生CLOSE-LOGOUT或CLOSE-SELECT