1
0
Fork 0
mirror of https://git.sr.ht/~rjarry/aerc synced 2025-02-23 07:53:59 +01:00
aerc/lib/hooks/mail-sent.go
Bence Ferdinandy fd35044023 hooks: add AERC_ACCOUNT_BACKEND to hooks with AERC_ACCOUNT
It can be good to know the backend used for an account in a hook. Add
this information to all hooks that already pass the account name along.

Changelog-added: Added `AERC_ACCOUNT_BACKEND` to hooks with
 `AERC_ACCOUNT`.
Signed-off-by: Bence Ferdinandy <bence@ferdinandy.com>
Acked-by: Robin Jarry <robin@jarry.cc>
2024-06-05 08:41:13 +02:00

33 lines
733 B
Go

package hooks
import (
"fmt"
"git.sr.ht/~rjarry/aerc/config"
"github.com/emersion/go-message/mail"
)
type MailSent struct {
Account string
Backend 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_ACCOUNT_BACKEND=%s", m.Backend),
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
}