如何在Go中将消息标记为未读?

huangapple go评论68阅读模式
英文:

How to mark message as unread in go?

问题

我想在Go语言中使用IMAP将消息标记为未读。我不知道在"Replace"函数中应该传入哪些参数。我正在使用http://godoc.org/github.com/mxk/go-imap/imap。

以下是我的代码:

set, _ := imap.NewSeqSet("")
set.AddNum(45364) // 45364是消息的UID
_, err = imap.Wait(c.UIDStore(set, "+FLAGS", imap.Replace()))
英文:

I wanna to mark message by IMAP as unread in go. I don't know, what parameters give to "Replace" function. I'm using http://godoc.org/github.com/mxk/go-imap/imap

It's my code:

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

答案1

得分: 1

查看RFC3501Replace的文档,看起来有点混乱。调查Replace的源代码,它只需要一个包含来自RFC3501的关键字的[]string。所以,例如:

flags := []string{}
// ....
_, err = imap.Wait(c.UIDStore(set, "+FLAGS", imap.Replace(flags)))
// 由于"\Seen"不在splice中,该消息将变为未读

请注意,Replace确实会删除所有的标志。您必须处理(将要保留的标志作为字符串值添加到splice中):

  • \Seen
  • \Answered
  • \Flagged
  • \Deleted
  • \Draft
  • \Recent

您可以从MessageInfo结构体/Flags中获取先前的值:

type MessageInfo struct {
    Attrs        FieldMap  // 返回的所有属性
    Seq          uint32    // 消息序列号
    UID          uint32    // 唯一标识符(在非UID FETCH中可选)
    Flags        FlagSet   // 为此消息设置的标志(可选)
    InternalDate time.Time // 服务器内部消息时间戳(可选)
    Size         uint32    // 消息大小(以字节为单位)(可选)
}
英文:

Taking a look at RFC3501 and the documentation for Replace, it looks a bit messy. Investigating the source for Replace, it just wants a []string with the keywords from RFC3501. So, for example

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

Please notice that Replace really removes all the flags. You have to handle (add to the splice as string values) what you want to preserve:

  • \Seen
  • \Answered
  • \Flagged
  • \Deleted
  • \Draft
  • \Recent

You can get the previous values from the 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)
}

答案2

得分: 0

你可以用另一种方式来做。你可以移除这个标记。示例代码如下:

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

You can do it another way. You can remove the flag. Example:

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

huangapple
  • 本文由 发表于 2014年11月28日 16:23:08
  • 转载请务必保留本文链接:https://go.coder-hub.com/27184562.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定