I've read over the go documentation as well as the general imap documentation but can't seem to find the correct way to get the status of a particular message - to know if it is marked as read or unread.
Here's what I've got so far:
//
//Code that set up 'c' and 'cmd' ...
//
for cmd.InProgress() {
// Wait for the next response (no timeout)
c.Recv(-1)
// Process command data
for _, rsp = range cmd.Data {
if err != nil {
fmt.Println(err)
}
header := imap.AsBytes(rsp.MessageInfo().Attrs["RFC822.HEADER"]) // Contains subject, from data
uid := imap.AsNumber(rsp.MessageInfo().Attrs["UID"]) // Message unique id
body := imap.AsBytes(rsp.MessageInfo().Attrs["RFC822.TEXT"]) // Message body
//seenState := imap.AsBytes(rsp.MessageInfo().Attrs["Flags"])
if msg, err := mail.ReadMessage(bytes.NewReader(header)); msg != nil {
if err != nil {
fmt.Println(err)
}
//START CUSTOM
if strings.Contains(msg.Header.Get("Subject"), genUUID()){
fmt.Println(rsp.Label)
fmt.Println(rsp.MessageInfo().Attrs["Flags"])
fmt.Println(c.Status("INBOX", string(uid)))
}
//END CUSTOM
For output I get:
FETCH
<nil>
LAOYU10 STATUS "INBOX" (Þ) <nil>
The documentation that I've cited has led me to believe that at least one of my methods should be printing if the message is marked as unseen. What am I missing?
EDIT: I am testing against an inbox (gmail) with four messages. The first two are read and second two are unread. Here is the output for all four messages.
FETCH
<nil>
SIHLB7 STATUS "INBOX" (Û) <nil>
FETCH
<nil>
SIHLB8 STATUS "INBOX" (Ü) <nil>
FETCH
<nil>
SIHLB9 STATUS "INBOX" (Ý) <nil>
FETCH
<nil>
SIHLB10 STATUS "INBOX" (Þ) <nil>