如何在 IMAP(Go)中将消息标记为已读(\Seen)?

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

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

问题

我正在尝试使用IMAP(Internet Mail Access Protocol)将一条消息/一组消息标记为“\SEEN”(永久性标记)。然而,与fetch、search和其他功能不同,IMAP包中似乎没有Flag函数。我应该使用UIDs发送原始命令吗?

英文:

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 ?

答案1

得分: 4

你必须将邮箱选择为可写的。

youImapConnection.Select(mailboxName, false) // true 表示只读

然后简单地执行以下操作:

seq, _ := imap.NewSeqSet("")
err := seq.AddNum(612) // 612 是你的 UID
_, err = imap.Wait(youImapConnection.UIDStore(seq, "+FLAGS", imap.NewFlagSet(`\Seen`))) // 在这里告诉它添加标记 \Seen

最后,你需要清除已删除的邮件:

_, err := imap.Wait(youImapConnection.Close(true)) // 在这里告诉它应用更改,如果你标记了一封邮件为已删除,这是必要的

然后你就完成了 如何在 IMAP(Go)中将消息标记为已读(\Seen)?

如果有需要,不要犹豫浏览文档/源代码,它很容易理解,你会找到所需的一切。

英文:

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 如何在 IMAP(Go)中将消息标记为已读(\Seen)?

And do not hesitate to browse the doc/source code, it's easy to understand and you'll find all you need.

答案2

得分: 2

IMAP使用STORE命令在消息上设置标志,例如:

foo UID STORE 135211 +FLAGS (\Seen)

所以我猜你应该使用StoreUIDStore函数来设置标志。

英文:

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.

huangapple
  • 本文由 发表于 2014年7月24日 00:38:30
  • 转载请务必保留本文链接:https://go.coder-hub.com/24916179.html
匿名

发表评论

匿名网友

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

确定