aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--commands/compose/send.go9
-rw-r--r--config/hooks.go1
-rw-r--r--doc/aerc-config.5.scd18
-rw-r--r--lib/hooks/mail-sent.go31
4 files changed, 59 insertions, 0 deletions
diff --git a/commands/compose/send.go b/commands/compose/send.go
index dfd531ee..13d9fd4a 100644
--- a/commands/compose/send.go
+++ b/commands/compose/send.go
@@ -19,6 +19,7 @@ import (
"git.sr.ht/~rjarry/aerc/commands/mode"
"git.sr.ht/~rjarry/aerc/commands/msg"
"git.sr.ht/~rjarry/aerc/lib"
+ "git.sr.ht/~rjarry/aerc/lib/hooks"
"git.sr.ht/~rjarry/aerc/log"
"git.sr.ht/~rjarry/aerc/models"
"git.sr.ht/~rjarry/aerc/worker/types"
@@ -247,6 +248,14 @@ func send(composer *app.Composer, ctx sendCtx,
}
app.PushStatus("Message sent.", 10*time.Second)
composer.SetSent(ctx.archive)
+ err = hooks.RunHook(&hooks.MailSent{
+ Account: composer.Account().Name(),
+ Header: header,
+ })
+ if err != nil {
+ log.Errorf("failed to trigger mail-sent hook: %v", err)
+ composer.Account().PushError(fmt.Errorf("[hook.mail-sent] failed: %w", err))
+ }
composer.Close()
}()
}
diff --git a/config/hooks.go b/config/hooks.go
index ed81296d..bc04ac75 100644
--- a/config/hooks.go
+++ b/config/hooks.go
@@ -11,6 +11,7 @@ type HooksConfig struct {
MailReceived string `ini:"mail-received"`
MailDeleted string `ini:"mail-deleted"`
MailAdded string `ini:"mail-added"`
+ MailSent string `ini:"mail-sent"`
}
var Hooks HooksConfig
diff --git a/doc/aerc-config.5.scd b/doc/aerc-config.5.scd
index f3d45085..043b738a 100644
--- a/doc/aerc-config.5.scd
+++ b/doc/aerc-config.5.scd
@@ -1021,6 +1021,24 @@ They are configured in the *[hooks]* section of aerc.conf.
*mail-added* = _mbsync "$AERC_ACCOUNT:$AERC_FOLDER"_
+*mail-sent* = _<command>_
+ Executed when a message is sent. This does not necessarily signify
+ successful posting, if a queueing system like msmtpq is used.
+
+ Variables:
+
+ - *AERC_ACCOUNT*
+ - *AERC_FROM_NAME*
+ - *AERC_FROM_ADDRESS*
+ - *AERC_SUBJECT*
+ - *AERC_TO*
+ - *AERC_CC*
+
+ Example:
+
+ *mail-sent* = _if [ "$AERC_ACCOUNT" = "gmail" ]; then mbsync
+ gmail; fi_
+
*aerc-shutdown* = _<command>_
Executed when aerc shuts down. Aerc will wait for the command to finish
before exiting.
diff --git a/lib/hooks/mail-sent.go b/lib/hooks/mail-sent.go
new file mode 100644
index 00000000..59edafa2
--- /dev/null
+++ b/lib/hooks/mail-sent.go
@@ -0,0 +1,31 @@
+package hooks
+
+import (
+ "fmt"
+
+ "git.sr.ht/~rjarry/aerc/config"
+ "github.com/emersion/go-message/mail"
+)
+
+type MailSent struct {
+ Account string
+ Header *mail.Header
+}
+
+func (m *MailSent) Cmd() string {
+ return config.Hooks.MailSent
+}
+
+func (m *MailSent) Env() []string {
+ from, _ := mail.ParseAddress(m.Header.Get("From"))
+ env := []string{
+ fmt.Sprintf("AERC_ACCOUNT=%s", m.Account),
+ fmt.Sprintf("AERC_FROM_NAME=%s", from.Name),
+ fmt.Sprintf("AERC_FROM_ADDRESS=%s", from.Address),
+ fmt.Sprintf("AERC_SUBJECT=%s", m.Header.Get("Subject")),
+ fmt.Sprintf("AERC_TO=%s", m.Header.Get("To")),
+ fmt.Sprintf("AERC_CC=%s", m.Header.Get("Cc")),
+ }
+
+ return env
+}