File: envelope_test.go

package info (click to toggle)
golang-github-emersion-go-imap 1.2.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 840 kB
  • sloc: makefile: 2
file content (40 lines) | stat: -rw-r--r-- 1,289 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
package backendutil

import (
	"bufio"
	"reflect"
	"strings"
	"testing"

	"github.com/emersion/go-imap"
	"github.com/emersion/go-message/textproto"
)

var testEnvelope = &imap.Envelope{
	Date:      testDate,
	Subject:   "Your Name.",
	From:      []*imap.Address{{PersonalName: "Mitsuha Miyamizu", MailboxName: "mitsuha.miyamizu", HostName: "example.org"}},
	Sender:    []*imap.Address{{PersonalName: "Mitsuha Miyamizu", MailboxName: "mitsuha.miyamizu", HostName: "example.org"}},
	ReplyTo:   []*imap.Address{{PersonalName: "Mitsuha Miyamizu", MailboxName: "mitsuha.miyamizu+replyto", HostName: "example.org"}},
	To:        []*imap.Address{{PersonalName: "Taki Tachibana", MailboxName: "taki.tachibana", HostName: "example.org"}},
	Cc:        []*imap.Address{},
	Bcc:       []*imap.Address{},
	InReplyTo: "",
	MessageId: "42@example.org",
}

func TestFetchEnvelope(t *testing.T) {
	hdr, err := textproto.ReadHeader(bufio.NewReader(strings.NewReader(testMailString)))
	if err != nil {
		t.Fatal("Expected no error while reading mail, got:", err)
	}

	env, err := FetchEnvelope(hdr)
	if err != nil {
		t.Fatal("Expected no error while fetching envelope, got:", err)
	}

	if !reflect.DeepEqual(env, testEnvelope) {
		t.Errorf("Expected envelope \n%+v\n but got \n%+v", testEnvelope, env)
	}
}