Skip to content

Commit

Permalink
fix timestamp matching regex, add lmtp to receving service regex and …
Browse files Browse the repository at this point in the history
…skip lines not including the main target service name in maillog parser

Signed-off-by: Michael Kaufmann <[email protected]>
  • Loading branch information
d00p committed Aug 31, 2024
1 parent 05ca08c commit 16d77a0
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions lib/Froxlor/MailLogParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,10 @@ private function parsePostfixLog($logFile)
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=<?(?:.*\@([a-zA-Z\d\.\-]+))?>?, size=(\d+),/", $line, $matches)) {
Expand All @@ -112,7 +116,7 @@ private function parsePostfixLog($logFile)
"domainFrom" => strtolower($matches[2]),
"size" => $matches[3]
];
} elseif (preg_match("/postfix\/(?:pipe|smtp).*(?::|\])\s([A-Z\d]+).*to=<?(?:.*\@([a-zA-Z\d\.\-]+))?>?,/", $line, $matches)) {
} elseif (preg_match("/postfix\/(?:pipe|smtp|lmtp).*(?::|\])\s([A-Z\d]+).*to=<?(?:.*\@([a-zA-Z\d\.\-]+))?>?,/", $line, $matches)) {
// Postfix to
if (array_key_exists($matches[1], $this->mails)) {
$this->mails[$matches[1]]["domainTo"] = strtolower($matches[2]);
Expand Down Expand Up @@ -149,7 +153,7 @@ private function parsePostfixLog($logFile)
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");
Expand Down Expand Up @@ -258,6 +262,10 @@ private function parseDovecotLog($logFile)
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)) {
Expand Down

0 comments on commit 16d77a0

Please sign in to comment.