Golang emersion go-imap如何获取回复的发件人名称

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

Golang emersion go-imap how to get the name that did the reply

问题

我正在使用Golang的Emersion包通过IMAP获取传入的电子邮件,在这里我正在尝试使用InReplyTo函数,但我得到的是发件人的ID,例如:CABkN-Fgn2o7L9Rqep2WDE70tfmk07O35+Ta2Snr+CoDdHcAD6rg@mail.gmail.com。我该如何将ID更改为回复名称?

这是我的代码:

  1. mbox, err := c.Select("INBOX", false)
  2. if err != nil {
  3. log.Fatal(err)
  4. }
  5. log.Println("Flags for INBOX:", mbox.Flags)
  6. // 获取最后4条消息
  7. from := uint32(1)
  8. to := mbox.Messages
  9. if mbox.Messages > 1 {
  10. // 这里使用无符号整数,只有在结果大于0时才进行减法运算
  11. from = mbox.Messages - 1
  12. }
  13. seqset := new(imap.SeqSet)
  14. seqset.AddRange(from, to)
  15. messages := make(chan *imap.Message, 10)
  16. done = make(chan error, 1)
  17. go func() {
  18. done <- c.Fetch(seqset, []imap.FetchItem{imap.FetchEnvelope}, messages)
  19. }()
  20. log.Println("Last 4 messages:")
  21. for msg := range messages {
  22. log.Println("=====================================")
  23. tes := msg.Envelope.From
  24. for i, v := range tes {
  25. log.Println("#########################")
  26. fmt.Println(i)
  27. fmt.Println(v.PersonalName)
  28. log.Println("#########################")
  29. }
  30. // fmt.Println(tes)
  31. // log.Println("Subject " + msg.Envelope.From)
  32. log.Println("In REply" + msg.Envelope.InReplyTo)
  33. log.Println("=====================================")
  34. }
  35. if err := <-done; err != nil {
  36. log.Fatal(err)
  37. }
  38. log.Println("Done!")

希望对你有帮助!

英文:

I'm here using the Golang Emersion package to get incoming email via IMAP, here I'm trying to use the InReplyTo function, but what I get is the ID of the sender, for example:
<CABkN-Fgn2o7L9Rqep2WDE70tfmk07O35+Ta2Snr+CoDdHcAD6rg@mail.gmail.com>

how do i change the ID to reply name,

this is my code

  1. mbox, err := c.Select(&quot;INBOX&quot;, false)
  2. if err != nil {
  3. log.Fatal(err)
  4. }
  5. log.Println(&quot;Flags for INBOX:&quot;, mbox.Flags)
  6. // Get the last 4 messages
  7. from := uint32(1)
  8. to := mbox.Messages
  9. if mbox.Messages &gt; 1 {
  10. // We&#39;re using unsigned integers here, only subtract if the result is &gt; 0
  11. from = mbox.Messages - 1
  12. }
  13. seqset := new(imap.SeqSet)
  14. seqset.AddRange(from, to)
  15. messages := make(chan *imap.Message, 10)
  16. done = make(chan error, 1)
  17. go func() {
  18. done &lt;- c.Fetch(seqset, []imap.FetchItem{imap.FetchEnvelope}, messages)
  19. }()
  20. log.Println(&quot;Last 4 messages:&quot;)
  21. for msg := range messages {
  22. log.Println(&quot;=====================================&quot;)
  23. tes := msg.Envelope.From
  24. for i, v := range tes {
  25. log.Println(&quot;#########################&quot;)
  26. fmt.Println(i)
  27. fmt.Println(v.PersonalName)
  28. log.Println(&quot;#########################&quot;)
  29. }
  30. // fmt.Println(tes)
  31. // log.Println(&quot;Subject &quot; + msg.Envelope.From)
  32. log.Println(&quot;In REply&quot; + msg.Envelope.InReplyTo)
  33. log.Println(&quot;=====================================&quot;)
  34. }
  35. if err := &lt;-done; err != nil {
  36. log.Fatal(err)
  37. }
  38. log.Println(&quot;Done!&quot;)

答案1

得分: 1

InReplyTo:In-Reply-To头部。包含父级Message-Id。这就是你获取到Id的原因。

使用ReplyTo代替InReplyTo

  1. log.Println("In REply" + msg.Envelope.ReplyTo)

请检查以下内容:

  1. type Envelope struct {
  2. // 消息日期。
  3. Date time.Time
  4. // 消息主题。
  5. Subject string
  6. // 发件人头部地址。
  7. From []*Address
  8. // 消息发送者。
  9. Sender []*Address
  10. // 回复地址头部地址。
  11. ReplyTo []*Address
  12. // 收件人头部地址。
  13. To []*Address
  14. // 抄送头部地址。
  15. Cc []*Address
  16. // 密送头部地址。
  17. Bcc []*Address
  18. // In-Reply-To头部。包含父级Message-Id。
  19. InReplyTo string
  20. // Message-Id头部。
  21. MessageId string
  22. }
英文:

InReplyTo :- The In-Reply-To header. Contains the parent Message-Id. This is why you are getting the Id.

Use ReplyTo instead of InReplyTo.

  1. log.Println(&quot;In REply&quot; + msg.Envelope.ReplyTo)

Check this :

  1. type Envelope struct {
  2. // The message date.
  3. Date time.Time
  4. // The message subject.
  5. Subject string
  6. // The From header addresses.
  7. From []*Address
  8. // The message senders.
  9. Sender []*Address
  10. // The Reply-To header addresses.
  11. ReplyTo []*Address
  12. // The To header addresses.
  13. To []*Address
  14. // The Cc header addresses.
  15. Cc []*Address
  16. // The Bcc header addresses.
  17. Bcc []*Address
  18. // The In-Reply-To header. Contains the parent Message-Id.
  19. InReplyTo string
  20. // The Message-Id header.
  21. MessageId string
  22. }

huangapple
  • 本文由 发表于 2022年1月3日 11:03:34
  • 转载请务必保留本文链接:https://go.coder-hub.com/70561322.html
匿名

发表评论

匿名网友

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

确定