From 16d77a03cb90a1370f9ca7bc76348b045419c3a2 Mon Sep 17 00:00:00 2001 From: Michael Kaufmann Date: Sat, 31 Aug 2024 08:41:09 +0200 Subject: [PATCH] fix timestamp matching regex, add lmtp to receving service regex and skip lines not including the main target service name in maillog parser Signed-off-by: Michael Kaufmann --- lib/Froxlor/MailLogParser.php | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/lib/Froxlor/MailLogParser.php b/lib/Froxlor/MailLogParser.php index 0d6fb925..41f36d2e 100644 --- a/lib/Froxlor/MailLogParser.php +++ b/lib/Froxlor/MailLogParser.php @@ -104,6 +104,10 @@ class MailLogParser unset($matches); $line = fgets($file_handle); + if (strpos($line, 'postfix') === false) { + continue; + } + $timestamp = $this->getLogTimestamp($line); if ($this->startTime < $timestamp) { if (preg_match("/postfix\/qmgr.*(?::|\])\s([A-Z\d]+).*from=?, size=(\d+),/", $line, $matches)) { @@ -112,7 +116,7 @@ class MailLogParser "domainFrom" => strtolower($matches[2]), "size" => $matches[3] ]; - } elseif (preg_match("/postfix\/(?:pipe|smtp).*(?::|\])\s([A-Z\d]+).*to=?,/", $line, $matches)) { + } elseif (preg_match("/postfix\/(?:pipe|smtp|lmtp).*(?::|\])\s([A-Z\d]+).*to=?,/", $line, $matches)) { // Postfix to if (array_key_exists($matches[1], $this->mails)) { $this->mails[$matches[1]]["domainTo"] = strtolower($matches[2]); @@ -149,7 +153,7 @@ class MailLogParser private function getLogTimestamp($line) { $matches = null; - if (preg_match("/((?:[A-Z]{3}\s{1,2}\d{1,2}|\d{4}-\d{2}-\d{2}) \d{2}:\d{2}:\d{2})/i", $line, $matches)) { + if (preg_match("/((?:[A-Z]{3}\s{1,2}\d{1,2}|\d{4}-\d{2}-\d{2}).\d{2}:\d{2}:\d{2})/i", $line, $matches)) { $timestamp = strtotime($matches[1]); if ($timestamp > ($this->startTime + 60 * 60 * 24)) { return strtotime($matches[1] . " -1 year"); @@ -258,6 +262,10 @@ class MailLogParser unset($matches); $line = fgets($file_handle); + if (strpos($line, 'dovecot') === false) { + continue; + } + $timestamp = $this->getLogTimestamp($line); if ($this->startTime < $timestamp) { if (preg_match("/dovecot.*(?::|\]) imap\(.*@([a-z0-9\.\-]+)\)(<\d+><[a-z0-9+\/=]+>)?:.*(?:in=(\d+) out=(\d+)|bytes=(\d+)\/(\d+))/i", $line, $matches)) {