Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DecodeRFC2047 fails to decode parameter list correctly #363

Open
mgnsk opened this issue Feb 26, 2025 · 2 comments
Open

DecodeRFC2047 fails to decode parameter list correctly #363

mgnsk opened this issue Feb 26, 2025 · 2 comments

Comments

@mgnsk
Copy link

mgnsk commented Feb 26, 2025

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?

@jhillyerd
Copy link
Owner

I'd be OK with renaming the existing to RFC2047DecodePair or similar, and removing the single parameter pair specialization from the originally named func, if you think that would make more sense to folks using it.

@mgnsk
Copy link
Author

mgnsk commented Mar 4, 2025

I'd be OK with renaming the existing to RFC2047DecodePair or similar, and removing the single parameter pair specialization from the originally named func, if you think that would make more sense to folks using it.

That would make sense. I think just in case, it should be marked as a breaking change, should anyone depend on the pair specialization in the current func.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants