~dricottone/digestion

ref: 8cc83015e2289b611448002a194f23cfaaa253b5 digestion/decoder/encodings.go -rw-r--r-- 808 bytes
8cc83015Dominic Ricottone Makefile updates 2 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, "utf-8") {
		return EncodedUTF8
	} else if strings.Contains(encoding, "base64") {
		return EncodedBase64
	} else if strings.Contains(encoding, "quoted-printable") {
		return EncodedQuotedPrintable
	} 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
	}
}