0

我的要求是我想从我的雅虎帐户中删除邮件,所有代码都可以在我的 Gmail 帐户中正常运行。

以下是删除代码 -

   Message msg[] = inbox.getMessages();
   inbox.setFlags(msg, new Flags(Flags.Flag.DELETED), true);

执行上述代码行后,我没有关闭文件夹。因为我在设置 DELETED 标志后无法关闭文件夹,因为我的代码正在并行运行以删除多个文件夹的多条消息。

以下是用于删除两条消息的 Gmail 和 Yahoo 的协议跟踪 -

我发现在两种情况下都设置了 DELETED 标志而不是关闭文件夹,然后如果我打电话 -

 Message msg[] = inbox.getMessages();

协议跟踪的主要区别 -

Gmail 显示

* 1 EXPUNGE
* 1 EXPUNGE
* 0 EXISTS

雅虎展示 -

* 2 EXISTS
* 0 RECENT

虽然我的代码没有改变,我也没有调用folder.close(true);. 但是两个邮件服务器使用相同的代码对删除有不同的响应。

一件有趣的事情是设置 DELETED 标志从 Yahoo 和 Gmail 帐户中的给定文件夹中删除消息。在 Yahoo 的情况下,只有 JavaMail 显示它们还活着。

完整的详细协议跟踪 -

Gmail 删除协议跟踪 -

DEBUG: setDebug: JavaMail version ${mail.version}
DEBUG: getProvider() returning javax.mail.Provider[STORE,imaps,com.sun.mail.imap.IMAPSSLStore,Sun Microsystems, Inc.,${mail.version}]
DEBUG IMAPS: mail.imap.fetchsize: 16384
DEBUG IMAPS: mail.imap.ignorebodystructuresize: false
DEBUG IMAPS: mail.imap.statuscachetimeout: 1000
DEBUG IMAPS: mail.imap.appendbuffersize: -1
DEBUG IMAPS: mail.imap.minidletime: 10
DEBUG IMAPS: trying to connect to host "imap.gmail.com", port 993, isSSL true
* OK Gimap ready for requests from 59.99.161.5 ky9if13244828pbc.236
A0 CAPABILITY
* CAPABILITY IMAP4rev1 UNSELECT IDLE NAMESPACE QUOTA ID XLIST CHILDREN X-GM-EXT-1 XYZZY SASL-IR AUTH=XOAUTH AUTH=XOAUTH2 AUTH=PLAIN AUTH=PLAIN-CLIENTTOKEN
A0 OK Thats all she wrote! ky9if13244828pbc.236
DEBUG IMAPS: AUTH: XOAUTH
DEBUG IMAPS: AUTH: XOAUTH2
DEBUG IMAPS: AUTH: PLAIN
DEBUG IMAPS: AUTH: PLAIN-CLIENTTOKEN
DEBUG IMAPS: protocolConnect login, host=imap.gmail.com, user=mymail@gmail.com, password=<non-null>
DEBUG IMAPS: AUTHENTICATE PLAIN command trace suppressed
DEBUG IMAPS: AUTHENTICATE PLAIN command result: A1 OK mymail@gmail.com mymail authenticated (Success)
A2 CAPABILITY
* CAPABILITY IMAP4rev1 UNSELECT IDLE NAMESPACE QUOTA ID XLIST CHILDREN X-GM-EXT-1 UIDPLUS COMPRESS=DEFLATE ENABLE MOVE CONDSTORE ESEARCH
A2 OK Success
imaps://mymail%40gmail.com@imap.gmail.com
DEBUG IMAPS: connection available -- size: 1
A3 SELECT Inbox
* FLAGS (\Answered \Flagged \Draft \Deleted \Seen XAOL-RECEIVED XAOL-BILLPAY-MAIL XAOL-READ $hasEmbedded $NotJunk $hasAttached NotJunk XAOL-GOOD XAOL-CERTIFIED-MAIL $Junk XAOL-GOODCHECK-DONE)
* OK [PERMANENTFLAGS (\Answered \Flagged \Draft \Deleted \Seen XAOL-RECEIVED XAOL-BILLPAY-MAIL XAOL-READ $hasEmbedded $NotJunk $hasAttached NotJunk XAOL-GOOD XAOL-CERTIFIED-MAIL $Junk XAOL-GOODCHECK-DONE \*)] Flags permitted.
* OK [UIDVALIDITY 622695996] UIDs valid.
* 2 EXISTS
* 0 RECENT
* OK [UIDNEXT 136] Predicted next UID.
* OK [HIGHESTMODSEQ 48713]
A3 OK [READ-WRITE] Inbox selected. (Success)
DEBUG IMAPS: IMAPProtocol noop
A4 NOOP
A4 OK Success
A5 STORE 1:2 +FLAGS (\Deleted)
* 1 FETCH (FLAGS (\Deleted))
* 2 FETCH (FLAGS (\Deleted))
A5 OK Success
A6 SEARCH DELETED ALL
* SEARCH
A6 OK SEARCH completed (Success)
DELETED MAILS: 0
DEBUG IMAPS: IMAPProtocol noop
A7 NOOP
* 1 EXPUNGE
* 1 EXPUNGE
* 0 EXISTS
A7 OK Success
TOTAL MAILS: 2
A8 SEARCH DELETED ALL
* SEARCH
A8 OK SEARCH completed (Success)
DELETED MAILS: 0
FOLDER: Inbox

