diff --git a/pyquarantine/cli.py b/pyquarantine/cli.py index 28f6029..f4695a3 100644 --- a/pyquarantine/cli.py +++ b/pyquarantine/cli.py @@ -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" diff --git a/pyquarantine/notify.py b/pyquarantine/notify.py index 9eb35ba..8bf681f 100644 --- a/pyquarantine/notify.py +++ b/pyquarantine/notify.py @@ -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 diff --git a/pyquarantine/storage.py b/pyquarantine/storage.py index d1b333c..e6c43ad 100644 --- a/pyquarantine/storage.py +++ b/pyquarantine/storage.py @@ -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}" diff --git a/pyquarantine/whitelist.py b/pyquarantine/whitelist.py index 34a923a..23b892d 100644 --- a/pyquarantine/whitelist.py +++ b/pyquarantine/whitelist.py @@ -39,6 +39,10 @@ class WhitelistBase: self.batv_regex = re.compile( r"^prvs=[0-9]{4}[0-9A-Fa-f]{6}=(?P.+?)@") + @property + def type(self): + return "Base" + def remove_batv(self, addr): return self.batv_regex.sub(r"\g", 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] = {