shorten file names
This commit is contained in:
@@ -13,14 +13,15 @@
|
|||||||
#
|
#
|
||||||
|
|
||||||
__all__ = [
|
__all__ = [
|
||||||
"actions",
|
"action",
|
||||||
"base",
|
"base",
|
||||||
"conditions",
|
"conditions",
|
||||||
"mailer",
|
"mailer",
|
||||||
"modifications",
|
"modify",
|
||||||
"rules",
|
"notify",
|
||||||
|
"rule",
|
||||||
"run",
|
"run",
|
||||||
"storages",
|
"storage",
|
||||||
"ModifyMilterConfig",
|
"ModifyMilterConfig",
|
||||||
"ModifyMilter"]
|
"ModifyMilter"]
|
||||||
|
|
||||||
@@ -45,7 +46,7 @@ from netaddr import IPNetwork, AddrFormatError
|
|||||||
|
|
||||||
from pymodmilter.base import CustomLogger, BaseConfig, MilterMessage
|
from pymodmilter.base import CustomLogger, BaseConfig, MilterMessage
|
||||||
from pymodmilter.base import replace_illegal_chars
|
from pymodmilter.base import replace_illegal_chars
|
||||||
from pymodmilter.rules import RuleConfig, Rule
|
from pymodmilter.rule import RuleConfig, Rule
|
||||||
|
|
||||||
|
|
||||||
class ModifyMilterConfig(BaseConfig):
|
class ModifyMilterConfig(BaseConfig):
|
||||||
@@ -339,12 +340,14 @@ class ModifyMilter(Milter.Base):
|
|||||||
self.msginfo = {
|
self.msginfo = {
|
||||||
"mailfrom": self.mailfrom,
|
"mailfrom": self.mailfrom,
|
||||||
"rcpts": self.rcpts,
|
"rcpts": self.rcpts,
|
||||||
"storage_id": None}
|
"vars": {}}
|
||||||
|
|
||||||
self._replacebody = False
|
self._replacebody = False
|
||||||
milter_action = None
|
milter_action = None
|
||||||
for rule in self.rules:
|
for rule in self.rules:
|
||||||
milter_action = rule.execute(self)
|
milter_action = rule.execute(self)
|
||||||
|
self.logger.debug(
|
||||||
|
f"current template variables: {self.msginfo['vars']}")
|
||||||
if milter_action is not None:
|
if milter_action is not None:
|
||||||
break
|
break
|
||||||
|
|
||||||
|
|||||||
@@ -23,7 +23,7 @@ from bs4 import BeautifulSoup
|
|||||||
|
|
||||||
from pymodmilter import CustomLogger, BaseConfig
|
from pymodmilter import CustomLogger, BaseConfig
|
||||||
from pymodmilter.conditions import ConditionsConfig, Conditions
|
from pymodmilter.conditions import ConditionsConfig, Conditions
|
||||||
from pymodmilter import modifications, storages
|
from pymodmilter import modify, storage
|
||||||
|
|
||||||
|
|
||||||
class ActionConfig(BaseConfig):
|
class ActionConfig(BaseConfig):
|
||||||
@@ -58,7 +58,7 @@ class ActionConfig(BaseConfig):
|
|||||||
self["type"] = cfg["type"]
|
self["type"] = cfg["type"]
|
||||||
|
|
||||||
if self["type"] == "add_header":
|
if self["type"] == "add_header":
|
||||||
self["class"] = modifications.AddHeader
|
self["class"] = modify.AddHeader
|
||||||
self["headersonly"] = True
|
self["headersonly"] = True
|
||||||
|
|
||||||
if "field" not in cfg and "header" in cfg:
|
if "field" not in cfg and "header" in cfg:
|
||||||
@@ -67,7 +67,7 @@ class ActionConfig(BaseConfig):
|
|||||||
self.add_string_arg(cfg, ("field", "value"))
|
self.add_string_arg(cfg, ("field", "value"))
|
||||||
|
|
||||||
elif self["type"] == "mod_header":
|
elif self["type"] == "mod_header":
|
||||||
self["class"] = modifications.ModHeader
|
self["class"] = modify.ModHeader
|
||||||
self["headersonly"] = True
|
self["headersonly"] = True
|
||||||
|
|
||||||
if "field" not in cfg and "header" in cfg:
|
if "field" not in cfg and "header" in cfg:
|
||||||
@@ -88,7 +88,7 @@ class ActionConfig(BaseConfig):
|
|||||||
raise ValueError(f"{self['name']}: {arg}: {e}")
|
raise ValueError(f"{self['name']}: {arg}: {e}")
|
||||||
|
|
||||||
elif self["type"] == "del_header":
|
elif self["type"] == "del_header":
|
||||||
self["class"] = modifications.DelHeader
|
self["class"] = modify.DelHeader
|
||||||
self["headersonly"] = True
|
self["headersonly"] = True
|
||||||
|
|
||||||
if "field" not in cfg and "header" in cfg:
|
if "field" not in cfg and "header" in cfg:
|
||||||
@@ -108,7 +108,7 @@ class ActionConfig(BaseConfig):
|
|||||||
raise ValueError(f"{self['name']}: {arg}: {e}")
|
raise ValueError(f"{self['name']}: {arg}: {e}")
|
||||||
|
|
||||||
elif self["type"] == "add_disclaimer":
|
elif self["type"] == "add_disclaimer":
|
||||||
self["class"] = modifications.AddDisclaimer
|
self["class"] = modify.AddDisclaimer
|
||||||
self["headersonly"] = False
|
self["headersonly"] = False
|
||||||
|
|
||||||
if "html_template" not in cfg and "html_file" in cfg:
|
if "html_template" not in cfg and "html_file" in cfg:
|
||||||
@@ -149,7 +149,7 @@ class ActionConfig(BaseConfig):
|
|||||||
f"{self['name']}: unable to open/read template file: {e}")
|
f"{self['name']}: unable to open/read template file: {e}")
|
||||||
|
|
||||||
elif self["type"] == "rewrite_links":
|
elif self["type"] == "rewrite_links":
|
||||||
self["class"] = modifications.RewriteLinks
|
self["class"] = modify.RewriteLinks
|
||||||
self["headersonly"] = False
|
self["headersonly"] = False
|
||||||
self.add_string_arg(cfg, "repl")
|
self.add_string_arg(cfg, "repl")
|
||||||
|
|
||||||
@@ -167,7 +167,7 @@ class ActionConfig(BaseConfig):
|
|||||||
self.add_bool_arg(cfg, "original")
|
self.add_bool_arg(cfg, "original")
|
||||||
|
|
||||||
if self["storage_type"] == "file":
|
if self["storage_type"] == "file":
|
||||||
self["class"] = storages.FileMailStorage
|
self["class"] = storage.FileMailStorage
|
||||||
self.add_string_arg(cfg, "directory")
|
self.add_string_arg(cfg, "directory")
|
||||||
# check if directory exists and is writable
|
# check if directory exists and is writable
|
||||||
if not os.path.isdir(self["args"]["directory"]) or \
|
if not os.path.isdir(self["args"]["directory"]) or \
|
||||||
@@ -264,7 +264,9 @@ class EMailNotification(BaseNotification):
|
|||||||
logger.debug("parsing email template")
|
logger.debug("parsing email template")
|
||||||
|
|
||||||
# generate dict containing all template variables
|
# generate dict containing all template variables
|
||||||
template_vars.update({
|
|
||||||
|
variables = defaultdict(str, template_vars)
|
||||||
|
variables.update({
|
||||||
"HTML_TEXT": sanitized_text,
|
"HTML_TEXT": sanitized_text,
|
||||||
"FROM": escape(msg["from"], quote=False),
|
"FROM": escape(msg["from"], quote=False),
|
||||||
"ENVELOPE_FROM": escape(mailfrom, quote=False),
|
"ENVELOPE_FROM": escape(mailfrom, quote=False),
|
||||||
@@ -276,7 +278,7 @@ class EMailNotification(BaseNotification):
|
|||||||
"SUBJECT": escape(msg["subject"], quote=False)})
|
"SUBJECT": escape(msg["subject"], quote=False)})
|
||||||
|
|
||||||
# parse template
|
# parse template
|
||||||
htmltext = self.template.format_map(template_vars)
|
htmltext = self.template.format_map(variables)
|
||||||
|
|
||||||
msg = MIMEMultipart('related')
|
msg = MIMEMultipart('related')
|
||||||
msg["From"] = self.from_header.format_map(
|
msg["From"] = self.from_header.format_map(
|
||||||
@@ -307,3 +309,11 @@ class EMailNotification(BaseNotification):
|
|||||||
mailer.sendmail(self.smtp_host, self.smtp_port, qid,
|
mailer.sendmail(self.smtp_host, self.smtp_port, qid,
|
||||||
self.mailfrom, recipient, msg.as_string(),
|
self.mailfrom, recipient, msg.as_string(),
|
||||||
"notification email")
|
"notification email")
|
||||||
|
|
||||||
|
def execute(self, milter, pretend=False,
|
||||||
|
logger=logging.getLogger(__name__)):
|
||||||
|
self.notify(msg=milter.msg, qid=milter.qid,
|
||||||
|
mailfrom=milter.msginfo["mailfrom"],
|
||||||
|
recipients=milter.msginfo["rcpts"],
|
||||||
|
template_vars=milter["msginfo"]["vars"],
|
||||||
|
logger=logger)
|
||||||
@@ -17,7 +17,7 @@ __all__ = [
|
|||||||
"Rule"]
|
"Rule"]
|
||||||
|
|
||||||
from pymodmilter import BaseConfig
|
from pymodmilter import BaseConfig
|
||||||
from pymodmilter.actions import ActionConfig, Action
|
from pymodmilter.action import ActionConfig, Action
|
||||||
from pymodmilter.conditions import ConditionsConfig, Conditions
|
from pymodmilter.conditions import ConditionsConfig, Conditions
|
||||||
|
|
||||||
|
|
||||||
@@ -134,10 +134,12 @@ class FileMailStorage(BaseMailStorage):
|
|||||||
recipients = list(milter.msginfo["rcpts"])
|
recipients = list(milter.msginfo["rcpts"])
|
||||||
subject = milter.msg["subject"] or ""
|
subject = milter.msg["subject"] or ""
|
||||||
|
|
||||||
|
if not pretend:
|
||||||
storage_id, datafile = self.add(
|
storage_id, datafile = self.add(
|
||||||
data(), milter.qid, mailfrom, recipients, subject)
|
data(), milter.qid, mailfrom, recipients, subject)
|
||||||
logger.info(f"stored message in file {datafile}")
|
logger.info(f"stored message in file {datafile}")
|
||||||
milter.msginfo["storage_id"] = storage_id
|
milter.msginfo["vars"]["STORAGEID"] = storage_id
|
||||||
|
milter.msginfo["vars"]["DATAFILE"] = datafile
|
||||||
|
|
||||||
def get_metadata(self, storage_id):
|
def get_metadata(self, storage_id):
|
||||||
"Return metadata of email in storage."
|
"Return metadata of email in storage."
|
||||||
Reference in New Issue
Block a user