diff --git a/htdocs/emailcollector/class/emailcollector.class.php b/htdocs/emailcollector/class/emailcollector.class.php index deef95bfd4c..fd027d9e91f 100644 --- a/htdocs/emailcollector/class/emailcollector.class.php +++ b/htdocs/emailcollector/class/emailcollector.class.php @@ -380,6 +380,11 @@ class EmailCollector extends CommonObject unset($object->fk_user_creat); unset($object->import_key); unset($object->password); + unset($object->lastresult); + unset($object->codelastresult); + unset($object->datelastresult); + unset($object->datelastok); + unset($object->debuginfo); // Clear fields $object->ref = "copy_of_".$object->ref; @@ -1112,7 +1117,6 @@ class EmailCollector extends CommonObject $now = dol_now(); - if (empty($this->host)) { $this->error = $langs->trans('ErrorFieldRequired', $langs->transnoentitiesnoconv('EMailHost')); return -1; @@ -1126,12 +1130,15 @@ class EmailCollector extends CommonObject return -1; } + $sourcedir = $this->source_directory; + $targetdir = ($this->target_directory ? $this->target_directory : ''); // Can be '[Gmail]/Trash' or 'mytag' + $this->fetchFilters(); $this->fetchActions(); if (getDolGlobalString('MAIN_IMAP_USE_PHPIMAP')) { if ($this->acces_type == 1) { - // Mode OAUth2 with PHP-IMAP + // Mode OAUth2 (access_type == 1) with PHP-IMAP require_once DOL_DOCUMENT_ROOT.'/core/lib/oauth.lib.php'; $supportedoauth2array = getSupportedOauth2Array(); @@ -1241,8 +1248,6 @@ class EmailCollector extends CommonObject $this->error = 'IMAP function not enabled on your PHP'; return -2; } - $sourcedir = $this->source_directory; - $targetdir = ($this->target_directory ? $this->target_directory : ''); // Can be '[Gmail]/Trash' or 'mytag' $connectstringserver = $this->getConnectStringIMAP(); $connectstringsource = $connectstringserver.imap_utf7_encode($sourcedir); @@ -1534,7 +1539,7 @@ class EmailCollector extends CommonObject try { //$criteria = [['ALL']]; //$Query = $client->getFolders()[0]->messages()->where($criteria); - $f = $client->getFolders(false, $this->source_directory); + $f = $client->getFolders(false, $sourcedir); $Query = $f[0]->messages()->where($criteria); } catch (InvalidWhereQueryCriteriaException $e) { $this->error = $e->getMessage(); @@ -1562,7 +1567,7 @@ class EmailCollector extends CommonObject return -1; } } else { - // Scan IMAP inbox + // Scan IMAP inbox (for native IMAP, the source dir is inside the $connection variable) $arrayofemail = imap_search($connection, $search, SE_UID, $charset); if ($arrayofemail === false) { @@ -2208,7 +2213,7 @@ class EmailCollector extends CommonObject $actioncode = 'EMAIL_IN'; // If we scan the Sent box, we use the code for out email - if ($this->source_directory == 'Sent') { + if (preg_match('/Sent$/', $sourcedir)) { $actioncode = 'EMAIL_OUT'; } @@ -3208,7 +3213,7 @@ class EmailCollector extends CommonObject if (getDolGlobalString('MAIN_IMAP_USE_PHPIMAP')) { // Move mail using PHP-IMAP dol_syslog("EmailCollector::doCollectOneCollector move message ".($imapemail->getHeader()->get('subject'))." to ".$targetdir, LOG_DEBUG); - if (empty($mode)) { + if (empty($mode)) { // $mode > 0 is test $imapemail->move($targetdir); } } else { @@ -3216,6 +3221,7 @@ class EmailCollector extends CommonObject $operationslog .= '
Move mail '.((string) $imapemail).' - '.$msgid; $arrayofemailtodelete[$imapemail] = $msgid; + // Note: Real move is done later using $arrayofemailtodelete } } else { if (getDolGlobalString('MAIN_IMAP_USE_PHPIMAP')) {