Golang emersion go-imap 如何获取回复的名字

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 更改为回复名称,

这是我的代码

mbox, err := c.Select("INBOX", false)
if err != nil {
    log.Fatal(err)
}
log.Println("Flags for INBOX:", mbox.Flags)

// Get the last 4 messages
from := uint32(1)
to := mbox.Messages
if mbox.Messages > 1 {
    // We're using unsigned integers here, only subtract if the result is > 0
    from = mbox.Messages - 1
}
seqset := new(imap.SeqSet)
seqset.AddRange(from, to)

messages := make(chan *imap.Message, 10)
done = make(chan error, 1)
go func() {
    done <- c.Fetch(seqset, []imap.FetchItem{imap.FetchEnvelope}, messages)
}()

log.Println("Last 4 messages:")
for msg := range messages {
    log.Println("=====================================")
    tes := msg.Envelope.From
    for i, v := range tes {
        log.Println("#########################")
        fmt.Println(i)
        fmt.Println(v.PersonalName)
        log.Println("#########################")
    }
    // fmt.Println(tes)
    // log.Println("Subject " + msg.Envelope.From)
    log.Println("In REply" + msg.Envelope.InReplyTo)
    log.Println("=====================================")
}

if err := <-done; err != nil {
    log.Fatal(err)
}

log.Println("Done!")

InReplyTo :- In-Reply-To header。包含 parent Message-Id。这就是您获取 Id 的原因。

使用 ReplyTo 而不是 InReplyTo

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

检查这个:

type Envelope struct {
    // The message date.
    Date time.Time
    // The message subject.
    Subject string
    // The From header addresses.
    From []*Address
    // The message senders.
    Sender []*Address
    // The Reply-To header addresses.
    ReplyTo []*Address
    // The To header addresses.
    To []*Address
    // The Cc header addresses.
    Cc []*Address
    // The Bcc header addresses.
    Bcc []*Address
    // The In-Reply-To header. Contains the parent Message-Id.
    InReplyTo string
    // The Message-Id header.
    MessageId string
}