From 8ac625f03bbccb4925032894270e8b0a95ca2e3c Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Mon, 12 Sep 2022 10:26:20 +0200 Subject: [PATCH] FIX reading of trackid in emailcollector (when on recipient suffix) --- htdocs/comm/mailing/card.php | 2 +- htdocs/core/class/notify.class.php | 2 +- .../class/emailcollector.class.php | 44 ++++++++++++++----- 3 files changed, 35 insertions(+), 13 deletions(-) diff --git a/htdocs/comm/mailing/card.php b/htdocs/comm/mailing/card.php index 748c5fabf10..63e79685311 100644 --- a/htdocs/comm/mailing/card.php +++ b/htdocs/comm/mailing/card.php @@ -475,7 +475,7 @@ if (empty($reshook)) { } } - $trackid = 'emailingtest'; + $trackid = 'emailing-test'; $mailfile = new CMailFile($tmpsujet, $object->sendto, $object->email_from, $tmpbody, $arr_file, $arr_mime, $arr_name, '', '', 0, $msgishtml, $object->email_errorsto, $arr_css, $trackid, '', 'emailing'); $result = $mailfile->sendfile(); diff --git a/htdocs/core/class/notify.class.php b/htdocs/core/class/notify.class.php index 3f26a98c728..5e12a30ba0e 100644 --- a/htdocs/core/class/notify.class.php +++ b/htdocs/core/class/notify.class.php @@ -456,7 +456,7 @@ class Notify $notifcodedefid = $obj->adid; $trackid = ''; if ($obj->type_target == 'tocontactid') { - $trackid = 'con'.$obj->cid; + $trackid = 'ctc'.$obj->cid; } if ($obj->type_target == 'touserid') { $trackid = 'use'.$obj->cid; diff --git a/htdocs/emailcollector/class/emailcollector.class.php b/htdocs/emailcollector/class/emailcollector.class.php index 47e3c1303da..1c8c0b8698f 100644 --- a/htdocs/emailcollector/class/emailcollector.class.php +++ b/htdocs/emailcollector/class/emailcollector.class.php @@ -1236,22 +1236,38 @@ class EmailCollector extends CommonObject $headers['Subject'] = $this->decodeSMTPSubject($headers['Subject']); + $emailto = $this->decodeSMTPSubject($overview[0]->to); + dol_syslog("** Process email ".$iforemailloop." References: ".$headers['References']." Subject: ".$headers['Subject']); //print "Process mail ".$iforemailloop." Subject: ".dol_escape_htmltag($headers['Subject'])." References: ".dol_escape_htmltag($headers['References'])." In-Reply-To: ".dol_escape_htmltag($headers['In-Reply-To'])."
\n"; + $trackidfoundintorecipienttype = ''; + $trackidfoundintorecipientid = 0; + $reg = array(); + // See also later list of all supported tags... + if (preg_match('/\+(thi|ctc|use|mem|sub|proj|tas|con|tic|job|pro|ord|inv|spro|sor|sin|leav|stockinv|job|surv|salary)([0-9]+)@/', $emailto, $reg)) { + $trackidfoundintorecipienttype = $reg[1]; + $trackidfoundintorecipientid = $reg[2]; + } elseif (preg_match('/\+emailing-(\w+)@/', $emailto, $reg)) { // Can be 'emailing-test' or 'emailing-IdMailing-IdRecipient' + $trackidfoundintorecipienttype = 'emailing'; + $trackidfoundintorecipientid = $reg[1]; + } + // If there is a filter on trackid if ($searchfilterdoltrackid > 0) { - if (empty($headers['References']) || !preg_match('/@'.preg_quote($host, '/').'/', $headers['References'])) { - $nbemailprocessed++; - dol_syslog(" Discarded - No header References found"); - continue; // Exclude email + if (empty($trackidfoundintorecipienttype)) { + if (empty($headers['References']) || !preg_match('/@'.preg_quote($host, '/').'/', $headers['References'])) { + $nbemailprocessed++; + dol_syslog(" Discarded - No suffix in email recipient and no Header References found matching signature of application so with a trackid"); + continue; // Exclude email + } } } if ($searchfilternodoltrackid > 0) { - if (!empty($headers['References']) && preg_match('/@'.preg_quote($host, '/').'/', $headers['References'])) { + if (!empty($trackidfoundintorecipienttype) || (!empty($headers['References']) && preg_match('/@'.preg_quote($host, '/').'/', $headers['References']))) { $nbemailprocessed++; - dol_syslog(" Discarded - Header References found and matching signature of application"); + dol_syslog(" Discarded - Suffix found into email or Header References found and matching signature of application so with a trackid"); continue; // Exclude email } } @@ -1431,13 +1447,19 @@ class EmailCollector extends CommonObject foreach ($arrayofreferences as $reference) { //print "Process mail ".$iforemailloop." email_msgid ".$msgid.", date ".dol_print_date($date, 'dayhour').", subject ".$subject.", reference ".dol_escape_htmltag($reference)."
\n"; - $resultsearchtrackid = preg_match('/dolibarr-([a-z]+)([0-9]+)@'.preg_quote($host, '/').'/', $reference, $reg); - if (empty($resultsearchtrackid) && getDolGlobalString('EMAIL_ALTERNATIVE_HOST_SIGNATURE')) { - $resultsearchtrackid = preg_match('/dolibarr-([a-z]+)([0-9]+)@'.preg_quote(getDolGlobalString('EMAIL_ALTERNATIVE_HOST_SIGNATURE'), '/').'/', $reference, $reg); + if (!empty($trackidfoundintorecipienttype)) { + $resultsearchtrackid = -1; + $reg[1] = $trackidfoundintorecipienttype; + $reg[2] = $trackidfoundintorecipientid; + } else { + $resultsearchtrackid = preg_match('/dolibarr-([a-z]+)([0-9]+)@'.preg_quote($host, '/').'/', $reference, $reg); + if (empty($resultsearchtrackid) && getDolGlobalString('EMAIL_ALTERNATIVE_HOST_SIGNATURE')) { + $resultsearchtrackid = preg_match('/dolibarr-([a-z]+)([0-9]+)@'.preg_quote(getDolGlobalString('EMAIL_ALTERNATIVE_HOST_SIGNATURE'), '/').'/', $reference, $reg); + } } - if ($resultsearchtrackid) { - // This is a Dolibarr reference of the server + if (!empty($resultsearchtrackid)) { + // We found a tracker (in recipient email or into a Reference matching the Dolibarr server) $trackid = $reg[1].$reg[2]; $objectid = $reg[2];