add action notify to action config
This commit is contained in:
@@ -131,6 +131,25 @@ class ActionConfig(BaseConfig):
|
|||||||
raise RuntimeError(
|
raise RuntimeError(
|
||||||
f"{self['name']}: storage_type: invalid storage type")
|
f"{self['name']}: storage_type: invalid storage type")
|
||||||
|
|
||||||
|
elif self["type"] == "notify":
|
||||||
|
self["headersonly"] = False
|
||||||
|
|
||||||
|
self.add_string_arg(
|
||||||
|
cfg, ["smtp_host", "envelope_from", "from", "subject",
|
||||||
|
"template"])
|
||||||
|
self.add_int_arg(cfg, "smtp_port")
|
||||||
|
|
||||||
|
if "embedded_imgs" in cfg:
|
||||||
|
assert isinstance(cfg["embedded_imgs"], list), \
|
||||||
|
f"{self['name']}: embedded_imgs: invalid value, " \
|
||||||
|
f"should be list"
|
||||||
|
for img in cfg["embedded_imgs"]:
|
||||||
|
assert isinstance(img, str), \
|
||||||
|
f"{self['name']}: embedded_imgs: invalid entry, " \
|
||||||
|
f"should be string"
|
||||||
|
|
||||||
|
self["args"]["embedded_imgs"] = cfg["embedded_imgs"]
|
||||||
|
|
||||||
else:
|
else:
|
||||||
raise RuntimeError(f"{self['name']}: type: invalid action type")
|
raise RuntimeError(f"{self['name']}: type: invalid action type")
|
||||||
|
|
||||||
|
|||||||
@@ -104,6 +104,17 @@ class BaseConfig:
|
|||||||
f"{self['name']}: {arg}: invalid value, should be bool"
|
f"{self['name']}: {arg}: invalid value, should be bool"
|
||||||
self["args"][arg] = cfg[arg]
|
self["args"][arg] = cfg[arg]
|
||||||
|
|
||||||
|
def add_int_arg(self, cfg, args):
|
||||||
|
if isinstance(args, str):
|
||||||
|
args = [args]
|
||||||
|
|
||||||
|
for arg in args:
|
||||||
|
assert arg in cfg, \
|
||||||
|
f"{self['name']}: mandatory parameter '{arg}' not found"
|
||||||
|
assert isinstance(cfg[arg], int), \
|
||||||
|
f"{self['name']}: {arg}: invalid value, should be integer"
|
||||||
|
self["args"][arg] = cfg[arg]
|
||||||
|
|
||||||
|
|
||||||
class MilterMessage(MIMEPart):
|
class MilterMessage(MIMEPart):
|
||||||
def replace_header(self, _name, _value, idx=None):
|
def replace_header(self, _name, _value, idx=None):
|
||||||
|
|||||||
@@ -121,12 +121,12 @@ class EMailNotification(BaseNotification):
|
|||||||
self.subject = subject
|
self.subject = subject
|
||||||
try:
|
try:
|
||||||
self.template = open(template, "r").read()
|
self.template = open(template, "r").read()
|
||||||
self.embedded_imgs = []
|
self.embed_imgs = []
|
||||||
for img_path in embed_imgs:
|
for img_path in embed_imgs:
|
||||||
img = MIMEImage(open(img_path, "rb").read())
|
img = MIMEImage(open(img_path, "rb").read())
|
||||||
filename = basename(img_path)
|
filename = basename(img_path)
|
||||||
img.add_header("Content-ID", f"<{filename}>")
|
img.add_header("Content-ID", f"<{filename}>")
|
||||||
self.embedded_imgs.append(img)
|
self.embed_imgs.append(img)
|
||||||
|
|
||||||
self.replacement_img = repl_img
|
self.replacement_img = repl_img
|
||||||
self.strip_images = strip_imgs
|
self.strip_images = strip_imgs
|
||||||
@@ -297,7 +297,7 @@ class EMailNotification(BaseNotification):
|
|||||||
logger.debug("attaching notification_replacement_img")
|
logger.debug("attaching notification_replacement_img")
|
||||||
msg.attach(self.replacement_img)
|
msg.attach(self.replacement_img)
|
||||||
|
|
||||||
for img in self.embedded_imgs:
|
for img in self.embed_imgs:
|
||||||
logger.debug("attaching imgage")
|
logger.debug("attaching imgage")
|
||||||
msg.attach(img)
|
msg.attach(img)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user