Use shell to execute filters, fix non-determinism
This commit is contained in:
parent
1a4cc31d67
commit
36419d85aa
|
@ -158,7 +158,8 @@ func LoadConfig(root *string) (*AercConfig, error) {
|
||||||
}
|
}
|
||||||
if filters, err := file.GetSection("filters"); err == nil {
|
if filters, err := file.GetSection("filters"); err == nil {
|
||||||
// TODO: Parse the filter more finely, e.g. parse the regex
|
// TODO: Parse the filter more finely, e.g. parse the regex
|
||||||
for match, cmd := range filters.KeysHash() {
|
for _, match := range filters.KeyStrings() {
|
||||||
|
cmd := filters.KeysHash()[match]
|
||||||
filter := FilterConfig{
|
filter := FilterConfig{
|
||||||
Command: cmd,
|
Command: cmd,
|
||||||
Filter: match,
|
Filter: match,
|
||||||
|
|
|
@ -107,16 +107,13 @@ func NewMessageViewer(conf *config.AercConfig, store *lib.MessageStore,
|
||||||
}
|
}
|
||||||
pager = exec.Command(cmd[0], cmd[1:]...)
|
pager = exec.Command(cmd[0], cmd[1:]...)
|
||||||
|
|
||||||
|
fmt.Printf("%v\n", conf.Filters)
|
||||||
for _, f := range conf.Filters {
|
for _, f := range conf.Filters {
|
||||||
cmd, err = shlex.Split(f.Command)
|
|
||||||
if err != nil {
|
|
||||||
goto handle_error
|
|
||||||
}
|
|
||||||
mime := msg.BodyStructure.MIMEType + "/" + msg.BodyStructure.MIMESubType
|
mime := msg.BodyStructure.MIMEType + "/" + msg.BodyStructure.MIMESubType
|
||||||
switch f.FilterType {
|
switch f.FilterType {
|
||||||
case config.FILTER_MIMETYPE:
|
case config.FILTER_MIMETYPE:
|
||||||
if fnmatch.Match(f.Filter, mime, 0) {
|
if fnmatch.Match(f.Filter, mime, 0) {
|
||||||
filter = exec.Command(cmd[0], cmd[1:]...)
|
filter = exec.Command("sh", "-c", f.Command)
|
||||||
}
|
}
|
||||||
case config.FILTER_HEADER:
|
case config.FILTER_HEADER:
|
||||||
var header string
|
var header string
|
||||||
|
@ -131,7 +128,7 @@ func NewMessageViewer(conf *config.AercConfig, store *lib.MessageStore,
|
||||||
header = formatAddresses(msg.Envelope.Cc)
|
header = formatAddresses(msg.Envelope.Cc)
|
||||||
}
|
}
|
||||||
if f.Regex.Match([]byte(header)) {
|
if f.Regex.Match([]byte(header)) {
|
||||||
filter = exec.Command(cmd[0], cmd[1:]...)
|
filter = exec.Command("sh", "-c", f.Command)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if filter != nil {
|
if filter != nil {
|
||||||
|
|
Loading…
Reference in New Issue