init: pristine aerc 0.20.0 source

This commit is contained in:
Mortdecai
2026-04-07 19:54:54 -04:00
commit 083402a548
502 changed files with 68722 additions and 0 deletions
+22
View File
@@ -0,0 +1,22 @@
package hooks
import (
"fmt"
"time"
"git.sr.ht/~rjarry/aerc/config"
)
type AercShutdown struct {
Lifetime time.Duration
}
func (a *AercShutdown) Cmd() string {
return config.Hooks.AercShutdown
}
func (a *AercShutdown) Env() []string {
return []string{
fmt.Sprintf("AERC_LIFETIME=%s", a.Lifetime.String()),
}
}
+23
View File
@@ -0,0 +1,23 @@
package hooks
import (
"fmt"
"os"
"git.sr.ht/~rjarry/aerc/config"
)
type AercStartup struct {
Version string
}
func (m *AercStartup) Cmd() string {
return config.Hooks.AercStartup
}
func (m *AercStartup) Env() []string {
return []string{
fmt.Sprintf("AERC_VERSION=%s", m.Version),
fmt.Sprintf("AERC_BINARY=%s", os.Args[0]),
}
}
+31
View File
@@ -0,0 +1,31 @@
package hooks
import (
"bytes"
"os"
"os/exec"
"git.sr.ht/~rjarry/aerc/lib/log"
)
func RunHook(h HookType) error {
cmd := h.Cmd()
if cmd == "" {
return nil
}
env := h.Env()
log.Debugf("hooks: running command %q (env %v)", cmd, env)
proc := exec.Command("sh", "-c", cmd)
var outb, errb bytes.Buffer
proc.Stdout = &outb
proc.Stderr = &errb
proc.Env = os.Environ()
proc.Env = append(proc.Env, env...)
err := proc.Run()
log.Tracef("hooks: %q stdout: %s", cmd, outb.String())
if err != nil {
log.Errorf("hooks:%q stderr: %s", cmd, errb.String())
}
return err
}
+31
View File
@@ -0,0 +1,31 @@
package hooks
import (
"fmt"
"git.sr.ht/~rjarry/aerc/config"
)
type FlagChanged struct {
Account string
Backend string
Folder string
Role string
FlagName string
}
func (m *FlagChanged) Cmd() string {
return config.Hooks.FlagChanged
}
func (m *FlagChanged) Env() []string {
env := []string{
fmt.Sprintf("AERC_ACCOUNT=%s", m.Account),
fmt.Sprintf("AERC_ACCOUNT_BACKEND=%s", m.Backend),
fmt.Sprintf("AERC_FOLDER=%s", m.Folder),
fmt.Sprintf("AERC_FOLDER_ROLE=%s", m.Role),
fmt.Sprintf("AERC_FLAG=%s", m.FlagName),
}
return env
}
+6
View File
@@ -0,0 +1,6 @@
package hooks
type HookType interface {
Cmd() string
Env() []string
}
+27
View File
@@ -0,0 +1,27 @@
package hooks
import (
"fmt"
"git.sr.ht/~rjarry/aerc/config"
)
type MailAdded struct {
Account string
Backend string
Folder string
Role string
}
func (m *MailAdded) Cmd() string {
return config.Hooks.MailAdded
}
func (m *MailAdded) Env() []string {
return []string{
fmt.Sprintf("AERC_ACCOUNT=%s", m.Account),
fmt.Sprintf("AERC_ACCOUNT_BACKEND=%s", m.Backend),
fmt.Sprintf("AERC_FOLDER=%s", m.Folder),
fmt.Sprintf("AERC_FOLDER_ROLE=%s", m.Role),
}
}
+27
View File
@@ -0,0 +1,27 @@
package hooks
import (
"fmt"
"git.sr.ht/~rjarry/aerc/config"
)
type MailDeleted struct {
Account string
Backend string
Folder string
Role string
}
func (m *MailDeleted) Cmd() string {
return config.Hooks.MailDeleted
}
func (m *MailDeleted) Env() []string {
return []string{
fmt.Sprintf("AERC_ACCOUNT=%s", m.Account),
fmt.Sprintf("AERC_ACCOUNT_BACKEND=%s", m.Backend),
fmt.Sprintf("AERC_FOLDER=%s", m.Folder),
fmt.Sprintf("AERC_FOLDER_ROLE=%s", m.Role),
}
}
+34
View File
@@ -0,0 +1,34 @@
package hooks
import (
"fmt"
"git.sr.ht/~rjarry/aerc/config"
"git.sr.ht/~rjarry/aerc/models"
)
type MailReceived struct {
Account string
Backend string
Folder string
Role string
MsgInfo *models.MessageInfo
}
func (m *MailReceived) Cmd() string {
return config.Hooks.MailReceived
}
func (m *MailReceived) Env() []string {
from := m.MsgInfo.Envelope.From[0]
return []string{
fmt.Sprintf("AERC_ACCOUNT=%s", m.Account),
fmt.Sprintf("AERC_ACCOUNT_BACKEND=%s", m.Backend),
fmt.Sprintf("AERC_FOLDER=%s", m.Folder),
fmt.Sprintf("AERC_FROM_NAME=%s", from.Name),
fmt.Sprintf("AERC_FROM_ADDRESS=%s", from.Address),
fmt.Sprintf("AERC_SUBJECT=%s", m.MsgInfo.Envelope.Subject),
fmt.Sprintf("AERC_MESSAGE_ID=%s", m.MsgInfo.Envelope.MessageId),
fmt.Sprintf("AERC_FOLDER_ROLE=%s", m.Role),
}
}
+33
View File
@@ -0,0 +1,33 @@
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
}
+28
View File
@@ -0,0 +1,28 @@
package hooks
import (
"fmt"
"git.sr.ht/~rjarry/aerc/config"
)
type TagModified struct {
Account string
Backend string
Add []string
Remove []string
}
func (m *TagModified) Cmd() string {
return config.Hooks.TagModified
}
func (m *TagModified) Env() []string {
env := []string{
fmt.Sprintf("AERC_ACCOUNT=%s", m.Account),
fmt.Sprintf("AERC_TAG_ADDED=%v", m.Add),
fmt.Sprintf("AERC_TAG_REMOVED=%v", m.Remove),
}
return env
}