MCPcopy Create free account
hub / github.com/buggregator/server / convertToUTF8

Function convertToUTF8

modules/smtp/handler.go:366–380  ·  view source on GitHub ↗

convertToUTF8 converts data from the given charset to UTF-8. If charset is empty, "utf-8", or "us-ascii", the data is returned as-is.

(data []byte, charset string)

Source from the content-addressed store, hash-verified

364// convertToUTF8 converts data from the given charset to UTF-8.
365// If charset is empty, "utf-8", or "us-ascii", the data is returned as-is.
366func convertToUTF8(data []byte, charset string) []byte {
367 charset = strings.ToLower(strings.TrimSpace(charset))
368 if charset == "" || charset == "utf-8" || charset == "us-ascii" {
369 return data
370 }
371 enc, err := ianaindex.MIME.Encoding(charset)
372 if err != nil || enc == nil {
373 return data
374 }
375 decoded, err := enc.NewDecoder().Bytes(data)
376 if err != nil {
377 return data
378 }
379 return decoded
380}

Callers 3

parseEmailFunction · 0.85
processPartFunction · 0.85
TestConvertToUTF8Function · 0.85

Calls

no outgoing calls

Tested by 1

TestConvertToUTF8Function · 0.68