mirror of
https://git.sr.ht/~sircmpwn/aerc
synced 2024-11-23 16:42:07 +01:00
Move findPlaintext / findFirstNonMultipart to utils
They are used by more than one command and as such need to be in a common file.
This commit is contained in:
parent
cff4476f3b
commit
d48ea6231c
@ -196,34 +196,3 @@ func (reply) Execute(aerc *widgets.Aerc, args []string) error {
|
|||||||
return addTab()
|
return addTab()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
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
|
|
||||||
}
|
|
||||||
|
@ -2,6 +2,7 @@ package msg
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
|
"strings"
|
||||||
|
|
||||||
"git.sr.ht/~sircmpwn/aerc/commands"
|
"git.sr.ht/~sircmpwn/aerc/commands"
|
||||||
"git.sr.ht/~sircmpwn/aerc/lib"
|
"git.sr.ht/~sircmpwn/aerc/lib"
|
||||||
@ -48,3 +49,34 @@ func (h *helper) messages() ([]*models.MessageInfo, error) {
|
|||||||
}
|
}
|
||||||
return commands.MsgInfoFromUids(store, uid)
|
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
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user