aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMoritz Poldrack <git@moritz.sh>2023-02-05 13:14:27 +0100
committerRobin Jarry <robin@jarry.cc>2023-02-12 00:41:57 +0100
commita553b33ebcbdf8b12ac1546ec45f4437dac1f8b0 (patch)
tree7e3f4e681d58d8ab96323d9c495535faefe36abb
parent2a0da301c51a8862c4e8a73b141adc0f416833a5 (diff)
downloadaerc-a553b33ebcbdf8b12ac1546ec45f4437dac1f8b0.tar.gz
compose: ensure signature uses standard delimiter
Since it has recently been a topic on IRC, and to guide users new to "raw" email, add a note on how signatures are detected and what they should look like. Prepend signature-file and signature-cmd with the standard delimiter if missing. Signed-off-by: Moritz Poldrack <git@moritz.sh> Signed-off-by: Robin Jarry <robin@jarry.cc>
-rw-r--r--CHANGELOG.md2
-rw-r--r--doc/aerc-accounts.5.scd5
-rw-r--r--widgets/compose.go17
3 files changed, 24 insertions, 0 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 450465e2..ccd714bd 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -20,6 +20,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
`PATH` has been modified to include all variations of the `libexec` subdirs.
- The built-in `colorize` filter theme is now configured in styleset files into
the `[viewer]` section.
+- The standard Usenet signature delimiter `"-- "` is now prepended to
+ `signature-file` and `signature-cmd` if not already present.
### Deprecated
diff --git a/doc/aerc-accounts.5.scd b/doc/aerc-accounts.5.scd
index a078e4bf..fdf10b76 100644
--- a/doc/aerc-accounts.5.scd
+++ b/doc/aerc-accounts.5.scd
@@ -160,6 +160,11 @@ Note that many of these configuration options are written for you, such as
Specifies the file to read in order to obtain the signature to be added
to emails sent from this account.
+ Please note that by convention the Usenet signature style of two dashes,
+ followed by a space ("-- ") should be placed at the top of the signature
+ to separate content and signature. Aerc will add that delimiter if it is
+ not already present.
+
*signature-cmd* = _<command>_
Specifies the command to execute with _sh -c_ in order to obtain the
signature to be added to emails sent from this account. If the command
diff --git a/widgets/compose.go b/widgets/compose.go
index 94fd79d5..7311de7a 100644
--- a/widgets/compose.go
+++ b/widgets/compose.go
@@ -1,6 +1,7 @@
package widgets
import (
+ "bufio"
"bytes"
"fmt"
"io"
@@ -550,6 +551,7 @@ func (c *Composer) AddSignature() {
} else {
signature = c.readSignatureFromFile()
}
+ signature = ensureSignatureDelimiter(signature)
c.AppendContents(bytes.NewReader(signature))
}
@@ -581,6 +583,21 @@ func (c *Composer) readSignatureFromFile() []byte {
return signature
}
+func ensureSignatureDelimiter(signature []byte) []byte {
+ buf := bytes.NewBuffer(signature)
+ scanner := bufio.NewScanner(buf)
+ for scanner.Scan() {
+ line := scanner.Text()
+ if line == "-- " {
+ // signature contains standard delimiter, we're good
+ return signature
+ }
+ }
+ // signature does not contain standard delimiter, prepend one
+ sig := "\n\n-- \n" + strings.TrimLeft(string(signature), " \t\r\n")
+ return []byte(sig)
+}
+
func (c *Composer) FocusTerminal() *Composer {
c.Lock()
defer c.Unlock()