Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix text/x-mail issue and quarantine operations #1306

Merged
merged 2 commits into from
Sep 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion mailscanner/do_message_ops.php
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,10 @@
echo '<td class="error">' . $items . '</td>' . "\n";
} else {
if (count($items) > 0) {
$num = 0;
// Originally this was 0, which assumed entire message was first item
// Now pass -1, which will inform quarantine_release and quarantine_learn
// to scan for entire message regardless of its position in the items list
$num = -1;
$itemnum = [$num];
echo '<td>';
if ('release' === $type) {
Expand Down
32 changes: 31 additions & 1 deletion mailscanner/functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -3528,7 +3528,12 @@ function quarantine_list_items($msgid, $rpc_only = false)
$quarantined[$count]['to'] = $row->to_address;
$quarantined[$count]['file'] = $f;
$file = escapeshellarg($quarantine . '/' . $f);
$quarantined[$count]['type'] = ltrim(rtrim(shell_exec('/usr/bin/file -bi ' . $file)));
$type = ltrim(rtrim(shell_exec('/usr/bin/file -bi ' . $file)));
// In some cases file returns text/x-mail instead of message/rfc822
if (preg_match('!^text/x-mail!', $type)) {
$type = 'message/rfc822';
}
$quarantined[$count]['type'] = $type;
$quarantined[$count]['path'] = $quarantine . '/' . $f;
$quarantined[$count]['md5'] = md5($quarantine . '/' . $f);
$quarantined[$count]['dangerous'] = $infected;
Expand Down Expand Up @@ -3576,6 +3581,18 @@ function quarantine_release($list, $num, $to, $rpc_only = false)
$new = quarantine_list_items($list[0]['msgid']);
$list = &$new;

// Check for [-1], indicating just to release message itself, regardless of its item position
if ($num[0] === -1) {
$num = [0];
// Locate message in items
for ($index=0;$index<count($list);$index++) {
if (preg_match('/message\/rfc822/', $list[$index]['type'])) {
$num = [$index];
break;
}
}
}

if (!$rpc_only && is_local($list[0]['host'])) {
if (!QUARANTINE_USE_SENDMAIL) {
// Load in the required PEAR modules
Expand Down Expand Up @@ -3698,6 +3715,19 @@ function quarantine_learn($list, $num, $type, $rpc_only = false)
}
$new = quarantine_list_items($list[0]['msgid']);
$list = &$new;

// Check for [-1], indicating just to release message itself, regardless of its item position
if ($num[0] === -1) {
$num = [0];
// Locate message in items
for ($index=0;$index<count($list);$index++) {
if (preg_match('/message\/rfc822/', $list[$index]['type'])) {
$num = [$index];
break;
}
}
}

$status = [];
if (!$rpc_only && is_local($list[0]['host'])) {
// prevent sa-learn process blocking complete apache server
Expand Down