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

BUG: GetHeader() doesn't add quote for especials #331

Open
iredmail opened this issue Apr 14, 2024 · 0 comments
Open

BUG: GetHeader() doesn't add quote for especials #331

iredmail opened this issue Apr 14, 2024 · 0 comments

Comments

@iredmail
Copy link
Contributor

iredmail commented Apr 14, 2024

I have an email with this From: header:

From: [List] My List <list@domain.com>

Since [ and ] are especials (RFC 5322, section 3.2.3), the value doesn't need to be base64 encoded.

When getting value with GetHeader("from"), it returns wrong value:

[List] My List <list@domain.com>

Correct value should be (display name is surrounded by quote characters):

"[List] My List" <list@domain.com>

This causes mail.ParseAddress() (std) cannot parse the value of GetHeader("from") (error: mail: missing word in phrase: mail: invalid string).

net/mail package handles this correctly:

package main

import (
	"fmt"
	"net/mail"
)

func main() {
	addr := mail.Address{Name: "[List] My List", Address: "list@domain.com"}
	hdr := mail.Header{}
	hdr["From"] = []string{addr.String()}

	fmt.Printf("%s", hdr.Get("from"))
}

It prints:

"[List] My List" <list@domain.com>
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

1 participant