diff --git a/go.mod b/go.mod index ba7d5d2b..bf8c5b9f 100644 --- a/go.mod +++ b/go.mod @@ -40,7 +40,7 @@ require ( github.com/stretchr/testify v1.8.0 github.com/urfave/cli/v2 v2.20.3 github.com/vmihailenco/msgpack/v5 v5.3.5 - gitlab.protontech.ch/go/liteapi v0.42.4 + gitlab.protontech.ch/go/liteapi v0.43.0 go.uber.org/goleak v1.2.0 golang.org/x/exp v0.0.0-20221023144134-a1e5550cf13e golang.org/x/net v0.1.0 diff --git a/go.sum b/go.sum index 2b50f82b..435ee859 100644 --- a/go.sum +++ b/go.sum @@ -403,8 +403,8 @@ github.com/xrash/smetrics v0.0.0-20201216005158-039620a65673/go.mod h1:N3UwUGtsr github.com/yuin/goldmark v1.3.5/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k= github.com/zclconf/go-cty v1.11.0 h1:726SxLdi2SDnjY+BStqB9J1hNp4+2WlzyXLuimibIe0= github.com/zclconf/go-cty v1.11.0/go.mod h1:s9IfD1LK5ccNMSWCVFCE2rJfHiZgi7JijgeWIMfhLvA= -gitlab.protontech.ch/go/liteapi v0.42.4 h1:TMm2JSDMSSSLDYk/CqeF/w/gAzXtfaHZVqOCEKccN2Y= -gitlab.protontech.ch/go/liteapi v0.42.4/go.mod h1:IM7ADWjgIL2hXopzx0WNamizEuMgM2QZl7QH12FNflk= +gitlab.protontech.ch/go/liteapi v0.43.0 h1:kHfy/ENivDoeha9lqkh3GpzknsnRZ3czBzsbBz5PoB4= +gitlab.protontech.ch/go/liteapi v0.43.0/go.mod h1:IM7ADWjgIL2hXopzx0WNamizEuMgM2QZl7QH12FNflk= go.etcd.io/bbolt v1.3.2/go.mod h1:IbVyRI1SCnLcuJnV2u8VeU0CEYM7e686BmAb1XKL+uU= go.opencensus.io v0.21.0/go.mod h1:mSImk1erAIZhrmZN+AvHh14ztQfjbGwt4TtuofqLduU= go.opencensus.io v0.22.0/go.mod h1:+kGneAE2xo2IficOXnaByMWTGM9T73dGwxeWcUqIpI8= diff --git a/pkg/message/build.go b/pkg/message/build.go index d94ded9a..747f1dd7 100644 --- a/pkg/message/build.go +++ b/pkg/message/build.go @@ -45,7 +45,7 @@ var ( // InternalIDDomain is used as a placeholder for reference/message ID headers to improve compatibility with various clients. const InternalIDDomain = `protonmail.internalid` -func BuildRFC822(kr *crypto.KeyRing, msg liteapi.Message, attData map[string][]byte, opts JobOptions) ([]byte, error) { +func BuildRFC822(kr *crypto.KeyRing, msg liteapi.Message, attData [][]byte, opts JobOptions) ([]byte, error) { switch { case len(msg.Attachments) > 0: return buildMultipartRFC822(kr, msg, attData, opts) @@ -91,7 +91,7 @@ func buildSimpleRFC822(kr *crypto.KeyRing, msg liteapi.Message, opts JobOptions) func buildMultipartRFC822( kr *crypto.KeyRing, msg liteapi.Message, - attData map[string][]byte, + attData [][]byte, opts JobOptions, ) ([]byte, error) { boundary := newBoundary(msg.ID) @@ -114,13 +114,13 @@ func buildMultipartRFC822( attachData [][]byte ) - for _, att := range msg.Attachments { + for index, att := range msg.Attachments { if att.Disposition == liteapi.InlineDisposition { inlineAtts = append(inlineAtts, att) - inlineData = append(inlineData, attData[att.ID]) + inlineData = append(inlineData, attData[index]) } else { attachAtts = append(attachAtts, att) - attachData = append(attachData, attData[att.ID]) + attachData = append(attachData, attData[index]) } } diff --git a/pkg/message/build_test.go b/pkg/message/build_test.go index 506d727b..c35b3541 100644 --- a/pkg/message/build_test.go +++ b/pkg/message/build_test.go @@ -631,7 +631,7 @@ func TestBuildHTMLMessageWithAttachment(t *testing.T) { msg := newTestMessage(t, kr, "messageID", "addressID", "text/html", "body", time.Now()) att := addTestAttachment(t, kr, &msg, "attachID", "file.png", "image/png", "attachment", "attachment") - res, err := BuildRFC822(kr, msg, map[string][]byte{"attachID": att}, JobOptions{}) + res, err := BuildRFC822(kr, msg, [][]byte{att}, JobOptions{}) require.NoError(t, err) section(t, res, 1). @@ -655,7 +655,7 @@ func TestBuildHTMLMessageWithRFC822Attachment(t *testing.T) { msg := newTestMessage(t, kr, "messageID", "addressID", "text/html", "body", time.Now()) att := addTestAttachment(t, kr, &msg, "attachID", "file.eml", "message/rfc822", "attachment", "... message/rfc822 ...") - res, err := BuildRFC822(kr, msg, map[string][]byte{"attachID": att}, JobOptions{}) + res, err := BuildRFC822(kr, msg, [][]byte{att}, JobOptions{}) require.NoError(t, err) section(t, res, 1). @@ -679,7 +679,7 @@ func TestBuildHTMLMessageWithInlineAttachment(t *testing.T) { msg := newTestMessage(t, kr, "messageID", "addressID", "text/html", "body", time.Now()) inl := addTestAttachment(t, kr, &msg, "inlineID", "file.png", "image/png", "inline", "inline") - res, err := BuildRFC822(kr, msg, map[string][]byte{"inlineID": inl}, JobOptions{}) + res, err := BuildRFC822(kr, msg, [][]byte{inl}, JobOptions{}) require.NoError(t, err) section(t, res, 1). @@ -709,11 +709,11 @@ func TestBuildHTMLMessageWithComplexAttachments(t *testing.T) { att0 := addTestAttachment(t, kr, &msg, "attachID0", "attach0.png", "image/png", "attachment", "attach0") att1 := addTestAttachment(t, kr, &msg, "attachID1", "attach1.png", "image/png", "attachment", "attach1") - res, err := BuildRFC822(kr, msg, map[string][]byte{ - "inlineID0": inl0, - "inlineID1": inl1, - "attachID0": att0, - "attachID1": att1, + res, err := BuildRFC822(kr, msg, [][]byte{ + inl0, + inl1, + att0, + att1, }, JobOptions{}) require.NoError(t, err) @@ -762,7 +762,7 @@ func TestBuildAttachmentWithExoticFilename(t *testing.T) { msg := newTestMessage(t, kr, "messageID", "addressID", "text/html", "body", time.Now()) att := addTestAttachment(t, kr, &msg, "attachID", `I řeally šhould leařn czech.png`, "image/png", "attachment", "attachment") - res, err := BuildRFC822(kr, msg, map[string][]byte{"attachID": att}, JobOptions{}) + res, err := BuildRFC822(kr, msg, [][]byte{att}, JobOptions{}) require.NoError(t, err) // The "name" and "filename" params should actually be RFC2047-encoded because they aren't 7-bit clean. @@ -784,7 +784,7 @@ func TestBuildAttachmentWithLongFilename(t *testing.T) { msg := newTestMessage(t, kr, "messageID", "addressID", "text/html", "body", time.Now()) att := addTestAttachment(t, kr, &msg, "attachID", veryLongName, "image/png", "attachment", "attachment") - res, err := BuildRFC822(kr, msg, map[string][]byte{"attachID": att}, JobOptions{}) + res, err := BuildRFC822(kr, msg, [][]byte{att}, JobOptions{}) require.NoError(t, err) // NOTE: hasMaxLineLength is too high! Long filenames should be linewrapped using multipart filenames. @@ -969,10 +969,10 @@ func TestBuildMessageIsDeterministic(t *testing.T) { inl := addTestAttachment(t, kr, &msg, "inlineID", "file.png", "image/png", "inline", "inline") att := addTestAttachment(t, kr, &msg, "attachID", "attach.png", "image/png", "attachment", "attachment") - res1, err := BuildRFC822(kr, msg, map[string][]byte{"inlineID": inl, "attachID": att}, JobOptions{}) + res1, err := BuildRFC822(kr, msg, [][]byte{inl, att}, JobOptions{}) require.NoError(t, err) - res2, err := BuildRFC822(kr, msg, map[string][]byte{"inlineID": inl, "attachID": att}, JobOptions{}) + res2, err := BuildRFC822(kr, msg, [][]byte{inl, att}, JobOptions{}) require.NoError(t, err) assert.Equal(t, res1, res2) @@ -1001,7 +1001,7 @@ func TestBuildUndecryptableAttachment(t *testing.T) { // Use a different keyring for encrypting the attachment; it won't be decryptable. att := addTestAttachment(t, utils.MakeKeyRing(t), &msg, "attachID", "file.png", "image/png", "attachment", "attachment") - _, err := BuildRFC822(kr, msg, map[string][]byte{"attachID": att}, JobOptions{}) + _, err := BuildRFC822(kr, msg, [][]byte{att}, JobOptions{}) require.ErrorIs(t, err, ErrDecryptionFailed) } @@ -1102,7 +1102,7 @@ func TestBuildCustomMessagePlainWithAttachment(t *testing.T) { att := addTestAttachment(t, foreignKR, &msg, "attachID", "file.png", "image/png", "attachment", "attachment") // Tell the job to ignore decryption errors; a custom message will be returned instead of an error. - res, err := BuildRFC822(kr, msg, map[string][]byte{"attachID": att}, JobOptions{IgnoreDecryptionErrors: true}) + res, err := BuildRFC822(kr, msg, [][]byte{att}, JobOptions{IgnoreDecryptionErrors: true}) require.NoError(t, err) section(t, res). @@ -1135,7 +1135,7 @@ func TestBuildCustomMessageHTMLWithAttachment(t *testing.T) { att := addTestAttachment(t, foreignKR, &msg, "attachID", "file.png", "image/png", "attachment", "attachment") // Tell the job to ignore decryption errors; a custom message will be returned instead of an error. - res, err := BuildRFC822(kr, msg, map[string][]byte{"attachID": att}, JobOptions{IgnoreDecryptionErrors: true}) + res, err := BuildRFC822(kr, msg, [][]byte{att}, JobOptions{IgnoreDecryptionErrors: true}) require.NoError(t, err) section(t, res). @@ -1170,7 +1170,7 @@ func TestBuildCustomMessageOnlyBodyIsUndecryptable(t *testing.T) { att := addTestAttachment(t, kr, &msg, "attachID", "file.png", "image/png", "attachment", "attachment") // Tell the job to ignore decryption errors; a custom message will be returned instead of an error. - res, err := BuildRFC822(kr, msg, map[string][]byte{"attachID": att}, JobOptions{IgnoreDecryptionErrors: true}) + res, err := BuildRFC822(kr, msg, [][]byte{att}, JobOptions{IgnoreDecryptionErrors: true}) require.NoError(t, err) section(t, res). @@ -1203,7 +1203,7 @@ func TestBuildCustomMessageOnlyAttachmentIsUndecryptable(t *testing.T) { att := addTestAttachment(t, foreignKR, &msg, "attachID", "file.png", "image/png", "attachment", "attachment") // Tell the job to ignore decryption errors; a custom message will be returned instead of an error. - res, err := BuildRFC822(kr, msg, map[string][]byte{"attachID": att}, JobOptions{IgnoreDecryptionErrors: true}) + res, err := BuildRFC822(kr, msg, [][]byte{att}, JobOptions{IgnoreDecryptionErrors: true}) require.NoError(t, err) section(t, res).