mirror of
https://github.com/wneessen/go-mail.git
synced 2024-12-22 18:50:37 +01:00
Extract and set charset from email content type
The diff modifies how the email library handles the extraction of the mime media type from an email header. It uses the mime.ParseMediaType function to parse the content type header. The function gives back the media type as a string and a mapping of different associated parameters. This mapping was previously just printed, but now the charset parameter is also used for setting the charset of the email if it exists.
This commit is contained in:
parent
d733b6e17d
commit
3d50370a4c
1 changed files with 6 additions and 3 deletions
9
eml.go
9
eml.go
|
@ -29,12 +29,15 @@ func EMLToMsg(fp string) (*Msg, error) {
|
|||
}
|
||||
|
||||
// Extract the transfer encoding of the body
|
||||
x, y, err := mime.ParseMediaType(pm.Header.Get(HeaderContentType.String()))
|
||||
mi, ar, err := mime.ParseMediaType(pm.Header.Get(HeaderContentType.String()))
|
||||
if err != nil {
|
||||
return m, fmt.Errorf("failed to extract content type: %w", err)
|
||||
}
|
||||
fmt.Printf("Encoding: %s\n", x)
|
||||
fmt.Printf("Params: %+v\n", y)
|
||||
if v, ok := ar["charset"]; ok {
|
||||
m.SetCharset(Charset(v))
|
||||
}
|
||||
fmt.Printf("Encoding: %s\n", mi)
|
||||
fmt.Printf("Params: %+v\n", ar)
|
||||
|
||||
return m, nil
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue