2020-06-19 17:58:08 +02:00
|
|
|
package lib
|
|
|
|
|
|
|
|
import (
|
|
|
|
"strings"
|
|
|
|
|
2021-11-05 10:19:46 +01:00
|
|
|
"git.sr.ht/~rjarry/aerc/models"
|
2020-06-19 17:58:08 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
func FindPlaintext(bs *models.BodyStructure, path []int) []int {
|
|
|
|
for i, part := range bs.Parts {
|
|
|
|
cur := append(path, i+1)
|
|
|
|
if strings.ToLower(part.MIMEType) == "text" &&
|
|
|
|
strings.ToLower(part.MIMESubType) == "plain" {
|
|
|
|
return cur
|
|
|
|
}
|
|
|
|
if strings.ToLower(part.MIMEType) == "multipart" {
|
|
|
|
if path := FindPlaintext(part, cur); path != nil {
|
|
|
|
return path
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func FindFirstNonMultipart(bs *models.BodyStructure, path []int) []int {
|
|
|
|
for i, part := range bs.Parts {
|
|
|
|
cur := append(path, i+1)
|
|
|
|
mimetype := strings.ToLower(part.MIMEType)
|
|
|
|
if mimetype != "multipart" {
|
2021-02-26 22:01:18 +01:00
|
|
|
return cur
|
2020-06-19 17:58:08 +02:00
|
|
|
} else if mimetype == "multipart" {
|
|
|
|
if path := FindFirstNonMultipart(part, cur); path != nil {
|
|
|
|
return path
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|