diff options
author | Reto Brunner <reto@labrat.space> | 2020-06-19 17:58:08 +0200 |
---|---|---|
committer | Reto Brunner <reto@labrat.space> | 2020-07-27 09:19:27 +0200 |
commit | c574a838fa89bf46bf7188442f400b206b04df95 (patch) | |
tree | 89c40ba4a7f5f5a2e67ca8fb225f7d5d3eb319ad /lib | |
parent | 494bd674a98bc9f2889acad0fda3ff4c77c641b5 (diff) | |
download | aerc-c574a838fa89bf46bf7188442f400b206b04df95.tar.gz |
Remove hard coded bodystruct path everywhere
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.
Diffstat (limited to 'lib')
-rw-r--r-- | lib/structure_helpers.go | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/lib/structure_helpers.go b/lib/structure_helpers.go new file mode 100644 index 00000000..21159a2b --- /dev/null +++ b/lib/structure_helpers.go @@ -0,0 +1,38 @@ +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 +} |