about summary refs log tree commit diff stats
path: root/shell/evaluate.mu
Commit message (Expand)AuthorAgeFilesLines
...
* deemphasize fn arg evaluation slightlyKartik K. Agaram2021-04-191-0/+2
* some primitives for monitoring code integrityKartik K. Agaram2021-04-181-0/+3
* shell: ctrl-r runs on real screen without a traceKartik K. Agaram2021-04-171-2/+16
* shell: reenable the traceKartik K. Agaram2021-04-171-0/+9
* evaluating fns is too similar to its inputKartik K. Agaram2021-04-171-1/+1
* Bresenham line-drawing now workingKartik K. Agaram2021-04-171-0/+16
* loosening a few more buffersKartik K. Agaram2021-04-171-3/+3
* data.img now has more than one sector of dataKartik K. Agaram2021-04-161-1/+1
* first session programming _within_ the Mu computerKartik K. Agaram2021-04-151-7/+15
* shell: full closuresKartik K. Agaram2021-04-101-6/+11
* apply doesn't need caller env in lexical scopeKartik K. Agaram2021-04-101-6/+9
* shell: none of our primitives need to be closuresKartik K. Agaram2021-04-101-1/+1
* .Kartik K. Agaram2021-04-101-2/+2
* shell: UI now showing fake keyboardKartik K. Agaram2021-04-101-21/+21
* shell: move fake screen to sandboxKartik K. Agaram2021-04-101-21/+22
* shell: structural equality checkKartik K. Agaram2021-04-091-3/+3
* shell: ifKartik K. Agaram2021-04-091-0/+41
* shell: 'set' for defining globalsKartik K. Agaram2021-04-061-0/+47
* shell: quoteKartik K. Agaram2021-04-061-0/+28
* shell: look up globalsKartik K. Agaram2021-04-061-31/+12
* shell: extensible array of globalsKartik K. Agaram2021-04-051-74/+22
* .Kartik K. Agaram2021-04-051-0/+822
ound-color: #fff0f0 } /* Literal.String.Interpol */ .highlight .sx { color: #22bb22; background-color: #f0fff0 } /* Literal.String.Other */ .highlight .sr { color: #008800; background-color: #fff0ff } /* Literal.String.Regex */ .highlight .s1 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Single */ .highlight .ss { color: #aa6600; background-color: #fff0f0 } /* Literal.String.Symbol */ .highlight .bp { color: #003388 } /* Name.Builtin.Pseudo */ .highlight .fm { color: #0066bb; font-weight: bold } /* Name.Function.Magic */ .highlight .vc { color: #336699 } /* Name.Variable.Class */ .highlight .vg { color: #dd7700 } /* Name.Variable.Global */ .highlight .vi { color: #3333bb } /* Name.Variable.Instance */ .highlight .vm { color: #336699 } /* Name.Variable.Magic */ .highlight .il { color: #0000DD; font-weight: bold } /* Literal.Number.Integer.Long */
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)
	}
}