diff options
Diffstat (limited to 'widgets')
-rw-r--r-- | widgets/compose.go | 17 |
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() |