如何将邮件标记为未读?

时间:2014-11-28 08:23:09

标签: go imap flags

我想通过IMAP将消息标记为未读。我不知道,哪些参数会给"替换"功能。我正在使用http://godoc.org/github.com/mxk/go-imap/imap

这是我的代码:

set, _ := imap.NewSeqSet("")
set.AddNum(45364) // 45364 is message's UID
_, err = imap.Wait(c.UIDStore(set, "+FLAGS", imap.Replace()))

2 个答案:

答案 0 :(得分:1)

看一下RFC3501Replace的文档,看起来有点乱。调查Replace的源代码,只需要一个带有RFC3501关键字的[]字符串。所以,例如

flags := []string{}
// ....
_, err = imap.Wait(c.UIDStore(set, "+FLAGS", imap.Replace(flags)))
// Since the "\Seen" is not in splice, the message will be unseen

请注意,Replace确实删除了所有标志。您必须处理(将拼接添加为字符串值)您要保留的内容:

  • \看
  • \回答
  • \已标记
  • \删除
  • \草案
  • \最近

您可以从MessageInfo struct / Flags中获取以前的值:

type MessageInfo struct {
    Attrs        FieldMap  // All returned attributes
    Seq          uint32    // Message sequence number
    UID          uint32    // Unique identifier (optional in non-UID FETCH)
    Flags        FlagSet   // Flags that are set for this message (optional)
    InternalDate time.Time // Internal to the server message timestamp (optional)
    Size         uint32    // Message size in bytes (optional)
}

答案 1 :(得分:0)

你可以用另一种方式做到。你可以删除标志。例如:

flags := `\Seen`
tmpSet, _ := imap.NewSeqSet("")
tmpSet.AddNum(emailUid)
_, err = imap.Wait(c.UIDStore(tmpSet, "-FLAGS", imap.NewFlagSet(flags)))
相关问题