diff options
author | Reto Brunner <reto@labrat.space> | 2020-05-17 12:09:34 +0200 |
---|---|---|
committer | Reto Brunner <reto@labrat.space> | 2020-05-17 12:15:50 +0200 |
commit | d48ea6231c76fbfff334be647c8c4d05bf9de387 (patch) | |
tree | 0ccd12d3cd190407a0918171baf6dac2945316e8 /commands/msg/utils.go | |
parent | cff4476f3bb61510acefd567deb39f58351de215 (diff) | |
download | aerc-d48ea6231c76fbfff334be647c8c4d05bf9de387.tar.gz |
Move findPlaintext / findFirstNonMultipart to utils
They are used by more than one command and as such need to be in a common file.
Diffstat (limited to 'commands/msg/utils.go')
-rw-r--r-- | commands/msg/utils.go | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/commands/msg/utils.go b/commands/msg/utils.go index cad0f82e..5eb5fe53 100644 --- a/commands/msg/utils.go +++ b/commands/msg/utils.go @@ -2,6 +2,7 @@ package msg import ( "errors" + "strings" "git.sr.ht/~sircmpwn/aerc/commands" "git.sr.ht/~sircmpwn/aerc/lib" @@ -48,3 +49,34 @@ func (h *helper) messages() ([]*models.MessageInfo, error) { } return commands.MsgInfoFromUids(store, uid) } + +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 := findPlaintext(part, cur); path != nil { + return path + } + } + } + return nil +} |