英文:
How to fetch the UIDs using golang imap?
问题
我正在使用Go的Imap包开发一个电子邮件客户端。为了同步数据,我需要唯一标识符,所以我花了一个小时试图找到如何设置收件箱返回UID而不是序列号。有什么想法吗?我尝试了一些命令,比如set, err := imap.NewSeqSet("UID set")
,但没有得到积极的结果。非常感谢任何帮助!
英文:
I'm developing an email client using Go Imap package. In order to sync the data I need unique identifiers so I'm trying for an hour to find how to set the inbox to return UIDs instead of sequence numbers. Any idea how ? I've tried blindly some commands such set, err := imap.NewSeqSet("UID set")
with no positive result. Any help is much appreciated!
答案1
得分: 2
这似乎有效...现在我需要找到如何获取并解码正文的方法:/
cmd, err = c.UIDFetch(set, "RFC822.HEADER")
if err != nil {
log.Error(err)
return
}
// 在命令运行时处理响应
fmt.Println("\n最近的消息:")
for cmd.InProgress() {
// 等待下一个响应(无超时)
c.Recv(-1)
var m Msg
// 处理命令数据
for _, rsp = range cmd.Data {
header := imap.AsBytes(rsp.MessageInfo().Attrs["RFC822.HEADER"])
UID := imap.AsNumber((rsp.MessageInfo().Attrs["UID"]))
英文:
this seems to work... now I need to find how to get the & decode the body:/
cmd, err = c.UIDFetch(set, "RFC822.HEADER")
if err != nil {
log.Error(err)
return
}
// Process responses while the command is running
fmt.Println("\nMost recent messages:")
for cmd.InProgress() {
// Wait for the next response (no timeout)
c.Recv(-1)
var m Msg
// Process command data
for _, rsp = range cmd.Data {
header := imap.AsBytes(rsp.MessageInfo().Attrs["RFC822.HEADER"])
UID := imap.AsNumber((rsp.MessageInfo().Attrs["UID"]))
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论