Selaa lähdekoodia

Fehlerberichte löschen

robert 1 vuosi sitten
vanhempi
commit
e155d30026
3 muutettua tiedostoa jossa 69 lisäystä ja 42 poistoa
  1. 1 1
      mailserver/blacklist.json
  2. 27 18
      mailserver/imap.py
  3. 41 23
      mailserver/whitelist.json

+ 1 - 1
mailserver/blacklist.json

@@ -1 +1 @@
-["Testnachricht", "Test message", "Abwesen", "Automatische Antwort", "Automatic reply", "Urlaub", "außer Haus", "nicht im Hause", "persönlich erreichbar", "krankheitsbedingt"]
+["Testnachricht", "Test message", "Abwesen", "Automatische Antwort", "Automatic reply", "Urlaub", "außer Haus", "nicht im Hause", "persönlich erreichbar", "krankheitsbedingt", "notifications@cognos.ibm.com"]

+ 27 - 18
mailserver/imap.py

@@ -4,12 +4,24 @@ import json
 import os
 import plac
 from datetime import datetime, date
+from dataclasses import dataclass
+
+
+@dataclass
+class ImapCredentials:
+    server: str
+    username: str
+    password: str
 
 
 class Imap:
     commands = ["cleanup", "move", "remove", "add_to_whitelist", "undelivered"]
     whitelist = {}
     blacklist = []
+    credentials = {
+        "archiv": ImapCredentials("mail.global-cube.com", "archiv", "Gc01am64!"),
+        "versand": ImapCredentials("mail.global-cube.com", "versand", "y6!avXX3tQvr"),
+    }
 
     def __init__(self):
         with open(os.path.dirname(__file__) + "/whitelist.json", "r") as frh:
@@ -17,12 +29,16 @@ class Imap:
         with open(os.path.dirname(__file__) + "/blacklist.json", "r") as frh:
             self.blacklist = json.load(frh)
 
+    def connect(self, key):
+        creds = self.credentials[key]
+        return MailBox(creds.server).login(creds.username, creds.password)
+
     def cleanup(self):
         date_now = datetime.now()
         date_criteria = date(date_now.year, date_now.month - 1, 1)
         msg_limit = 100
 
-        with MailBox("mail.global-cube.com").login("archiv", "Gc01am64!") as mb:
+        with self.connect("archiv") as mb:
             folder_list = [f.name for f in mb.folder.list() if "Archive." in f.name]
 
             for folder in folder_list:
@@ -39,16 +55,16 @@ class Imap:
                     mb.delete(uids[0 : (msg_count - msg_limit)])
 
     def move(self):
-        with MailBox("mail.global-cube.com").login("archiv", "Gc01am64!") as mb:
+        with self.connect("archiv") as mb:
             messages = mb.fetch(
-                criteria=AND(from_="@global-cube.com"),
-                mark_seen=True,
-                bulk=True,
-                limit=1000,
-                headers_only=True,
+                criteria=AND(from_="@global-cube.com"), mark_seen=True, bulk=True, limit=1000, headers_only=True
             )
 
             for msg in messages:
+                if msg.subject.count(";") > 3:
+                    # statusmail
+                    mb.delete([msg.uid])
+                    continue
                 match = re.findall(r"\+(.*)@", msg.from_)
                 if not match:
                     # print(msg.from_, msg.to, msg.subject)
@@ -79,14 +95,10 @@ class Imap:
         return True
 
     def add_to_whitelist(self):
-        with MailBox("mail.global-cube.com").login("archiv", "Gc01am64!") as mb:
+        with self.connect("archiv") as mb:
             mb.folder.set("whitelist")
             messages = mb.fetch(
-                criteria=AND(from_="@global-cube.com"),
-                mark_seen=True,
-                bulk=True,
-                limit=1000,
-                headers_only=True,
+                criteria=AND(from_="@global-cube.com"), mark_seen=True, bulk=True, limit=1000, headers_only=True
             )
 
             for msg in messages:
@@ -108,12 +120,9 @@ class Imap:
             mb.delete(uids)
 
     def remove_absence_messages(self):
-        with MailBox("mail.global-cube.com").login("versand", "y6!avXX3tQvr") as mb:
+        with self.connect("versand") as mb:
             messages = mb.fetch(
-                criteria=AND(to="@global-cube.com"),
-                mark_seen=False,
-                bulk=True,
-                limit=1000,
+                criteria=AND(to="@global-cube.com"), mark_seen=False, bulk=True, limit=1000, headers_only=True
             )
             selected = []
             for msg in messages:

+ 41 - 23
mailserver/whitelist.json

@@ -1,25 +1,43 @@
 {
-    "@auto-greiner.de": [
-        "@opel-greiner.de"
-    ],
-    "@autohaus-berkemeier.de": [
-        "@auto-berkemeier.de"
-    ],
-    "@mvcmotors.at": [
-        "@mvcautomotive.com"
-    ],
-    "@opel-thomas.de": [
-        "info@auto-steinhaeusser.de",
-        "info@opel-weber.com",
-        "auto-wabner@t-online.de"
-    ],
-    "@autohaus-rueschkamp.de": [
-        "j.rueschkamp@gmail.com"
-    ],
-    "@hedtke.de": [
-        "holger.hedtke@heicosportiv.de"
-    ],
-    "@opel-gerds-grimmen.de": [
-        "verkauf@opel-gerds.de"
-    ]
+  "@auto-greiner.de": [
+    "@opel-greiner.de"
+  ],
+  "@autohaus-berkemeier.de": [
+    "@auto-berkemeier.de"
+  ],
+  "@mvcmotors.at": [
+    "@mvcautomotive.com"
+  ],
+  "@opel-thomas.de": [
+    "info@auto-steinhaeusser.de",
+    "info@opel-weber.com",
+    "auto-wabner@t-online.de",
+    "kai.schultheiss@scharf-automobile.de"
+  ],
+  "@autohaus-rueschkamp.de": [
+    "j.rueschkamp@gmail.com"
+  ],
+  "@hedtke.de": [
+    "holger.hedtke@heicosportiv.de"
+  ],
+  "@opel-gerds-grimmen.de": [
+    "verkauf@opel-gerds.de"
+  ],
+  "@dresen.de": [
+    "niko.fardis@dahlmann-autovermietung.de"
+  ],
+  "@renault-mueller-freising.de": [
+    "bb@ahm.gmbh",
+    "betriebsleiter@ahm.gmbh"
+  ],
+  "@auto-schmid-gmbh.de": [
+    "m.schaefer@autoschmidgmbh.de"
+  ],
+  "@bmw-schmidt.com": [
+    "robert.mueller@rolls-roycemotorcars-muenchen.de",
+    "sascha.schiwon@rolls-roycemotorcars-muenchen.de"
+  ],
+  "@liegert.de": [
+    "dahlhauser@boesken.eu"
+  ]
 }