aboutsummaryrefslogtreecommitdiffstats
path: root/widgets
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 /widgets
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>
Diffstat (limited to 'widgets')
-rw-r--r--widgets/compose.go17
1 files changed, 17 insertions, 0 deletions
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()