mirror of
https://git.sr.ht/~sircmpwn/aerc
synced 2024-11-23 08:32:12 +01:00
c574a838fa
Aerc usually used the path []int{1} if it didn't know what the proper path is. However this only works for multipart messages and breaks if it isn't one. This patch removes all the hard coding and extracts the necessary helpers to lib.
39 lines
830 B
Go
39 lines
830 B
Go
package lib
|
|
|
|
import (
|
|
"strings"
|
|
|
|
"git.sr.ht/~sircmpwn/aerc/models"
|
|
)
|
|
|
|
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" {
|
|
return path
|
|
} else if mimetype == "multipart" {
|
|
if path := FindFirstNonMultipart(part, cur); path != nil {
|
|
return path
|
|
}
|
|
}
|
|
}
|
|
return nil
|
|
}
|