Skip to content

ReadPartErrorPolicy not called for part content with malformed base64 #315

Open
@dcormier

Description

What I did:

package main

import (
	"strings"
	"testing"

	"github.com/jhillyerd/enmime"
	"github.com/stretchr/testify/require"
)

func TestWrongContentTransferEncoding(t *testing.T) {
	called := false
	parser := enmime.NewParser(
		enmime.SetReadPartErrorPolicy(func(p *enmime.Part, err error) bool {
			called = true

			return true
		}),
	)

	email, err := parser.ReadEnvelope(strings.NewReader(EMAIL))
	require.NoError(t, err)

	attachment := email.Attachments[0]
	t.Logf("Attachment part errors: %d", len(attachment.Errors))
	require.True(t, len(attachment.Errors) > 0, "No errors while parsing this part")
	require.True(t, called, "ReadPartErrorPolicy was not called")
}

const EMAIL = `From: <>
Subject: An email with an attachment
Date: Mon, 16 Aug 2021 15:29:07 +0000
Content-Type: multipart/mixed; boundary="outer"
MIME-Version: 1.0

--outer
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: quoted-printable

The message body.

--outer
Content-Description: attachment.eml
Content-Disposition: attachment; filename="attachment.eml";
	size=15826; creation-date="Mon, 16 Aug 2021 15:29:04 GMT";
	modification-date="Mon, 16 Aug 2021 15:29:04 GMT"
Content-Transfer-Encoding: base64
MIME-Version: 1.0
Content-Type: message/rfc822; name="attachment.eml"

From: <>
Subject: The attached email
Date: Mon, 16 Aug 2021 09:32:48 -0400
MIME-Version: 1.0
Content-type: text/plain; charset=utf-8
Content-Transfer-Encoding: Quoted-printable
Content-Disposition: inline
Content-Description: Message text

The body of the attached email.

--outer--
`

What I expected:

I expected the ReadPartErrorPolicy function to be called, where I could hopefully handle the incorrect content transfer encoding.

What I got:

The function was not called.

Release or branch I am using:

1.1.0

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions