Skip to content

Commit

Permalink
Merge pull request #1306 from shawniverson/090124fix
Browse files Browse the repository at this point in the history
Fix text/x-mail issue and quarantine operations
  • Loading branch information
endelwar authored Sep 5, 2024
2 parents ae0d5d1 + 7006c78 commit 3272c67
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 2 deletions.
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

0 comments on commit 3272c67

Please sign in to comment.