1
0
Fork 0
mirror of https://git.sr.ht/~rjarry/aerc synced 2025-02-22 23:23:57 +01:00
aerc/commands/compose/multipart.go
Robin Jarry fa0b99800e compose: differentiate between edit and review commands
Split the compose commands into two categories: edit and review. Some
commands can belong to both categories and be available whether the text
editor or the review screen is visible.

Update man page to reflect that. Remove duplicate (and misplaced) :save
command from the COMPOSE section.

Signed-off-by: Robin Jarry <robin@jarry.cc>
Reviewed-by: Bence Ferdinandy <bence@ferdinandy.com>
2025-01-14 15:00:56 +01:00

66 lines
1.5 KiB
Go

package compose
import (
"fmt"
"git.sr.ht/~rjarry/aerc/app"
"git.sr.ht/~rjarry/aerc/commands"
"git.sr.ht/~rjarry/aerc/config"
)
type Multipart struct {
Remove bool `opt:"-d" desc:"Remove the specified mime/type."`
Mime string `opt:"mime" metavar:"<mime/type>" complete:"CompleteMime" desc:"MIME/type name."`
}
func init() {
commands.Register(Multipart{})
}
func (Multipart) Description() string {
return "Convert the message to multipart with the given mime/type part."
}
func (Multipart) Context() commands.CommandContext {
return commands.COMPOSE_EDIT | commands.COMPOSE_REVIEW
}
func (Multipart) Aliases() []string {
return []string{"multipart"}
}
func (*Multipart) CompleteMime(arg string) []string {
var completions []string
for mime := range config.Converters {
completions = append(completions, mime)
}
return commands.FilterList(completions, arg, nil)
}
func (m Multipart) Execute(args []string) error {
composer, ok := app.SelectedTabContent().(*app.Composer)
if !ok {
return fmt.Errorf(":multipart is only available on the compose::review screen")
}
if m.Remove {
return composer.RemovePart(m.Mime)
} else {
_, found := config.Converters[m.Mime]
if !found {
return fmt.Errorf("no command defined for MIME type: %s", m.Mime)
}
err := composer.AppendPart(
m.Mime,
map[string]string{"Charset": "UTF-8"},
// the actual content of the part will be rendered
// every time the body of the email is updated
nil,
)
if err != nil {
return err
}
}
return nil
}