add condition on variables
This commit is contained in:
@@ -41,7 +41,6 @@ class ActionConfig(BaseConfig):
|
||||
|
||||
self["pretend"] = rule_cfg["pretend"]
|
||||
self["conditions"] = None
|
||||
self["type"] = ""
|
||||
|
||||
if "pretend" in cfg:
|
||||
pretend = cfg["pretend"]
|
||||
@@ -53,13 +52,12 @@ class ActionConfig(BaseConfig):
|
||||
f"{self['name']}: mandatory parameter 'type' not found"
|
||||
assert isinstance(cfg["type"], str), \
|
||||
f"{self['name']}: type: invalid value, should be string"
|
||||
self["type"] = cfg["type"]
|
||||
|
||||
if self["type"] == "add_header":
|
||||
if cfg["type"] == "add_header":
|
||||
self["class"] = modify.AddHeader
|
||||
self["headersonly"] = True
|
||||
self.add_string_arg(cfg, ["field", "value"])
|
||||
elif self["type"] == "mod_header":
|
||||
elif cfg["type"] == "mod_header":
|
||||
self["class"] = modify.ModHeader
|
||||
self["headersonly"] = True
|
||||
args = ["field", "value"]
|
||||
@@ -67,7 +65,7 @@ class ActionConfig(BaseConfig):
|
||||
args.append("search")
|
||||
|
||||
self.add_string_arg(cfg, args)
|
||||
elif self["type"] == "del_header":
|
||||
elif cfg["type"] == "del_header":
|
||||
self["class"] = modify.DelHeader
|
||||
self["headersonly"] = True
|
||||
args = ["field"]
|
||||
@@ -75,7 +73,7 @@ class ActionConfig(BaseConfig):
|
||||
args.append("value")
|
||||
|
||||
self.add_string_arg(cfg, args)
|
||||
elif self["type"] == "add_disclaimer":
|
||||
elif cfg["type"] == "add_disclaimer":
|
||||
self["class"] = modify.AddDisclaimer
|
||||
self["headersonly"] = False
|
||||
if "error_policy" not in cfg:
|
||||
@@ -93,17 +91,17 @@ class ActionConfig(BaseConfig):
|
||||
f"{self['name']}: error_policy: invalid value, " \
|
||||
f"should be 'wrap', 'ignore' or 'reject'"
|
||||
|
||||
elif self["type"] == "rewrite_links":
|
||||
elif cfg["type"] == "rewrite_links":
|
||||
self["class"] = modify.RewriteLinks
|
||||
self["headersonly"] = False
|
||||
self.add_string_arg(cfg, "repl")
|
||||
|
||||
elif self["type"] == "store":
|
||||
elif cfg["type"] == "store":
|
||||
self["headersonly"] = False
|
||||
|
||||
assert "storage_type" in cfg, \
|
||||
f"{self['name']}: mandatory parameter 'storage_type' not found"
|
||||
assert isinstance(cfg["type"], str), \
|
||||
assert isinstance(cfg["storage_type"], str), \
|
||||
f"{self['name']}: storage_type: invalid value, " \
|
||||
f"should be string"
|
||||
self["storage_type"] = cfg["storage_type"]
|
||||
@@ -132,7 +130,7 @@ class ActionConfig(BaseConfig):
|
||||
raise RuntimeError(
|
||||
f"{self['name']}: storage_type: invalid storage type")
|
||||
|
||||
elif self["type"] == "notify":
|
||||
elif cfg["type"] == "notify":
|
||||
self["headersonly"] = False
|
||||
self["class"] = notify.EMailNotification
|
||||
|
||||
@@ -166,7 +164,7 @@ class ActionConfig(BaseConfig):
|
||||
|
||||
self.logger.debug(f"{self['name']}: pretend={self['pretend']}, "
|
||||
f"loglevel={self['loglevel']}, "
|
||||
f"type={self['type']}, "
|
||||
f"type={cfg['type']}, "
|
||||
f"args={self['args']}")
|
||||
|
||||
|
||||
|
||||
@@ -49,6 +49,9 @@ class ConditionsConfig(BaseConfig):
|
||||
if "header" in cfg:
|
||||
self.add_string_arg(cfg, "header")
|
||||
|
||||
if "var" in cfg:
|
||||
self.add_string_arg(cfg, "var")
|
||||
|
||||
if "metavar" in cfg:
|
||||
self.add_string_arg(cfg, "metavar")
|
||||
|
||||
@@ -64,7 +67,8 @@ class Conditions:
|
||||
self._local_addrs = milter_cfg["local_addrs"]
|
||||
self._name = cfg["name"]
|
||||
|
||||
for arg in ("local", "hosts", "envfrom", "envto", "header", "metavar"):
|
||||
for arg in ("local", "hosts", "envfrom", "envto", "header", "metavar",
|
||||
"var"):
|
||||
value = cfg["args"][arg] if arg in cfg["args"] else None
|
||||
setattr(self, arg, value)
|
||||
if value is None:
|
||||
@@ -176,8 +180,10 @@ class Conditions:
|
||||
f"condition header matches for "
|
||||
f"header: {header}")
|
||||
if self.metavar is not None:
|
||||
named_subgroups = match.groupdict(default="")
|
||||
named_subgroups = match.groupdict(default=None)
|
||||
for group, value in named_subgroups.items():
|
||||
if value is None:
|
||||
continue
|
||||
name = f"{self.metavar}_{group}"
|
||||
milter.msginfo["vars"][name] = value
|
||||
break
|
||||
@@ -188,4 +194,8 @@ class Conditions:
|
||||
"condition header does not match")
|
||||
return False
|
||||
|
||||
if self.var is not None:
|
||||
if self.var not in milter.msginfo["vars"]:
|
||||
return False
|
||||
|
||||
return True
|
||||
|
||||
Reference in New Issue
Block a user