From 70a914a98cc8aa992fff0b06848746c0e50c12d5 Mon Sep 17 00:00:00 2001 From: andryyy Date: Thu, 25 Oct 2018 23:03:35 +0200 Subject: [PATCH] [Web] More mailq fixes --- data/web/inc/functions.mailq.inc.php | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/data/web/inc/functions.mailq.inc.php b/data/web/inc/functions.mailq.inc.php index 97a86861..24de47be 100644 --- a/data/web/inc/functions.mailq.inc.php +++ b/data/web/inc/functions.mailq.inc.php @@ -37,7 +37,6 @@ function mailq($_action, $_data = null) { 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) { @@ -45,17 +44,21 @@ function mailq($_action, $_data = null) { 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'] . ')'; + if ($mq_line !== NULL) { + $rcpts = array(); + foreach ($mq_line['recipients'] as $rcpt) { + if (isset($rcpt['delay_reason'])) { + $rcpts[] = $rcpt['address'] . ' (' . $rcpt['delay_reason'] . ')'; + } + else { + $rcpts[] = $rcpt['address']; + } } - else { - $rcpts[] = $rcpt['address']; + if (!empty($rcpts)) { + $mq_line['recipients'] = $rcpts; } + $line[] = $mq_line; } - $mq_line['recipients'] = $rcpts; - $line[] = $mq_line; } if (!isset($line) || empty($line)) { return '{}';