From f8f292ca9116b1f02bdc5ba2f04f56cfe925c2e6 Mon Sep 17 00:00:00 2001 From: Hystepik Date: Mon, 23 Dec 2024 10:49:54 +0100 Subject: [PATCH 1/2] 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 a354bf6fa37..6ab373d4e26 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) { @@ -3635,6 +3636,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 { @@ -3736,7 +3738,7 @@ class EmailCollector extends CommonObject } if (empty($error) && empty($mode)) { - $this->datelastok = $now; + $this->datelastok = $datelastok; } if (!empty($this->errors)) { From 93499c29f187f3eff6dc3d5c770199751ddfc6a8 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Sat, 22 Feb 2025 17:30:38 +0100 Subject: [PATCH 2/2] Update emailcollector.class.php --- htdocs/emailcollector/class/emailcollector.class.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/emailcollector/class/emailcollector.class.php b/htdocs/emailcollector/class/emailcollector.class.php index 93e8b25f12c..a3dd9f7d495 100644 --- a/htdocs/emailcollector/class/emailcollector.class.php +++ b/htdocs/emailcollector/class/emailcollector.class.php @@ -1691,7 +1691,7 @@ class EmailCollector extends CommonObject if ($mode > 0) { $Query->leaveUnread(); } - $arrayofemail = $Query->limit($this->maxemailpercollect)->setFetchOrder("desc")->get(); + $arrayofemail = $Query->limit($this->maxemailpercollect)->setFetchOrder("asc")->get(); dol_syslog("EmailCollector::doCollectOneCollector nb arrayofemail ".(is_array($arrayofemail) ? count($arrayofemail) : 'Not array')); // @phpstan-ignore-line //var_dump($arrayofemail); } catch (Exception $e) {