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:
Mahlon E. Smith 2023-07-01 04:47:54 +00:00
parent 22542f9864
commit c3d931cb2e
2 changed files with 17 additions and 3 deletions

View file

@ -34,6 +34,7 @@ const CONFFILES = @[
type
Rule* = object
comment* {.defaultVal: ""}: string
match* {.defaultVal: initTable[string, string]()}: Table[ string, string ]
deliver* {.defaultVal: ""}: string
filter* {.defaultVal: @[]}: seq[ seq[string] ]
@ -61,6 +62,9 @@ proc parse( path: string ): Config =
except YamlConstructionError as err:
err.msg.debug
return Config()
except YamlStreamError as err:
err.msg.debug
return Config()
finally:
stream.close

View file

@ -266,8 +266,14 @@ proc evalRules*( msg: var Message, rules: seq[Rule], default: Maildir ): bool =
for rule in rules:
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:
for header, regexp in rule.match:
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 ):
values = msg.headers[ header_chk ]
else:
" nonexistent header, skipping others".debug
var m = " nonexistent header"
if ruleCount > 1: m = m & ", skipping other tests"
m.debug
break thisRule
for val in values:
@ -308,7 +316,9 @@ proc evalRules*( msg: var Message, rules: seq[Rule], default: Maildir ): bool =
if hmatch:
match = true
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
result = match