query('SELECT department_id FROM imap_accounts WHERE department_id IS NOT NULL')->fetchAll(PDO::FETCH_COLUMN))); $priorities = $pdo->query('SELECT * FROM priorities ORDER BY sort_order')->fetchAll(); if ($_SERVER['REQUEST_METHOD'] === 'POST') { verify_csrf(); $action = $_POST['action'] ?? ''; if ($action === 'create' || $action === 'update') { $label = trim($_POST['label'] ?? '') ?: 'Postfach'; $host = trim($_POST['host'] ?? ''); $port = (int) ($_POST['port'] ?? 993) ?: 993; $enc = in_array($_POST['encryption'] ?? 'ssl', ['ssl','tls','none'], true) ? $_POST['encryption'] : 'ssl'; $username = trim($_POST['username'] ?? ''); $folder = trim($_POST['folder'] ?? '') ?: 'INBOX'; $afterFetch = in_array($_POST['after_fetch'] ?? 'seen', ['seen','archive','delete'], true) ? $_POST['after_fetch'] : 'seen'; $archiveFolder = trim($_POST['archive_folder'] ?? '') ?: 'Processed'; $spamFolder = trim($_POST['spam_folder'] ?? '') ?: 'Junk'; $deptId = $_POST['department_id'] !== '' ? (int) $_POST['department_id'] : null; $prioId = $_POST['priority_id'] !== '' ? (int) $_POST['priority_id'] : null; $isActive = !empty($_POST['is_active']) ? 1 : 0; $plainPass = trim($_POST['password'] ?? ''); if ($host === '') $errors[] = 'Bitte einen Server (Host) angeben.'; if ($username === '') $errors[] = 'Bitte einen Benutzernamen angeben.'; if ($action === 'create' && $plainPass === '') $errors[] = 'Bitte ein Passwort angeben.'; if (!$errors) { if ($action === 'create') { $pdo->prepare( 'INSERT INTO imap_accounts (label, host, port, encryption, username, password_enc, folder, after_fetch, archive_folder, spam_folder, department_id, priority_id, is_active, created_at) VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?)' )->execute([ $label, $host, $port, $enc, $username, encrypt_secret($plainPass), $folder, $afterFetch, $archiveFolder, $spamFolder, $deptId, $prioId, $isActive, db_now(), ]); audit_log($staff['id'], "IMAP-Postfach angelegt: {$label} ({$host})"); flash('success', 'Postfach angelegt.'); } else { $id = (int) $_POST['id']; if ($plainPass !== '') { $pdo->prepare( 'UPDATE imap_accounts SET label=?, host=?, port=?, encryption=?, username=?, password_enc=?, folder=?, after_fetch=?, archive_folder=?, spam_folder=?, department_id=?, priority_id=?, is_active=? WHERE id=?' )->execute([$label, $host, $port, $enc, $username, encrypt_secret($plainPass), $folder, $afterFetch, $archiveFolder, $spamFolder, $deptId, $prioId, $isActive, $id]); } else { // Passwort leer = unverändert lassen $pdo->prepare( 'UPDATE imap_accounts SET label=?, host=?, port=?, encryption=?, username=?, folder=?, after_fetch=?, archive_folder=?, spam_folder=?, department_id=?, priority_id=?, is_active=? WHERE id=?' )->execute([$label, $host, $port, $enc, $username, $folder, $afterFetch, $archiveFolder, $spamFolder, $deptId, $prioId, $isActive, $id]); } audit_log($staff['id'], "IMAP-Postfach aktualisiert: {$label} ({$host})"); flash('success', 'Postfach gespeichert.'); } redirect('/staff/imap_accounts.php'); } } if ($action === 'delete') { $id = (int) $_POST['id']; $lblStmt = $pdo->prepare('SELECT label FROM imap_accounts WHERE id = ?'); $lblStmt->execute([$id]); $lbl = $lblStmt->fetchColumn(); $pdo->prepare('DELETE FROM imap_accounts WHERE id = ?')->execute([$id]); audit_log($staff['id'], "IMAP-Postfach gelöscht: {$lbl}"); flash('success', 'Postfach gelöscht.'); redirect('/staff/imap_accounts.php'); } if ($action === 'test') { $id = (int) $_POST['id']; $stmt = $pdo->prepare('SELECT * FROM imap_accounts WHERE id = ?'); $stmt->execute([$id]); $acc = $stmt->fetch(); if (!$acc) { flash('error', 'Postfach nicht gefunden.'); } elseif (!function_exists('imap_open')) { flash('error', 'PHP-IMAP-Erweiterung (php-imap) ist auf diesem Server nicht installiert.'); } else { $sslFlag = match ($acc['encryption']) { 'ssl' => '/imap/ssl', 'tls' => '/imap/tls', default => '/imap/notls', }; $mailbox = '{' . $acc['host'] . ':' . $acc['port'] . $sslFlag . '}' . $acc['folder']; $mbox = @imap_open($mailbox, $acc['username'], decrypt_secret($acc['password_enc']), 0, 1); if ($mbox) { $unseen = imap_search($mbox, 'UNSEEN') ?: []; imap_close($mbox); flash('success', "Verbindung zu „{$acc['label']}" . "\" erfolgreich. " . count($unseen) . ' ungelesene Mail(s) im Postfach.'); } else { flash('error', "Verbindung zu „{$acc['label']}\" fehlgeschlagen: " . imap_last_error()); } } redirect('/staff/imap_accounts.php'); } } $accounts = $pdo->query( 'SELECT ia.*, d.name AS department_name, p.name AS priority_name FROM imap_accounts ia LEFT JOIN departments d ON d.id = ia.department_id LEFT JOIN priorities p ON p.id = ia.priority_id WHERE ia.email_address_id IS NULL ORDER BY ia.id' )->fetchAll(); $editId = $_GET['edit'] ?? null; $editAcc = null; if ($editId) { $stmt = $pdo->prepare('SELECT * FROM imap_accounts WHERE id = ?'); $stmt->execute([$editId]); $editAcc = $stmt->fetch(); } $pageTitle = 'Postfächer (E-Mail-Abruf)'; $activePage = 'imap_accounts'; require __DIR__ . '/_header.php'; ?>
Postfächer werden jetzt direkt bei der jeweiligen E-Mail-Adresse im Reiter „Entferntes Postfach“ eingerichtet. Diese Seite zeigt nur noch ältere, nicht verknüpfte Postfächer.

Postfächer für den E-Mail-Abruf

Jedes Postfach wird beim Abruf (Cronjob fetch_emails.php) einzeln per IMAP abgefragt. Nutzt ihr getrennte Mail-Konten pro Abteilung (statt eines Sammelpostfachs mit Weiterleitungen), legt hier einfach für jede Abteilung ein eigenes Postfach an und wählt die passende Standardabteilung – die Abteilungs-Routing-Tabelle per Empfängeradresse ist dann optional und greift nur noch zusätzlich, falls ein einzelnes Postfach doch Mails für mehrere Abteilungen empfängt.

PostfachServerStandardabteilungAktivLetzter Abruf

:
· Bearbeiten ·
Noch kein Postfach angelegt.

Wird verwendet, wenn ein eingegangenes E-Mail-Ticket als Spam markiert wird.