~sircmpwn/aerc

Add option to insert signatures at most once v1 PROPOSED

Luke Drummond
Luke Drummond: 1
 Add option to insert signatures at most once

 5 files changed, 33 insertions(+), 1 deletions(-)
Export patchset (mbox)
How do I use this?

Copy & paste the following snippet into your terminal to import this patchset into git:

curl -s https://lists.sr.ht/~sircmpwn/aerc/patches/9088/mbox | git am -3
Learn more about email & git

[PATCH] Add option to insert signatures at most once Export this patch

Luke Drummond
When replying multiple times, the quoted reply can often end up
containing multiple redundant copies of the users' signatures. For large
signatures this can make email basically unreadable. This patch adds an
optional feature to ensure that the content of the signature only
appears once in the body of a quoted reply.
---
 commands/msg/reply.go |  1 +
 config/aerc.conf.in   |  2 ++
 config/config.go      |  1 +
 doc/aerc-config.5.scd |  5 +++++
 widgets/compose.go    | 25 ++++++++++++++++++++++++-
 5 files changed, 33 insertions(+), 1 deletion(-)

diff --git a/commands/msg/reply.go b/commands/msg/reply.go
index b13e254..5d0c55e 100644
--- a/commands/msg/reply.go
+++ b/commands/msg/reply.go
@@ -146,6 +146,7 @@ func (reply) Execute(aerc *widgets.Aerc, args []string) error {
 			}
 			tab.Content.Invalidate()
 		})
+		go composer.AddSignature()
 
 		return nil
 	}
diff --git a/config/aerc.conf.in b/config/aerc.conf.in
index 16e3da1..4459422 100644
--- a/config/aerc.conf.in
+++ b/config/aerc.conf.in
@@ -113,6 +113,8 @@ editor=
 # Default: To|From,Subject
 header-layout=To|From,Subject
 
+# SignatureOnce
+
 [filters]
 #
 # Filters allow you to pipe an email body through a shell command to render
diff --git a/config/config.go b/config/config.go
index 32d07fc..9ce0313 100644
--- a/config/config.go
+++ b/config/config.go
@@ -61,6 +61,7 @@ type AccountConfig struct {
 	OutgoingCredCmd string
 	SignatureFile   string
 	SignatureCmd    string
+	SignatureOnce   string
 }
 
 type BindingConfig struct {
diff --git a/doc/aerc-config.5.scd b/doc/aerc-config.5.scd
index 02fe4d6..729d1c1 100644
--- a/doc/aerc-config.5.scd
+++ b/doc/aerc-config.5.scd
@@ -346,6 +346,11 @@ Note that many of these configuration options are written for you, such as
 	signature to be added to emails sent from this account. If the command
 	fails then *signature-file* is used instead.
 
+*signature-once*
+	If this option is set, the signature will not be duplicated in quoted
+	replies. This avoids polluting long threads with multiple copies of the
+	signature.
+
 # BINDS.CONF
 
 This file is used for configuring keybindings used in the aerc interactive
diff --git a/widgets/compose.go b/widgets/compose.go
index 62aaafe..8e5cd78 100644
--- a/widgets/compose.go
+++ b/widgets/compose.go
@@ -88,7 +88,6 @@ func NewComposer(aerc *Aerc, conf *config.AercConfig,
 		focusable: focusable,
 	}
 
-	c.AddSignature()
 	if err := c.AddTemplate(template, templateData); err != nil {
 		return nil, err
 	}
@@ -207,9 +206,33 @@ func (c *Composer) AddSignature() {
 	} else {
 		signature = c.readSignatureFromFile()
 	}
+	if c.acct.SignatureOnce == "yes" && c.HasLines(strings.Split(string(signature), "\n")) {
+		return
+	}
 	c.AppendContents(bytes.NewReader(signature))
 }
 
+func (c *Composer) HasLines(lines []string) bool {
+	buf := bytes.NewBuffer(nil)
+	c.email.Seek(0, io.SeekStart)
+	io.Copy(buf, c.email)
+	contentLines := strings.Split(string(buf.Bytes()), "\n")
+	for i := range contentLines {
+		hasLines := false
+		for j, l := range lines {
+			if !strings.Contains(contentLines[i+j], l) {
+				goto outer
+			}
+			hasLines = true
+		}
+		if hasLines {
+			return true
+		}
+	outer:
+	}
+	return false
+}
+
 func (c *Composer) readSignatureFromCmd() ([]byte, error) {
 	sigCmd := c.acct.SignatureCmd
 	cmd := exec.Command("sh", "-c", sigCmd)
-- 
2.24.0
This seems kind of weird and unnecessary. This encourages behavior like
top posting. NACK.
Luke Drummond
I *think* that the config option belongs under accounts, as I envisioned
that this will be something a user might need to configure on a
per-account basis, but I'm happy to move it into aerc-config if not.
-- 
Codeplay Software Ltd.
Company registered in England and Wales, number: 04567874
Registered office: Regent House, 316 Beulah Hill, London, SE19 3HF
View this thread in the archives