Reputation: 2855
My requirement is that I want to delete messages from my Yahoo account, all the code running fine with my Gmail account.
Below is the delete code -
Message msg[] = inbox.getMessages();
inbox.setFlags(msg, new Flags(Flags.Flag.DELETED), true);
I am not closing folder after performing above lines of code. As I can not close the folder after setting DELETED flag because my code is running parallel for delete multiple messages of multiple folders.
These are the protocol trace for Gmail and Yahoo for delete two messages are below -
I found that on setting DELETED flag and not closing folder in both case, then after if I call -
Message msg[] = inbox.getMessages();
The major difference in protocol trace for -
Gmail Showing
* 1 EXPUNGE
* 1 EXPUNGE
* 0 EXISTS
Yahoo Showing -
* 2 EXISTS
* 0 RECENT
Though my code is not changed nor I did call to folder.close(true);
. But both mail server have different response for delete by using same code.
One interesting thing is that setting DELETED flag delete message from given folder in Yahoo as well as in Gmail account. Only JavaMail showing them alive in case of Yahoo.
COMPLETE DETAILED PROTOCOL TRACE -
Gmail Delete Protocol Trace -
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, [email protected], password=<non-null>
DEBUG IMAPS: AUTHENTICATE PLAIN command trace suppressed
DEBUG IMAPS: AUTHENTICATE PLAIN command result: A1 OK [email protected] 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%[email protected]
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 Delete Messages Protocol Trace
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, [email protected], 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%[email protected]
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...
Is there other way to delete messages without calling folder.close(true);
?
Thanks,
Neelam Sharma
Upvotes: 0
Views: 1184
Reputation: 10985
Yes, call EXPUNGE or UID EXPUNGE . Marking a message deleted is only a mark. To actually get rid of them you must expunge.
Upvotes: 1