aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--CHANGELOG.md1
-rw-r--r--doc/aerc-templates.7.scd10
-rw-r--r--lib/templates/functions.go19
-rw-r--r--templates/quoted_reply2
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}}