Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: jhillyerd/enmime
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v0.11.0
Choose a base ref
...
head repository: jhillyerd/enmime
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: v0.11.1
Choose a head ref
  • 3 commits
  • 26 files changed
  • 3 contributors

Commits on Mar 9, 2023

  1. Copy the full SHA
    87c0655 View commit details

Commits on Mar 13, 2023

  1. Maintain an internal copy of net/textproto with few fixes for email h…

    …eader (#283)
    
    * Copy net/textproto from Golang git repo.
    
    * New method: ReadEmailMIMEHeader.
    New functions: readEmailMIMEHeader, CanonicalEmailMIMEHeaderKey, validEmailHeaderFieldByte, canonicalEmailMIMEHeaderKey.
    
    * Add file textproto/reader_email.go
    
    * Remove duplicate validHeaderFieldByte.
    Use CanonicalEmailMIMEHeaderKey instead of CanonicalMIMEHeaderKey in MIMEHeader methods.
    
    * Add missing internal package in test files.
    
    * Drop Go v1.16.x support in GitHub Action.
    
    * Replace `bytes.Clone()` to support Go v1.18.
    
    * Recover function canonicalEmailMIMEHeaderKey.
    
    ---------
    
    Co-authored-by: ly020044 <ly020044@gmail.com>
    iredmail and ly020044 authored Mar 13, 2023
    Copy the full SHA
    340151c View commit details
  2. Fix lint errors introduced by textproto import (#285)

    * textproto: Add comments to make go vet pass
    
    * textproto: fix errcheck lint errors from imported files
    jhillyerd authored Mar 13, 2023
    Copy the full SHA
    67b5cbe View commit details
2 changes: 1 addition & 1 deletion .github/workflows/build-and-test.yml
Original file line number Diff line number Diff line change
@@ -7,7 +7,7 @@ jobs:
strategy:
matrix:
go:
- 1.16.x
- 1.18.x
- 1.19.x
- 1.20.x
name: Go ${{ matrix.go }} build
2 changes: 1 addition & 1 deletion builder.go
Original file line number Diff line number Diff line change
@@ -7,12 +7,12 @@ import (
"math/rand"
"mime"
"net/mail"
"net/textproto"
"path/filepath"
"reflect"
"time"

"github.com/jhillyerd/enmime/internal/stringutil"
"github.com/jhillyerd/enmime/internal/textproto"
)

// MailBuilder facilitates the easy construction of a MIME message. Each manipulation method
2 changes: 1 addition & 1 deletion detect.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package enmime

import (
"net/textproto"
"strings"

"github.com/jhillyerd/enmime/internal/textproto"
"github.com/jhillyerd/enmime/mediatype"
)

3 changes: 2 additions & 1 deletion detect_test.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
package enmime

import (
"net/textproto"
"os"
"path/filepath"
"testing"

"github.com/jhillyerd/enmime/internal/textproto"
)

func TestDetectSinglePart(t *testing.T) {
3 changes: 2 additions & 1 deletion dsn/dsn.go
Original file line number Diff line number Diff line change
@@ -3,8 +3,9 @@
package dsn

import (
"net/textproto"
"strings"

"github.com/jhillyerd/enmime/internal/textproto"
)

// Report represents delivery status report as per https://datatracker.ietf.org/doc/html/rfc6522.
2 changes: 1 addition & 1 deletion dsn/parse.go
Original file line number Diff line number Diff line change
@@ -6,9 +6,9 @@ import (
"errors"
"fmt"
"io"
"net/textproto"

"github.com/jhillyerd/enmime"
"github.com/jhillyerd/enmime/internal/textproto"
)

// ParseReport parses p as a "container" for delivery status report (per rfc6522) if p is "multipart/report".
3 changes: 2 additions & 1 deletion dsn/parse_internal_test.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
package dsn

import (
"net/textproto"
"testing"

"github.com/jhillyerd/enmime"
"github.com/jhillyerd/enmime/internal/textproto"

"github.com/stretchr/testify/assert"
)

3 changes: 2 additions & 1 deletion dsn/parse_test.go
Original file line number Diff line number Diff line change
@@ -2,13 +2,14 @@ package dsn_test

import (
"bytes"
"net/textproto"
"os"
"path/filepath"
"testing"

"github.com/jhillyerd/enmime"
"github.com/jhillyerd/enmime/dsn"
"github.com/jhillyerd/enmime/internal/textproto"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
2 changes: 1 addition & 1 deletion encode.go
Original file line number Diff line number Diff line change
@@ -6,12 +6,12 @@ import (
"io"
"mime"
"mime/quotedprintable"
"net/textproto"
"sort"
"time"

"github.com/jhillyerd/enmime/internal/coding"
"github.com/jhillyerd/enmime/internal/stringutil"
"github.com/jhillyerd/enmime/internal/textproto"
)

// b64Percent determines the percent of non-ASCII characters enmime will tolerate before switching
5 changes: 3 additions & 2 deletions envelope.go
Original file line number Diff line number Diff line change
@@ -5,13 +5,14 @@ import (
"io"
"mime"
"net/mail"
"net/textproto"
"strings"
"time"

"github.com/jaytaylor/html2text"
"github.com/jhillyerd/enmime/internal/coding"
"github.com/jhillyerd/enmime/internal/textproto"
"github.com/jhillyerd/enmime/mediatype"

"github.com/pkg/errors"
)

@@ -57,7 +58,7 @@ func (e *Envelope) GetHeaderValues(name string) []string {
return []string{}
}

rawValues := (*e.header)[textproto.CanonicalMIMEHeaderKey(name)]
rawValues := (*e.header)[textproto.CanonicalEmailMIMEHeaderKey(name)]
values := make([]string, 0, len(rawValues))
for _, v := range rawValues {
values = append(values, coding.DecodeExtHeader(v))
17 changes: 12 additions & 5 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,17 +1,24 @@
module github.com/jhillyerd/enmime

go 1.18

require (
github.com/cention-sany/utf7 v0.0.0-20170124080048-26cad61bd60a
github.com/go-test/deep v1.0.7
github.com/gogs/chardet v0.0.0-20191104214054-4b6791f73a28
github.com/jaytaylor/html2text v0.0.0-20200412013138-3577fbdbcff7
github.com/pkg/errors v0.9.1
github.com/stretchr/testify v1.7.0
golang.org/x/text v0.8.0
)

require (
github.com/davecgh/go-spew v1.1.0 // indirect
github.com/mattn/go-runewidth v0.0.12 // indirect
github.com/olekukonko/tablewriter v0.0.5 // indirect
github.com/pkg/errors v0.9.1
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/rivo/uniseg v0.2.0 // indirect
github.com/ssor/bom v0.0.0-20170718123548-6386211fdfcf // indirect
github.com/stretchr/testify v1.7.0
golang.org/x/text v0.3.8
golang.org/x/net v0.8.0 // indirect
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c // indirect
)

go 1.13
30 changes: 4 additions & 26 deletions go.sum
Original file line number Diff line number Diff line change
@@ -25,32 +25,10 @@ github.com/ssor/bom v0.0.0-20170718123548-6386211fdfcf/go.mod h1:RJID2RhlZKId02n
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY=
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4=
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=
golang.org/x/net v0.0.0-20220722155237-a158d28d115b h1:PxfKdU9lEEDYjdIzOtC4qFWgkU2rGHdKlKowJSMN9h0=
golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c=
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ=
golang.org/x/text v0.3.8 h1:nAL+RVCQ9uMn3vJZbV+MRnydTJFPf8qqY42YiA6MrqY=
golang.org/x/text v0.3.8/go.mod h1:E6s5w1FMmriuDzIBO73fBruAKo1PCIq6d2Q6DHfQ8WQ=
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc=
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/net v0.8.0 h1:Zrh2ngAOFYneWTAIAPethzeaQLuHwhuBkuV6ZiRnUaQ=
golang.org/x/net v0.8.0/go.mod h1:QVkue5JL9kW//ek3r6jTKnTFis1tRmNAW2P1shuFdJc=
golang.org/x/text v0.8.0 h1:57P1ETyNKtuIjB4SRd15iJxuhj8Gc416Y78H3qgMh68=
golang.org/x/text v0.8.0/go.mod h1:e1OnstbJyHTd6l/uOt8jFFHp6TRDWZR/bV3emEE/zU8=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo=
36 changes: 4 additions & 32 deletions header.go
Original file line number Diff line number Diff line change
@@ -6,12 +6,13 @@ import (
"fmt"
"mime"
"net/mail"
"net/textproto"
"strings"

"github.com/jhillyerd/enmime/internal/coding"
"github.com/jhillyerd/enmime/internal/stringutil"
"github.com/jhillyerd/enmime/internal/textproto"
"github.com/jhillyerd/enmime/mediatype"

"github.com/pkg/errors"
)

@@ -159,7 +160,7 @@ line:
// Behavior change in net/textproto package in Golang 1.20: invalid characters
// in header keys are no longer allowed; https://github.com/golang/go/issues/53188
for _, c := range s[:firstColon] {
if c != ' ' && !validHeaderFieldByte(c) {
if c != ' ' && !textproto.ValidEmailHeaderFieldByte(c) {
p.addError(
ErrorMalformedHeader, "Header name %q contains invalid character %q", s, c)
continue line
@@ -192,7 +193,7 @@ line:

buf.Write([]byte{'\r', '\n'})
tr := textproto.NewReader(bufio.NewReader(buf))
header, err := tr.ReadMIMEHeader()
header, err := tr.ReadEmailMIMEHeader()
return header, errors.WithStack(err)
}

@@ -252,32 +253,3 @@ func quotedDisplayName(s string) string {
func whiteSpaceRune(r rune) bool {
return r == ' ' || r == '\t' || r == '\r' || r == '\n'
}

// Mirror of func in net/textproto/reader.go; from go 1.20.0-rc.2
func validHeaderFieldByte(c byte) bool {
// mask is a 128-bit bitmap with 1s for allowed bytes,
// so that the byte c can be tested with a shift and an and.
// If c >= 128, then 1<<c and 1<<(c-64) will both be zero,
// and this function will return false.
const mask = 0 |
(1<<(10)-1)<<'0' |
(1<<(26)-1)<<'a' |
(1<<(26)-1)<<'A' |
1<<'!' |
1<<'#' |
1<<'$' |
1<<'%' |
1<<'&' |
1<<'\'' |
1<<'*' |
1<<'+' |
1<<'-' |
1<<'.' |
1<<'^' |
1<<'_' |
1<<'`' |
1<<'|' |
1<<'~'
return ((uint64(1)<<c)&(mask&(1<<64-1)) |
(uint64(1)<<(c-64))&(mask>>64)) != 0
}
24 changes: 18 additions & 6 deletions header_test.go
Original file line number Diff line number Diff line change
@@ -3,9 +3,10 @@ package enmime
import (
"bufio"
"net/mail"
"net/textproto"
"strings"
"testing"

"github.com/jhillyerd/enmime/internal/textproto"
)

// Test re-encoding to base64
@@ -250,9 +251,20 @@ func TestReadHeader(t *testing.T) {
correct: true,
},
{
label: "equals in name",
input: "name=value:text\n",
correct: false,
// all special characters of printable ASCII characters (exclude
// 0-9, a-z, A-Z, :, and ` (tested in next case).
label: "special characters in header field",
input: `X-!"#$%&'()*+,-./;<=>?@[\]^_{|}~:text` + "\n",
hname: `X-!"#$%&'()*+,-./;<=>?@[\]^_{|}~`,
want: "text",
correct: true,
},
{
label: "special character (`) in header field",
input: "X-`:text\n",
hname: "X-`",
want: "text",
correct: true,
},
{
label: "no space before continuation",
@@ -367,9 +379,9 @@ func TestReadHeader(t *testing.T) {
// Check for extra headers by removing expected ones.
delete(header, "From")
delete(header, "Subject")
delete(header, textproto.CanonicalMIMEHeaderKey(tt.hname))
delete(header, textproto.CanonicalEmailMIMEHeaderKey(tt.hname))
for _, hname := range tt.extras {
delete(header, textproto.CanonicalMIMEHeaderKey(hname))
delete(header, textproto.CanonicalEmailMIMEHeaderKey(hname))
}
for hname := range header {
t.Errorf("Found unexpected header %q after parsing", hname)
5 changes: 3 additions & 2 deletions inspect.go
Original file line number Diff line number Diff line change
@@ -4,9 +4,10 @@ import (
"bufio"
"bytes"
"io"
"net/textproto"

"github.com/jhillyerd/enmime/internal/coding"
"github.com/jhillyerd/enmime/internal/textproto"

"github.com/pkg/errors"
)

@@ -49,7 +50,7 @@ func DecodeHeaders(b []byte, addtlHeaders ...string) (textproto.MIMEHeader, erro
headerList = append(headerList, addtlHeaders...)
res := map[string][]string{}
for _, header := range headerList {
h := textproto.CanonicalMIMEHeaderKey(header)
h := textproto.CanonicalEmailMIMEHeaderKey(header)
res[h] = make([]string, 0, len(headers[h]))
for _, value := range headers[h] {
res[h] = append(res[h], DecodeRFC2047(value))
2 changes: 1 addition & 1 deletion inspect_test.go
Original file line number Diff line number Diff line change
@@ -5,12 +5,12 @@ import (
"io"
"io/ioutil"
"net/mail"
"net/textproto"
"strings"
"testing"

"github.com/jhillyerd/enmime"
"github.com/jhillyerd/enmime/internal/test"
"github.com/jhillyerd/enmime/internal/textproto"
)

func TestDecodeRFC2047(t *testing.T) {
Loading