Skip to content

Commit

Permalink
Add remaining address headers (#10)
Browse files Browse the repository at this point in the history
Added remaining address headers from https://tools.ietf.org/html/rfc2822#section-3.6
  • Loading branch information
ts2909 authored and jhillyerd committed Dec 7, 2016
1 parent 05c1f73 commit 2856163
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 8 deletions.
15 changes: 15 additions & 0 deletions envelope_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -536,6 +536,21 @@ func TestParseEncodedAddressList(t *testing.T) {
if got != want {
t.Errorf("To was: %q, want: %q", got, want)
}

senderAddresses, err := e.AddressList("Sender")
if err != nil {
t.Fatal("Failed to parse Sender list:", err)
}
if len(senderAddresses) != 1 {
t.Fatalf("len(senderAddresses) == %v, want: %v", len(senderAddresses), 1)
}

// Confirm address name was decoded properly
want = "André Pirard"
got = senderAddresses[0].Name
if got != want {
t.Errorf("Sender was: %q, want: %q", got, want)
}
}

func TestDetectCharacterSetInHTML(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion example_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ func Example() {
fmt.Printf("Attachments: %v\n", len(env.Attachments))

// Output:
// From: James Hillyerd <jamehi03@jamehi03lx.noa.com>
// From: James Hillyerd <jamehi03@jamehi03lx.noa.com>, André Pirard <PIRARD@vm1.ulg.ac.be>
// To: Mirosław Marczak <marczak@inbucket.com>
// Subject: MIME UTF8 Test ¢ More Text
// Text Body: 1300 chars
Expand Down
19 changes: 13 additions & 6 deletions header.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,19 @@ var errEmptyHeaderBlock = errors.New("empty header block")
// AddressHeaders is the set of SMTP headers that contain email addresses, used by
// Envelope.AddressList(). Key characters must be all lowercase.
var AddressHeaders = map[string]bool{
"bcc": true,
"cc": true,
"delivered-to": true,
"from": true,
"reply-to": true,
"to": true,
"bcc": true,
"cc": true,
"delivered-to": true,
"from": true,
"reply-to": true,
"to": true,
"sender": true,
"resent-bcc": true,
"resent-cc": true,
"resent-from": true,
"resent-reply-to": true,
"resent-to": true,
"resent-sender": true,
}

func debug(format string, args ...interface{}) {
Expand Down
3 changes: 2 additions & 1 deletion testdata/mail/qp-utf8-header.raw
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
Message-ID: <5081A889.3020108@jamehi03lx.noa.com>
Date: Fri, 19 Oct 2012 12:22:49 -0700
From: James Hillyerd <jamehi03@jamehi03lx.noa.com>
From: James Hillyerd <jamehi03@jamehi03lx.noa.com>, =?ISO-8859-1?Q?Andr=E9?= Pirard <PIRARD@vm1.ulg.ac.be>
Sender: =?ISO-8859-1?Q?Andr=E9?= Pirard <PIRARD@vm1.ulg.ac.be>
User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:16.0) Gecko/20121010 Thunderbird/16.0.1
MIME-Version: 1.0
To: =?UTF-8?Q?Miros=C5=82aw_Marczak?= <marczak@inbucket.com>
Expand Down

0 comments on commit 2856163

Please sign in to comment.