reordering for better structure
This commit is contained in:
parent
036990f946
commit
89642c258e
|
@ -89,6 +89,15 @@ func decodeSubject(subject string) (string, error) {
|
|||
return dec.DecodeHeader(subject)
|
||||
}
|
||||
|
||||
func attachmentName(contentDisposition string) string {
|
||||
_, params, err := mime.ParseMediaType(contentDisposition)
|
||||
if filename, ok := params["filename"]; err == nil && ok {
|
||||
return filename
|
||||
} else {
|
||||
return ""
|
||||
}
|
||||
}
|
||||
|
||||
func getPlainParts(mail *mail.Message) ([]string, []error) {
|
||||
parts := make([]string, 0)
|
||||
errs := make([]error, 0)
|
||||
|
@ -104,26 +113,23 @@ func getPlainParts(mail *mail.Message) ([]string, []error) {
|
|||
if err != nil {
|
||||
errs = append(errs, err)
|
||||
}
|
||||
if contentType := p.Header.Get("Content-Type"); strings.HasPrefix(contentType, "text/plain") {
|
||||
if contentDisposition := p.Header.Get("Content-Disposition"); !strings.HasPrefix(contentDisposition, "attachment") {
|
||||
body, _ := ioutil.ReadAll(p)
|
||||
encoding := p.Header.Get("Content-Transfer-Encoding")
|
||||
if encoding != "" {
|
||||
body, err = normalize(body, encoding)
|
||||
if err != nil {
|
||||
body = nil
|
||||
errs = append(errs, err)
|
||||
}
|
||||
}
|
||||
parts = append(parts, string(body))
|
||||
} else {
|
||||
_, params, errDispo := mime.ParseMediaType(contentDisposition)
|
||||
if filename, ok := params["filename"]; errDispo == nil && ok {
|
||||
parts = append(parts, "Plain attachment: "+filename)
|
||||
}
|
||||
if contentType := p.Header.Get("Content-Type"); !strings.HasPrefix(contentType, "text/plain") {
|
||||
parts = append(parts, "Non-plain part: "+contentType)
|
||||
} else if contentDisposition := p.Header.Get("Content-Disposition"); strings.HasPrefix(contentDisposition, "attachment") {
|
||||
if filename := attachmentName(contentDisposition); filename != "" {
|
||||
parts = append(parts, "Plain attachment: "+filename)
|
||||
}
|
||||
} else {
|
||||
parts = append(parts, "Non-plain part: "+contentType)
|
||||
body, _ := ioutil.ReadAll(p)
|
||||
encoding := p.Header.Get("Content-Transfer-Encoding")
|
||||
if encoding != "" {
|
||||
body, err = normalize(body, encoding)
|
||||
if err != nil {
|
||||
body = nil
|
||||
errs = append(errs, err)
|
||||
}
|
||||
}
|
||||
parts = append(parts, string(body))
|
||||
}
|
||||
}
|
||||
} else {
|
||||
|
|
Loading…
Reference in New Issue
Block a user