From 48047a364cb2cf516e007cea8b72415e3c4591b5 Mon Sep 17 00:00:00 2001 From: andryyy Date: Thu, 25 Oct 2018 22:41:57 +0200 Subject: [PATCH] [Web] Move 'get' method to mailq functions file --- data/web/inc/functions.mailq.inc.php | 29 ++++++++++++++++++++++++++++ data/web/json_api.php | 24 ++++++++++------------- 2 files changed, 39 insertions(+), 14 deletions(-) diff --git a/data/web/inc/functions.mailq.inc.php b/data/web/inc/functions.mailq.inc.php index 2bae36cc..97a86861 100644 --- a/data/web/inc/functions.mailq.inc.php +++ b/data/web/inc/functions.mailq.inc.php @@ -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(); diff --git a/data/web/json_api.php b/data/web/json_api.php index 36ec41df..26ccbb25 100644 --- a/data/web/json_api.php +++ b/data/web/json_api.php @@ -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;