Revert "Beta Mail Parser Add inline images as attachments keeps the DB clean"

This reverts commit 87fd23f443.
This commit is contained in:
johnnyq
2026-02-26 16:41:03 -05:00
parent 87fd23f443
commit 04a74b5a34

View File

@@ -722,47 +722,31 @@ foreach ($messages as $message) {
// ignore inline replacement errors // ignore inline replacement errors
} }
// Attachments (inline CID replacement + collect non-inline) // Collect non-inline attachments from the high-level Attachment API
$attachments = [];
$inline_cids = [];
try { try {
foreach ($message->attachments() as $att) { foreach ($message->attachments() as $att) {
$name = $att->filename() ?: 'attachment'; if (!$att) continue;
$content = (string)$att->contents();
$cid = $att->contentId(); // Content-ID for inline parts
$mime = (string)($att->contentType() ?: 'application/octet-stream');
// If it has a CID, attempt to inline it into the HTML body $name = $att->filename() ?: 'attachment';
if (!empty($cid) && !empty($message_body)) { $content = $att->contents();
$cid_trim = trim((string)$cid, "<> \t\r\n"); $cid = null;
try { $cid = $att->contentId(); } catch (\Throwable $e) { $cid = null; }
$cid_trim = $cid ? trim((string)$cid, "<> \t\r\n") : null;
// Only inline if the body actually references it (prevents incorrectly hiding real attachments) // Skip inline ones we already embedded
// Covers: src="cid:abc", src="cid:<abc>", etc. if ($cid_trim && isset($inline_cids[$cid_trim])) {
if ($cid_trim !== '' && preg_match('/cid:\s*<?' . preg_quote($cid_trim, '/') . '>?/i', $message_body)) { continue;
$dataUri = "data:$mime;base64," . base64_encode($content);
$message_body = str_replace(
["cid:$cid_trim", "cid:<$cid_trim>", "cid:$cid"],
$dataUri,
$message_body
);
$inline_cids[$cid_trim] = true;
continue; // don't save as a ticket attachment
}
} }
// Otherwise treat it as a normal attachment if ($content !== null && $content !== '') {
if ($content !== '') {
$attachments[] = [ $attachments[] = [
'name' => $name, 'name' => $name,
'content' => $content 'content' => $content,
]; ];
} }
} }
} catch (\Throwable $e) { } catch (\Throwable $e) {
// ignore attachment parse errors // ignore
} }
// 1. Reply to existing ticket with the number in subject // 1. Reply to existing ticket with the number in subject