emersion / go-imap

📥 An IMAP library for clients and servers
MIT License
2.1k stars 297 forks source link

GetBody() error:ENVELOPE doesn't contain 10 fields #546

Closed SinDeng closed 1 year ago

SinDeng commented 1 year ago

error info: 2023/09/18 16:18:33 ENVELOPE doesn't contain 10 fields panic: runtime error: invalid memory address or nil pointer dereference [signal SIGSEGV: segmentation violation code=0x1 addr=0x58 pc=0x166fa50]

goroutine 143 [running]: github.com/emersion/go-imap.(*Message).GetBody(0xc000253dd8?, 0x1?) /Users/aa/go/pkg/mod/github.com/emersion/go-imap@v1.2.1/message.go:341 +0x110

code: seqset := new(imap.SeqSet) seqset.AddNum(uid) sect := &imap.BodySectionName{Peek: true} items := []imap.FetchItem{imap.FetchEnvelope, imap.FetchFlags, imap.FetchInternalDate, sect.FetchItem()} messages := make(chan *imap.Message,1) messageDone := make(chan error, 1)

    go func() {
        messageDone <- c.UidFetch(seqset, items, messages)
    }()

    msg := <- messages

    if err := <-messageDone; err != nil {
        log.Println(err)
    }
    fmt.Println(msg.GetBody(sect))
SinDeng commented 1 year ago

change FetchItem normal.

items := []imap.FetchItem{imap.FetchBody, sect.FetchItem()}