mirror of
https://git.sr.ht/~sircmpwn/aerc
synced 2024-11-23 16:42:07 +01:00
b9d2938f9f
Note that, until we get color configuration, this means that the user *must* have the %Z verb in the index format else it'll be horribly confusing as no visual indication is provided
52 lines
1.1 KiB
Go
52 lines
1.1 KiB
Go
package config
|
|
|
|
import (
|
|
"errors"
|
|
"fmt"
|
|
|
|
"github.com/google/shlex"
|
|
|
|
"git.sr.ht/~sircmpwn/aerc/lib/format"
|
|
"git.sr.ht/~sircmpwn/aerc/models"
|
|
)
|
|
|
|
func (trig *TriggersConfig) ExecTrigger(triggerCmd string,
|
|
triggerFmt func(string) (string, error)) error {
|
|
|
|
if len(triggerCmd) == 0 {
|
|
return errors.New("Trigger command empty")
|
|
}
|
|
triggerCmdParts, err := shlex.Split(triggerCmd)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
var command []string
|
|
for _, part := range triggerCmdParts {
|
|
formattedPart, err := triggerFmt(part)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
command = append(command, formattedPart)
|
|
}
|
|
return trig.ExecuteCommand(command)
|
|
}
|
|
|
|
func (trig *TriggersConfig) ExecNewEmail(account *AccountConfig,
|
|
conf *AercConfig, msg *models.MessageInfo) {
|
|
err := trig.ExecTrigger(trig.NewEmail,
|
|
func(part string) (string, error) {
|
|
formatstr, args, err := format.ParseMessageFormat(
|
|
account.From,
|
|
part,
|
|
conf.Ui.TimestampFormat, account.Name, 0, msg, false)
|
|
if err != nil {
|
|
return "", err
|
|
}
|
|
return fmt.Sprintf(formatstr, args...), nil
|
|
})
|
|
if err != nil {
|
|
fmt.Printf("Error from the new-email trigger: %s\n", err)
|
|
}
|
|
}
|