[Postfix][Rspamd] Send archive copies as SMTP journal through Postfix

This commit is contained in:
FreddleSpl0it committed 2026-11-07 00:27:42 +01:00
1 parent fc56d53029
commit fb85a9eb5c
9 files changed
+311 -4

No files matched your search

+47
View File
@@ -0,0 +1,47 @@
<?php
// Archive decision for an accepted mail, asked by the MAILCOW_ARCHIVE symbol of rspamd
// Request: JSON {from, rcpt[], user, bcc, qid, received, sha256}; answer: JSON {archive, rcpt, sender, headers}
header('Content-Type: application/json');
require_once "vars.inc.php";
require_once __DIR__ . '/../web/inc/lib/vendor/autoload.php';
// Do not show errors, we log to using error_log
ini_set('error_reporting', 0);
// Init database
$dsn = $database_type . ":unix_socket=" . $database_sock . ";dbname=" . $database_name;
$opt = [
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC,
PDO::ATTR_EMULATE_PREPARES => false,
];
try {
$pdo = new PDO($dsn, $database_user, $database_pass, $opt);
}
catch (PDOException $e) {
error_log("ARCHIVE: " . $e . PHP_EOL);
http_response_code(501);
exit;
}
// Init Redis, only to mirror the switch rspamd reads
$redis = new Redis();
try {
$redis->connect('redis-mailcow', 6379);
$redis->auth(getenv("REDISPASS"));
}
catch (Exception $e) {
$redis = null;
}
$request = json_decode(file_get_contents('php://input'), true);
if (!is_array($request)) {
http_response_code(400);
exit;
}
try {
$archive = \Mailcow\Archive\ArchiveModule::create($pdo, \Mailcow\Core\Context::system(), $redis);
echo json_encode($archive->journal->prepare($request));
}
catch (Throwable $e) {
error_log("ARCHIVE: " . $e->getMessage() . PHP_EOL);
http_response_code(502);
}