如何使用golang imap获取UID?

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

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"]))

huangapple
  • 本文由 发表于 2014年7月20日 22:10:49
  • 转载请务必保留本文链接:https://go.coder-hub.com/24851303.html
匿名

发表评论

匿名网友

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

确定