Skip to content

Commit

Permalink
reply,forward: use selected message part
Browse files Browse the repository at this point in the history
Use the currently selected message part (if any) as the original message
for quote-reply and forward. Honor viewer::alternatives if no message
part was selected.

Signed-off-by: Sebastien Binet <[email protected]>
Reviewed-by: Koni Marti <[email protected]>
Acked-by: Robin Jarry <[email protected]>
  • Loading branch information
sbinet authored and rjarry committed Jan 17, 2024
1 parent 680244d commit ec8b22b
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 9 deletions.
3 changes: 2 additions & 1 deletion commands/msg/forward.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,11 +143,12 @@ func (f forward) Execute(args []string) error {
f.Template = config.Templates.Forwards
}

part := lib.FindPlaintext(msg.BodyStructure, nil)
part := getMessagePart(msg, widget)
if part == nil {
part = lib.FindFirstNonMultipart(msg.BodyStructure, nil)
// if it's still nil here, we don't have a multipart msg, that's fine
}

err = addMimeType(msg, part, &original)
if err != nil {
return err
Expand Down
9 changes: 1 addition & 8 deletions commands/msg/reply.go
Original file line number Diff line number Diff line change
Expand Up @@ -222,14 +222,7 @@ func (r reply) Execute(args []string) error {
return nil
}

var part []int
for _, mime := range config.Viewer.Alternatives {
part = lib.FindMIMEPart(mime, msg.BodyStructure, nil)
if part != nil {
break
}
}

part := getMessagePart(msg, widget)
if part == nil {
// 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
Expand Down
15 changes: 15 additions & 0 deletions commands/msg/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (

"git.sr.ht/~rjarry/aerc/app"
"git.sr.ht/~rjarry/aerc/commands"
"git.sr.ht/~rjarry/aerc/config"
"git.sr.ht/~rjarry/aerc/lib"
"git.sr.ht/~rjarry/aerc/models"
)
Expand Down Expand Up @@ -59,3 +60,17 @@ func (h *helper) messages() ([]*models.MessageInfo, error) {
}
return commands.MsgInfoFromUids(store, uid, h.statusInfo)
}

func getMessagePart(msg *models.MessageInfo, provider app.ProvidesMessage) []int {
p := provider.SelectedMessagePart()
if p != nil {
return p.Index
}
for _, mime := range config.Viewer.Alternatives {
part := lib.FindMIMEPart(mime, msg.BodyStructure, nil)
if part != nil {
return part
}
}
return nil
}

0 comments on commit ec8b22b

Please sign in to comment.