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.