雅虎删除消息协议跟踪

DEBUG: setDebug: JavaMail version ${mail.version}
DEBUG: getProvider() returning javax.mail.Provider[STORE,imaps,com.sun.mail.imap.IMAPSSLStore,Sun Microsystems, Inc.,${mail.version}]
DEBUG IMAPS: mail.imap.fetchsize: 16384
DEBUG IMAPS: mail.imap.ignorebodystructuresize: false
DEBUG IMAPS: mail.imap.statuscachetimeout: 1000
DEBUG IMAPS: mail.imap.appendbuffersize: -1
DEBUG IMAPS: mail.imap.minidletime: 10
DEBUG IMAPS: trying to connect to host "imap.mail.yahoo.com", port 993, isSSL true
* OK [CAPABILITY IMAP4rev1 ID NAMESPACE X-ID-ACLID UIDPLUS LITERAL+ CHILDREN XAPPLEPUSHSERVICE XYMHIGHESTMODSEQ AUTH=PLAIN AUTH=LOGIN AUTH=XYMCOOKIE AUTH=XYMECOOKIE AUTH=XYMCOOKIEB64 AUTH=XYMPKI] IMAP4rev1 imapgate-0.7.68_14.446672 imap424.mail.bf1.yahoo.com
DEBUG IMAPS: AUTH: PLAIN
DEBUG IMAPS: AUTH: LOGIN
DEBUG IMAPS: AUTH: XYMCOOKIE
DEBUG IMAPS: AUTH: XYMECOOKIE
DEBUG IMAPS: AUTH: XYMCOOKIEB64
DEBUG IMAPS: AUTH: XYMPKI
DEBUG IMAPS: protocolConnect login, host=imap.mail.yahoo.com, user=mymail@yahoo.com, password=<non-null>
DEBUG IMAPS: AUTHENTICATE PLAIN command trace suppressed
DEBUG IMAPS: AUTHENTICATE PLAIN command result: A0 OK AUTHENTICATE completed - Mailbox size in bytes is 70034
A1 CAPABILITY
* CAPABILITY IMAP4rev1 ID NAMESPACE X-ID-ACLID UIDPLUS LITERAL+ XAPPLEPUSHSERVICE XYMHIGHESTMODSEQ
A1 OK CAPABILITY completed
imaps://mymail%40yahoo.com@imap.mail.yahoo.com
DEBUG IMAPS: connection available -- size: 1
A2 SELECT nsharma
* 2 EXISTS
* 0 RECENT
* OK [UIDVALIDITY 1379585757] UIDs valid
* OK [UIDNEXT 17] Predicted next UID
* FLAGS (\Answered \Flagged \Deleted \Seen \Draft)
* OK [PERMANENTFLAGS (\Answered \Flagged \Deleted \Seen \Draft)] Permanent flags
* OK [HIGHESTMODSEQ 5926770610774517536]
A2 OK [READ-WRITE] SELECT completed; now in selected state
DEBUG IMAPS: IMAPProtocol noop
A3 NOOP
A3 OK NOOP completed
DEBUG IMAPS: IMAPProtocol noop
A4 NOOP
A4 OK NOOP completed
A5 STORE 1:2 +FLAGS (\Deleted)
* 1 FETCH (FLAGS (\Deleted))
* 2 FETCH (FLAGS (\Deleted))
A5 OK STORE completed
A6 SEARCH DELETED ALL
* SEARCH 1 2 
A6 OK SEARCH completed
DELETED MAILS: 2
DEBUG IMAPS: IMAPProtocol noop
A7 NOOP
* 2 EXISTS
* 0 RECENT
A7 OK NOOP completed
TOTAL MAILS: 2
A8 SEARCH DELETED ALL
* SEARCH 1 2 
A8 OK SEARCH completed
DELETED MAILS: 2
FOLDER: nsharma
...details of both mails was printed...

有没有其他方法可以在不打电话的情况下删除消息folder.close(true);

谢谢,

尼拉姆夏尔马

4

1 回答 1

1

是的,请致电 EXPUNGE 或 UID EXPUNGE 。将消息标记为已删除只是一个标记。要真正摆脱它们,您必须删除它们。

于 2013-09-24T16:59:06.593 回答