From ef7327f674166b225d71e701f1c1dabdc5c41e80 Mon Sep 17 00:00:00 2001 From: Hystepik Date: Mon, 23 Dec 2024 10:49:54 +0100 Subject: [PATCH] Fix email collector datetimelast ok and email fetching --- htdocs/emailcollector/class/emailcollector.class.php | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/htdocs/emailcollector/class/emailcollector.class.php b/htdocs/emailcollector/class/emailcollector.class.php index dcab6c1f349..91a23463c71 100644 --- a/htdocs/emailcollector/class/emailcollector.class.php +++ b/htdocs/emailcollector/class/emailcollector.class.php @@ -1165,6 +1165,7 @@ class EmailCollector extends CommonObject $arrayofemail = array(); $now = dol_now(); + $datelastok = $now; if (empty($this->host)) { $this->error = $langs->trans('ErrorFieldRequired', $langs->transnoentitiesnoconv('EMailHost')); @@ -1690,7 +1691,7 @@ class EmailCollector extends CommonObject if ($mode > 0) { $Query->leaveUnread(); } - $arrayofemail = $Query->limit($this->maxemailpercollect)->setFetchOrder("asc")->get(); + $arrayofemail = $Query->limit($this->maxemailpercollect)->setFetchOrder("desc")->get(); dol_syslog("EmailCollector::doCollectOneCollector nb arrayofemail ".(is_array($arrayofemail) ? count($arrayofemail) : 'Not array')); // @phpstan-ignore-line //var_dump($arrayofemail); } catch (Exception $e) { @@ -3642,6 +3643,7 @@ class EmailCollector extends CommonObject // Stop the loop to process email if we reach maximum collected per collect if ($this->maxemailpercollect > 0 && $nbemailok >= $this->maxemailpercollect) { dol_syslog("EmailCollect::doCollectOneCollector We reach maximum of ".$nbemailok." collected with success, so we stop this collector now."); + $datelastok = strtotime($headers['Date']); // Set datetime break; } } else { @@ -3743,7 +3745,7 @@ class EmailCollector extends CommonObject } if (empty($error) && empty($mode)) { - $this->datelastok = $now; + $this->datelastok = $datelastok; } if (!empty($this->errors)) {