Skip to content

DecodeRFC2047 fails to decode parameter list correctly #363

Description

@mgnsk

I've created the following testcase which fails:

diff --git a/internal/coding/headerext_test.go b/internal/coding/headerext_test.go
index 05d35ff..f92fd73 100644
--- a/internal/coding/headerext_test.go
+++ b/internal/coding/headerext_test.go
@@ -144,6 +144,7 @@ func TestRfc2047Decode(t *testing.T) {
 		{"quoted", "=?US-ASCII?q?Hello=20World?=", "Hello World"},
 		{"base64", "=?US-ASCII?b?SGVsbG8gV29ybGQ=?=", "Hello World"},
 		{"nested qp+b64", "=?utf-8?b?PT9VUy1BU0NJST9xP0hlbGxvPTIwV29ybGQ/PQ==?=", "Hello World"},
+		{"qp special header", "=?UTF-8?Q?s=3Dgreen;d=3Ddomain;i=3Dsender+=C3=A4@domain?=", "s=green;d=domain;i=sender+ä@domain"},
 	}
 
 	for _, tt := range ttable {

It outputs s="green;d=domain;i=sender+ä@domain" instead of the expected s=green;d=domain;i=sender+ä@domain.

In isolation, I expected the decoding function to return the exact original UTF-8 text but when I looked into it, I found that mediatype parsing depends on this function being aware it is being used to parse only a single parameter pair, hence the quote adding logic.
I tried moving the quote logic to mediatype parsing but got stuck on the "voice call" testcases.

When I run my string through mime.WordDecoder, I get the correct result.

Should this be fixed? i.e. move the quote logic to mediatype parsing and keep this function as a pure RFC2047 decoder or should its documentation mention that you can't just decode any random header value with it?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions