improve CLI output

This commit is contained in:
2021-09-30 23:51:06 +02:00
parent 01ae131088
commit 6a242e7d02
4 changed files with 27 additions and 3 deletions

View File

@@ -96,15 +96,15 @@ def list_quarantines(quarantines, args):
else:
qlist = []
for q in quarantines:
storage_type = type(q.storage).__name__
storage_type = q.storage.type
if q.notification:
notification_type = type(q.notification).__name__
notification_type = q.notification.type
else:
notification_type = "NONE"
if q.whitelist:
whitelist_type = type(q.whitelist).__name__
whitelist_type = q.whitelist.type
else:
whitelist_type = "NONE"

View File

@@ -41,6 +41,10 @@ class BaseNotification:
def __init__(self, pretend=False):
self.pretend = pretend
@property
def type(self):
return "Base"
def execute(self, milter, logger):
return
@@ -143,6 +147,10 @@ class EMailNotification(BaseNotification):
self.parser_lib = parser_lib
@property
def type(self):
return "E-Mail"
def get_email_body_soup(self, msg, logger):
"Extract and decode email body and return it as BeautifulSoup object."
# try to find the body part

View File

@@ -47,6 +47,10 @@ class BaseMailStorage:
self.metavar = metavar
self.pretend = False
@property
def type(self):
return "Base"
def add(self, data, qid, mailfrom, recipients, subject, variables):
"Add email to storage."
return ("", "")
@@ -103,6 +107,10 @@ class FileMailStorage(BaseMailStorage):
cfg.append(f"original={self.original}")
return "FileMailStorage(" + ", ".join(cfg) + ")"
@property
def type(self):
return "File"
def get_storageid(self, qid):
timestamp = datetime.now().strftime("%Y%m%d%H%M%S")
return f"{timestamp}_{qid}"

View File

@@ -39,6 +39,10 @@ class WhitelistBase:
self.batv_regex = re.compile(
r"^prvs=[0-9]{4}[0-9A-Fa-f]{6}=(?P<LEFT_PART>.+?)@")
@property
def type(self):
return "Base"
def remove_batv(self, addr):
return self.batv_regex.sub(r"\g<LEFT_PART>", addr, count=1)
@@ -137,6 +141,10 @@ class DatabaseWhitelist(WhitelistBase):
cfg.append(f"{arg}={self.cfg[arg]}")
return "DatabaseWhitelist(" + ", ".join(cfg) + ")"
@property
def type(self):
return "DB"
def _entry_to_dict(self, entry):
result = {}
result[entry.id] = {