diff options
author | Moritz Poldrack <git@moritz.sh> | 2023-01-27 19:48:55 +0100 |
---|---|---|
committer | Robin Jarry <robin@jarry.cc> | 2023-01-29 21:54:05 +0100 |
commit | 17ce7c762cb10ce4272de8ddd45367ba94360456 (patch) | |
tree | 586a22def17636d4db31a185de6a25e08bc370c7 | |
parent | 549eab7f2ce96d8b1c80b922515b3ae3c3914fc8 (diff) | |
download | aerc-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>
-rw-r--r-- | CHANGELOG.md | 1 | ||||
-rw-r--r-- | doc/aerc-templates.7.scd | 10 | ||||
-rw-r--r-- | lib/templates/functions.go | 19 | ||||
-rw-r--r-- | templates/quoted_reply | 2 |
4 files changed, 30 insertions, 2 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md index db160094..53c1dcbe 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). - New column-based message list format with `index-columns`. - Add a `msglist_answered` style for answered messages. - Compose `Format=Flowed` messages with `format-flowed=true` in `aerc.conf`. +- Add a `trimSignature` function to the templating engine. ### Changed diff --git a/doc/aerc-templates.7.scd b/doc/aerc-templates.7.scd index 87713429..bfba05c4 100644 --- a/doc/aerc-templates.7.scd +++ b/doc/aerc-templates.7.scd @@ -172,6 +172,14 @@ aerc provides the following additional functions: {{quote .OriginalText}} ``` +*trimSignature* + Removes the signature froma passed in mail. Quoted signatures are kept + as they are. + + ``` + {{trimSignature .OriginalText}} + ``` + *join* Join the provided list of strings with a separator: @@ -274,7 +282,7 @@ aerc provides the following additional functions: {{if eq .OriginalMIMEType "text/html"}} {{exec `/usr/libexec/aerc/filters/html` .OriginalText | wrap 72 | quote}} {{else}} - {{wrap 72 .OriginalText | quote}} + {{wrap 72 .OriginalText | trimSignature | quote}} {{end}} ``` 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, } diff --git a/templates/quoted_reply b/templates/quoted_reply index 9e622cd9..95162172 100644 --- a/templates/quoted_reply +++ b/templates/quoted_reply @@ -1,4 +1,4 @@ X-Mailer: aerc {{version}} On {{dateFormat (.OriginalDate | toLocal) "Mon Jan 2, 2006 at 3:04 PM MST"}}, {{(index .OriginalFrom 0).Name}} wrote: -{{quote .OriginalText}} +{{trimSignature .OriginalText | quote}} |