From dec35ff489334770159e2f4f530cbaed064f52e9 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Mon, 19 Jan 2026 20:33:47 +0100 Subject: [PATCH] Merge manually #36851 emailcollector phpimap in reply to oauth v22. --- .../class/emailcollector.class.php | 36 +++++++++++++------ 1 file changed, 25 insertions(+), 11 deletions(-) diff --git a/htdocs/emailcollector/class/emailcollector.class.php b/htdocs/emailcollector/class/emailcollector.class.php index 4e3b19c07f3..9a469df0fe2 100644 --- a/htdocs/emailcollector/class/emailcollector.class.php +++ b/htdocs/emailcollector/class/emailcollector.class.php @@ -1224,12 +1224,14 @@ class EmailCollector extends CommonObject try { $tokenobj = $storage->retrieveAccessToken($OAUTH_SERVICENAME); - $expire = true; - // TODO - // Is token expired or will token expire in the next 30 seconds - // if (is_object($tokenobj)) { - // $expire = ($tokenobj->getEndOfLife() !== -9002 && $tokenobj->getEndOfLife() !== -9001 && time() > ($tokenobj->getEndOfLife() - 30)); - // } + $expire = false; + if (is_object($tokenobj) && method_exists($tokenobj, 'getEndOfLife')) { + $endOfLife = $tokenobj->getEndOfLife(); + if ($endOfLife !== -9002 && $endOfLife !== -9001 && time() > ($endOfLife - 30)) { + $expire = true; + } + } + // Token expired so we refresh it if (is_object($tokenobj) && $expire) { $this->debuginfo .= 'Refresh token '.$OAUTH_SERVICENAME.'
'; @@ -1840,20 +1842,32 @@ class EmailCollector extends CommonObject // Now apply some filters. - //If there is an emailcollector filter on trackid + // If there is an emailcollector filter on trackid if ($searchfilterdoltrackid > 0) { + $referencesForFilter = $headers['References'] ?? ''; + if (!empty($headers['References']) && !empty($headers['In-Reply-To'])) { + $referencesForFilter .= ' '; + } + $referencesForFilter .= ($headers['In-Reply-To'] ?? ''); + if (empty($trackidfoundintorecipienttype) && empty($trackidfoundintomsgidtype)) { - if (empty($headers['References']) || !preg_match('/@'.preg_quote($host, '/').'/', $headers['References'])) { + if (empty($referencesForFilter) || !preg_match('/@'.preg_quote($host, '/').'/', $referencesForFilter)) { $nbemailprocessed++; - dol_syslog(" Discarded - No suffix in email recipient and no Header References found matching the signature of the application, so with a trackid coming from the application"); + dol_syslog(" Discarded - No suffix in email recipient, and no Header 'References/In-Reply-To' found matching the signature of the application, so with a trackid coming from the application"); continue; // Exclude email } } } if ($searchfilternodoltrackid > 0) { - if (!empty($trackidfoundintorecipienttype) || !empty($trackidfoundintomsgidtype) || (!empty($headers['References']) && preg_match('/@'.preg_quote($host, '/').'/', $headers['References']))) { + $referencesForFilter = $headers['References'] ?? ''; + if (!empty($headers['References']) && !empty($headers['In-Reply-To'])) { + $referencesForFilter .= ' '; + } + $referencesForFilter .= ($headers['In-Reply-To'] ?? ''); + + if (!empty($trackidfoundintorecipienttype) || !empty($trackidfoundintomsgidtype) || (!empty($referencesForFilter) && preg_match('/@'.preg_quote($host, '/').'/', $referencesForFilter))) { $nbemailprocessed++; - dol_syslog(" Discarded - Suffix found into email or Header References found and matching signature of application so with a trackid"); + dol_syslog(" Discarded - Suffix found into email recipient, or Header 'References/In-Reply-To' found and matching signature of application so with a trackid"); continue; // Exclude email } }