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

2019-05-19 23:25发布

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 ?

标签: go imap
2条回答
爱情/是我丢掉的垃圾
2楼-- · 2019-05-19 23:47

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.

查看更多
Deceive 欺骗
3楼-- · 2019-05-19 23:56

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.

查看更多
登录 后发表回答