diff --git a/integrations/mailinblack/manifest.yaml b/integrations/mailinblack/manifest.yaml new file mode 100644 index 0000000..c21ece8 --- /dev/null +++ b/integrations/mailinblack/manifest.yaml @@ -0,0 +1,65 @@ +id: mailinblack +name: Mailinblack +version: 1.0.0 +description: "Mailinblack (email protection API) — anti-phishing operations: list quarantined messages, release a message, and manage sender allow/block lists. Bearer-token authentication; stdlib-only, no extra Python dependencies. (French vendor. NOTE: exact API paths are best-effort — verify against the Mailinblack API documentation before production use.)" +changelog: "1.0.0 — Initial release: list quarantine, release message, block/allow sender." +category: email + +# Per-instance configuration. Auth header 'Authorization: Bearer '. +config_schema: + properties: + base_url: + type: string + description: "Mailinblack API base URL" + api_token: + type: string + description: "API token" + x-soar-sensitive: true + required: + - base_url + - api_token + +commands: + - id: list_quarantine + name: mailinblack-list-quarantine + description: "List quarantined messages." + risk: read + inputs_schema: + properties: + recipient: { type: string, description: "Optional recipient filter" } + limit: { type: number, description: "Max messages (default 25)" } + required: [] + outputs_schema: { properties: {} } + - id: release_message + name: mailinblack-release-message + description: "Release a quarantined message for delivery." + inputs_schema: + properties: + message_id: { type: string, description: "Message ID" } + required: [message_id] + outputs_schema: { properties: {} } + - id: block_sender + name: mailinblack-block-sender + description: "Add a sender to the block list." + inputs_schema: + properties: + sender: { type: string, description: "Sender address to block" } + required: [sender] + outputs_schema: { properties: {} } + - id: allow_sender + name: mailinblack-allow-sender + description: "Add a sender to the allow list." + inputs_schema: + properties: + sender: { type: string, description: "Sender address to allow" } + required: [sender] + outputs_schema: { properties: {} } + + - id: test_connection + name: mailinblack-test-connection + description: "Verify the API token (used by the Test button)." + risk: read + inputs_schema: + properties: {} + required: [] + outputs_schema: { properties: {} } diff --git a/integrations/mailinblack/scripts/allow_sender.py b/integrations/mailinblack/scripts/allow_sender.py new file mode 100644 index 0000000..7da0b27 --- /dev/null +++ b/integrations/mailinblack/scripts/allow_sender.py @@ -0,0 +1,49 @@ +import json, os, sys, urllib.parse, urllib.request, urllib.error + + +def _cfg(): + return json.loads(os.environ.get("INTEGRATION_SECRETS", "{}")) + + +def _inputs(): + return json.loads(os.environ.get("INTEGRATION_INPUTS", "{}")) + + +def request(method, path, cfg, body=None, params=None): + url = str(cfg.get("base_url", "")).rstrip("/") + path + if params: + clean = {k: v for k, v in params.items() if v not in (None, "")} + if clean: + url += "?" + urllib.parse.urlencode(clean) + data = json.dumps(body).encode("utf-8") if body is not None else None + headers = {"Authorization": "Bearer " + str(cfg.get("api_token", "")), "Accept": "application/json"} + if data is not None: + headers["Content-Type"] = "application/json" + req = urllib.request.Request(url, data=data, headers=headers, method=method) + with urllib.request.urlopen(req, timeout=60) as r: + raw = r.read() + return json.loads(raw) if raw else {} + + +def _run(fn): + try: + print(json.dumps(fn(_cfg(), _inputs()))) + except urllib.error.HTTPError as e: + print(json.dumps({"error": "HTTP " + str(e.code), "detail": e.read().decode("utf-8", "replace")})) + sys.exit(1) + except Exception as e: + print(json.dumps({"error": str(e)})) + sys.exit(1) + + +def main(cfg, inputs): + sender = inputs.get("sender") + if not sender: + raise Exception("sender is required") + result = request("POST", "/senders/allow", cfg, body={"sender": sender}) + if not result: + return {"ok": True, "sender": sender, "action": "allow"} + return result + + +_run(main) diff --git a/integrations/mailinblack/scripts/block_sender.py b/integrations/mailinblack/scripts/block_sender.py new file mode 100644 index 0000000..952602c --- /dev/null +++ b/integrations/mailinblack/scripts/block_sender.py @@ -0,0 +1,49 @@ +import json, os, sys, urllib.parse, urllib.request, urllib.error + + +def _cfg(): + return json.loads(os.environ.get("INTEGRATION_SECRETS", "{}")) + + +def _inputs(): + return json.loads(os.environ.get("INTEGRATION_INPUTS", "{}")) + + +def request(method, path, cfg, body=None, params=None): + url = str(cfg.get("base_url", "")).rstrip("/") + path + if params: + clean = {k: v for k, v in params.items() if v not in (None, "")} + if clean: + url += "?" + urllib.parse.urlencode(clean) + data = json.dumps(body).encode("utf-8") if body is not None else None + headers = {"Authorization": "Bearer " + str(cfg.get("api_token", "")), "Accept": "application/json"} + if data is not None: + headers["Content-Type"] = "application/json" + req = urllib.request.Request(url, data=data, headers=headers, method=method) + with urllib.request.urlopen(req, timeout=60) as r: + raw = r.read() + return json.loads(raw) if raw else {} + + +def _run(fn): + try: + print(json.dumps(fn(_cfg(), _inputs()))) + except urllib.error.HTTPError as e: + print(json.dumps({"error": "HTTP " + str(e.code), "detail": e.read().decode("utf-8", "replace")})) + sys.exit(1) + except Exception as e: + print(json.dumps({"error": str(e)})) + sys.exit(1) + + +def main(cfg, inputs): + sender = inputs.get("sender") + if not sender: + raise Exception("sender is required") + result = request("POST", "/senders/block", cfg, body={"sender": sender}) + if not result: + return {"ok": True, "sender": sender, "action": "block"} + return result + + +_run(main) diff --git a/integrations/mailinblack/scripts/list_quarantine.py b/integrations/mailinblack/scripts/list_quarantine.py new file mode 100644 index 0000000..3e3632e --- /dev/null +++ b/integrations/mailinblack/scripts/list_quarantine.py @@ -0,0 +1,46 @@ +import json, os, sys, urllib.parse, urllib.request, urllib.error + + +def _cfg(): + return json.loads(os.environ.get("INTEGRATION_SECRETS", "{}")) + + +def _inputs(): + return json.loads(os.environ.get("INTEGRATION_INPUTS", "{}")) + + +def request(method, path, cfg, body=None, params=None): + url = str(cfg.get("base_url", "")).rstrip("/") + path + if params: + clean = {k: v for k, v in params.items() if v not in (None, "")} + if clean: + url += "?" + urllib.parse.urlencode(clean) + data = json.dumps(body).encode("utf-8") if body is not None else None + headers = {"Authorization": "Bearer " + str(cfg.get("api_token", "")), "Accept": "application/json"} + if data is not None: + headers["Content-Type"] = "application/json" + req = urllib.request.Request(url, data=data, headers=headers, method=method) + with urllib.request.urlopen(req, timeout=60) as r: + raw = r.read() + return json.loads(raw) if raw else {} + + +def _run(fn): + try: + print(json.dumps(fn(_cfg(), _inputs()))) + except urllib.error.HTTPError as e: + print(json.dumps({"error": "HTTP " + str(e.code), "detail": e.read().decode("utf-8", "replace")})) + sys.exit(1) + except Exception as e: + print(json.dumps({"error": str(e)})) + sys.exit(1) + + +def main(cfg, inputs): + recipient = inputs.get("recipient") + limit = inputs.get("limit") + limit = int(limit) if limit not in (None, "") else 25 + return request("GET", "/quarantine", cfg, params={"recipient": recipient, "limit": limit}) + + +_run(main) diff --git a/integrations/mailinblack/scripts/release_message.py b/integrations/mailinblack/scripts/release_message.py new file mode 100644 index 0000000..fa68376 --- /dev/null +++ b/integrations/mailinblack/scripts/release_message.py @@ -0,0 +1,52 @@ +import json, os, sys, urllib.parse, urllib.request, urllib.error + + +def _cfg(): + return json.loads(os.environ.get("INTEGRATION_SECRETS", "{}")) + + +def _inputs(): + return json.loads(os.environ.get("INTEGRATION_INPUTS", "{}")) + + +def request(method, path, cfg, body=None, params=None): + url = str(cfg.get("base_url", "")).rstrip("/") + path + if params: + clean = {k: v for k, v in params.items() if v not in (None, "")} + if clean: + url += "?" + urllib.parse.urlencode(clean) + data = json.dumps(body).encode("utf-8") if body is not None else None + headers = {"Authorization": "Bearer " + str(cfg.get("api_token", "")), "Accept": "application/json"} + if data is not None: + headers["Content-Type"] = "application/json" + req = urllib.request.Request(url, data=data, headers=headers, method=method) + with urllib.request.urlopen(req, timeout=60) as r: + raw = r.read() + return json.loads(raw) if raw else {} + + +def _run(fn): + try: + print(json.dumps(fn(_cfg(), _inputs()))) + except urllib.error.HTTPError as e: + print(json.dumps({"error": "HTTP " + str(e.code), "detail": e.read().decode("utf-8", "replace")})) + sys.exit(1) + except Exception as e: + print(json.dumps({"error": str(e)})) + sys.exit(1) + + +q = lambda v: urllib.parse.quote(str(v), safe="") + + +def main(cfg, inputs): + message_id = inputs.get("message_id") + if not message_id: + raise Exception("message_id is required") + result = request("POST", "/quarantine/" + q(message_id) + "/release", cfg, body={}) + if not result: + return {"ok": True, "message_id": message_id, "action": "release"} + return result + + +_run(main) diff --git a/integrations/mailinblack/scripts/test_connection.py b/integrations/mailinblack/scripts/test_connection.py new file mode 100644 index 0000000..9ea581d --- /dev/null +++ b/integrations/mailinblack/scripts/test_connection.py @@ -0,0 +1,44 @@ +import json, os, sys, urllib.parse, urllib.request, urllib.error + + +def _cfg(): + return json.loads(os.environ.get("INTEGRATION_SECRETS", "{}")) + + +def _inputs(): + return json.loads(os.environ.get("INTEGRATION_INPUTS", "{}")) + + +def request(method, path, cfg, body=None, params=None): + url = str(cfg.get("base_url", "")).rstrip("/") + path + if params: + clean = {k: v for k, v in params.items() if v not in (None, "")} + if clean: + url += "?" + urllib.parse.urlencode(clean) + data = json.dumps(body).encode("utf-8") if body is not None else None + headers = {"Authorization": "Bearer " + str(cfg.get("api_token", "")), "Accept": "application/json"} + if data is not None: + headers["Content-Type"] = "application/json" + req = urllib.request.Request(url, data=data, headers=headers, method=method) + with urllib.request.urlopen(req, timeout=60) as r: + raw = r.read() + return json.loads(raw) if raw else {} + + +def _run(fn): + try: + print(json.dumps(fn(_cfg(), _inputs()))) + except urllib.error.HTTPError as e: + print(json.dumps({"error": "HTTP " + str(e.code), "detail": e.read().decode("utf-8", "replace")})) + sys.exit(1) + except Exception as e: + print(json.dumps({"error": str(e)})) + sys.exit(1) + + +def main(cfg, inputs): + request("GET", "/quarantine", cfg, params={"limit": 1}) + return {"ok": True} + + +_run(main)