问题
I am looking for the best way to get the sizes of messages using IMAP(i am writing a simple c# lib for myself). Basically a POP3 STAT command equivalent would be good, but it does not exist. I am thinking of fetching the message header and getting the content-length field. Anyone got a better idea or solution?
回答1:
Perhaps using the FETCH NNN HEADER
is the only way of doing that. Have you checked the spec for FETCH NNN RFC822.SIZE
? Also perhaps a good idea would be to learn from fetchmail
logs:
fetchmail: IMAP< * OK GroupWise IMAP4rev1 Server Ready
fetchmail: IMAP> A0001 CAPABILITY
fetchmail: IMAP< * CAPABILITY IMAP4rev1 AUTH=XGWTRUSTEDAPP XGWEXTENSIONS
fetchmail: IMAP< A0001 OK CAPABILITY completed
fetchmail: IMAP> A0002 LOGIN "user1" *
fetchmail: IMAP< A0002 OK LOGIN completed
fetchmail: IMAP> A0003 SELECT "INBOX"
fetchmail: IMAP< * 260 EXISTS
fetchmail: IMAP< * 1 RECENT
fetchmail: IMAP< * OK [UNSEEN 260]
fetchmail: IMAP< * OK [UIDVALIDITY 1301053702]
fetchmail: IMAP< * OK [UIDNEXT 545]
fetchmail: IMAP< * FLAGS (Answered Flagged Deleted Draft Seen)
fetchmail: IMAP< * OK [PERMANENTFLAGS (Answered Flagged Deleted Draft Seen *)]
fetchmail: IMAP< A0003 OK [READ-WRITE] SELECT completed
fetchmail: IMAP> A0004 SEARCH UNSEEN NOT DELETED
fetchmail: IMAP< * SEARCH 260
fetchmail: IMAP< A0004 OK SEARCH completed
260 messages (259 seen) for user1 at host_address.
skipping message user1@host_address:1 not flushed
{ ... etc ... }
skipping message user1@host_address:258 not flushed
skipping message user1@host_address:259 not flushed
fetchmail: IMAP> A0005 FETCH 260 RFC822.SIZE
fetchmail: IMAP< * 260 FETCH (RFC822.SIZE 23853)
fetchmail: IMAP< A0005 OK FETCH completed
fetchmail: IMAP> A0006 FETCH 260 RFC822.HEADER
fetchmail: IMAP< * 260 FETCH (RFC822.HEADER {367}
fetchmail: IMAP< )
fetchmail: IMAP< A0006 OK FETCH completed
fetchmail: IMAP> A0007 FETCH 260 BODY.PEEK[TEXT]
fetchmail: IMAP< * 260 FETCH (BODY[TEXT] {23486}
(23486 body octets) *********************
fetchmail: IMAP< A0007 OK FETCH completed
fetchmail: IMAP> A0008 STORE 260 +FLAGS (Seen)
fetchmail: IMAP< * 260 FETCH (FLAGS (Seen Recent))
fetchmail: IMAP< A0008 OK STORE completed
fetchmail: IMAP> A0009 LOGOUT
fetchmail: IMAP< * BYE IMAP4rev1 Server Disconnect
fetchmail: IMAP< A0009 OK LOGOUT completed
来源:https://stackoverflow.com/questions/8023723/imap-command-to-get-size-of-message