Add rule comments for logging.
Be more explicit with log output when skipping other header matches for a single rule. FossilOrigin-Name: 0abd42e75e28170a09f5932305c82f8791180768d4da8a6840ea4fc571cbc029
This commit is contained in:
parent
22542f9864
commit
c3d931cb2e
2 changed files with 17 additions and 3 deletions
|
|
@ -34,6 +34,7 @@ const CONFFILES = @[
|
||||||
|
|
||||||
type
|
type
|
||||||
Rule* = object
|
Rule* = object
|
||||||
|
comment* {.defaultVal: ""}: string
|
||||||
match* {.defaultVal: initTable[string, string]()}: Table[ string, string ]
|
match* {.defaultVal: initTable[string, string]()}: Table[ string, string ]
|
||||||
deliver* {.defaultVal: ""}: string
|
deliver* {.defaultVal: ""}: string
|
||||||
filter* {.defaultVal: @[]}: seq[ seq[string] ]
|
filter* {.defaultVal: @[]}: seq[ seq[string] ]
|
||||||
|
|
@ -61,6 +62,9 @@ proc parse( path: string ): Config =
|
||||||
except YamlConstructionError as err:
|
except YamlConstructionError as err:
|
||||||
err.msg.debug
|
err.msg.debug
|
||||||
return Config()
|
return Config()
|
||||||
|
except YamlStreamError as err:
|
||||||
|
err.msg.debug
|
||||||
|
return Config()
|
||||||
finally:
|
finally:
|
||||||
stream.close
|
stream.close
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -266,8 +266,14 @@ proc evalRules*( msg: var Message, rules: seq[Rule], default: Maildir ): bool =
|
||||||
|
|
||||||
for rule in rules:
|
for rule in rules:
|
||||||
var match = false
|
var match = false
|
||||||
|
let ruleCount = rule.match.len
|
||||||
|
|
||||||
|
if ruleCount > 0:
|
||||||
|
if rule.comment == "":
|
||||||
|
"Evaluating rule...".debug
|
||||||
|
else:
|
||||||
|
"Evaluating rule \"$#\"".debug( rule.comment )
|
||||||
|
|
||||||
if rule.match.len > 0: "Evaluating rule...".debug
|
|
||||||
block thisRule:
|
block thisRule:
|
||||||
for header, regexp in rule.match:
|
for header, regexp in rule.match:
|
||||||
let header_chk = header.toLower
|
let header_chk = header.toLower
|
||||||
|
|
@ -290,7 +296,9 @@ proc evalRules*( msg: var Message, rules: seq[Rule], default: Maildir ): bool =
|
||||||
elif msg.headers.hasKey( header_chk ):
|
elif msg.headers.hasKey( header_chk ):
|
||||||
values = msg.headers[ header_chk ]
|
values = msg.headers[ header_chk ]
|
||||||
else:
|
else:
|
||||||
" nonexistent header, skipping others".debug
|
var m = " nonexistent header"
|
||||||
|
if ruleCount > 1: m = m & ", skipping other tests"
|
||||||
|
m.debug
|
||||||
break thisRule
|
break thisRule
|
||||||
|
|
||||||
for val in values:
|
for val in values:
|
||||||
|
|
@ -308,7 +316,9 @@ proc evalRules*( msg: var Message, rules: seq[Rule], default: Maildir ): bool =
|
||||||
if hmatch:
|
if hmatch:
|
||||||
match = true
|
match = true
|
||||||
else:
|
else:
|
||||||
" no match for \"$#\", skipping others".debug( regexp )
|
var m = " no match for \"$#\""
|
||||||
|
if ruleCount > 1: m = m & ", skipping other tests"
|
||||||
|
m.debug( regexp )
|
||||||
break thisRule
|
break thisRule
|
||||||
|
|
||||||
result = match
|
result = match
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue