fix logging
This commit is contained in:
@@ -253,11 +253,12 @@ class ModifyMilter(Milter.Base):
|
|||||||
self._headersonly = True
|
self._headersonly = True
|
||||||
for rule in ModifyMilter._rules:
|
for rule in ModifyMilter._rules:
|
||||||
if rule.conditions is None or \
|
if rule.conditions is None or \
|
||||||
rule.conditions.match(host=self.IP):
|
rule.conditions.match(host=self.IP, qid=self.qid):
|
||||||
actions = []
|
actions = []
|
||||||
for action in rule.actions:
|
for action in rule.actions:
|
||||||
if action.conditions is None or \
|
if action.conditions is None or \
|
||||||
action.conditions.match(host=self.IP):
|
action.conditions.match(host=self.IP,
|
||||||
|
qid=self.qid):
|
||||||
actions.append(action)
|
actions.append(action)
|
||||||
if not action.headersonly():
|
if not action.headersonly():
|
||||||
self._headersonly = False
|
self._headersonly = False
|
||||||
|
|||||||
@@ -18,9 +18,10 @@ __all__ = [
|
|||||||
|
|
||||||
import os
|
import os
|
||||||
|
|
||||||
from pymodmilter import CustomLogger, BaseConfig
|
from pymodmilter import BaseConfig
|
||||||
from pymodmilter.conditions import ConditionsConfig, Conditions
|
|
||||||
from pymodmilter import modify, notify, storage
|
from pymodmilter import modify, notify, storage
|
||||||
|
from pymodmilter.base import CustomLogger
|
||||||
|
from pymodmilter.conditions import ConditionsConfig, Conditions
|
||||||
|
|
||||||
|
|
||||||
class ActionConfig(BaseConfig):
|
class ActionConfig(BaseConfig):
|
||||||
@@ -173,8 +174,6 @@ class Action:
|
|||||||
"""Action to implement a pre-configured action to perform on e-mails."""
|
"""Action to implement a pre-configured action to perform on e-mails."""
|
||||||
|
|
||||||
def __init__(self, milter_cfg, cfg):
|
def __init__(self, milter_cfg, cfg):
|
||||||
self.logger = cfg.logger
|
|
||||||
|
|
||||||
if cfg["conditions"] is None:
|
if cfg["conditions"] is None:
|
||||||
self.conditions = None
|
self.conditions = None
|
||||||
else:
|
else:
|
||||||
@@ -184,6 +183,7 @@ class Action:
|
|||||||
self._name = cfg["name"]
|
self._name = cfg["name"]
|
||||||
self._class = cfg["class"](**cfg["args"])
|
self._class = cfg["class"](**cfg["args"])
|
||||||
self._headersonly = cfg["headersonly"]
|
self._headersonly = cfg["headersonly"]
|
||||||
|
self.logger = cfg.logger
|
||||||
|
|
||||||
def headersonly(self):
|
def headersonly(self):
|
||||||
"""Return the needs of this action."""
|
"""Return the needs of this action."""
|
||||||
@@ -191,11 +191,12 @@ class Action:
|
|||||||
|
|
||||||
def execute(self, milter):
|
def execute(self, milter):
|
||||||
"""Execute configured action."""
|
"""Execute configured action."""
|
||||||
|
logger = CustomLogger(
|
||||||
|
self.logger, {"qid": milter.qid, "name": self._name})
|
||||||
if self.conditions is None or \
|
if self.conditions is None or \
|
||||||
self.conditions.match(envfrom=milter.mailfrom,
|
self.conditions.match(envfrom=milter.mailfrom,
|
||||||
envto=[*milter.rcpts],
|
envto=[*milter.rcpts],
|
||||||
headers=milter.msg.items()):
|
headers=milter.msg.items(),
|
||||||
logger = CustomLogger(
|
qid=milter.qid):
|
||||||
self.logger, {"name": self._name, "qid": milter.qid})
|
|
||||||
return self._class.execute(
|
return self._class.execute(
|
||||||
milter=milter, pretend=self.pretend, logger=logger)
|
milter=milter, pretend=self.pretend, logger=logger)
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ __all__ = [
|
|||||||
import re
|
import re
|
||||||
|
|
||||||
from netaddr import IPAddress, IPNetwork, AddrFormatError
|
from netaddr import IPAddress, IPNetwork, AddrFormatError
|
||||||
from pymodmilter import CustomLogger, BaseConfig
|
from pymodmilter import BaseConfig, CustomLogger
|
||||||
|
|
||||||
|
|
||||||
class ConditionsConfig(BaseConfig):
|
class ConditionsConfig(BaseConfig):
|
||||||
@@ -76,14 +76,19 @@ class Conditions:
|
|||||||
"""Conditions to implement conditions for rules and actions."""
|
"""Conditions to implement conditions for rules and actions."""
|
||||||
|
|
||||||
def __init__(self, milter_cfg, cfg):
|
def __init__(self, milter_cfg, cfg):
|
||||||
self.logger = cfg.logger
|
|
||||||
|
|
||||||
self._local_addrs = milter_cfg["local_addrs"]
|
self._local_addrs = milter_cfg["local_addrs"]
|
||||||
self._name = cfg["name"]
|
self._name = cfg["name"]
|
||||||
self._args = cfg["args"]
|
self._args = cfg["args"]
|
||||||
|
self.logger = cfg.logger
|
||||||
|
|
||||||
|
def match(self, host=None, envfrom=None, envto=None, headers=None,
|
||||||
|
qid=None):
|
||||||
|
if qid is None:
|
||||||
|
logger = self.logger
|
||||||
|
else:
|
||||||
|
logger = CustomLogger(
|
||||||
|
self.logger, {"qid": qid, "name": self._name})
|
||||||
|
|
||||||
def match(self, host=None, envfrom=None, envto=None, headers=None):
|
|
||||||
logger = CustomLogger(self.logger, {"name": self._name})
|
|
||||||
if host:
|
if host:
|
||||||
ip = IPAddress(host)
|
ip = IPAddress(host)
|
||||||
|
|
||||||
|
|||||||
@@ -268,7 +268,7 @@ class EMailNotification(BaseNotification):
|
|||||||
"FROM": escape(msg["from"], quote=False),
|
"FROM": escape(msg["from"], quote=False),
|
||||||
"ENVELOPE_FROM": escape(mailfrom, quote=False),
|
"ENVELOPE_FROM": escape(mailfrom, quote=False),
|
||||||
"ENVELOPE_FROM_URL": escape(quote(mailfrom),
|
"ENVELOPE_FROM_URL": escape(quote(mailfrom),
|
||||||
quote=False),
|
quote=False),
|
||||||
"TO": escape(msg["to"], quote=False),
|
"TO": escape(msg["to"], quote=False),
|
||||||
"ENVELOPE_TO": escape(recipient, quote=False),
|
"ENVELOPE_TO": escape(recipient, quote=False),
|
||||||
"ENVELOPE_TO_URL": escape(quote(recipient)),
|
"ENVELOPE_TO_URL": escape(quote(recipient)),
|
||||||
|
|||||||
@@ -88,7 +88,8 @@ class Rule:
|
|||||||
if self.conditions is None or \
|
if self.conditions is None or \
|
||||||
self.conditions.match(envfrom=milter.mailfrom,
|
self.conditions.match(envfrom=milter.mailfrom,
|
||||||
envto=[*milter.rcpts],
|
envto=[*milter.rcpts],
|
||||||
headers=milter.msg.items()):
|
headers=milter.msg.items(),
|
||||||
|
qid=milter.qid):
|
||||||
for action in self.actions:
|
for action in self.actions:
|
||||||
milter_action = action.execute(milter)
|
milter_action = action.execute(milter)
|
||||||
if milter_action is not None:
|
if milter_action is not None:
|
||||||
|
|||||||
Reference in New Issue
Block a user