42b4302ba3
When a message has been sent today (or this year) allow formatting the date differently. For example, with: [ui] index-format=%-25.25n %-25.25D %s timestamp-format=2006 Jan 02, 15:04 GMT-0700 this-day-time-format=Today at 15:04 this-year-time-format=Jan 02 The message list would look like this (spaces collapsed): Robin Jarry Today at 16:30 [PATCH 1/2] bindings: prepare for more modifers bugzilla@dpdk.org Oct 26 [dpdk-dev] [Bug 839] pdump: any subsequent runs of pdump_autotest fail Holger Levsen 2020 Mar 15, 13:44 GMT+01 +1 (Re: FTP Team -- call for volunteers) Signed-off-by: Robin Jarry <robin@jarry.cc>
56 lines
1.2 KiB
Go
56 lines
1.2 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(
|
|
part, conf.Ui.TimestampFormat,
|
|
conf.Ui.ThisDayTimeFormat,
|
|
conf.Ui.ThisYearTimeFormat,
|
|
format.Ctx{
|
|
FromAddress: account.From,
|
|
AccountName: account.Name,
|
|
MsgInfo: msg},
|
|
)
|
|
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)
|
|
}
|
|
}
|