Navigation Menu

Skip to content

Commit

Permalink
Provides administrator the ability to combine quarantine reports into…
Browse files Browse the repository at this point in the history
… a single report (#640)

Provides administrator the ability to combine quarantine reports into a single report when used with user filters

New constant QUARANTINE_FILTERS_COMBINED

Fixes #608
  • Loading branch information
asuweb authored and endelwar committed Mar 16, 2017
1 parent 0e9cc00 commit 589155b
Show file tree
Hide file tree
Showing 4 changed files with 77 additions and 12 deletions.
2 changes: 1 addition & 1 deletion mailscanner/auto-release.php
Expand Up @@ -91,7 +91,7 @@
<div class="autorelease">
<img src="<?php echo MAILWATCH_HOSTURL . IMAGES_DIR . MW_LOGO; ?>" alt="<?php echo __('mwlogo99'); ?>">
<div class="border-rounded">
<h1><?php echo __('title63'); ?></h1>
<h1><?php echo __('title59'); ?></h1>
<?php
foreach ($output as $msg) {
echo '<p>' . $msg . '</p>';
Expand Down
2 changes: 2 additions & 0 deletions mailscanner/conf.php.example
Expand Up @@ -156,6 +156,8 @@ define('MAILWATCH_HOSTURL', 'http://' . rtrim(gethostname()) . '/mailscanner');
// the clean.quarantine script provided with MailScanner.
define('QUARANTINE_USE_FLAG', true);
define('QUARANTINE_DAYS_TO_KEEP', 30);
//Set QUARANTINE_FILTERS_COMBINED to true to combine quarantine report into a single report when user filters are present
define('QUARANTINE_FILTERS_COMBINED', false);
define('QUARANTINE_REPORT_FROM_NAME', 'MailWatch for MailScanner');
define('QUARANTINE_REPORT_SUBJECT', 'Message Quarantine Report');
define('QUARANTINE_SUBJECT', 'Message released from quarantine');
Expand Down
1 change: 1 addition & 0 deletions mailscanner/functions.php
Expand Up @@ -3969,6 +3969,7 @@ function checkConfVariables()
'PROXY_TYPE',
'PROXY_USER',
'QUARANTINE_DAYS_TO_KEEP',
'QUARANTINE_FILTERS_COMBINED',
'QUARANTINE_MSG_BODY',
'QUARANTINE_REPORT_DAYS',
'QUARANTINE_REPORT_FROM_NAME',
Expand Down
84 changes: 73 additions & 11 deletions tools/Cron_jobs/mailwatch_quarantine_report.php
Expand Up @@ -50,7 +50,8 @@
'SUBJECT_MAXLEN',
'TIME_ZONE',
'DATE_FORMAT',
'TIME_FORMAT'
'TIME_FORMAT',
'QUARANTINE_FILTERS_COMBINED'
);
$required_constant_missing_count = 0;
foreach ($required_constant as $constant) {
Expand Down Expand Up @@ -178,6 +179,7 @@
SELECT DISTINCT
a.id AS id,
DATE_FORMAT(timestamp,'" . str_replace('%', '%%', DATE_FORMAT) . ' <br/>' . str_replace('%', '%%', TIME_FORMAT) . "') AS datetime,
a.timestamp AS timestamp,
a.to_address AS to_address,
a.from_address AS from_address,
a.subject AS subject,
Expand All @@ -201,8 +203,7 @@
maillog a
WHERE
a.quarantined = 1
AND
((to_address=%s) OR (to_domain=%s))
AND ((to_address =%s) OR (to_domain =%s))
AND
a.date >= DATE_SUB(CURRENT_DATE(), INTERVAL " . QUARANTINE_REPORT_DAYS . ' DAY)';

Expand Down Expand Up @@ -288,14 +289,60 @@
if (!empty($email) && false !== $email) {
dbg(" ==== Recipient e-mail address is $email");
// Get any additional reports required
$filters = array_merge(array($email), return_user_filters($user->username));
foreach ($filters as $filter) {
dbg(" ==== Building list for $filter");
$quarantined = return_quarantine_list_array($filter, $to_domain);
dbg(' ==== Found ' . count($quarantined) . ' quarantined e-mails');
//print_r($quarantined);
$filters = array_merge(array($to_address), return_user_filters($user->username));
if (false === QUARANTINE_FILTERS_COMBINED) {
foreach ($filters as $filter) {
if ($user->type === 'D') {
if (preg_match('/(\S+)@(\S+)/', $filter, $split)) {
$filter_domain = $split[2];
} else {
$filter_domain = $filter;
}
dbg(" ==== Building list for $filter_domain");
$quarantined = return_quarantine_list_array($filter, $filter_domain);
} else {
dbg(" ==== Building list for $filter");
$quarantined = return_quarantine_list_array($filter, $to_domain);
}
dbg(' ==== Found ' . count($quarantined) . ' quarantined e-mails');
//print_r($quarantined);
if (count($quarantined) > 0) {
if ($user->type === 'D') {
send_quarantine_email($email, $filter_domain, $quarantined);
} else {
send_quarantine_email($email, $filter, $quarantined);
}
}
unset($quarantined);
}
} else {
//combined
$quarantine_list = array();
foreach ($filters as $filter) {
if ($user->type === 'D') {
if (preg_match('/(\S+)@(\S+)/', $filter, $split)) {
$filter_domain = $split[2];
} else {
$filter_domain = $filter;
}
$quarantine_list[] = $filter_domain;
dbg(" ==== Building list for $filter_domain");
$tmp_quarantined = return_quarantine_list_array($filter, $filter_domain);
} else {
$quarantine_list[] = $filter;
dbg(" ==== Building list for $filter");
$tmp_quarantined = return_quarantine_list_array($filter, $to_domain);
}
dbg(' ==== Found ' . count($tmp_quarantined) . ' quarantined e-mails');
if (isset($quarantined) && is_array($quarantined)) {
$quarantined = array_merge($quarantined, $tmp_quarantined);
} else {
$quarantined = $tmp_quarantined;
}
}
if (count($quarantined) > 0) {
send_quarantine_email($email, $filter, $quarantined);
$list = implode(', ', $quarantine_list);
send_quarantine_email($email, $list, quarantine_sort($quarantined));
}
unset($quarantined);
}
Expand Down Expand Up @@ -351,7 +398,8 @@ function return_quarantine_list_array($to_address, $to_domain)
'to' => trim_output($row->to_address, FROMTO_MAXLEN),
'from' => trim_output($row->from_address, FROMTO_MAXLEN),
'subject' => trim_output($row->subject, SUBJECT_MAXLEN),
'reason' => trim($row->reason)
'reason' => trim($row->reason),
'timestamp' => trim($row->timestamp)
);
}
}
Expand Down Expand Up @@ -476,3 +524,17 @@ function send_quarantine_email($email, $filter, $quarantined)
dbg(" ==== ERROR sending e-mail to $email ". $isSent);
}
}

/**
* @param $q
* @return array
*/
function quarantine_sort($q)
{
$key = 'timestamp';
usort($q, function ($a, $b) use (&$key) {
return strtotime($a[$key]) - strtotime($b[$key]);
});
$sorted = array_reverse($q);
return $sorted;
}

0 comments on commit 589155b

Please sign in to comment.