繁体   English   中英

如何将邮件标记为未读?

[英]How to mark message as unread in go?

我想通过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()))

看一下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

请注意,“替换”确实删除了所有标志。 您必须处理(作为字符串值添加到接头)要保留的内容:

  • \\看
  • \\回答
  • \\被举报
  • \\删除
  • \\草案
  • \\最近

您可以从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)
}

您可以使用另一种方式。 您可以删除该标志。 例:

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM