aboutsummaryrefslogtreecommitdiffstats
path: root/commands/msg
diff options
context:
space:
mode:
Diffstat (limited to 'commands/msg')
-rw-r--r--commands/msg/forward.go9
-rw-r--r--commands/msg/recall.go4
-rw-r--r--commands/msg/reply.go13
-rw-r--r--commands/msg/utils.go32
4 files changed, 12 insertions, 46 deletions
diff --git a/commands/msg/forward.go b/commands/msg/forward.go
index 5f4da5cf..3ff0194f 100644
--- a/commands/msg/forward.go
+++ b/commands/msg/forward.go
@@ -10,6 +10,7 @@ import (
"path"
"strings"
+ "git.sr.ht/~sircmpwn/aerc/lib"
"git.sr.ht/~sircmpwn/aerc/models"
"git.sr.ht/~sircmpwn/aerc/widgets"
"git.sr.ht/~sircmpwn/aerc/worker/types"
@@ -137,12 +138,10 @@ func (forward) Execute(aerc *widgets.Aerc, args []string) error {
}
// TODO: add attachments!
- part := findPlaintext(msg.BodyStructure, nil)
+ part := lib.FindPlaintext(msg.BodyStructure, nil)
if part == nil {
- part = findFirstNonMultipart(msg.BodyStructure, nil)
- if part == nil {
- part = []int{1}
- }
+ part = lib.FindFirstNonMultipart(msg.BodyStructure, nil)
+ // if it's still nil here, we don't have a multipart msg, that's fine
}
store.FetchBodyPart(msg.Uid, part, func(reader io.Reader) {
buf := new(bytes.Buffer)
diff --git a/commands/msg/recall.go b/commands/msg/recall.go
index 7c9ac193..5212041e 100644
--- a/commands/msg/recall.go
+++ b/commands/msg/recall.go
@@ -8,6 +8,7 @@ import (
"github.com/emersion/go-message/mail"
"github.com/pkg/errors"
+ "git.sr.ht/~sircmpwn/aerc/lib"
"git.sr.ht/~sircmpwn/aerc/models"
"git.sr.ht/~sircmpwn/aerc/widgets"
"git.sr.ht/~sircmpwn/aerc/worker/types"
@@ -107,12 +108,11 @@ func (Recall) Execute(aerc *widgets.Aerc, args []string) error {
part *models.BodyStructure
)
if len(msgInfo.BodyStructure.Parts) != 0 {
- path = findPlaintext(msgInfo.BodyStructure, path)
+ path = lib.FindPlaintext(msgInfo.BodyStructure, path)
}
part, err = msgInfo.BodyStructure.PartAtIndex(path)
if part == nil || err != nil {
part = msgInfo.BodyStructure
- path = []int{1}
}
store.FetchBodyPart(msgInfo.Uid, path, func(reader io.Reader) {
diff --git a/commands/msg/reply.go b/commands/msg/reply.go
index 1deab316..6fd61413 100644
--- a/commands/msg/reply.go
+++ b/commands/msg/reply.go
@@ -10,6 +10,7 @@ import (
"git.sr.ht/~sircmpwn/getopt"
+ "git.sr.ht/~sircmpwn/aerc/lib"
"git.sr.ht/~sircmpwn/aerc/models"
"git.sr.ht/~sircmpwn/aerc/widgets"
)
@@ -169,14 +170,12 @@ func (reply) Execute(aerc *widgets.Aerc, args []string) error {
template = aerc.Config().Templates.QuotedReply
}
- part := findPlaintext(msg.BodyStructure, nil)
+ part := lib.FindPlaintext(msg.BodyStructure, nil)
if part == nil {
- //mkey... let's get the first thing that isn't a container
- part = findFirstNonMultipart(msg.BodyStructure, nil)
- if part == nil {
- // give up, use whatever is first
- part = []int{1}
- }
+ // mkey... let's get the first thing that isn't a container
+ // if that's still nil it's either not a multipart msg (ok) or
+ // broken (containers only)
+ part = lib.FindFirstNonMultipart(msg.BodyStructure, nil)
}
store.FetchBodyPart(msg.Uid, part, func(reader io.Reader) {
buf := new(bytes.Buffer)
diff --git a/commands/msg/utils.go b/commands/msg/utils.go
index 5eb5fe53..cad0f82e 100644
--- a/commands/msg/utils.go
+++ b/commands/msg/utils.go
@@ -2,7 +2,6 @@ package msg
import (
"errors"
- "strings"
"git.sr.ht/~sircmpwn/aerc/commands"
"git.sr.ht/~sircmpwn/aerc/lib"
@@ -49,34 +48,3 @@ 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
-}