~dricottone/digestion

ref: ce5b7f835e1ffb0d4aed72bbaf9920a025293312 digestion/decoder/encodings.go -rw-r--r-- 808 bytes
ce5b7f83Dominic Ricottone Refactored and refined API 4 years ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
package decoder

import (
	"strings"
)

const (
	EncodedUTF8            = "EncodedUTF8"
	EncodedBase64          = "EncodedBase64"
	EncodedQuotedPrintable = "EncodedQuotedPrintable"
	EncodedUnknown         = "EncodedUnknown"
)

func DetermineEncoding(encoding string) string {
	if strings.Contains(encoding, "base64") {
		return EncodedBase64
	} else if strings.Contains(encoding, "quoted-printable") {
		return EncodedQuotedPrintable
	} else if strings.Contains(encoding, "utf-8") {
		return EncodedUTF8
	} else {
		return EncodedUnknown
	}
}

func DecodeArray(lines []string, encoding string) ([]string, error) {
	switch DetermineEncoding(encoding) {
	case EncodedBase64:
		return decode_base64(lines)
	case EncodedQuotedPrintable:
		return decode_quotedprintable(lines)
	default:
		return lines, nil
	}
}