From aaaa0c184fb43879cc84551983309cad06d665ee Mon Sep 17 00:00:00 2001 From: Robin Jarry Date: Wed, 1 Feb 2023 23:35:42 +0100 Subject: triggers: use templates instead of % mini language Since previous commit, all commands now support expanding text/template markup. Reuse that for the new-email trigger command. Update commands.ExecuteCommand to take optional *AccountConfig and *MessageInfo arguments. If these are nil, fallback to using the currently selected account and message (if any). Pass the proper *AccountConfig and *MessageInfo objects when firing the trigger command so that these are used instead of the currently selected ones. If new-email contains % placeholders, try to convert them to template markup reusing the same conversion added in commit 535300cfdbfc ("config: add columns based index format"). Warn the user that they need to update their configuration file. Signed-off-by: Robin Jarry Reviewed-by: Moritz Poldrack --- lib/format/format.go | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'lib/format/format.go') diff --git a/lib/format/format.go b/lib/format/format.go index ad0b778c..7466cfd5 100644 --- a/lib/format/format.go +++ b/lib/format/format.go @@ -93,6 +93,23 @@ func TruncateHead(s string, w int, head string) string { return head + s[pos:] } +func ShellQuote(args []string) string { + quoted := make([]string, len(args)) + + for i, arg := range args { + if strings.ContainsAny(arg, " '\"|&!#$;[](){}<>*\n\t") { + if strings.ContainsAny(arg, "!\"$") { + arg = "'" + arg + "'" + } else { + arg = "\"" + arg + "\"" + } + } + quoted[i] = arg + } + + return strings.Join(quoted, " ") +} + type Ctx struct { FromAddress string AccountName string -- cgit