aboutsummaryrefslogtreecommitdiffstats
path: root/lib/templates
diff options
context:
space:
mode:
authorMoritz Poldrack <git@moritz.sh>2023-01-27 19:48:55 +0100
committerRobin Jarry <robin@jarry.cc>2023-01-29 21:54:05 +0100
commit17ce7c762cb10ce4272de8ddd45367ba94360456 (patch)
tree586a22def17636d4db31a185de6a25e08bc370c7 /lib/templates
parent549eab7f2ce96d8b1c80b922515b3ae3c3914fc8 (diff)
downloadaerc-17ce7c762cb10ce4272de8ddd45367ba94360456.tar.gz
templates: add trimSignature function
Some contacts, especially corporate, include a wall of text in their signatures. To not clutter the reply chain, this commit introduces a new function to the templating engine that removes the signature from a message. Link: https://learn.microsoft.com/en-us/microsoft-365/admin/setup/create-signatures-and-disclaimers Signed-off-by: Moritz Poldrack <git@moritz.sh> Acked-by: Robin Jarry <robin@jarry.cc>
Diffstat (limited to 'lib/templates')
-rw-r--r--lib/templates/functions.go19
1 files changed, 19 insertions, 0 deletions
diff --git a/lib/templates/functions.go b/lib/templates/functions.go
index 2e551594..f6cb0df4 100644
--- a/lib/templates/functions.go
+++ b/lib/templates/functions.go
@@ -1,6 +1,7 @@
package templates
import (
+ "bufio"
"bytes"
"fmt"
"os"
@@ -181,6 +182,23 @@ func join(sep string, elems []string) string {
return strings.Join(elems, sep)
}
+// removes a signature from the piped in message
+func trimSignature(message string) string {
+ var res strings.Builder
+
+ input := bufio.NewScanner(strings.NewReader(message))
+
+ for input.Scan() {
+ line := input.Text()
+ if line == "-- " {
+ break
+ }
+ res.WriteString(line)
+ res.WriteRune('\n')
+ }
+ return res.String()
+}
+
var templateFuncs = template.FuncMap{
"quote": quote,
"wrapText": wrapText,
@@ -196,4 +214,5 @@ var templateFuncs = template.FuncMap{
"humanReadable": humanReadable,
"cwd": cwd,
"join": join,
+ "trimSignature": trimSignature,
}