Ok: un message peut être lu avec pas mal d'information

This commit is contained in:
Laurent Ulrich
2025-07-28 20:09:38 +02:00
parent a559784462
commit 881f09fa20

View File

@@ -2,6 +2,7 @@ package main
import (
"bytes"
"fmt"
"io"
"log"
"mime"
@@ -66,10 +67,11 @@ func (mb *MailBox) Connect() error {
log.Fatal("Error fetching mails:", err)
}
for _, msg := range messages {
log.Println(msg.Envelope.From)
log.Println(msg.Envelope.To)
log.Println(msg.Envelope.Date)
log.Println(msg.Envelope.Subject)
log.Println("**************MESSAGE**************")
log.Println("From:", msg.Envelope.From)
log.Println("To:", msg.Envelope.To)
log.Println("Date:", msg.Envelope.Date)
log.Println("Subject:", msg.Envelope.Subject)
section := msg.FindBodySection(bodySection)
ioReader := bytes.NewReader(section)
@@ -80,16 +82,21 @@ func (mb *MailBox) Connect() error {
for {
part, err := mailReader.NextPart()
if err == io.EOF {
log.Println("------------")
break
} else if err != nil {
log.Fatal("Error reading part", err)
}
log.Println("------------PART-----------")
fmt.Println("Content-Type:", part.Header.Get("Content-Type"))
fmt.Println("Content-Transfer-Encoding:", part.Header.Get("Content-Transfer-Encoding"))
fmt.Println("header:", part.Header)
switch header := part.Header.(type) {
case *mail.AttachmentHeader:
filename, _ := header.Filename()
log.Println("------------FILE-----------")
log.Println("Attachment:", filename)
case *mail.InlineHeader:
log.Println("------------INLINE-----------")
body, _ := io.ReadAll(part.Body)
log.Println(string(body))
}