From cbcabfafaab20eaffad642f20151e890161efddc Mon Sep 17 00:00:00 2001 From: Robin Jarry Date: Tue, 6 Dec 2022 20:08:49 +0100 Subject: compose: allow writing multipart/alternative messages Add a new :multipart command that can be executed on the composer review screen. This command takes a MIME type as argument which needs to match a setting in the new [multipart-converters] section of aerc.conf. A part can be removed by using the -d flag. The [multipart-converters] section has MIME types associated with commands. These commands are executed with sh -c every time the main email body is updated to generate each part content. The commands are expected to output valid UTF-8 text. If a command fails, an explicit error will be printed next to the part MIME type to allow users to debug their issue but the email may still be sent anyway with an empty alternative part. This is mostly intended for people who *really* need to send html messages for their boss or for corporate reasons. For now, it is a manual and explicit action to convert a message in such a way. Here is an example configuration: [multipart-converters] text/html = pandoc -f markdown -t html And the associated binding to append an HTML alternative to a message: [compose::review] H = :multipart text/html hh = :multipart -d text/html Link: https://lists.sr.ht/~rjarry/aerc-discuss/%3CCO5KH4W57XNB.2PZLR1CNFK22H%40mashenka%3E Co-authored-by: Eric McConville Signed-off-by: Robin Jarry Tested-by: Bence Ferdinandy Acked-by: Moritz Poldrack --- config/converters.go | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 config/converters.go (limited to 'config/converters.go') diff --git a/config/converters.go b/config/converters.go new file mode 100644 index 00000000..8c6b88df --- /dev/null +++ b/config/converters.go @@ -0,0 +1,34 @@ +package config + +import ( + "fmt" + "strings" + + "git.sr.ht/~rjarry/aerc/log" + "github.com/go-ini/ini" +) + +func (config *AercConfig) parseConverters(file *ini.File) error { + converters, err := file.GetSection("multipart-converters") + if err != nil { + goto out + } + + for mimeType, command := range converters.KeysHash() { + mimeType = strings.ToLower(mimeType) + if mimeType == "text/plain" { + return fmt.Errorf( + "multipart-converters: text/plain is reserved") + } + if !strings.HasPrefix(mimeType, "text/") { + return fmt.Errorf( + "multipart-converters: %q: only text/* MIME types are supported", + mimeType) + } + config.Converters[mimeType] = command + } + +out: + log.Debugf("aerc.conf: [multipart-converters] %#v", config.Converters) + return nil +} -- cgit