Fix mail conditions, polishing
This commit is contained in:
@@ -44,7 +44,9 @@ const (
|
||||
HeaderMatchNameReplyTo = "reply-to"
|
||||
HeaderMatchNameSubject = "subject"
|
||||
|
||||
HMOpEqualCi HMOp = ""
|
||||
// Keeping -ci suffix in case we get
|
||||
// feature request to separete ci & cs operators
|
||||
HMOpEqualCi HMOp = "equal-ci"
|
||||
HMOpSuffixCi = "suffix-ci"
|
||||
HMOpPrefixCi = "prefix-ci"
|
||||
HMOpRegex = "regex"
|
||||
@@ -124,7 +126,6 @@ func (m *HeaderMatcher) isMatch(header mail.Header, exists userExistanceVerifier
|
||||
switch m.Op {
|
||||
case HMOpEqualCi:
|
||||
match = m.Match == lcHeader
|
||||
// spew.Dump("doing simple string match", match, m, v)
|
||||
case HMOpSuffixCi:
|
||||
match = strings.HasSuffix(lcHeader, m.Match)
|
||||
case HMOpPrefixCi:
|
||||
|
||||
@@ -90,6 +90,30 @@ func Test_makeMailHeaderChecker(t *testing.T) {
|
||||
},
|
||||
expecting: false,
|
||||
},
|
||||
{
|
||||
name: "match by prefix",
|
||||
mh: types.MailMessageHeader{Raw: map[string][]string{"Subject": []string{"abcd"}}},
|
||||
tc: Condition{Headers: []HeaderMatcher{{Name: HeaderMatchNameSubject, Op: HMOpPrefixCi, Match: "ab"}}},
|
||||
expecting: true,
|
||||
},
|
||||
{
|
||||
name: "match by prefix",
|
||||
mh: types.MailMessageHeader{Raw: map[string][]string{"Subject": []string{"abcd"}}},
|
||||
tc: Condition{Headers: []HeaderMatcher{{Name: HeaderMatchNameSubject, Op: HMOpPrefixCi, Match: "cd"}}},
|
||||
expecting: false,
|
||||
},
|
||||
{
|
||||
name: "match by suffix",
|
||||
mh: types.MailMessageHeader{Raw: map[string][]string{"Subject": []string{"abcd"}}},
|
||||
tc: Condition{Headers: []HeaderMatcher{{Name: HeaderMatchNameSubject, Op: HMOpSuffixCi, Match: "cd"}}},
|
||||
expecting: true,
|
||||
},
|
||||
{
|
||||
name: "match by suffix",
|
||||
mh: types.MailMessageHeader{Raw: map[string][]string{"Subject": []string{"abcd"}}},
|
||||
tc: Condition{Headers: []HeaderMatcher{{Name: HeaderMatchNameSubject, Op: HMOpSuffixCi, Match: "ab"}}},
|
||||
expecting: false,
|
||||
},
|
||||
{
|
||||
name: "regex check",
|
||||
mh: types.MailMessageHeader{Raw: map[string][]string{"Subject": []string{"SIMPLE"}}},
|
||||
|
||||
@@ -78,7 +78,8 @@ func (svc automationRunner) findMailScripts(headers types.MailMessageHeader) aut
|
||||
return u != nil && err == nil
|
||||
}
|
||||
|
||||
ss, _ := svc.scriptFinder.FindRunnableScripts("system:mail", "onReceive", mailTrigger.MakeChecker(headers, uev)).
|
||||
ss, _ := svc.scriptFinder.
|
||||
FindRunnableScripts("system:mail", "onReceive", mailTrigger.MakeChecker(headers, uev)).
|
||||
Filter(func(script *automation.Script) (bool, error) {
|
||||
// Filter out user-agent scripts && scripts w/o defined runner.
|
||||
return !script.RunInUA && script.RunAsDefined(), nil
|
||||
|
||||
@@ -115,11 +115,13 @@ func (svc automationScript) Update(ctx context.Context, mod *automation.Script)
|
||||
s.Source = mod.Source
|
||||
s.Async = mod.Async
|
||||
s.RunAs = mod.RunAs
|
||||
s.RunInUA = mod.RunInUA
|
||||
s.Timeout = mod.Timeout
|
||||
s.Critical = mod.Critical
|
||||
s.Enabled = mod.Enabled
|
||||
|
||||
// Never run in a UA
|
||||
s.RunInUA = false
|
||||
|
||||
err = mod.Triggers().Walk(func(t *automation.Trigger) error {
|
||||
return svc.trg.isValid(ctx, mod, t)
|
||||
})
|
||||
|
||||
@@ -81,7 +81,7 @@ type MailMessage_Header struct {
|
||||
Bcc []*MailMessage_Header_MailAddress `protobuf:"bytes,4,rep,name=bcc,proto3" json:"bcc,omitempty"`
|
||||
From []*MailMessage_Header_MailAddress `protobuf:"bytes,5,rep,name=from,proto3" json:"from,omitempty"`
|
||||
ReplyTo []*MailMessage_Header_MailAddress `protobuf:"bytes,6,rep,name=replyTo,proto3" json:"replyTo,omitempty"`
|
||||
Raw map[string]*MailMessage_Header_HeaderValues `protobuf:"bytes,15,rep,name=Raw,proto3" json:"Raw,omitempty" protobuf_key:"bytes,1,opt,name=key,proto3" protobuf_val:"bytes,2,opt,name=value,proto3"`
|
||||
Raw map[string]*MailMessage_Header_HeaderValues `protobuf:"bytes,15,rep,name=raw,proto3" json:"raw,omitempty" protobuf_key:"bytes,1,opt,name=key,proto3" protobuf_val:"bytes,2,opt,name=value,proto3"`
|
||||
XXX_NoUnkeyedLiteral struct{} `json:"-"`
|
||||
XXX_unrecognized []byte `json:"-"`
|
||||
XXX_sizecache int32 `json:"-"`
|
||||
@@ -274,7 +274,7 @@ var fileDescriptor_d142ecb16d253662 = []byte{
|
||||
0x4e, 0x12, 0x66, 0xf3, 0xf7, 0x4b, 0xe8, 0xd5, 0xef, 0xa2, 0x10, 0x4c, 0x4a, 0x62, 0x2b, 0xde,
|
||||
0x72, 0x79, 0x8e, 0x9d, 0x61, 0x5c, 0x9e, 0xa3, 0x25, 0x38, 0xfb, 0x3c, 0xc7, 0xee, 0x20, 0xb0,
|
||||
0x45, 0xd0, 0x0a, 0xdc, 0x83, 0xe0, 0x15, 0xf6, 0x06, 0xa1, 0x9a, 0x41, 0xbf, 0x20, 0x10, 0xac,
|
||||
0x2e, 0x9b, 0x2d, 0xc7, 0xfe, 0x20, 0xbc, 0xc7, 0xd0, 0x37, 0x70, 0x08, 0xbd, 0xe2, 0xa9, 0xa6,
|
||||
0x2e, 0x9b, 0x2d, 0xc7, 0xfe, 0x20, 0xbc, 0xc7, 0xd0, 0x37, 0x70, 0x04, 0xbd, 0xe2, 0xa9, 0xa6,
|
||||
0x3f, 0xdf, 0xa1, 0x09, 0xbd, 0xfe, 0x39, 0x2b, 0xd1, 0x90, 0xd6, 0x1f, 0xfd, 0x30, 0x67, 0xef,
|
||||
0xe2, 0xda, 0x13, 0x52, 0x23, 0xf5, 0x81, 0xc6, 0xa4, 0x1f, 0x11, 0x02, 0xf7, 0x4c, 0x2b, 0x86,
|
||||
0x6d, 0xbd, 0xd6, 0x3a, 0x9a, 0xc3, 0xc4, 0x84, 0xfe, 0xa7, 0xe5, 0x85, 0x49, 0xf4, 0x01, 0xfc,
|
||||
@@ -282,5 +282,5 @@ var fileDescriptor_d142ecb16d253662 = []byte{
|
||||
0xf3, 0xc4, 0x9a, 0x2e, 0xbd, 0x95, 0xe8, 0x27, 0x78, 0xda, 0xa7, 0xa3, 0xc3, 0xec, 0xcb, 0x9d,
|
||||
0xee, 0xb7, 0xaf, 0x11, 0x43, 0xad, 0xec, 0xa5, 0xf5, 0xcf, 0x1d, 0x05, 0xb3, 0x29, 0xf1, 0x6a,
|
||||
0x2a, 0x94, 0x5c, 0x07, 0x0f, 0x9e, 0xf9, 0x9b, 0x7c, 0xfd, 0xf9, 0xfa, 0x16, 0x00, 0x00, 0xff,
|
||||
0xff, 0x29, 0x3b, 0x5c, 0x39, 0x19, 0x03, 0x00, 0x00,
|
||||
0xff, 0x16, 0x0c, 0x9f, 0x19, 0x19, 0x03, 0x00, 0x00,
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user