How to mark a message as read , \\Seen on IMAP ( G

2019-05-19 23:02发布

问题:

I'm trying to mark a message/list of messages as "\SEEN" (permanently) using IMAP . However unlike fetch, search and friends there seem to be no Flag function on the imap package. Should I send raw commands with the UIDs ?

回答1:

You have to select the mailbox as writable

youImapConnection.Select(mailboxName, false) // true would be for readonly

And then simply do the following

seq, _ := imap.NewSeqSet("")
err := seq.AddNum(612) // 612 is your UID
_, err = imap.Wait(youImapConnection.UIDStore(seq, "+FLAGS", imap.NewFlagSet(`\Seen`))) // Here you tell to add the flag \Seen

Finally you will have to expunge:

_, err := imap.Wait(youImapConnection.Close(true)) // Here you tell to apply changes, necessary if you mark an Email as deleted

And you should be good :-)

And do not hesitate to browse the doc/source code, it's easy to understand and you'll find all you need.



回答2:

IMAP uses the STORE command to set flags on messages, e.g.:

foo UID STORE 135211 +FLAGS (\Seen)

So I'd guess that you should use the Store or UIDStore functions to set flags.



标签: go imap