make store procedure aware of pretend option

This commit is contained in:
2021-09-07 23:03:50 +02:00
parent f25909b34b
commit be715d8b01
2 changed files with 12 additions and 10 deletions

View File

@@ -243,7 +243,6 @@ class ModifyMilter(Milter.Base):
# pre-filter rules and actions by the host condition, other # pre-filter rules and actions by the host condition, other
# conditions (headers, envelope-from, envelope-to) may get # conditions (headers, envelope-from, envelope-to) may get
# changed by executed actions later on. # changed by executed actions later on.
# rules are copied to preserve the originally configured actions.
# also check if the mail body is needed by any upcoming action. # also check if the mail body is needed by any upcoming action.
self.rules = [] self.rules = []
@@ -260,6 +259,7 @@ class ModifyMilter(Milter.Base):
self._headersonly = False self._headersonly = False
if actions: if actions:
# copy needed rules to preserve configured actions
rule = copy(rule) rule = copy(rule)
rule.actions = actions rule.actions = actions
self.rules.append(rule) self.rules.append(rule)

View File

@@ -324,15 +324,17 @@ def store(milter, directory, original=False, pretend=False,
datafile = os.path.join(directory, store_id) datafile = os.path.join(directory, store_id)
logger.info(f"store message in file {datafile}") logger.info(f"store message in file {datafile}")
try:
with open(datafile, "wb") as fp: if not pretend:
if original: try:
milter.fp.seek(0) with open(datafile, "wb") as fp:
fp.write(milter.fp.read()) if original:
else: milter.fp.seek(0)
fp.write(milter.msg.as_bytes()) fp.write(milter.fp.read())
except IOError as e: else:
raise RuntimeError(f"unable to store message: {e}") fp.write(milter.msg.as_bytes())
except IOError as e:
raise RuntimeError(f"unable to store message: {e}")
class ActionConfig(BaseConfig): class ActionConfig(BaseConfig):