Add config option for reject reason
This commit is contained in:
@@ -48,6 +48,11 @@ The following configuration options are mandatory in each quarantine section:
|
|||||||
* **smtp_port**
|
* **smtp_port**
|
||||||
SMTP port
|
SMTP port
|
||||||
|
|
||||||
|
The following configuration options are optional in each quarantine section:
|
||||||
|
* **reject_reason**
|
||||||
|
Reason to return to the client if action is set to reject.
|
||||||
|
|
||||||
|
|
||||||
### Quarantine types
|
### Quarantine types
|
||||||
* **NONE**
|
* **NONE**
|
||||||
Original e-mails scrapped, sent to nirvana, black-holed or however you want to call it.
|
Original e-mails scrapped, sent to nirvana, black-holed or however you want to call it.
|
||||||
|
|||||||
@@ -70,6 +70,12 @@ quarantine_directory = /var/lib/pyquarantine/spam
|
|||||||
#
|
#
|
||||||
action = discard
|
action = discard
|
||||||
|
|
||||||
|
# Option: reject_reason
|
||||||
|
# Notes: Optionally set the reason to return if action is set to reject.
|
||||||
|
# Values: [ REASON ]
|
||||||
|
#
|
||||||
|
reject_reason = Message rejected
|
||||||
|
|
||||||
# Option: notification
|
# Option: notification
|
||||||
# Notes: Set the notification type.
|
# Notes: Set the notification type.
|
||||||
# Values: [ email | none ]
|
# Values: [ email | none ]
|
||||||
|
|||||||
@@ -181,6 +181,8 @@ class QuarantineMilter(Milter.Base):
|
|||||||
quarantine = self._get_preferred_quarantine()
|
quarantine = self._get_preferred_quarantine()
|
||||||
self.logger.info("{}: {} matching quarantine is '{}', performing milter action {}".format(self.queueid, self.global_config["preferred_quarantine_action"],
|
self.logger.info("{}: {} matching quarantine is '{}', performing milter action {}".format(self.queueid, self.global_config["preferred_quarantine_action"],
|
||||||
quarantine["name"], quarantine["action"].upper()))
|
quarantine["name"], quarantine["action"].upper()))
|
||||||
|
if quarantine["action"] == "reject":
|
||||||
|
self.setreply("554", "5.7.0", quarantine["reject_reason"])
|
||||||
return quarantine["milter_action"]
|
return quarantine["milter_action"]
|
||||||
|
|
||||||
return Milter.CONTINUE
|
return Milter.CONTINUE
|
||||||
@@ -249,6 +251,8 @@ class QuarantineMilter(Milter.Base):
|
|||||||
quarantine = self._get_preferred_quarantine()
|
quarantine = self._get_preferred_quarantine()
|
||||||
self.logger.info("{}: {} matching quarantine is '{}', performing milter action {}".format(self.queueid, self.global_config["preferred_quarantine_action"],
|
self.logger.info("{}: {} matching quarantine is '{}', performing milter action {}".format(self.queueid, self.global_config["preferred_quarantine_action"],
|
||||||
quarantine["name"], quarantine["action"].upper()))
|
quarantine["name"], quarantine["action"].upper()))
|
||||||
|
if quarantine["action"] == "reject":
|
||||||
|
self.setreply("554", "5.7.0", quarantine["reject_reason"])
|
||||||
return quarantine["milter_action"]
|
return quarantine["milter_action"]
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
@@ -314,6 +318,17 @@ def generate_milter_config(configtest=False, config_files=[]):
|
|||||||
if option not in config.keys():
|
if option not in config.keys():
|
||||||
raise RuntimeError("mandatory option '{}' not present in config section '{}' or 'global'".format(option, quarantine_name))
|
raise RuntimeError("mandatory option '{}' not present in config section '{}' or 'global'".format(option, quarantine_name))
|
||||||
|
|
||||||
|
# check if optional config options are present in config
|
||||||
|
defaults = {
|
||||||
|
"reject_reason": "Message rejected"
|
||||||
|
}
|
||||||
|
for option in defaults.keys():
|
||||||
|
if option not in config.keys() and \
|
||||||
|
option in global_config.keys():
|
||||||
|
config[option] = global_config[option]
|
||||||
|
if option not in config.keys():
|
||||||
|
config[option] = defaults[option]
|
||||||
|
|
||||||
# set quarantine name
|
# set quarantine name
|
||||||
config["name"] = quarantine_name
|
config["name"] = quarantine_name
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user