-
Notifications
You must be signed in to change notification settings - Fork 100
/
options.go
126 lines (95 loc) · 4.15 KB
/
options.go
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
package enmime
// Option to configure parsing.
type Option interface {
apply(p *Parser)
}
// SkipMalformedParts sets parsing to skip parts that's can't be parsed.
func SkipMalformedParts(s bool) Option {
return skipMalformedPartsOption(s)
}
type skipMalformedPartsOption bool
func (o skipMalformedPartsOption) apply(p *Parser) {
p.skipMalformedParts = bool(o)
}
// MultipartWOBoundaryAsSinglePart if set to true will treat a multi-part messages without boundary parameter as single-part.
// Otherwise, will return error that boundary is not found.
func MultipartWOBoundaryAsSinglePart(a bool) Option {
return multipartWOBoundaryAsSinglePartOption(a)
}
type multipartWOBoundaryAsSinglePartOption bool
func (o multipartWOBoundaryAsSinglePartOption) apply(p *Parser) {
p.multipartWOBoundaryAsSinglePart = bool(o)
}
// SetReadPartErrorPolicy sets the given callback function to readPartErrorPolicy.
func SetReadPartErrorPolicy(f ReadPartErrorPolicy) Option {
return readPartErrorPolicyOption(f)
}
type readPartErrorPolicyOption ReadPartErrorPolicy
func (o readPartErrorPolicyOption) apply(p *Parser) {
p.readPartErrorPolicy = ReadPartErrorPolicy(o)
}
// MaxStoredPartErrors limits number of part parsing errors, errors beyond the limit are discarded.
// Zero, the default, means all errors will be kept.
func MaxStoredPartErrors(n int) Option {
return maxStoredPartErrorsOption(n)
}
type maxStoredPartErrorsOption int
func (o maxStoredPartErrorsOption) apply(p *Parser) {
p.maxStoredPartErrors = int(o)
}
// RawContent if set to true will not try to decode the CTE and return the raw part content.
// Otherwise, will try to automatically decode the CTE.
func RawContent(a bool) Option {
return rawContentOption(a)
}
type rawContentOption bool
func (o rawContentOption) apply(p *Parser) {
p.rawContent = bool(o)
}
// SetCustomParseMediaType if provided, will be used to parse media type instead of the default ParseMediaType
// function. This may be used to parse media type parameters that would otherwise be considered malformed.
// By default parsing happens using ParseMediaType
func SetCustomParseMediaType(customParseMediaType CustomParseMediaType) Option {
return parseMediaTypeOption(customParseMediaType)
}
type parseMediaTypeOption CustomParseMediaType
func (o parseMediaTypeOption) apply(p *Parser) {
p.customParseMediaType = CustomParseMediaType(o)
}
type stripMediaTypeInvalidCharactersOption bool
func (o stripMediaTypeInvalidCharactersOption) apply(p *Parser) {
p.stripMediaTypeInvalidCharacters = bool(o)
}
// StripMediaTypeInvalidCharacters sets stripMediaTypeInvalidCharacters option. If true, invalid characters
// will be removed from media type during parsing.
func StripMediaTypeInvalidCharacters(stripMediaTypeInvalidCharacters bool) Option {
return stripMediaTypeInvalidCharactersOption(stripMediaTypeInvalidCharacters)
}
type disableTextConversionOption bool
func (o disableTextConversionOption) apply(p *Parser) {
p.disableTextConversion = bool(o)
}
// DisableTextConversion sets the disableTextConversion option. When true, there will be no
// automated down conversion of HTML to text when a plain/text body is missing.
func DisableTextConversion(disableTextConversion bool) Option {
return disableTextConversionOption(disableTextConversion)
}
type disableCharacterDetectionOption bool
func (o disableCharacterDetectionOption) apply(p *Parser) {
p.disableCharacterDetection = bool(o)
}
// DisableCharacterDetection sets the disableCharacterDetection option. When true, the parser will use the
// defined character set if it is defined in the message part.
func DisableCharacterDetection(disableCharacterDetection bool) Option {
return disableCharacterDetectionOption(disableCharacterDetection)
}
type minCharsetDetectRunesOption int
func (o minCharsetDetectRunesOption) apply(p *Parser) {
p.minCharsetDetectRunes = int(o)
}
// MinCharsetDetectRunes sets the minimum length of a MIME part before enmime will attempt to
// detect its character set. The shorter the text, the more likely an incorrect character set
// will be chosen. The default is 100.
func MinCharsetDetectRunes(minCharsetDetectRunes int) Option {
return minCharsetDetectRunesOption(minCharsetDetectRunes)
}