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

Declared header character encoding cannot always be trusted #338

Open
zdiff opened this issue May 30, 2024 · 1 comment
Open

Declared header character encoding cannot always be trusted #338

zdiff opened this issue May 30, 2024 · 1 comment

Comments

@zdiff
Copy link

zdiff commented May 30, 2024

I have been receiving emails that have headers with the defined character encoding GB2312. However, it appears as though these headers require the GB18030 character encoding to properly display the decoded headers. Is there a way I can force the header decoder to use GB18030 instead of GB2312?

What I did:

package main

import (
	"fmt"
	"log"
	"strings"

	"github.com/jhillyerd/enmime"
)

func main() {
	header := "Subject: =?GB2312?B?gzD+MIMziTmDMu4zIIMy4zGDNfozoaRIVEMggzW+OIM2jzGDNoU2gzOXNYMw2zEggjfoMII30jM=?="
	parser := enmime.NewParser()
	env, err := parser.ReadEnvelope(strings.NewReader(header))
	if err != nil {
		log.Fatal(err)
	}
	fmt.Println(env.GetHeader("Subject"))
}

What I expected:
법원에 애플·HTC 특허합의문 공개

What I got:
�0�0�3�9�2�3 �2�1�5�3·HTC �5�8�6�1�6�6�3�5�0�1 �7�0�7�3

Release or branch I am using:
v1.2.0

@jhillyerd
Copy link
Owner

We don't currently have a way to configure that. The quickest fix for you would be to fork and modify rule(s) in https://github.com/jhillyerd/enmime/blob/main/internal/coding/charsets.go

I think adding a parser option to specify custom mappings would make sense, so we can consider this a feature request.

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

No branches or pull requests

2 participants