Add TNEF handling and email loading improvements

- Implement TNEF extraction and recursive parsing in new `tnef_reader.go` and associated tests.
- Create tests for TNEF extraction scenarios in `tnef_diag_test.go`, `tnef_diag7_test.go`, and `tnef_diag8_test.go`.
This commit is contained in:
Flavio Fois
2026-02-14 09:03:41 +01:00
parent 33cb171fb1
commit 54a3dff1c2
23 changed files with 2029 additions and 18 deletions

View File

@@ -0,0 +1,59 @@
package internal
import (
"fmt"
"os"
"testing"
)
func TestReadEmlWithTNEF(t *testing.T) {
testFile := `H:\Dev\Gits\EMLy\EML_TNEF.eml`
if _, err := os.Stat(testFile); os.IsNotExist(err) {
t.Skip("test EML file not present")
}
// First try the PEC reader (this is a PEC email)
email, err := ReadPecInnerEml(testFile)
if err != nil {
t.Fatalf("ReadPecInnerEml failed: %v", err)
}
fmt.Printf("Subject: %s\n", email.Subject)
fmt.Printf("From: %s\n", email.From)
fmt.Printf("Attachment count: %d\n", len(email.Attachments))
hasWinmailDat := false
for i, att := range email.Attachments {
fmt.Printf(" [%d] %s (%s, %d bytes)\n", i, att.Filename, att.ContentType, len(att.Data))
if att.Filename == "winmail.dat" {
hasWinmailDat = true
}
}
if hasWinmailDat {
t.Error("winmail.dat should have been expanded into its contained attachments")
}
if len(email.Attachments) == 0 {
t.Error("expected at least one attachment after TNEF expansion")
}
}
func TestReadEmlFallback(t *testing.T) {
testFile := `H:\Dev\Gits\EMLy\EML_TNEF.eml`
if _, err := os.Stat(testFile); os.IsNotExist(err) {
t.Skip("test EML file not present")
}
// Also verify the plain EML reader path
email, err := ReadEmlFile(testFile)
if err != nil {
t.Fatalf("ReadEmlFile failed: %v", err)
}
fmt.Printf("[EML] Subject: %s\n", email.Subject)
fmt.Printf("[EML] Attachment count: %d\n", len(email.Attachments))
for i, att := range email.Attachments {
fmt.Printf(" [%d] %s (%s, %d bytes)\n", i, att.Filename, att.ContentType, len(att.Data))
}
}