mirror of
https://github.com/wneessen/go-mail.git
synced 2024-11-22 05:40:50 +01:00
Refactor EML encoding and content-type parsing to separate functions
The commit includes extraction of blocks of code related to EML message encoding and content-type parsing into their own separate functions. By doing so, it improves code readability and maintainability.
This commit is contained in:
parent
04c41a1f10
commit
29305675d6
1 changed files with 30 additions and 20 deletions
50
eml.go
50
eml.go
|
@ -112,26 +112,8 @@ func parseEMLHeaders(mailHeader *netmail.Header, msg *Msg) error {
|
|||
}
|
||||
|
||||
// Extract content type, charset and encoding first
|
||||
if value := mailHeader.Get(HeaderContentTransferEnc.String()); value != "" {
|
||||
switch {
|
||||
case strings.EqualFold(value, EncodingQP.String()):
|
||||
msg.SetEncoding(EncodingQP)
|
||||
case strings.EqualFold(value, EncodingB64.String()):
|
||||
msg.SetEncoding(EncodingB64)
|
||||
default:
|
||||
msg.SetEncoding(NoEncoding)
|
||||
}
|
||||
}
|
||||
if value := mailHeader.Get(HeaderContentType.String()); value != "" {
|
||||
contentType, charSet := parseContentType(value)
|
||||
if charSet != "" {
|
||||
msg.SetCharset(Charset(charSet))
|
||||
}
|
||||
msg.setEncoder()
|
||||
if contentType != "" {
|
||||
msg.SetGenHeader(HeaderContentType, contentType)
|
||||
}
|
||||
}
|
||||
parseEMLEncoding(mailHeader, msg)
|
||||
parseEMLContentTypeCharset(mailHeader, msg)
|
||||
|
||||
// Extract address headers
|
||||
if value := mailHeader.Get(HeaderFrom.String()); value != "" {
|
||||
|
@ -297,6 +279,34 @@ func parseEMLMultipartAlternative(params map[string]string, bodybuf *bytes.Buffe
|
|||
return nil
|
||||
}
|
||||
|
||||
// parseEMLEncoding parses and determines the encoding of the message
|
||||
func parseEMLEncoding(mailHeader *netmail.Header, msg *Msg) {
|
||||
if value := mailHeader.Get(HeaderContentTransferEnc.String()); value != "" {
|
||||
switch {
|
||||
case strings.EqualFold(value, EncodingQP.String()):
|
||||
msg.SetEncoding(EncodingQP)
|
||||
case strings.EqualFold(value, EncodingB64.String()):
|
||||
msg.SetEncoding(EncodingB64)
|
||||
default:
|
||||
msg.SetEncoding(NoEncoding)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// parseEMLContentTypeCharset parses and determines the charset and content type of the message
|
||||
func parseEMLContentTypeCharset(mailHeader *netmail.Header, msg *Msg) {
|
||||
if value := mailHeader.Get(HeaderContentType.String()); value != "" {
|
||||
contentType, charSet := parseContentType(value)
|
||||
if charSet != "" {
|
||||
msg.SetCharset(Charset(charSet))
|
||||
}
|
||||
msg.setEncoder()
|
||||
if contentType != "" {
|
||||
msg.SetGenHeader(HeaderContentType, contentType)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// handleEMLMultiPartBase64Encoding sets the content body of a base64 encoded Part
|
||||
func handleEMLMultiPartBase64Encoding(multiPartData []byte, part *Part) error {
|
||||
part.SetEncoding(EncodingB64)
|
||||
|
|
Loading…
Reference in a new issue