无法从Yahoo IMAP帐户中删除邮件

时间:2013-09-24 11:59:38

标签: java javamail imap

我的要求是我要删除我的Yahoo帐户中的邮件,所有代码都可以通过我的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);。但是两个邮件服务器使用相同的代码都有不同的删除响应。

有趣的是,在Yahoo和Gmail帐户中从给定文件夹设置DELETED标记删除邮件。只有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

Yahoo删除邮件协议跟踪

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);的情况下删除邮件?

谢谢,

Neelam Sharma

1 个答案:

答案 0 :(得分:1)

是的,请拨打EXPUNGE或UID EXPUNGE。标记删除的邮件只是一个标记。要真正摆脱它们你必须消除。