| 1 |
package enmime |
| 2 |
|
| 3 |
import ( |
| 4 |
"fmt" |
| 5 |
) |
| 6 |
|
| 7 |
const ( |
| 8 |
// ErrorMalformedBase64 name. |
| 9 |
ErrorMalformedBase64 = "Malformed Base64" |
| 10 |
// ErrorMalformedHeader name. |
| 11 |
ErrorMalformedHeader = "Malformed Header" |
| 12 |
// ErrorMissingBoundary name. |
| 13 |
ErrorMissingBoundary = "Missing Boundary" |
| 14 |
// ErrorMissingContentType name. |
| 15 |
ErrorMissingContentType = "Missing Content-Type" |
| 16 |
// ErrorCharsetConversion name. |
| 17 |
ErrorCharsetConversion = "Character Set Conversion" |
| 18 |
// ErrorContentEncoding name. |
| 19 |
ErrorContentEncoding = "Content Encoding" |
| 20 |
// ErrorPlainTextFromHTML name. |
| 21 |
ErrorPlainTextFromHTML = "Plain Text from HTML" |
| 22 |
// ErrorCharsetDeclaration name. |
| 23 |
ErrorCharsetDeclaration = "Character Set Declaration Mismatch" |
| 24 |
// ErrorMissingRecipient name. |
| 25 |
ErrorMissingRecipient = "no recipients (to, cc, bcc) set" |
| 26 |
) |
| 27 |
|
| 28 |
// Error describes an error encountered while parsing. |
| 29 |
type Error struct { |
| 30 |
Name string // The name or type of error encountered, from Error consts. |
| 31 |
Detail string // Additional detail about the cause of the error, if available. |
| 32 |
Severe bool // Indicates that a portion of the message was lost during parsing. |
| 33 |
} |
| 34 |
|
| 35 |
// Error formats the enmime.Error as a string. |
| 36 |
func (e *Error) Error() string { |
| 37 |
sev := "W" |
| 38 |
if e.Severe { |
| 39 |
sev = "E" |
| 40 |
} |
| 41 |
return fmt.Sprintf("[%s] %s: %s", sev, e.Name, e.Detail) |
| 42 |
} |
| 43 |
|
| 44 |
// String formats the enmime.Error as a string. DEPRECATED; use Error() instead. |
| 45 |
func (e *Error) String() string { |
| 46 |
return e.Error() |
| 47 |
} |
| 48 |
|
| 49 |
// addWarning builds a severe Error and appends to the Part error slice. |
| 50 |
func (p *Part) addError(name string, detailFmt string, args ...interface{}) { |
| 51 |
p.Errors = append( |
| 52 |
p.Errors, |
| 53 |
&Error{ |
| 54 |
name, |
| 55 |
fmt.Sprintf(detailFmt, args...), |
| 56 |
true, |
| 57 |
}) |
| 58 |
} |
| 59 |
|
| 60 |
// addWarning builds a non-severe Error and appends to the Part error slice. |
| 61 |
func (p *Part) addWarning(name string, detailFmt string, args ...interface{}) { |
| 62 |
p.Errors = append( |
| 63 |
p.Errors, |
| 64 |
&Error{ |
| 65 |
name, |
| 66 |
fmt.Sprintf(detailFmt, args...), |
| 67 |
false, |
| 68 |
}) |
| 69 |
} |