[Web] Move 'get' method to mailq functions file
parent
5f02f7d38f
commit
48047a364c
|
@ -35,6 +35,35 @@ function mailq($_action, $_data = null) {
|
|||
}
|
||||
global $lang;
|
||||
switch ($_action) {
|
||||
case 'get':
|
||||
$mailq_lines = docker('post', 'postfix-mailcow', 'exec', array('cmd' => 'mailq', 'task' => 'list'));
|
||||
$mailq_lines .= '{"queue_name":"hold","queue_id":"6004D1021DE","arrival_time":1540195064,"message_size":269,"sender":"watchdog@invalid","recipients":[{"address":"test@example.com","delay_reason":"connect to 123.0.0.1[123.0.0.1]:25: Connection refused"},{"address":"test@example.com","delay_reason":"connect to 123.0.0.1[123.0.0.1]:25: Connection refused"}]}';
|
||||
$lines = 0;
|
||||
// Hard limit to 10000 items
|
||||
foreach (preg_split("/((\r?\n)|(\r\n?))/", $mailq_lines) as $mailq_item) if ($lines++ < 10000) {
|
||||
if (empty($mailq_item) || $mailq_item == '1') {
|
||||
continue;
|
||||
}
|
||||
$mq_line = json_decode($mailq_item, true);
|
||||
$rcpts = array();
|
||||
foreach ($mq_line['recipients'] as $rcpt) {
|
||||
if (isset($rcpt['delay_reason'])) {
|
||||
$rcpts[] = $rcpt['address'] . ' (' . $rcpt['delay_reason'] . ')';
|
||||
}
|
||||
else {
|
||||
$rcpts[] = $rcpt['address'];
|
||||
}
|
||||
}
|
||||
$mq_line['recipients'] = $rcpts;
|
||||
$line[] = $mq_line;
|
||||
}
|
||||
if (!isset($line) || empty($line)) {
|
||||
return '{}';
|
||||
}
|
||||
else {
|
||||
return json_encode($line);
|
||||
}
|
||||
break;
|
||||
case 'delete':
|
||||
if (!is_array($_data['qid'])) {
|
||||
$qids = array();
|
||||
|
|
|
@ -219,20 +219,16 @@ if (isset($_SESSION['mailcow_cc_role']) || isset($_SESSION['pending_mailcow_cc_u
|
|||
break;
|
||||
|
||||
case "mailq":
|
||||
$mailq_lines = docker('post', 'postfix-mailcow', 'exec', array('cmd' => 'mailq', 'task' => 'list'));
|
||||
$lines = 0;
|
||||
// Hard limit to 1000 items
|
||||
foreach (preg_split("/((\r?\n)|(\r\n?))/", $mailq_lines) as $mailq_item) if ($lines++ < 1000) {
|
||||
if (empty($mailq_item) || $mailq_item == '1') {
|
||||
continue;
|
||||
}
|
||||
$line[] = json_decode($mailq_item, true);
|
||||
}
|
||||
if (!isset($line) || empty($line)) {
|
||||
echo '{}';
|
||||
}
|
||||
else {
|
||||
echo json_encode($line);
|
||||
switch ($object) {
|
||||
case "all":
|
||||
$mailq = mailq('get');
|
||||
if (!empty($mailq)) {
|
||||
echo $mailq;
|
||||
}
|
||||
else {
|
||||
echo '{}';
|
||||
}
|
||||
break;
|
||||
}
|
||||
break;
|
||||
|
||||
|
|
Loading…
Reference in New Issue