有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java当IMAP文件夹关闭时,JavaMail API如何删除消息

我想知道,当调用Folder.close(true)时,JavaMail API如何删除IMAP消息?根据文档,方法“close”的唯一参数“expunge”决定是否删除以前标记为\Deleted标志的所有邮件。然而,在source code (V. 1.4.7)中,我看不到方法close(类IMAPFolder)中的任何代码片段,该代码片段删除了任何内容,或者执行了任何与该方向相关的操作。有人能帮我理解expunge参数的效果吗

提前非常感谢您,祝您今天愉快


共 (1) 个答案

  1. # 1 楼答案

    IMAPFolder。课堂,第1310行:

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

    伊马普洛托科。班级,第1201行:

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

    https://www.rfc-editor.org/rfc/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.

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

    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