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)
|
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) {
|
func getPlainParts(mail *mail.Message) ([]string, []error) {
|
||||||
parts := make([]string, 0)
|
parts := make([]string, 0)
|
||||||
errs := make([]error, 0)
|
errs := make([]error, 0)
|
||||||
|
@ -104,26 +113,23 @@ func getPlainParts(mail *mail.Message) ([]string, []error) {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
errs = append(errs, err)
|
errs = append(errs, err)
|
||||||
}
|
}
|
||||||
if contentType := p.Header.Get("Content-Type"); strings.HasPrefix(contentType, "text/plain") {
|
if contentType := p.Header.Get("Content-Type"); !strings.HasPrefix(contentType, "text/plain") {
|
||||||
if contentDisposition := p.Header.Get("Content-Disposition"); !strings.HasPrefix(contentDisposition, "attachment") {
|
parts = append(parts, "Non-plain part: "+contentType)
|
||||||
body, _ := ioutil.ReadAll(p)
|
} else if contentDisposition := p.Header.Get("Content-Disposition"); strings.HasPrefix(contentDisposition, "attachment") {
|
||||||
encoding := p.Header.Get("Content-Transfer-Encoding")
|
if filename := attachmentName(contentDisposition); filename != "" {
|
||||||
if encoding != "" {
|
parts = append(parts, "Plain attachment: "+filename)
|
||||||
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)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
} else {
|
} 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 {
|
} else {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user