64 public $element =
'emailcollector';
69 public $table_element =
'emailcollector_emailcollector';
74 public $picto =
'email';
79 public $fk_element =
'fk_emailcollector';
84 protected $childtables = array();
89 protected $childtablesoncascade = array(
'emailcollector_emailcollectorfilter',
'emailcollector_emailcollectoraction');
115 public $fields = array(
116 'rowid' => array(
'type' =>
'integer',
'label' =>
'TechnicalID',
'visible' => 2,
'enabled' => 1,
'position' => 1,
'notnull' => 1,
'index' => 1),
117 'entity' => array(
'type' =>
'integer',
'label' =>
'Entity',
'enabled' => 1,
'visible' => 0,
'default' => 1,
'notnull' => 1,
'index' => 1,
'position' => 20),
118 'ref' => array(
'type' =>
'varchar(128)',
'label' =>
'Ref',
'enabled' => 1,
'visible' => 1,
'notnull' => 1,
'showoncombobox' => 1,
'index' => 1,
'position' => 10,
'searchall' => 1,
'help' =>
'Example: MyCollector1',
'csslist' =>
'tdoverflowmax200'),
119 'label' => array(
'type' =>
'varchar(255)',
'label' =>
'Label',
'visible' => 1,
'enabled' => 1,
'position' => 30,
'notnull' => -1,
'searchall' => 1,
'help' =>
'Example: My Email collector',
'csslist' =>
'tdoverflowmax150',
'tdcss' =>
'titlefieldmiddle'),
120 'description' => array(
'type' =>
'text',
'label' =>
'Description',
'visible' => -1,
'enabled' => 1,
'position' => 60,
'notnull' => -1,
'cssview' =>
'small',
'csslist' =>
'small tdoverflowmax200'),
121 'host' => array(
'type' =>
'varchar(255)',
'label' =>
'EMailHost',
'visible' => 1,
'enabled' => 1,
'position' => 90,
'notnull' => 1,
'searchall' => 1,
'comment' =>
"IMAP server",
'help' =>
'Example: imap.gmail.com',
'csslist' =>
'tdoverflowmax125'),
122 'port' => array(
'type' =>
'varchar(10)',
'label' =>
'EMailHostPort',
'visible' => 1,
'enabled' => 1,
'position' => 91,
'notnull' => 1,
'searchall' => 0,
'comment' =>
"IMAP server port",
'help' =>
'Example: 993',
'csslist' =>
'tdoverflowmax50',
'default' =>
'993'),
123 'imap_encryption' => array(
'type' =>
'varchar(16)',
'label' =>
'ImapEncryption',
'visible' => -1,
'enabled' => 1,
'position' => 92,
'searchall' => 0,
'comment' =>
"IMAP encryption",
'help' =>
'ImapEncryptionHelp',
'arrayofkeyval' => array(
'ssl' =>
'SSL',
'tls' =>
'TLS',
'notls' =>
'NOTLS'),
'default' =>
'ssl'),
124 'hostcharset' => array(
'type' =>
'varchar(16)',
'label' =>
'HostCharset',
'visible' => -1,
'enabled' => 1,
'position' => 93,
'notnull' => 0,
'searchall' => 0,
'comment' =>
"IMAP server charset",
'help' =>
'Example: "UTF-8" (May be "US-ASCII" with some Office365)',
'default' =>
'UTF-8'),
125 'norsh' => array(
'type' =>
'integer',
'label' =>
'NoRSH',
'visible' => -1,
'enabled' =>
"!getDolGlobalInt('MAIN_IMAP_USE_PHPIMAP')",
'position' => 94,
'searchall' => 0,
'help' =>
'NoRSHHelp',
'arrayofkeyval' => array(0 =>
'No', 1 =>
'Yes'),
'default' => 0),
126 'acces_type' => array(
'type' =>
'integer',
'label' =>
'AuthenticationMethod',
'visible' => -1,
'enabled' =>
"getDolGlobalInt('MAIN_IMAP_USE_PHPIMAP')",
'position' => 101,
'notnull' => 1,
'index' => 1,
'comment' =>
"IMAP login type",
'arrayofkeyval' => array(
'0' =>
'loginPassword',
'1' =>
'oauthToken'),
'default' =>
'0',
'help' =>
''),
127 'login' => array(
'type' =>
'varchar(128)',
'label' =>
'Login',
'visible' => -1,
'enabled' => 1,
'position' => 102,
'notnull' => -1,
'index' => 1,
'comment' =>
"IMAP login",
'help' =>
'Example: myaccount@gmail.com'),
128 'password' => array(
'type' =>
'password',
'label' =>
'Password',
'visible' => -1,
'enabled' =>
"1",
'position' => 103,
'notnull' => -1,
'comment' =>
"IMAP password",
'help' =>
'WithGMailYouCanCreateADedicatedPassword'),
129 'oauth_service' => array(
'type' =>
'varchar(128)',
'label' =>
'oauthService',
'visible' => -1,
'enabled' =>
"getDolGlobalInt('MAIN_IMAP_USE_PHPIMAP')",
'position' => 104,
'notnull' => 0,
'index' => 1,
'comment' =>
"IMAP login oauthService",
'arrayofkeyval' => array(),
'help' =>
'TokenMustHaveBeenCreated'),
130 'source_directory' => array(
'type' =>
'varchar(255)',
'label' =>
'MailboxSourceDirectory',
'visible' => -1,
'enabled' => 1,
'position' => 109,
'notnull' => 1,
'default' =>
'Inbox',
'csslist' =>
'tdoverflowmax100',
'help' =>
'Example: INBOX, [Gmail]/Spam, [Gmail]/Draft, [Gmail]/Brouillons, [Gmail]/Sent Mail, [Gmail]/Messages envoyés, ...'),
131 'target_directory' => array(
'type' =>
'varchar(255)',
'label' =>
'MailboxTargetDirectory',
'visible' => 1,
'enabled' => 1,
'position' => 110,
'notnull' => 0,
'csslist' =>
'tdoverflowmax100',
'help' =>
"EmailCollectorTargetDir"),
132 'maxemailpercollect' => array(
'type' =>
'integer',
'label' =>
'MaxEmailCollectPerCollect',
'visible' => -1,
'enabled' => 1,
'position' => 111,
'default' => 50),
133 'datelastresult' => array(
'type' =>
'datetime',
'label' =>
'DateLastCollectResult',
'visible' => 1,
'enabled' =>
'$action != "create" && $action != "edit"',
'position' => 121,
'notnull' => -1,
'csslist' =>
'nowraponall'),
134 'codelastresult' => array(
'type' =>
'varchar(16)',
'label' =>
'CodeLastResult',
'visible' => 1,
'enabled' =>
'$action != "create" && $action != "edit"',
'position' => 122,
'notnull' => -1,),
135 'lastresult' => array(
'type' =>
'varchar(255)',
'label' =>
'LastResult',
'visible' => 1,
'enabled' =>
'$action != "create" && $action != "edit"',
'position' => 123,
'notnull' => -1,
'cssview' =>
'small',
'csslist' =>
'small tdoverflowmax200'),
136 'datelastok' => array(
'type' =>
'datetime',
'label' =>
'DateLastcollectResultOk',
'visible' => 1,
'enabled' =>
'$action != "create"',
'position' => 125,
'notnull' => -1,
'csslist' =>
'nowraponall'),
137 'note_public' => array(
'type' =>
'html',
'label' =>
'NotePublic',
'visible' => 0,
'enabled' => 1,
'position' => 61,
'notnull' => -1,),
138 'note_private' => array(
'type' =>
'html',
'label' =>
'NotePrivate',
'visible' => 0,
'enabled' => 1,
'position' => 62,
'notnull' => -1,),
139 'date_creation' => array(
'type' =>
'datetime',
'label' =>
'DateCreation',
'visible' => -2,
'enabled' => 1,
'position' => 500,
'notnull' => 1,),
140 'tms' => array(
'type' =>
'timestamp',
'label' =>
'DateModification',
'visible' => -2,
'enabled' => 1,
'position' => 501,
'notnull' => 1,),
142 'fk_user_creat' => array(
'type' =>
'integer:User:user/class/user.class.php',
'label' =>
'UserAuthor',
'visible' => -2,
'enabled' => 1,
'position' => 510,
'notnull' => 1,),
143 'fk_user_modif' => array(
'type' =>
'integer:User:user/class/user.class.php',
'label' =>
'UserModif',
'visible' => -2,
'enabled' => 1,
'position' => 511,
'notnull' => -1,),
145 'import_key' => array(
'type' =>
'varchar(14)',
'label' =>
'ImportId',
'visible' => -2,
'enabled' => 1,
'position' => 1000,
'notnull' => -1,),
146 'status' => array(
'type' =>
'integer',
'label' =>
'Status',
'visible' => 1,
'enabled' => 1,
'position' => 1000,
'notnull' => 1,
'default' =>
'0',
'index' => 1,
'arrayofkeyval' => array(
'0' =>
'Inactive',
'1' =>
'Active'))
183 public $fk_user_creat;
188 public $fk_user_modif;
222 public $oauth_service;
226 public $imap_encryption;
234 public $source_directory;
238 public $target_directory;
242 public $maxemailpercollect;
247 public $datelastresult;
252 public $codelastresult;
277 const STATUS_DISABLED = 0;
278 const STATUS_ENABLED = 1;
288 global
$conf, $langs;
292 $this->ismultientitymanaged = 1;
293 $this->isextrafieldmanaged = 0;
296 $this->fields[
'rowid'][
'visible'] = 0;
298 if (!isModEnabled(
'multicompany') && isset($this->fields[
'entity'])) {
299 $this->fields[
'entity'][
'enabled'] = 0;
303 $oauthservices = array();
305 foreach (
$conf->global as $key => $val) {
306 if (!empty($val) && preg_match(
'/^OAUTH_.*_ID$/', $key)) {
307 $key = preg_replace(
'/^OAUTH_/',
'', $key);
308 $key = preg_replace(
'/_ID$/',
'', $key);
309 if (preg_match(
'/^.*-/', $key)) {
310 $name = preg_replace(
'/^.*-/',
'', $key);
312 $name = $langs->trans(
"NoName");
314 $provider = preg_replace(
'/-.*$/',
'', $key);
315 $provider = ucfirst(strtolower($provider));
317 $oauthservices[$key] = $name.
" (".$provider.
")";
321 $this->fields[
'oauth_service'][
'arrayofkeyval'] = $oauthservices;
324 foreach ($this->fields as $key => $val) {
325 if (isset($val[
'enabled']) && empty($val[
'enabled'])) {
326 unset($this->fields[$key]);
331 foreach ($this->fields as $key => $val) {
332 if (!empty($val[
'arrayofkeyval']) && is_array($val[
'arrayofkeyval'])) {
333 foreach ($val[
'arrayofkeyval'] as $key2 => $val2) {
334 $this->fields[$key][
'arrayofkeyval'][$key2] = $langs->trans($val2);
352 if ($this->host && preg_match(
'/^http:/i', trim($this->host))) {
353 $langs->load(
"errors");
354 $this->error = $langs->trans(
"ErrorHostMustNotStartWithHttp", $this->host);
358 include_once DOL_DOCUMENT_ROOT.
'/core/lib/security.lib.php';
359 $this->password =
dolEncrypt($this->password);
363 $this->password =
dolDecrypt($this->password);
365 if (is_array($this->filters) && count($this->filters)) {
368 foreach ($this->filters as $filter) {
369 $emailcollectorfilter->type = $filter[
'type'];
370 $emailcollectorfilter->rulevalue = $filter[
'rulevalue'];
371 $emailcollectorfilter->fk_emailcollector = $this->id;
372 $emailcollectorfilter->status = $filter[
'status'];
374 $emailcollectorfilter->create($user);
378 if (is_array($this->actions) && count($this->actions)) {
381 foreach ($this->actions as $operation) {
382 $emailcollectoroperation->type = $operation[
'type'];
383 $emailcollectoroperation->actionparam = $operation[
'actionparam'];
384 $emailcollectoroperation->fk_emailcollector = $this->id;
385 $emailcollectoroperation->status = $operation[
'status'];
386 $emailcollectoroperation->position = $operation[
'position'];
388 $emailcollectoroperation->create($user);
404 global $langs, $extrafields;
425 unset(
$object->codelastresult);
426 unset(
$object->datelastresult);
431 $object->ref =
"copy_of_".$object->ref;
434 $object->host =
'imap.example.com';
437 if (is_array(
$object->array_options) && count(
$object->array_options) > 0) {
438 $extrafields->fetch_name_optionals_label($this->table_element);
439 foreach (
$object->array_options as $key => $option) {
440 $shortkey = preg_replace(
'/options_/',
'', $key);
441 if (!empty($extrafields->attributes[$this->element][
'unique'][$shortkey])) {
443 unset(
$object->array_options[$key]);
449 $object->context[
'createfromclone'] =
'createfromclone';
450 $result =
$object->create($user);
454 $this->errors =
$object->errors;
457 unset(
$object->context[
'createfromclone']);
464 $this->db->rollback();
476 public function fetch($id, $ref =
null)
480 include_once DOL_DOCUMENT_ROOT.
'/core/lib/security.lib.php';
481 $this->password =
dolDecrypt($this->password);
514 public function fetchAll(
User $user, $activeOnly = 0, $sortfield =
's.rowid', $sortorder =
'ASC', $limit = 100, $page = 0)
520 $sql =
"SELECT s.rowid";
521 $sql .=
" FROM ".MAIN_DB_PREFIX.
"emailcollector_emailcollector as s";
522 $sql .=
' WHERE s.entity IN ('.getEntity(
'emailcollector').
')';
524 $sql .=
" AND s.status = 1";
526 $sql .= $this->db->order($sortfield, $sortorder);
531 $offset = $limit * $page;
533 $sql .= $this->db->plimit($limit + 1, $offset);
536 $result = $this->db->query($sql);
538 $num = $this->db->num_rows($result);
541 $obj = $this->db->fetch_object($result);
543 if ($emailcollector_static->fetch($obj->rowid)) {
544 $obj_ret[] = $emailcollector_static;
549 $this->errors[] =
'EmailCollector::fetchAll Error when retrieve emailcollector list';
550 dol_syslog(
'EmailCollector::fetchAll Error when retrieve emailcollector list', LOG_ERR);
553 if (!count($obj_ret)) {
554 dol_syslog(
'EmailCollector::fetchAll No emailcollector found', LOG_DEBUG);
572 if ($this->host && preg_match(
'/^http:/i', trim($this->host))) {
573 $langs->load(
"errors");
574 $this->error = $langs->trans(
"ErrorHostMustNotStartWithHttp", $this->host);
578 include_once DOL_DOCUMENT_ROOT.
'/core/lib/security.lib.php';
579 $this->password =
dolEncrypt($this->password);
583 $this->password =
dolDecrypt($this->password);
595 public function delete(
User $user, $notrigger = 0)
610 public function getNomUrl($withpicto = 0, $option =
'', $notooltip = 0, $morecss =
'', $save_lastsearch_value = -1)
612 global
$conf, $langs, $action, $hookmanager;
614 if (!empty(
$conf->dol_no_mouse_hover)) {
620 $label =
'<u>'.$langs->trans(
"EmailCollector").
'</u>';
622 $label .=
'<b>'.$langs->trans(
'Ref').
':</b> '.$this->ref;
624 $url = DOL_URL_ROOT.
'/admin/emailcollector_card.php?id='.$this->id;
626 if ($option !=
'nolink') {
628 $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
629 if ($save_lastsearch_value == -1 && isset($_SERVER[
"PHP_SELF"]) && preg_match(
'/list\.php/', $_SERVER[
"PHP_SELF"])) {
630 $add_save_lastsearch_values = 1;
632 if ($add_save_lastsearch_values) {
633 $url .=
'&save_lastsearch_values=1';
638 if (empty($notooltip)) {
640 $label = $langs->trans(
"ShowEmailCollector");
641 $linkclose .=
' alt="'.dol_escape_htmltag($label, 1).
'"';
643 $linkclose .=
' title="'.dol_escape_htmltag($label, 1).
'"';
644 $linkclose .=
' class="classfortooltip'.($morecss ?
' '.$morecss :
'').
'"';
646 $linkclose = ($morecss ?
' class="'.$morecss.
'"' :
'');
649 $linkstart =
'<a href="'.$url.
'"';
650 $linkstart .= $linkclose.
'>';
653 $result .= $linkstart;
655 $result .=
img_object(($notooltip ?
'' : $label), ($this->picto ? $this->picto :
'generic'), ($notooltip ? (($withpicto != 2) ?
'class="paddingright"' :
'') :
'class="'.(($withpicto != 2) ?
'paddingright ' :
'').
'classfortooltip"'), 0, 0, $notooltip ? 0 : 1);
657 if ($withpicto != 2) {
658 $result .= $this->ref;
663 $hookmanager->initHooks(array(
'emailcollectordao'));
664 $parameters = array(
'id' => $this->
id,
'getnomurl' => &$result);
665 $reshook = $hookmanager->executeHooks(
'getNomUrl', $parameters, $this, $action);
667 $result = $hookmanager->resPrint;
669 $result .= $hookmanager->resPrint;
697 if (empty($this->labelStatus) || empty($this->labelStatusShort)) {
700 $this->labelStatus[self::STATUS_ENABLED] = $langs->transnoentitiesnoconv(
'Enabled');
701 $this->labelStatus[self::STATUS_DISABLED] = $langs->transnoentitiesnoconv(
'Disabled');
702 $this->labelStatusShort[self::STATUS_ENABLED] = $langs->transnoentitiesnoconv(
'Enabled');
703 $this->labelStatusShort[self::STATUS_DISABLED] = $langs->transnoentitiesnoconv(
'Disabled');
706 $statusType =
'status5';
707 if ($status == self::STATUS_ENABLED) {
708 $statusType =
'status4';
711 return dolGetStatus($this->labelStatus[$status], $this->labelStatusShort[$status],
'', $statusType, $mode);
722 $sql =
'SELECT rowid, date_creation as datec, tms as datem,';
723 $sql .=
' fk_user_creat, fk_user_modif';
724 $sql .=
' FROM '.MAIN_DB_PREFIX.$this->table_element.
' as t';
725 $sql .=
' WHERE t.rowid = '.((int) $id);
726 $result = $this->db->query($sql);
728 if ($this->db->num_rows($result)) {
729 $obj = $this->db->fetch_object($result);
731 $this->
id = $obj->rowid;
733 $this->user_creation_id = $obj->fk_user_creat;
734 $this->user_modification_id = $obj->fk_user_modif;
735 $this->date_creation = $this->db->jdate($obj->datec);
736 $this->date_modification = empty($obj->datem) ?
'' : $this->db->jdate($obj->datem);
739 $this->db->free($result);
753 $this->host =
'localhost';
754 $this->login =
'alogin';
767 $this->filters = array();
769 $sql =
'SELECT rowid, type, rulevalue, status';
770 $sql .=
' FROM '.MAIN_DB_PREFIX.
'emailcollector_emailcollectorfilter';
771 $sql .=
' WHERE fk_emailcollector = '.((int) $this->
id);
774 $resql = $this->db->query($sql);
776 $num = $this->db->num_rows($resql);
779 $obj = $this->db->fetch_object($resql);
780 $this->filters[$obj->rowid] = array(
'id' => $obj->rowid,
'type' => $obj->type,
'rulevalue' => $obj->rulevalue,
'status' => $obj->status);
783 $this->db->free($resql);
799 $this->actions = array();
801 $sql =
'SELECT rowid, type, actionparam, status';
802 $sql .=
' FROM '.MAIN_DB_PREFIX.
'emailcollector_emailcollectoraction';
803 $sql .=
' WHERE fk_emailcollector = '.((int) $this->
id);
804 $sql .=
' ORDER BY position';
806 $resql = $this->db->query($sql);
808 $num = $this->db->num_rows($resql);
811 $obj = $this->db->fetch_object($resql);
812 $this->actions[$obj->rowid] = array(
'id' => $obj->rowid,
'type' => $obj->type,
'actionparam' => $obj->actionparam,
'status' => $obj->status);
815 $this->db->free($resql);
834 $flags =
'/service=imap';
837 } elseif (empty($this->imap_encryption) || ($this->imap_encryption ==
'ssl' &&
getDolGlobalString(
'IMAP_FORCE_NOSSL'))) {
840 $flags .=
'/' . $this->imap_encryption;
843 $flags .=
'/novalidate-cert';
850 if (!empty($this->login) && strpos($this->login,
'/') !=
false) {
851 $partofauth = explode(
'/', $this->login);
852 $flags .=
'/authuser='.$partofauth[0].
'/user='.$partofauth[1];
855 $connectstringserver =
'{'.$this->host.
':'.$this->port.$flags.
'}';
857 return $connectstringserver;
868 if (function_exists(
'mb_convert_encoding')) {
870 $str = preg_replace(
"/ /",
"xxxSPACExxx", $str);
871 $str = preg_replace(
"/\[Gmail\]/",
"xxxGMAILxxx", $str);
873 if ($str = mb_convert_encoding($str,
"UTF-7")) {
875 $str = preg_replace(
"/\+A/",
"&A", $str);
877 $str = preg_replace(
"/xxxSPACExxx/",
" ", $str);
879 $str = preg_replace(
"/xxxGMAILxxx/",
"[Gmail]", $str);
883 $this->error =
"error: is not possible to encode this string '".$str.
"'";
903 $arrayofcollectors = $this->
fetchAll($user, 1);
906 foreach ($arrayofcollectors as $emailcollector) {
907 $result = $emailcollector->doCollectOneCollector(0);
908 dol_syslog(
"doCollect result = ".$result.
" for emailcollector->id = ".$emailcollector->id);
910 $this->error .=
'EmailCollector ID '.$emailcollector->id.
':'.$emailcollector->error.
'<br>';
911 if (!empty($emailcollector->errors)) {
912 $this->error .= implode(
'<br>', $emailcollector->errors);
914 $this->output .=
'EmailCollector ID '.$emailcollector->id.
': '.$emailcollector->lastresult.
'<br>';
933 global
$conf, $langs;
935 $errorforthisaction = 0;
938 $outputlangs = $langs;
941 $newlang =
GETPOST(
'lang_id',
'aZ09');
944 $newlang = !empty(
$object->thirdparty->default_lang) ?
$object->thirdparty->default_lang : $newlang;
946 if (!empty($newlang)) {
948 $outputlangs->setDefaultLang($newlang);
958 foreach ($arrayvaluetouse as $propertytooverwrite => $valueforproperty) {
961 $tmparray = explode(
'.', $propertytooverwrite);
962 if (count($tmparray) == 2) {
963 $tmpclass = $tmparray[0];
964 $tmpproperty = $tmparray[1];
966 $tmpproperty = $tmparray[0];
968 if ($tmpclass && ($tmpclass !=
$object->element)) {
978 $regforregex = array();
979 if (preg_match(
'/^EXTRACT:([a-zA-Z0-9_]+):(.*):([^:])$/', $valueforproperty, $regforregex)) {
980 $sourcefield = $regforregex[1];
981 $regexstring = $regforregex[2];
983 } elseif (preg_match(
'/^EXTRACT:([a-zA-Z0-9_]+):(.*)$/', $valueforproperty, $regforregex)) {
984 $sourcefield = $regforregex[1];
985 $regexstring = $regforregex[2];
988 if (!empty($sourcefield) && !empty($regexstring)) {
989 if (strtolower($sourcefield) ==
'body') {
990 $sourcestring = $messagetext;
991 } elseif (strtolower($sourcefield) ==
'subject') {
992 $sourcestring = $subject;
993 } elseif (strtolower($sourcefield) ==
'header') {
994 $sourcestring = $header;
998 $regforval = array();
1000 if (strtolower($sourcefield) ==
'body') {
1001 $regexoptions =
'ms';
1003 if (strtolower($sourcefield) ==
'header') {
1004 $regexoptions =
'm';
1008 if (preg_match(
'/'.$regexstring.
'/'.$regexoptions, $sourcestring, $regforval)) {
1010 $valueextracted = isset($regforval[count($regforval) - 1]) ? trim($regforval[count($regforval) - 1]) :
null;
1011 if (strtolower($sourcefield) ==
'header') {
1012 if (preg_match(
'/^options_/', $tmpproperty)) {
1015 if (property_exists(
$object, $tmpproperty)) {
1022 if (preg_match(
'/^options_/', $tmpproperty)) {
1025 if (property_exists(
$object, $tmpproperty)) {
1032 if (preg_match(
'/^options_/', $tmpproperty)) {
1033 $operationslog .=
'<br>Regex /'.dol_escape_htmltag($regexstring).
'/'.
dol_escape_htmltag($regexoptions).
' into '.strtolower($sourcefield).
' -> found '.
dol_escape_htmltag(
dol_trunc(
$object->array_options[preg_replace(
'/^options_/',
'', $tmpproperty)], 128));
1035 if (property_exists(
$object, $tmpproperty)) {
1043 if (property_exists(
$object, $tmpproperty)) {
1046 $tmp[$tmpproperty] =
null;
1049 $operationslog .=
'<br>Regex /'.dol_escape_htmltag($regexstring).
'/'.
dol_escape_htmltag($regexoptions).
' into '.strtolower($sourcefield).
' -> not found, so property '.
dol_escape_htmltag($tmpproperty).
' is set to null.';
1053 $errorforthisaction++;
1054 $this->error =
'The extract rule to use to overwrite properties has on an unknown source (must be HEADER, SUBJECT or BODY)';
1055 $this->errors[] = $this->error;
1057 $operationslog .=
'<br>'.$this->error;
1059 } elseif (preg_match(
'/^(SET|SETIFEMPTY):(.*)$/', $valueforproperty, $regforregex)) {
1061 if (preg_match(
'/^options_/', $tmpproperty)) {
1062 $valuecurrent =
$object->array_options[preg_replace(
'/^options_/',
'', $tmpproperty)];
1064 if (property_exists(
$object, $tmpproperty)) {
1065 $valuecurrent =
$object->$tmpproperty;
1068 $valuecurrent = $tmp[$tmpproperty];
1072 if ($regforregex[1] ==
'SET' || empty($valuecurrent)) {
1073 $valuetouse = $regforregex[2];
1076 $matcharray = array();
1077 preg_match_all(
'/__([a-z0-9]+(?:_[a-z0-9]+)?)__/i', $valuetouse, $matcharray);
1079 if (is_array($matcharray[1])) {
1080 foreach ($matcharray[1] as $keytoreplace) {
1081 if ($keytoreplace) {
1082 if (preg_match(
'/^options_/', $keytoreplace)) {
1083 $substitutionarray[
'__'.$keytoreplace.
'__'] =
$object->array_options[preg_replace(
'/^options_/',
'', $keytoreplace)];
1085 if (property_exists(
$object, $keytoreplace)) {
1086 $substitutionarray[
'__'.$keytoreplace.
'__'] =
$object->$keytoreplace;
1089 $substitutionarray[
'__'.$keytoreplace.
'__'] = $tmp[$keytoreplace];
1099 if (preg_match(
'/^options_/', $tmpproperty)) {
1100 $object->array_options[preg_replace(
'/^options_/',
'', $tmpproperty)] = $valuetouse;
1102 $operationslog .=
'<br>Set value '.dol_escape_htmltag($valuetouse).
' into object->array_options['.
dol_escape_htmltag(preg_replace(
'/^options_/',
'', $tmpproperty)).
']';
1104 if (property_exists(
$object, $tmpproperty)) {
1105 $object->$tmpproperty = $valuetouse;
1107 $tmp[$tmpproperty] = $valuetouse;
1110 $operationslog .=
'<br>Set value '.dol_escape_htmltag($valuetouse).
' into object->'.
dol_escape_htmltag($tmpproperty);
1114 $errorforthisaction++;
1115 $this->error =
'Bad syntax for description of action parameters: '.$actionparam;
1116 $this->errors[] = $this->error;
1121 return $errorforthisaction;
1130 public function doCollectOneCollector($mode = 0)
1132 global $db,
$conf, $langs, $user;
1133 global $hookmanager;
1137 require_once DOL_DOCUMENT_ROOT.
'/comm/action/class/actioncomm.class.php';
1139 require_once DOL_DOCUMENT_ROOT.
'/includes/webklex/php-imap/vendor/autoload.php';
1142 dol_syslog(
"EmailCollector::doCollectOneCollector start for id=".$this->
id.
" - ".$this->
ref, LOG_INFO);
1144 $langs->loadLangs(array(
"project",
"companies",
"mails",
"errors",
"ticket",
"agenda",
"commercial"));
1149 $this->debuginfo =
'';
1153 $searchfilterdoltrackid = 0;
1154 $searchfilternodoltrackid = 0;
1155 $searchfilterisanswer = 0;
1156 $searchfilterisnotanswer = 0;
1157 $searchfilterreplyto = 0;
1158 $searchfilterexcludebodyarray = array();
1159 $searchfilterexcludesubjectarray = array();
1160 $operationslog =
'';
1161 $rulesreplyto = array();
1162 $connectstringsource =
'';
1163 $connectstringtarget =
'';
1164 $connection =
false;
1165 $arrayofemail = array();
1169 if (empty($this->host)) {
1170 $this->error = $langs->trans(
'ErrorFieldRequired', $langs->transnoentitiesnoconv(
'EMailHost'));
1173 if (empty($this->login)) {
1174 $this->error = $langs->trans(
'ErrorFieldRequired', $langs->transnoentitiesnoconv(
'Login'));
1177 if (empty($this->source_directory)) {
1178 $this->error = $langs->trans(
'ErrorFieldRequired', $langs->transnoentitiesnoconv(
'MailboxSourceDirectory'));
1184 $sourcedir = $this->source_directory;
1185 $targetdir = ($this->target_directory ? $this->target_directory :
'');
1190 $sourcedir = $this->source_directory;
1191 $targetdir = ($this->target_directory ? $this->target_directory :
'');
1194 if ($this->acces_type == 1) {
1196 $this->debuginfo .=
'doCollectOneCollector is using method MAIN_IMAP_USE_PHPIMAP=1, access_type=1 (OAUTH2)<br>';
1198 require_once DOL_DOCUMENT_ROOT.
'/core/lib/oauth.lib.php';
1202 $keyforsupportedoauth2array = $this->oauth_service;
1203 if (preg_match(
'/^.*-/', $keyforsupportedoauth2array)) {
1204 $keyforprovider = preg_replace(
'/^.*-/',
'', $keyforsupportedoauth2array);
1206 $keyforprovider =
'';
1208 $keyforsupportedoauth2array = preg_replace(
'/-.*$/',
'', strtoupper($keyforsupportedoauth2array));
1209 $keyforsupportedoauth2array =
'OAUTH_'.$keyforsupportedoauth2array.
'_NAME';
1211 if (!empty($supportedoauth2array)) {
1212 $nameofservice = ucfirst(strtolower(empty($supportedoauth2array[$keyforsupportedoauth2array][
'callbackfile']) ?
'Unknown' : $supportedoauth2array[$keyforsupportedoauth2array][
'callbackfile']));
1213 $nameofservice .= ($keyforprovider ?
'-'.$keyforprovider :
'');
1214 $OAUTH_SERVICENAME = $nameofservice;
1216 $OAUTH_SERVICENAME =
'Unknown';
1219 $keyforparamtenant =
'OAUTH_'.strtoupper(empty($supportedoauth2array[$keyforsupportedoauth2array][
'callbackfile']) ?
'Unknown' : $supportedoauth2array[$keyforsupportedoauth2array][
'callbackfile']).($keyforprovider ?
'-'.$keyforprovider :
'').
'_TENANT';
1221 require_once DOL_DOCUMENT_ROOT.
'/includes/OAuth/bootstrap.php';
1230 $tokenobj = $storage->retrieveAccessToken($OAUTH_SERVICENAME);
1239 if (is_object($tokenobj) && $expire) {
1240 $this->debuginfo .=
'Refresh token '.$OAUTH_SERVICENAME.
'<br>';
1241 $credentials =
new Credentials(
1246 $serviceFactory = new \OAuth\ServiceFactory();
1247 $oauthname = explode(
'-', $OAUTH_SERVICENAME);
1251 if (preg_match(
'/^Microsoft/', $OAUTH_SERVICENAME)) {
1253 $tmp = explode(
'-', $OAUTH_SERVICENAME);
1254 $scopes = explode(
',',
getDolGlobalString(
'OAUTH_'.strtoupper($tmp[0]).(empty($tmp[1]) ?
'' :
'-'.$tmp[1]).
'_SCOPE'));
1257 $apiService = $serviceFactory->createService($oauthname[0], $credentials, $storage, $scopes);
1259 '@phan-var-force OAuth\OAuth2\Service\AbstractService|OAuth\OAuth1\Service\AbstractService $apiService';
1261 $refreshtoken = $tokenobj->getRefreshToken();
1262 $tokenobj = $apiService->refreshAccessToken($tokenobj);
1265 $tokenobj->setRefreshToken($refreshtoken);
1266 $storage->storeAccessToken($OAUTH_SERVICENAME, $tokenobj);
1268 $tokenobj = $storage->retrieveAccessToken($OAUTH_SERVICENAME);
1269 if (is_object($tokenobj)) {
1270 $token = $tokenobj->getAccessToken();
1272 $this->error =
"Token not found";
1277 $this->error = $e->getMessage();
1278 dol_syslog(
"CMailFile::sendfile: mail end error=".$this->error, LOG_ERR);
1282 $cm =
new ClientManager();
1283 $client = $cm->make([
1284 'host' => $this->host,
1285 'port' => $this->port,
1286 'encryption' => !empty($this->imap_encryption) ? $this->imap_encryption : false,
1287 'validate_cert' => true,
1288 'protocol' =>
'imap',
1289 'username' => $this->login,
1290 'password' => $token,
1291 'authentication' =>
"oauth",
1295 $this->debuginfo .=
'doCollectOneCollector is using method MAIN_IMAP_USE_PHPIMAP=1, access_type=0 (LOGIN)<br>';
1297 $cm =
new ClientManager();
1298 $client = $cm->make([
1299 'host' => $this->host,
1300 'port' => $this->port,
1301 'encryption' => !empty($this->imap_encryption) ? $this->imap_encryption : false,
1302 'validate_cert' => true,
1303 'protocol' =>
'imap',
1304 'username' => $this->login,
1305 'password' => $this->password,
1306 'authentication' =>
"login",
1314 }
catch (ConnectionFailedException $e) {
1315 $this->error = $e->getMessage();
1316 $this->errors[] = $this->error;
1317 dol_syslog(
"EmailCollector::doCollectOneCollector ".$this->error, LOG_ERR);
1321 $host = dol_getprefix(
'email');
1324 $this->debuginfo .=
'doCollectOneCollector is using method MAIN_IMAP_USE_PHPIMAP=0 (native PHP imap, LOGIN)<br>';
1326 if (!function_exists(
'imap_open')) {
1327 $this->error =
'IMAP function not enabled on your PHP';
1333 $connectstringsource = $connectstringserver.$this->getEncodedUtf7($sourcedir);
1334 $connectstringtarget = $connectstringserver.$this->getEncodedUtf7($targetdir);
1336 $connectstringsource = $connectstringserver.$sourcedir;
1337 $connectstringtarget = $connectstringserver.$targetdir;
1340 $this->debuginfo .=
'connectstringsource = '.$connectstringsource.
', $connectstringtarget='.$connectstringtarget.
'<br>';
1342 $connection = imap_open($connectstringsource, $this->login, $this->password);
1343 if ($connection ===
false) {
1344 $this->error =
'Failed to open IMAP connection '.$connectstringsource.
' '.imap_last_error();
1349 $host = dol_getprefix(
'email');
1358 $criteria = array();
1361 $criteria = array(array(
'UNDELETED'));
1362 foreach ($this->filters as $rule) {
1363 if (empty($rule[
'status'])) {
1368 if (strpos($rule[
'rulevalue'],
'!') === 0) {
1372 $rule[
'rulevalue'] = substr($rule[
'rulevalue'], 1);
1375 if ($rule[
'type'] ==
'from') {
1376 $tmprulevaluearray = explode(
'*', $rule[
'rulevalue']);
1377 if (count($tmprulevaluearray) >= 2) {
1378 foreach ($tmprulevaluearray as $tmprulevalue) {
1379 array_push($criteria, array($not.
"FROM" => $tmprulevalue));
1382 array_push($criteria, array($not.
"FROM" => $rule[
'rulevalue']));
1385 if ($rule[
'type'] ==
'to') {
1386 $tmprulevaluearray = explode(
'*', $rule[
'rulevalue']);
1387 if (count($tmprulevaluearray) >= 2) {
1388 foreach ($tmprulevaluearray as $tmprulevalue) {
1389 array_push($criteria, array($not.
"TO" => $tmprulevalue));
1392 array_push($criteria, array($not.
"TO" => $rule[
'rulevalue']));
1395 if ($rule[
'type'] ==
'bcc') {
1396 array_push($criteria, array($not.
"BCC" => $rule[
'rulevalue']));
1398 if ($rule[
'type'] ==
'cc') {
1399 array_push($criteria, array($not.
"CC" => $rule[
'rulevalue']));
1401 if ($rule[
'type'] ==
'subject') {
1402 if (strpos($rule[
'rulevalue'],
'!') === 0) {
1404 $searchfilterexcludesubjectarray[] = preg_replace(
'/^!/',
'', $rule[
'rulevalue']);
1406 array_push($criteria, array(
"SUBJECT" => $rule[
'rulevalue']));
1409 if ($rule[
'type'] ==
'body') {
1410 if (strpos($rule[
'rulevalue'],
'!') === 0) {
1412 $searchfilterexcludebodyarray[] = preg_replace(
'/^!/',
'', $rule[
'rulevalue']);
1414 array_push($criteria, array(
"BODY" => $rule[
'rulevalue']));
1417 if ($rule[
'type'] ==
'header') {
1418 array_push($criteria, array($not.
"HEADER" => $rule[
'rulevalue']));
1430 if ($rule[
'type'] ==
'seen') {
1431 array_push($criteria, array($not.
"SEEN"));
1433 if ($rule[
'type'] ==
'unseen') {
1434 array_push($criteria, array($not.
"UNSEEN"));
1436 if ($rule[
'type'] ==
'unanswered') {
1437 array_push($criteria, array($not.
"UNANSWERED"));
1439 if ($rule[
'type'] ==
'answered') {
1440 array_push($criteria, array($not.
"ANSWERED"));
1442 if ($rule[
'type'] ==
'smaller') {
1443 array_push($criteria, array($not.
"SMALLER"));
1445 if ($rule[
'type'] ==
'larger') {
1446 array_push($criteria, array($not.
"LARGER"));
1450 if ($rule[
'type'] ==
'withtrackingidinmsgid') {
1451 $searchfilterdoltrackid++;
1452 $searchhead .=
'/Message-ID.*@'.preg_quote($host,
'/').
'/';
1454 if ($rule[
'type'] ==
'withouttrackingidinmsgid') {
1455 $searchfilterdoltrackid++;
1456 $searchhead .=
'/Message-ID.*@'.preg_quote($host,
'/').
'/';
1458 if ($rule[
'type'] ==
'withtrackingid') {
1459 $searchfilterdoltrackid++;
1460 $searchhead .=
'/References.*@'.preg_quote($host,
'/').
'/';
1462 if ($rule[
'type'] ==
'withouttrackingid') {
1463 $searchfilternodoltrackid++;
1464 $searchhead .=
'! /References.*@'.preg_quote($host,
'/').
'/';
1467 if ($rule[
'type'] ==
'isanswer') {
1468 $searchfilterisanswer++;
1469 $searchhead .=
'/References.*@.*/';
1471 if ($rule[
'type'] ==
'isnotanswer') {
1472 $searchfilterisnotanswer++;
1473 $searchhead .=
'! /References.*@.*/';
1476 if ($rule[
'type'] ==
'replyto') {
1477 $searchfilterreplyto++;
1478 $rulesreplyto[] = $rule[
'rulevalue'];
1479 $searchhead .=
'/Reply-To.*'.preg_quote($rule[
'rulevalue'],
'/').
'/';
1483 if (empty($targetdir) || !
getDolGlobalString(
'EMAILCOLLECTOR_NO_FILTER_ON_DATE_IF_THERE_IS_A_TARGETDIR')) {
1485 if ($this->datelastok) {
1486 $fromdate = $this->datelastok;
1488 if ($fromdate > 0) {
1490 array_push($criteria, array(
"SINCE" => date(
'j-M-Y', $fromdate - 1)));
1495 dol_syslog(
"IMAP search string = ".var_export($criteria,
true));
1496 $search = var_export($criteria,
true);
1499 $search =
'UNDELETED';
1500 foreach ($this->filters as $rule) {
1501 if (empty($rule[
'status'])) {
1509 if (!empty($rule[
'rulevalue']) && strpos($rule[
'rulevalue'],
'!') === 0) {
1513 $rule[
'rulevalue'] = substr($rule[
'rulevalue'], 1);
1516 if ($rule[
'type'] ==
'from') {
1517 $tmprulevaluearray = explode(
'*', $rule[
'rulevalue']);
1518 if (count($tmprulevaluearray) >= 2) {
1519 foreach ($tmprulevaluearray as $tmprulevalue) {
1520 $search .= ($search ?
' ' :
'').$not.
'FROM "'.str_replace(
'"',
'', $tmprulevalue).
'"';
1523 $search .= ($search ?
' ' :
'').$not.
'FROM "'.str_replace(
'"',
'', $rule[
'rulevalue']).
'"';
1526 if ($rule[
'type'] ==
'to') {
1527 $tmprulevaluearray = explode(
'*', $rule[
'rulevalue']);
1528 if (count($tmprulevaluearray) >= 2) {
1529 foreach ($tmprulevaluearray as $tmprulevalue) {
1530 $search .= ($search ?
' ' :
'').$not.
'TO "'.str_replace(
'"',
'', $tmprulevalue).
'"';
1533 $search .= ($search ?
' ' :
'').$not.
'TO "'.str_replace(
'"',
'', $rule[
'rulevalue']).
'"';
1536 if ($rule[
'type'] ==
'bcc') {
1537 $search .= ($search ?
' ' :
'').$not.
'BCC';
1539 if ($rule[
'type'] ==
'cc') {
1540 $search .= ($search ?
' ' :
'').$not.
'CC';
1542 if ($rule[
'type'] ==
'subject') {
1545 $searchfilterexcludesubjectarray[] = $rule[
'rulevalue'];
1547 $search .= ($search ?
' ' :
'').
'SUBJECT "'.str_replace(
'"',
'', $rule[
'rulevalue']).
'"';
1550 if ($rule[
'type'] ==
'body') {
1553 $searchfilterexcludebodyarray[] = $rule[
'rulevalue'];
1556 $search .= ($search ?
' ' :
'').
'BODY "'.str_replace(
'"',
'', $rule[
'rulevalue']).
'"';
1559 if ($rule[
'type'] ==
'header') {
1560 $search .= ($search ?
' ' :
'').$not.
'HEADER '.$rule[
'rulevalue'];
1572 if ($rule[
'type'] ==
'seen') {
1573 $search .= ($search ?
' ' :
'').$not.
'SEEN';
1575 if ($rule[
'type'] ==
'unseen') {
1576 $search .= ($search ?
' ' :
'').$not.
'UNSEEN';
1578 if ($rule[
'type'] ==
'unanswered') {
1579 $search .= ($search ?
' ' :
'').$not.
'UNANSWERED';
1581 if ($rule[
'type'] ==
'answered') {
1582 $search .= ($search ?
' ' :
'').$not.
'ANSWERED';
1584 if ($rule[
'type'] ==
'smaller') {
1585 $search .= ($search ?
' ' :
'').$not.
'SMALLER "'.str_replace(
'"',
'', $rule[
'rulevalue']).
'"';
1587 if ($rule[
'type'] ==
'larger') {
1588 $search .= ($search ?
' ' :
'').$not.
'LARGER "'.str_replace(
'"',
'', $rule[
'rulevalue']).
'"';
1592 if ($rule[
'type'] ==
'withtrackingidinmsgid') {
1593 $searchfilterdoltrackid++;
1594 $searchhead .=
'/Message-ID.*@'.preg_quote($host,
'/').
'/';
1596 if ($rule[
'type'] ==
'withouttrackingidinmsgid') {
1597 $searchfilterdoltrackid++;
1598 $searchhead .=
'/Message-ID.*@'.preg_quote($host,
'/').
'/';
1600 if ($rule[
'type'] ==
'withtrackingid') {
1601 $searchfilterdoltrackid++;
1602 $searchhead .=
'/References.*@'.preg_quote($host,
'/').
'/';
1604 if ($rule[
'type'] ==
'withouttrackingid') {
1605 $searchfilternodoltrackid++;
1606 $searchhead .=
'! /References.*@'.preg_quote($host,
'/').
'/';
1609 if ($rule[
'type'] ==
'isanswer') {
1610 $searchfilterisanswer++;
1611 $searchhead .=
'/References.*@.*/';
1613 if ($rule[
'type'] ==
'isnotanswer') {
1614 $searchfilterisnotanswer++;
1615 $searchhead .=
'! /References.*@.*/';
1618 if ($rule[
'type'] ==
'replyto') {
1619 $searchfilterreplyto++;
1620 $rulesreplyto[] = $rule[
'rulevalue'];
1621 $searchhead .=
'/Reply-To.*'.preg_quote($rule[
'rulevalue'],
'/').
'/';
1625 if (empty($targetdir)) {
1627 if ($this->datelastok) {
1628 $fromdate = $this->datelastok;
1630 if ($fromdate > 0) {
1631 $search .= ($search ?
' ' :
'').
'SINCE '.date(
'j-M-Y', $fromdate - 1);
1640 $nbemailprocessed = 0;
1643 $charset = ($this->hostcharset ? $this->hostcharset :
"UTF-8");
1644 $arrayofemail = array();
1651 $tmpsourcedir = $sourcedir;
1656 $f = $client->getFolders(
false, $tmpsourcedir);
1659 if ($folder instanceof Webklex\PHPIMAP\Folder) {
1660 $Query = $folder->messages()->where($criteria);
1663 $this->error =
"Source directory ".$sourcedir.
" not found";
1664 $this->errors[] = $this->error;
1665 dol_syslog(
"EmailCollector::doCollectOneCollector ".$this->error, LOG_WARNING);
1670 $this->error =
"Failed to execute getfolders";
1671 $this->errors[] = $this->error;
1672 dol_syslog(
"EmailCollector::doCollectOneCollector ".$this->error, LOG_ERR);
1675 }
catch (InvalidWhereQueryCriteriaException $e) {
1676 $this->error = $e->getMessage();
1677 $this->errors[] = $this->error;
1678 dol_syslog(
"EmailCollector::doCollectOneCollector ".$this->error, LOG_ERR);
1681 $this->error = $e->getMessage();
1682 $this->errors[] = $this->error;
1683 dol_syslog(
"EmailCollector::doCollectOneCollector ".$this->error, LOG_ERR);
1687 '@phan-var-force Webklex\PHPIMAP\Query\Query $Query';
1691 $Query->leaveUnread();
1693 $arrayofemail = $Query->limit($this->maxemailpercollect)->setFetchOrder(
"asc")->get();
1694 dol_syslog(
"EmailCollector::doCollectOneCollector nb arrayofemail ".(is_array($arrayofemail) ? count($arrayofemail) :
'Not array'));
1697 $this->error = $e->getMessage();
1698 $this->errors[] = $this->error;
1699 dol_syslog(
"EmailCollector::doCollectOneCollector ".$this->error, LOG_ERR);
1702 } elseif ($connection !==
false) {
1704 $arrayofemail = imap_search($connection, $search, SE_UID, $charset);
1706 if ($arrayofemail ===
false) {
1708 $mapoferrrors = imap_errors();
1709 if ($mapoferrrors !==
false) {
1711 $this->error =
"Search string not understood - ".implode(
',', $mapoferrrors);
1712 $this->errors[] = $this->error;
1717 $arrayofemailtodelete = array();
1720 if (!$error && !empty($arrayofemail) && count($arrayofemail) > 0 && $connection !==
false) {
1737 dol_syslog(
"Start of loop on email", LOG_INFO, 1);
1739 $richarrayofemail = array();
1741 foreach ($arrayofemail as $imapemail) {
1742 if ($nbemailprocessed > 1000) {
1748 '@phan-var-force Webklex\PHPIMAP\Message $imapemail';
1749 $header = $imapemail->getHeader()->raw;
1750 $overview = $imapemail->getAttributes();
1752 $header = imap_fetchheader($connection, $imapemail, FT_UID);
1753 $overview = imap_fetch_overview($connection, $imapemail, FT_UID);
1756 $header = preg_replace(
'/\r\n\s+/m',
' ', $header);
1759 preg_match_all(
'/([^: ]+): (.+?(?:\r\n\s(?:.+?))*)(\r\n|\s$)/m', $header, $matches);
1760 $headers = array_combine($matches[1], $matches[2]);
1763 $richarrayofemail[] = array(
'imapemail' => $imapemail,
'header' => $header,
'headers' => $headers,
'overview' => $overview,
'date' => strtotime($headers[
'Date']));
1768 $richarrayofemail =
dol_sort_array($richarrayofemail,
'date',
'asc');
1772 foreach ($richarrayofemail as $tmpval) {
1775 $imapemail = $tmpval[
'imapemail'];
1776 $header = $tmpval[
'header'];
1777 $overview = $tmpval[
'overview'];
1778 $headers = $tmpval[
'headers'];
1780 if (!empty($headers[
'in-reply-to']) && empty($headers[
'In-Reply-To'])) {
1781 $headers[
'In-Reply-To'] = $headers[
'in-reply-to'];
1783 if (!empty($headers[
'references']) && empty($headers[
'References'])) {
1784 $headers[
'References'] = $headers[
'references'];
1786 if (!empty($headers[
'message-id']) && empty($headers[
'Message-ID'])) {
1787 $headers[
'Message-ID'] = $headers[
'message-id'];
1789 if (!empty($headers[
'subject']) && empty($headers[
'Subject'])) {
1790 $headers[
'Subject'] = $headers[
'subject'];
1796 $emailto = (string) $overview[
'to'];
1803 $operationslog .=
'<br>** Process email #'.dol_escape_htmltag((
string) $iforemailloop);
1807 '@phan-var-force Webklex\PHPIMAP\Message $imapemail';
1809 $msgid = str_replace(array(
'<',
'>'),
'', $overview[
'message_id']);
1811 $operationslog .=
" - ".dol_escape_htmltag((
string) $imapemail);
1812 $msgid = str_replace(array(
'<',
'>'),
'', $overview[0]->message_id);
1814 $operationslog .=
" - MsgId: ".$msgid;
1815 $operationslog .=
" - Date: ".($headers[
'Date'] ?? $langs->transnoentitiesnoconv(
"NotFound"));
1816 $operationslog .=
" - References: ".dol_escape_htmltag($headers[
'References'] ?? $langs->transnoentitiesnoconv(
"NotFound")).
" - Subject: ".
dol_escape_htmltag($headers[
'Subject']);
1818 dol_syslog(
"-- Process email #".$iforemailloop.
", MsgId: ".$msgid.
", Date: ".($headers[
'Date'] ??
'').
", References: ".($headers[
'References'] ??
'').
", Subject: ".$headers[
'Subject']);
1821 $trackidfoundintorecipienttype =
'';
1822 $trackidfoundintorecipientid = 0;
1827 if (preg_match(
'/\+(th[i]|ctc|use|mem|sub|proj|tas|con|tic|pro|ord|inv|spro|sor|sin|leav|stockinv|job|surv|salary)([0-9]+)@/', $emailto, $reg)) {
1828 $trackidfoundintorecipienttype = $reg[1];
1829 $trackidfoundintorecipientid = $reg[2];
1830 } elseif (preg_match(
'/\+emailing-(\w+)@/', $emailto, $reg)) {
1831 $trackidfoundintorecipienttype =
'emailing';
1832 $trackidfoundintorecipientid = $reg[1];
1835 $trackidfoundintomsgidtype =
'';
1836 $trackidfoundintomsgidid = 0;
1841 if (preg_match(
'/(?:[\+\-])(th[i]|ctc|use|mem|sub|proj|tas|con|tic|pro|ord|inv|spro|sor|sin|leav|stockinv|job|surv|salary)([0-9]+)@/', $msgid, $reg)) {
1842 $trackidfoundintomsgidtype = $reg[1];
1843 $trackidfoundintomsgidid = $reg[2];
1844 } elseif (preg_match(
'/(?:[\+\-])emailing-(\w+)@/', $msgid, $reg)) {
1845 $trackidfoundintomsgidtype =
'emailing';
1846 $trackidfoundintomsgidid = $reg[1];
1850 if ($searchfilterdoltrackid > 0) {
1851 if (empty($trackidfoundintorecipienttype) && empty($trackidfoundintomsgidtype)) {
1852 if (empty($headers[
'References']) || !preg_match(
'/@'.preg_quote($host,
'/').
'/', $headers[
'References'])) {
1853 $nbemailprocessed++;
1854 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");
1859 if ($searchfilternodoltrackid > 0) {
1860 if (!empty($trackidfoundintorecipienttype) || !empty($trackidfoundintomsgidtype) || (!empty($headers[
'References']) && preg_match(
'/@'.preg_quote($host,
'/').
'/', $headers[
'References']))) {
1861 $nbemailprocessed++;
1862 dol_syslog(
" Discarded - Suffix found into email or Header References found and matching signature of application so with a trackid");
1867 if ($searchfilterisanswer > 0) {
1868 if (empty($headers[
'In-Reply-To'])) {
1869 $nbemailprocessed++;
1870 dol_syslog(
" Discarded - Email is not an answer (no In-Reply-To header)");
1874 if (preg_match(
'/^(Re|AW)\s*:\s+/i', $headers[
'Subject'])) {
1880 if (!empty($headers[
'In-Reply-To'])) {
1888 $nbemailprocessed++;
1889 dol_syslog(
" Discarded - Email is not an answer (no RE prefix in subject)");
1893 if ($searchfilterisnotanswer > 0) {
1894 if (!empty($headers[
'In-Reply-To'])) {
1898 if (preg_match(
'/Re\s*:\s+/i', $headers[
'Subject'])) {
1904 $nbemailprocessed++;
1905 dol_syslog(
" Discarded - Email is an answer");
1910 if ($searchfilterreplyto > 0) {
1911 if (!empty($headers[
'Reply-To'])) {
1913 foreach ($rulesreplyto as $key => $rulereplyto) {
1914 if (preg_match(
'/'.preg_quote($rulereplyto,
'/').
'/', $headers[
'Reply-To'])) {
1919 if (!$isreplytook || $isreplytook != count($rulesreplyto)) {
1920 $nbemailprocessed++;
1921 dol_syslog(
" Discarded - Reply-to does not match");
1929 $thirdpartystatic =
new Societe($this->db);
1930 $contactstatic =
new Contact($this->db);
1931 $projectstatic =
new Project($this->db);
1933 $nbactiondoneforemail = 0;
1935 $errorforactions = 0;
1936 $thirdpartyfoundby =
'';
1937 $contactfoundby =
'';
1938 $projectfoundby =
'';
1939 $ticketfoundby =
'';
1940 $candidaturefoundby =
'';
1944 dol_syslog(
"msgid=".$overview[
'message_id'].
" date=".
dol_print_date($overview[
'date'],
'dayrfc',
'gmt').
" from=".$overview[
'from'].
" to=".$overview[
'to'].
" subject=".$overview[
'subject']);
1949 dol_syslog(
"msgid=".$overview[0]->message_id.
" date=".
dol_print_date($overview[0]->udate,
'dayrfc',
'gmt').
" from=".$overview[0]->from.
" to=".$overview[0]->to.
" subject=".$overview[0]->subject);
1959 global $htmlmsg, $plainmsg, $charset, $attachments;
1963 '@phan-var-force Webklex\PHPIMAP\Message $imapemail';
1964 if ($imapemail->hasHTMLBody()) {
1965 $htmlmsg = $imapemail->getHTMLBody();
1967 if ($imapemail->hasTextBody()) {
1968 $plainmsg = $imapemail->getTextBody();
1970 if ($imapemail->hasAttachments()) {
1971 $attachments = $imapemail->getAttachments()->all();
1976 $this->
getmsg($connection, $imapemail);
1978 '@phan-var-force Webklex\PHPIMAP\Attachment[] $attachments';
1990 $operationslog .=
'<br>Discarded - Email body is not valid utf8';
1991 dol_syslog(
" Discarded - Email body is not valid utf8");
1995 if (!empty($searchfilterexcludebodyarray)) {
1996 foreach ($searchfilterexcludebodyarray as $searchfilterexcludebody) {
1997 if (preg_match(
'/'.preg_quote($searchfilterexcludebody,
'/').
'/ms', $messagetext)) {
1998 $nbemailprocessed++;
1999 $operationslog .=
'<br>Discarded - Email body contains string '.$searchfilterexcludebody;
2000 dol_syslog(
" Discarded - Email body contains string ".$searchfilterexcludebody);
2062 $replytostring =
'';
2065 $fromstring = $overview[
'from'];
2066 $replytostring = empty($overview[
'in_reply-to']) ? $headers[
'Reply-To'] : $overview[
'in_reply-to'];
2068 $sender = $overview[
'sender'];
2069 $to = $overview[
'to'];
2070 $sendtocc = empty($overview[
'cc']) ?
'' : $overview[
'cc'];
2071 $sendtobcc = empty($overview[
'bcc']) ?
'' : $overview[
'bcc'];
2073 $tmpdate = $overview[
'date']->toDate();
2074 $tmptimezone = $tmpdate->getTimezone()->getName();
2077 if (preg_match(
'/^([+\-])(\d\d):(\d\d)/', $tmptimezone, $reg)) {
2078 if ($reg[1] ==
'+' && ($reg[2] !=
'00' || $reg[3] !=
'00')) {
2079 $dateemail -= (3600 * (int) $reg[2]);
2080 $dateemail -= (60 * (int) $reg[3]);
2082 if ($reg[1] ==
'-' && ($reg[2] !=
'00' || $reg[3] !=
'00')) {
2083 $dateemail += (3600 * (int) $reg[2]);
2084 $dateemail += (60 * (int) $reg[3]);
2087 $subject = $overview[
'subject'];
2089 $fromstring = $overview[0]->from;
2090 $replytostring = (!empty($overview[
'in_reply-to']) ? $overview[
'in_reply-to'] : (!empty($headers[
'Reply-To']) ? $headers[
'Reply-To'] :
"")) ;
2092 $sender = !empty($overview[0]->sender) ? $overview[0]->sender :
'';
2093 $to = $overview[0]->to;
2094 $sendtocc = !empty($overview[0]->cc) ? $overview[0]->cc :
'';
2095 $sendtobcc = !empty($overview[0]->bcc) ? $overview[0]->bcc :
'';
2097 $subject = $overview[0]->subject;
2101 if (!empty($searchfilterexcludesubjectarray)) {
2102 foreach ($searchfilterexcludesubjectarray as $searchfilterexcludesubject) {
2103 if (preg_match(
'/'.preg_quote($searchfilterexcludesubject,
'/').
'/ms', $subject)) {
2104 $nbemailprocessed++;
2105 $operationslog .=
'<br>Discarded - Email subject contains string '.$searchfilterexcludesubject;
2106 dol_syslog(
" Discarded - Email subject contains string ".$searchfilterexcludesubject);
2113 if (preg_match(
'/^(.*)<(.*)>$/', $fromstring, $reg)) {
2115 $fromtext = $reg[1];
2117 $from = $fromstring;
2120 if (preg_match(
'/^(.*)<(.*)>$/', $replytostring, $reg)) {
2122 $replytotext = $reg[1];
2124 $replyto = $replytostring;
2128 $fk_element_type =
'';
2145 $objectemail =
null;
2148 $arrayofreferences = array();
2149 if (!empty($headers[
'References'])) {
2150 $arrayofreferences = preg_split(
'/(,|\s+)/', $headers[
'References']);
2152 if (!in_array(
'<'.$msgid.
'>', $arrayofreferences)) {
2153 $arrayofreferences = array_merge($arrayofreferences, array(
'<'.$msgid.
'>'));
2158 foreach ($arrayofreferences as $reference) {
2160 if (!empty($trackidfoundintorecipienttype)) {
2161 $resultsearchtrackid = -1;
2162 $reg[1] = $trackidfoundintorecipienttype;
2163 $reg[2] = $trackidfoundintorecipientid;
2164 } elseif (!empty($trackidfoundintomsgidtype)) {
2165 $resultsearchtrackid = -1;
2166 $reg[1] = $trackidfoundintomsgidtype;
2167 $reg[2] = $trackidfoundintomsgidid;
2169 $resultsearchtrackid = preg_match(
'/dolibarr-([a-z]+)([0-9]+)@'.preg_quote($host,
'/').
'/', $reference, $reg);
2170 if (empty($resultsearchtrackid) &&
getDolGlobalString(
'EMAIL_ALTERNATIVE_HOST_SIGNATURE')) {
2171 $resultsearchtrackid = preg_match(
'/dolibarr-([a-z]+)([0-9]+)@'.preg_quote(
getDolGlobalString(
'EMAIL_ALTERNATIVE_HOST_SIGNATURE'),
'/').
'/', $reference, $reg);
2175 if (!empty($resultsearchtrackid)) {
2177 $trackid = $reg[1].$reg[2];
2179 $objectid = $reg[2];
2181 if ($reg[1] ==
'thi') {
2182 $objectemail =
new Societe($this->db);
2184 if ($reg[1] ==
'ctc') {
2185 $objectemail =
new Contact($this->db);
2187 if ($reg[1] ==
'inv') {
2188 $objectemail =
new Facture($this->db);
2190 if ($reg[1] ==
'sinv') {
2193 if ($reg[1] ==
'pro') {
2194 $objectemail =
new Propal($this->db);
2196 if ($reg[1] ==
'ord') {
2197 $objectemail =
new Commande($this->db);
2199 if ($reg[1] ==
'shi') {
2202 if ($reg[1] ==
'spro') {
2205 if ($reg[1] ==
'sord') {
2208 if ($reg[1] ==
'rec') {
2209 $objectemail =
new Reception($this->db);
2211 if ($reg[1] ==
'proj') {
2212 $objectemail =
new Project($this->db);
2213 $projectfoundby =
'TrackID dolibarr-'.$trackid.
'@...';
2215 if ($reg[1] ==
'tas') {
2216 $objectemail =
new Task($this->db);
2218 if ($reg[1] ==
'con') {
2219 $objectemail =
new Contact($this->db);
2221 if ($reg[1] ==
'use') {
2222 $objectemail =
new User($this->db);
2224 if ($reg[1] ==
'tic') {
2225 $objectemail =
new Ticket($this->db);
2226 $ticketfoundby =
'TrackID dolibarr-'.$trackid.
'@...';
2228 if ($reg[1] ==
'recruitmentcandidature') {
2230 $candidaturefoundby =
'TrackID dolibarr-'.$trackid.
'@...';
2232 if ($reg[1] ==
'mem') {
2233 $objectemail =
new Adherent($this->db);
2241 } elseif (preg_match(
'/<(.*@.*)>/', $reference, $reg)) {
2243 if (is_null($objectemail) && isModEnabled(
'ticket')) {
2244 $sql =
"SELECT rowid FROM ".MAIN_DB_PREFIX.
"ticket";
2245 $sql .=
" WHERE email_msgid = '".$this->db->escape($reg[1]).
"' OR origin_references like '%".$this->db->escape($this->db->escapeforlike($reg[1])).
"%'";
2246 $resql = $this->db->query($sql);
2248 $obj = $this->db->fetch_object($resql);
2250 $objectid = $obj->rowid;
2251 $objectemail =
new Ticket($this->db);
2252 $ticketfoundby = $langs->transnoentitiesnoconv(
"EmailMsgID").
' ('.$reg[1].
')';
2259 if (!is_object($objectemail) && isModEnabled(
'project')) {
2260 $sql =
"SELECT rowid FROM ".MAIN_DB_PREFIX.
"projet where email_msgid = '".$this->db->escape($reg[1]).
"'";
2261 $resql = $this->db->query($sql);
2263 $obj = $this->db->fetch_object($resql);
2265 $objectid = $obj->rowid;
2266 $objectemail =
new Project($this->db);
2267 $projectfoundby = $langs->transnoentitiesnoconv(
"EmailMsgID").
' ('.$reg[1].
')';
2274 if (!is_object($objectemail) && isModEnabled(
'recruitment')) {
2275 $sql =
"SELECT rowid FROM ".MAIN_DB_PREFIX.
"recruitment_recruitmentcandidature where email_msgid = '".$this->db->escape($reg[1]).
"'";
2276 $resql = $this->db->query($sql);
2278 $obj = $this->db->fetch_object($resql);
2280 $objectid = $obj->rowid;
2282 $candidaturefoundby = $langs->transnoentitiesnoconv(
"EmailMsgID").
' ('.$reg[1].
')';
2291 if (is_object($objectemail)) {
2292 $result = $objectemail->fetch($objectid);
2294 $fk_element_id = $objectemail->id;
2295 $fk_element_type = $objectemail->element;
2297 if ($fk_element_type ==
'facture') {
2298 $fk_element_type =
'invoice';
2301 if (get_class($objectemail) !=
'Societe') {
2302 $thirdpartyid = $objectemail->fk_soc ?? $objectemail->socid;
2304 $thirdpartyid = $objectemail->id;
2307 if (get_class($objectemail) !=
'Contact') {
2308 $contactid = $objectemail->fk_socpeople;
2310 $contactid = $objectemail->id;
2313 if (get_class($objectemail) !=
'Project') {
2314 $projectid = isset($objectemail->fk_project) ? $objectemail->fk_project : $objectemail->fk_projet;
2316 $projectid = $objectemail->id;
2319 if ($objectemail instanceof
Ticket) {
2320 $ticketid = $objectemail->id;
2322 $changeonticket_references =
false;
2323 if (empty($trackid)) {
2324 $trackid = $objectemail->track_id;
2326 if (empty($objectemail->origin_references)) {
2327 $objectemail->origin_references = $headers[
'References'];
2328 $changeonticket_references =
true;
2330 foreach ($arrayofreferences as $key => $referencetmp) {
2331 if (!str_contains($objectemail->origin_references, $referencetmp)) {
2332 $objectemail->origin_references .=
" ".$referencetmp;
2333 $changeonticket_references =
true;
2337 if ($changeonticket_references) {
2338 $objectemail->update($user, 1);
2345 if ($projectid > 0) {
2346 $result = $projectstatic->fetch($projectid);
2348 $projectstatic->id = 0;
2350 $projectid = $projectstatic->id;
2352 $projectfoundby =
'trackid ('.$trackid.
')';
2354 if (empty($contactid)) {
2355 $contactid = $projectstatic->fk_contact;
2357 if (empty($thirdpartyid)) {
2358 $thirdpartyid = $projectstatic->fk_soc;
2363 if ($contactid > 0) {
2364 $result = $contactstatic->fetch($contactid);
2366 $contactstatic->id = 0;
2368 $contactid = $contactstatic->id;
2370 $contactfoundby =
'trackid ('.$trackid.
')';
2372 if (empty($thirdpartyid)) {
2373 $thirdpartyid = $contactstatic->fk_soc;
2378 if ($thirdpartyid > 0) {
2379 $result = $thirdpartystatic->fetch($thirdpartyid);
2381 $thirdpartystatic->id = 0;
2383 $thirdpartyid = $thirdpartystatic->id;
2385 $thirdpartyfoundby =
'trackid ('.$trackid.
')';
2390 if (is_object($objectemail)) {
2395 if (empty($contactid)) {
2396 $result = $contactstatic->fetch(0,
null,
'', $from);
2399 dol_syslog(
"We found a contact with the email ".$from);
2400 $contactid = $contactstatic->id;
2401 $contactfoundby =
'email of contact ('.$from.
')';
2402 if (empty($thirdpartyid) && $contactstatic->socid > 0) {
2403 $result = $thirdpartystatic->fetch($contactstatic->socid);
2405 $thirdpartyid = $thirdpartystatic->id;
2406 $thirdpartyfoundby =
'email of contact ('.$from.
')';
2412 if (empty($thirdpartyid)) {
2413 $result = $thirdpartystatic->fetch(0,
'',
'',
'',
'',
'',
'',
'',
'',
'', $from);
2415 dol_syslog(
"We found a thirdparty with the email ".$from);
2416 $thirdpartyid = $thirdpartystatic->id;
2417 $thirdpartyfoundby =
'email ('.$from.
')';
2453 foreach ($this->actions as $operation) {
2454 $errorforthisaction = 0;
2455 $ticketalreadyexists = 0;
2456 if ($errorforactions) {
2459 if (empty($operation[
'status'])) {
2463 $operationslog .=
'<br>* Process operation '.$operation[
'type'];
2466 dol_syslog(
"Execute action ".$operation[
'type'].
" actionparam=".$operation[
'actionparam'].
' thirdpartystatic->id='.$thirdpartystatic->id.
' contactstatic->id='.$contactstatic->id.
' projectstatic->id='.$projectstatic->id);
2467 dol_syslog(
"Execute action fk_element_id=".$fk_element_id.
" fk_element_type=".$fk_element_type);
2470 $actioncode =
'EMAIL_IN';
2472 if (preg_match(
'/Sent$/', $sourcedir) || preg_match(
'/envoyés$/i', $sourcedir)) {
2473 $actioncode =
'EMAIL';
2476 $arrayofemailtoconsideresender = explode(
',',
getDolGlobalString(
'MAIL_FROM_EMAILS_TO_CONSIDER_SENDING'));
2477 foreach ($arrayofemailtoconsideresender as $emailtoconsidersender) {
2478 if (preg_match(
'/'.preg_quote($emailtoconsidersender,
'/').
'/', $fromstring)) {
2479 $actioncode =
'EMAIL';
2482 $operationslog .=
'<br>Email will have actioncode='.$actioncode;
2484 $description = $descriptiontitle = $descriptionmeta = $descriptionfull =
'';
2486 $descriptiontitle = $langs->transnoentitiesnoconv(
"RecordCreatedByEmailCollector", $this->
ref);
2491 $descriptionmeta =
dol_concatdesc($descriptionmeta, $langs->trans(
"MailFrom").($langs->trans(
"MailFrom") !=
'From' ?
' (From)' :
'').
' : '.
dol_escape_htmltag($fromstring));
2493 $descriptionmeta =
dol_concatdesc($descriptionmeta, $langs->trans(
"Sender").($langs->trans(
"Sender") !=
'Sender' ?
' (Sender)' :
'').
' : '.
dol_escape_htmltag($sender));
2495 $descriptionmeta =
dol_concatdesc($descriptionmeta, $langs->trans(
"MailTo").($langs->trans(
"MailTo") !=
'To' ?
' (To)' :
'').
' : '.
dol_escape_htmltag($to));
2497 $descriptionmeta =
dol_concatdesc($descriptionmeta, $langs->trans(
"MailReply").($langs->trans(
"MailReply") !=
'Reply to' ?
' (Reply to)' :
'').
' : '.
dol_escape_htmltag($replyto));
2500 $descriptionmeta =
dol_concatdesc($descriptionmeta, $langs->trans(
"MailCC").($langs->trans(
"MailCC") !=
'CC' ?
' (CC)' :
'').
' : '.
dol_escape_htmltag($sendtocc));
2503 if ($operation[
'type'] ==
'ticket') {
2505 $tickettocreate =
new Ticket($this->db);
2506 $errorfetchticket = 0;
2507 $alreadycreated = 0;
2508 if (!empty($trackid)) {
2509 $alreadycreated = $tickettocreate->fetch(0,
'', $trackid);
2511 if ($alreadycreated == 0 && !empty($msgid)) {
2512 $alreadycreated = $tickettocreate->fetch(0,
'',
'', $msgid);
2514 if ($alreadycreated < 0) {
2515 $errorfetchticket++;
2517 if (empty($errorfetchticket)) {
2518 if ($alreadycreated == 0) {
2519 $operationslog .=
'<br>Ticket not found using trackid='.$trackid.
' or msgid='.$msgid;
2520 $ticketalreadyexists = 0;
2522 $operationslog .=
'<br>Ticket already found using trackid='.$trackid.
' or msgid='.$msgid;
2523 $ticketalreadyexists = 1;
2524 $operation[
'type'] =
'recordevent';
2527 $ticketalreadyexists = -1;
2534 if ($operation[
'type'] ==
'loadthirdparty' || $operation[
'type'] ==
'loadandcreatethirdparty') {
2535 if (empty($operation[
'actionparam'])) {
2537 $this->error =
"Action loadthirdparty or loadandcreatethirdparty has empty parameter. Must be a rule like 'name=HEADER:^From:(.*);' or 'name=SET:xxx' or 'name=EXTRACT:(body|subject):regex where 'name' can be replaced with 'id' or 'email' to define how to set or extract data. More properties can also be set, for example client=SET:2;";
2538 $this->errors[] = $this->error;
2540 $actionparam = $operation[
'actionparam'];
2541 $idtouseforthirdparty =
'';
2542 $nametouseforthirdparty =
'';
2543 $emailtouseforthirdparty =
'';
2544 $namealiastouseforthirdparty =
'';
2546 $operationslog .=
'<br>Loop on each property to set into actionparam';
2550 foreach ($arrayvaluetouse as $propertytooverwrite => $valueforproperty) {
2554 $regforregex = array();
2556 if (preg_match(
'/^EXTRACT:([a-zA-Z0-9_]+):(.*)$/', $valueforproperty, $regforregex)) {
2557 $sourcefield = $regforregex[1];
2558 $regexstring = $regforregex[2];
2561 if (!empty($sourcefield) && !empty($regexstring)) {
2562 if (strtolower($sourcefield) ==
'body') {
2563 $sourcestring = $messagetext;
2564 } elseif (strtolower($sourcefield) ==
'subject') {
2565 $sourcestring = $subject;
2566 } elseif (strtolower($sourcefield) ==
'header') {
2567 $sourcestring = $header;
2570 if ($sourcestring) {
2571 $regforval = array();
2573 if (preg_match(
'/'.$regexstring.
'/ms', $sourcestring, $regforval)) {
2576 if ($propertytooverwrite ==
'id') {
2577 $idtouseforthirdparty = isset($regforval[count($regforval) - 1]) ? trim($regforval[count($regforval) - 1]) : null;
2579 $operationslog .=
'<br>propertytooverwrite='.$propertytooverwrite.
' Regex /'.
dol_escape_htmltag($regexstring).
'/ms into '.strtoupper($sourcefield).
' -> Found idtouseforthirdparty='.
dol_escape_htmltag($idtouseforthirdparty);
2580 } elseif ($propertytooverwrite ==
'email') {
2581 $emailtouseforthirdparty = isset($regforval[count($regforval) - 1]) ? trim($regforval[count($regforval) - 1]) : null;
2583 $operationslog .=
'<br>propertytooverwrite='.$propertytooverwrite.
' Regex /'.
dol_escape_htmltag($regexstring).
'/ms into '.strtoupper($sourcefield).
' -> Found emailtouseforthirdparty='.
dol_escape_htmltag($emailtouseforthirdparty);
2584 } elseif ($propertytooverwrite ==
'name') {
2585 $nametouseforthirdparty = isset($regforval[count($regforval) - 1]) ? trim($regforval[count($regforval) - 1]) : null;
2587 $operationslog .=
'<br>propertytooverwrite='.$propertytooverwrite.
' Regex /'.
dol_escape_htmltag($regexstring).
'/ms into '.strtoupper($sourcefield).
' -> Found nametouseforthirdparty='.
dol_escape_htmltag($nametouseforthirdparty);
2588 } elseif ($propertytooverwrite ==
'name_alias') {
2589 $namealiastouseforthirdparty = isset($regforval[count($regforval) - 1]) ? trim($regforval[count($regforval) - 1]) : null;
2591 $operationslog .=
'<br>propertytooverwrite='.$propertytooverwrite.
' Regex /'.
dol_escape_htmltag($regexstring).
'/ms into '.strtoupper($sourcefield).
' -> Found namealiastouseforthirdparty='.
dol_escape_htmltag($namealiastouseforthirdparty);
2593 $operationslog .=
'<br>propertytooverwrite='.$propertytooverwrite.
' Regex /'.
dol_escape_htmltag($regexstring).
'/ms into '.strtoupper($sourcefield).
' -> We discard this, not a field used to search an existing thirdparty';
2597 if (in_array($propertytooverwrite, array(
'id',
'email',
'name',
'name_alias'))) {
2598 $idtouseforthirdparty =
null;
2599 $nametouseforthirdparty =
null;
2600 $emailtouseforthirdparty =
null;
2601 $namealiastouseforthirdparty =
null;
2603 $operationslog .=
'<br>propertytooverwrite='.$propertytooverwrite.
' Regex /'.
dol_escape_htmltag($regexstring).
'/ms into '.strtoupper($sourcefield).
' -> Not found. Property searched is critical so we cancel the search.';
2605 $operationslog .=
'<br>propertytooverwrite='.$propertytooverwrite.
' Regex /'.
dol_escape_htmltag($regexstring).
'/ms into '.strtoupper($sourcefield).
' -> Not found';
2612 $this->error =
'The extract rule to use to load thirdparty for email '.$msgid.
' has an unknown source (must be HEADER, SUBJECT or BODY)';
2613 $this->errors[] = $this->error;
2615 $operationslog .=
'<br>'.$this->error;
2617 } elseif (preg_match(
'/^(SET|SETIFEMPTY):(.*)$/', $valueforproperty, $reg)) {
2621 if ($propertytooverwrite ==
'id') {
2622 $idtouseforthirdparty = $reg[2];
2624 $operationslog .=
'<br>propertytooverwrite='.$propertytooverwrite.
' We set property idtouseforthrdparty='.
dol_escape_htmltag($idtouseforthirdparty);
2625 } elseif ($propertytooverwrite ==
'email') {
2626 $emailtouseforthirdparty = $reg[2];
2628 $operationslog .=
'<br>propertytooverwrite='.$propertytooverwrite.
' We set property emailtouseforthrdparty='.
dol_escape_htmltag($emailtouseforthirdparty);
2629 } elseif ($propertytooverwrite ==
'name') {
2630 $nametouseforthirdparty = $reg[2];
2632 $operationslog .=
'<br>propertytooverwrite='.$propertytooverwrite.
' We set property nametouseforthirdparty='.
dol_escape_htmltag($nametouseforthirdparty);
2633 } elseif ($propertytooverwrite ==
'name_alias') {
2634 $namealiastouseforthirdparty = $reg[2];
2636 $operationslog .=
'<br>propertytooverwrite='.$propertytooverwrite.
' We set property namealiastouseforthirdparty='.
dol_escape_htmltag($namealiastouseforthirdparty);
2640 $this->error =
'Bad syntax for description of action parameters: '.$actionparam;
2641 $this->errors[] = $this->error;
2646 if (!$errorforactions && ($idtouseforthirdparty || $emailtouseforthirdparty || $nametouseforthirdparty || $namealiastouseforthirdparty)) {
2648 $operationslog .=
'<br>We have this initial main data to search thirdparty: id='.$idtouseforthirdparty.
', email='.$emailtouseforthirdparty.
', name='.$nametouseforthirdparty.
', name_alias='.$namealiastouseforthirdparty.
'.';
2651 $tmpobject->element =
'generic';
2652 $tmpobject->id = $idtouseforthirdparty;
2653 $tmpobject->name = $nametouseforthirdparty;
2654 $tmpobject->name_alias = $namealiastouseforthirdparty;
2655 $tmpobject->email = $emailtouseforthirdparty;
2659 $idtouseforthirdparty = $tmpobject->id;
2660 $nametouseforthirdparty = $tmpobject->name;
2661 $namealiastouseforthirdparty = $tmpobject->name_alias;
2662 $emailtouseforthirdparty = $tmpobject->email;
2664 $operationslog .=
'<br>We try to search existing thirdparty with idtouseforthirdparty='.$idtouseforthirdparty.
' emailtouseforthirdparty='.$emailtouseforthirdparty.
' nametouseforthirdparty='.$nametouseforthirdparty.
' namealiastouseforthirdparty='.$namealiastouseforthirdparty;
2667 $result = $thirdpartystatic->findNearest($idtouseforthirdparty, $nametouseforthirdparty,
'',
'',
'',
'',
'',
'',
'',
'', $emailtouseforthirdparty, $namealiastouseforthirdparty);
2671 $this->error =
'Error when getting thirdparty with name '.$nametouseforthirdparty.
' (may be 2 record exists with same name ?)';
2672 $this->errors[] = $this->error;
2674 } elseif ($result == 0) {
2675 if ($operation[
'type'] ==
'loadthirdparty') {
2676 dol_syslog(
"Third party with id=".$idtouseforthirdparty.
" email=".$emailtouseforthirdparty.
" name=".$nametouseforthirdparty.
" name_alias=".$namealiastouseforthirdparty.
" was not found");
2679 $resultContact = $contactstatic->findNearest(0,
'',
'',
'', $emailtouseforthirdparty,
'', 0);
2680 if ($resultContact > 0) {
2681 $idtouseforthirdparty = $contactstatic->socid;
2682 $result = $thirdpartystatic->fetch($idtouseforthirdparty);
2684 dol_syslog(
"Third party with id=".$idtouseforthirdparty.
" email=".$emailtouseforthirdparty.
" name=".$nametouseforthirdparty.
" name_alias=".$namealiastouseforthirdparty.
" was found thanks to linked contact search");
2687 $langs->load(
"errors");
2688 $this->error = $langs->trans(
'ErrorFailedToLoadThirdParty', $idtouseforthirdparty, $emailtouseforthirdparty, $nametouseforthirdparty, $namealiastouseforthirdparty);
2689 $this->errors[] = $this->error;
2693 $langs->load(
"errors");
2694 $this->error = $langs->trans(
'ErrorFailedToLoadThirdParty', $idtouseforthirdparty, $emailtouseforthirdparty, $nametouseforthirdparty, $namealiastouseforthirdparty);
2695 $this->errors[] = $this->error;
2697 } elseif ($operation[
'type'] ==
'loadandcreatethirdparty') {
2698 dol_syslog(
"Third party with id=".$idtouseforthirdparty.
" email=".$emailtouseforthirdparty.
" name=".$nametouseforthirdparty.
" name_alias=".$namealiastouseforthirdparty.
" was not found. We try to create it.");
2701 $thirdpartystatic =
new Societe($db);
2702 $thirdpartystatic->name = (string) $nametouseforthirdparty;
2703 if (!empty($namealiastouseforthirdparty)) {
2704 if ($namealiastouseforthirdparty != $nametouseforthirdparty) {
2705 $thirdpartystatic->name_alias = $namealiastouseforthirdparty;
2708 $thirdpartystatic->name_alias = (empty($replytostring) ? (empty($fromtext) ?
'' : $fromtext) : $replytostring);
2710 $thirdpartystatic->email = (empty($emailtouseforthirdparty) ? (empty($replyto) ? (empty($from) ?
'' : $from) : $replyto) : $emailtouseforthirdparty);
2713 $errorforthisaction = $this->
overwritePropertiesOfObject($thirdpartystatic, $operation[
'actionparam'], $messagetext, $subject, $header, $operationslog);
2715 if ($thirdpartystatic->client && empty($thirdpartystatic->code_client)) {
2716 $thirdpartystatic->code_client =
'auto';
2718 if ($thirdpartystatic->fournisseur && empty($thirdpartystatic->code_fournisseur)) {
2719 $thirdpartystatic->code_fournisseur =
'auto';
2722 if ($errorforthisaction) {
2725 $result = $thirdpartystatic->create($user);
2728 $this->error = $thirdpartystatic->error;
2729 $this->errors = $thirdpartystatic->errors;
2731 $operationslog .=
'<br>Thirdparty created -> id = '.dol_escape_htmltag($thirdpartystatic->id);
2736 dol_syslog(
"One and only one existing third party has been found");
2738 $thirdpartystatic->fetch($result);
2740 $operationslog .=
'<br>Thirdparty already exists with id = '.dol_escape_htmltag($thirdpartystatic->id).
" and name ".
dol_escape_htmltag($thirdpartystatic->name);
2744 } elseif ($operation[
'type'] ==
'loadandcreatecontact') {
2745 if (empty($operation[
'actionparam'])) {
2747 $this->error =
"Action loadandcreatecontact has empty parameter. Must be 'SET:xxx' or 'EXTRACT:(body|subject):regex' to define how to extract data";
2748 $this->errors[] = $this->error;
2750 $contact_static =
new Contact($this->db);
2752 $errorforthisaction = $this->
overwritePropertiesOfObject($contact_static, $operation[
'actionparam'], $messagetext, $subject, $header, $operationslog);
2753 if ($errorforthisaction) {
2756 if (!empty($contact_static->email) && $contact_static->email != $from) {
2757 $from = $contact_static->email;
2760 $result = $contactstatic->fetch(0,
null,
'', $from);
2763 $this->error =
'Error when getting contact with email ' . $from;
2764 $this->errors[] = $this->error;
2766 } elseif ($result == 0) {
2767 dol_syslog(
"Contact with email " . $from .
" was not found. We try to create it.");
2768 $contactstatic =
new Contact($this->db);
2771 $contactstatic->email = $from;
2772 $operationslog .=
'<br>We set property email='.dol_escape_htmltag($from);
2775 $errorforthisaction = $this->
overwritePropertiesOfObject($contactstatic, $operation[
'actionparam'], $messagetext, $subject, $header, $operationslog);
2777 if ($errorforthisaction) {
2781 if (!empty($contactstatic->country)) {
2782 require_once DOL_DOCUMENT_ROOT .
'/core/lib/company.lib.php';
2783 $result =
getCountry(
'',
'3', $this->db,
null, 1, $contactstatic->country);
2784 if ($result ==
'NotDefined') {
2786 $this->error =
"Error country not found by this name '" . $contactstatic->country .
"'";
2787 } elseif (!($result > 0)) {
2789 $this->error =
"Error when search country by this name '" . $contactstatic->country .
"'";
2790 $this->errors[] = $this->db->lasterror();
2792 $contactstatic->country_id = $result;
2793 $operationslog .=
'<br>We set property country_id='.dol_escape_htmltag($result);
2795 } elseif (!empty($contactstatic->country_code)) {
2796 require_once DOL_DOCUMENT_ROOT .
'/core/lib/company.lib.php';
2797 $result =
getCountry($contactstatic->country_code,
'3', $this->db);
2798 if ($result ==
'NotDefined') {
2800 $this->error =
"Error country not found by this code '" . $contactstatic->country_code .
"'";
2801 } elseif (!($result > 0)) {
2803 $this->error =
"Error when search country by this code '" . $contactstatic->country_code .
"'";
2804 $this->errors[] = $this->db->lasterror();
2806 $contactstatic->country_id = $result;
2807 $operationslog .=
'<br>We set property country_id='.dol_escape_htmltag($result);
2811 if (!$errorforactions) {
2813 if (!empty($contactstatic->state)) {
2814 require_once DOL_DOCUMENT_ROOT .
'/core/lib/functions.lib.php';
2815 $result =
dol_getIdFromCode($this->db, $contactstatic->state,
'c_departements',
'nom',
'rowid');
2816 if (empty($result)) {
2818 $this->error =
"Error state not found by this name '" . $contactstatic->state .
"'";
2819 } elseif (!($result > 0)) {
2821 $this->error =
"Error when search state by this name '" . $contactstatic->state .
"'";
2822 $this->errors[] = $this->db->lasterror();
2824 $contactstatic->state_id = $result;
2825 $operationslog .=
'<br>We set property state_id='.dol_escape_htmltag($result);
2827 } elseif (!empty($contactstatic->state_code)) {
2828 require_once DOL_DOCUMENT_ROOT .
'/core/lib/functions.lib.php';
2829 $result =
dol_getIdFromCode($this->db, $contactstatic->state_code,
'c_departements',
'code_departement',
'rowid');
2830 if (empty($result)) {
2832 $this->error =
"Error state not found by this code '" . $contactstatic->state_code .
"'";
2833 } elseif (!($result > 0)) {
2835 $this->error =
"Error when search state by this code '" . $contactstatic->state_code .
"'";
2836 $this->errors[] = $this->db->lasterror();
2838 $contactstatic->state_id = $result;
2839 $operationslog .=
'<br>We set property state_id='.dol_escape_htmltag($result);
2844 if (!$errorforactions) {
2845 $result = $contactstatic->create($user);
2848 $this->error = $contactstatic->error;
2849 $this->errors = $contactstatic->errors;
2851 $operationslog .=
'<br>Contact created -> id = '.dol_escape_htmltag($contactstatic->id);
2858 } elseif ($operation[
'type'] ==
'recordevent') {
2862 $alreadycreated = $actioncomm->fetch(0,
'',
'', $msgid);
2863 if ($alreadycreated == 0) {
2864 $operationslog .=
'<br>We did not find existing actionmail with msgid='.$msgid;
2866 if ($projectstatic->id > 0) {
2867 if ($projectfoundby) {
2868 $descriptionmeta =
dol_concatdesc($descriptionmeta,
'Project found from '.$projectfoundby);
2871 if ($thirdpartystatic->id > 0) {
2872 if ($thirdpartyfoundby) {
2873 $descriptionmeta =
dol_concatdesc($descriptionmeta,
'Third party found from '.$thirdpartyfoundby);
2876 if ($contactstatic->id > 0) {
2877 if ($contactfoundby) {
2878 $descriptionmeta =
dol_concatdesc($descriptionmeta,
'Contact/address found from '.$contactfoundby);
2882 $description = $descriptiontitle;
2888 $descriptionfull = $description;
2890 $descriptionfull =
dol_concatdesc($descriptionfull,
"----- Header");
2895 $actioncomm->type_code =
'AC_OTH_AUTO';
2896 $actioncomm->code =
'AC_'.$actioncode;
2897 $actioncomm->label = $langs->trans(
"ActionAC_".$actioncode).
' - '.$langs->trans(
"MailFrom").
' '.$from;
2898 $actioncomm->note_private = $descriptionfull;
2899 $actioncomm->fk_project = $projectstatic->id;
2900 $actioncomm->datep = $dateemail;
2901 $actioncomm->datef = $dateemail;
2902 $actioncomm->percentage = -1;
2903 $actioncomm->socid = $thirdpartystatic->id;
2904 $actioncomm->contact_id = $contactstatic->id;
2905 $actioncomm->socpeopleassigned = (!empty($contactstatic->id) ? array($contactstatic->id) : array());
2906 $actioncomm->authorid = $user->id;
2907 $actioncomm->userownerid = $user->id;
2909 $actioncomm->email_msgid = $msgid;
2910 $actioncomm->email_from = $fromstring;
2911 $actioncomm->email_sender = $sender;
2912 $actioncomm->email_to = $to;
2913 $actioncomm->email_tocc = $sendtocc;
2914 $actioncomm->email_tobcc = $sendtobcc;
2915 $actioncomm->email_subject = $subject;
2916 $actioncomm->errors_to =
'';
2918 if (!in_array($fk_element_type, array(
'societe',
'contact',
'project',
'user'))) {
2919 $actioncomm->fk_element = $fk_element_id;
2920 $actioncomm->elementid = $fk_element_id;
2921 $actioncomm->elementtype = $fk_element_type;
2922 if (is_object($objectemail) && $objectemail->module) {
2923 $actioncomm->elementtype .=
'@'.$objectemail->module;
2930 $errorforthisaction = $this->
overwritePropertiesOfObject($actioncomm, $operation[
'actionparam'], $messagetext, $subject, $header, $operationslog);
2932 if ($errorforthisaction) {
2935 $result = $actioncomm->create($user);
2938 $this->errors = $actioncomm->errors;
2940 if ($fk_element_type ==
"ticket" && is_object($objectemail)) {
2941 if ($objectemail->status == Ticket::STATUS_CLOSED || $objectemail->status == Ticket::STATUS_CANCELED) {
2942 if ($objectemail->fk_user_assign !=
null) {
2943 $res = $objectemail->setStatut(Ticket::STATUS_ASSIGNED);
2945 $res = $objectemail->setStatut(Ticket::STATUS_NOT_READ);
2949 $operationslog .=
'<br>Ticket Re-Opened successfully -> ref='.$objectemail->ref;
2952 $this->error =
'Error while changing the ticket status -> ref='.$objectemail->ref;
2953 $this->errors[] = $this->error;
2956 if (!empty($attachments)) {
2958 $ticket =
new Ticket($this->db);
2959 $ticket->fetch($fk_element_id);
2960 $destdir =
$conf->ticket->dir_output.
'/'.$ticket->ref;
2965 foreach ($attachments as $attachment) {
2966 $attachment->save($destdir.
'/');
2969 $this->
getmsg($connection, $imapemail, $destdir);
2974 $operationslog .=
'<br>Event created -> id='.dol_escape_htmltag($actioncomm->id);
2978 } elseif ($operation[
'type'] ==
'recordjoinpiece') {
2981 foreach ($attachments as $attachment) {
2982 if ($attachment->getName() ===
'undefined') {
2985 $data[$attachment->getName()] = $attachment->getContent();
2989 foreach ($pj as $key => $val) {
2990 $data[$val[
'filename']] =
getFileData($imapemail, (
string) $val[
'pos'], $val[
'type'], $connection);
2993 if (count($data) > 0) {
2994 $sql =
"SELECT rowid as id FROM ".MAIN_DB_PREFIX.
"user WHERE email LIKE '%".$this->db->escape($from).
"%'";
2995 $resql = $this->db->query($sql);
2996 if ($this->db->num_rows($resql) == 0) {
2997 $this->errors[] =
"User Not allowed to add documents ({$from})";
2999 $arrayobject = array(
3000 'propale' => array(
'table' =>
'propal',
3001 'fields' => array(
'ref'),
3002 'class' =>
'comm/propal/class/propal.class.php',
3003 'object' =>
'Propal'),
3004 'holiday' => array(
'table' =>
'holiday',
3005 'fields' => array(
'ref'),
3006 'class' =>
'holiday/class/holiday.class.php',
3007 'object' =>
'Holiday'),
3008 'expensereport' => array(
'table' =>
'expensereport',
3009 'fields' => array(
'ref'),
3010 'class' =>
'expensereport/class/expensereport.class.php',
3011 'object' =>
'ExpenseReport'),
3012 'recruitment/recruitmentjobposition' => array(
'table' =>
'recruitment_recruitmentjobposition',
3013 'fields' => array(
'ref'),
3014 'class' =>
'recruitment/class/recruitmentjobposition.class.php',
3015 'object' =>
'RecruitmentJobPosition'),
3016 'recruitment/recruitmentcandidature' => array(
'table' =>
'recruitment_recruitmentcandidature',
3017 'fields' => array(
'ref'),
3018 'class' =>
'recruitment/class/recruitmentcandidature.class.php',
3019 'object' =>
'RecruitmentCandidature'),
3020 'societe' => array(
'table' =>
'societe',
3021 'fields' => array(
'code_client',
'code_fournisseur'),
3022 'class' =>
'societe/class/societe.class.php',
3023 'object' =>
'Societe'),
3024 'commande' => array(
'table' =>
'commande',
3025 'fields' => array(
'ref'),
3026 'class' =>
'commande/class/commande.class.php',
3027 'object' =>
'Commande'),
3028 'expedition' => array(
'table' =>
'expedition',
3029 'fields' => array(
'ref'),
3030 'class' =>
'expedition/class/expedition.class.php',
3031 'object' =>
'Expedition'),
3032 'contract' => array(
'table' =>
'contrat',
3033 'fields' => array(
'ref'),
3034 'class' =>
'contrat/class/contrat.class.php',
3035 'object' =>
'Contrat'),
3036 'fichinter' => array(
'table' =>
'fichinter',
3037 'fields' => array(
'ref'),
3038 'class' =>
'fichinter/class/fichinter.class.php',
3039 'object' =>
'Fichinter'),
3040 'ticket' => array(
'table' =>
'ticket',
3041 'fields' => array(
'ref'),
3042 'class' =>
'ticket/class/ticket.class.php',
3043 'object' =>
'Ticket'),
3044 'knowledgemanagement' => array(
'table' =>
'knowledgemanagement_knowledgerecord',
3045 'fields' => array(
'ref'),
3046 'class' =>
'knowledgemanagement/class/knowledgemanagement.class.php',
3047 'object' =>
'KnowledgeRecord'),
3048 'supplier_proposal' => array(
'table' =>
'supplier_proposal',
3049 'fields' => array(
'ref'),
3050 'class' =>
'supplier_proposal/class/supplier_proposal.class.php',
3051 'object' =>
'SupplierProposal'),
3052 'fournisseur/commande' => array(
'table' =>
'commande_fournisseur',
3053 'fields' => array(
'ref',
'ref_supplier'),
3054 'class' =>
'fourn/class/fournisseur.commande.class.php',
3055 'object' =>
'SupplierProposal'),
3056 'facture' => array(
'table' =>
'facture',
3057 'fields' => array(
'ref'),
3058 'class' =>
'compta/facture/class/facture.class.php',
3059 'object' =>
'Facture'),
3060 'fournisseur/facture' => array(
'table' =>
'facture_fourn',
3061 'fields' => array(
'ref',
'ref_client'),
3062 'class' =>
'fourn/class/fournisseur.facture.class.php',
3063 'object' =>
'FactureFournisseur'),
3064 'produit' => array(
'table' =>
'product',
3065 'fields' => array(
'ref'),
3066 'class' =>
'product/class/product.class.php',
3067 'object' =>
'Product'),
3068 'productlot' => array(
'table' =>
'product_lot',
3069 'fields' => array(
'batch'),
3070 'class' =>
'product/stock/class/productlot.class.php',
3071 'object' =>
'Productlot'),
3072 'projet' => array(
'table' =>
'projet',
3073 'fields' => array(
'ref'),
3074 'class' =>
'projet/class/projet.class.php',
3075 'object' =>
'Project'),
3076 'projet_task' => array(
'table' =>
'projet_task',
3077 'fields' => array(
'ref'),
3078 'class' =>
'projet/class/task.class.php',
3079 'object' =>
'Task'),
3080 'ressource' => array(
'table' =>
'resource',
3081 'fields' => array(
'ref'),
3082 'class' =>
'ressource/class/dolressource.class.php',
3083 'object' =>
'Dolresource'),
3084 'bom' => array(
'table' =>
'bom_bom',
3085 'fields' => array(
'ref'),
3086 'class' =>
'bom/class/bom.class.php',
3088 'mrp' => array(
'table' =>
'mrp_mo',
3089 'fields' => array(
'ref'),
3090 'class' =>
'mrp/class/mo.class.php',
3094 if (!is_object($hookmanager)) {
3095 include_once DOL_DOCUMENT_ROOT.
'/core/class/hookmanager.class.php';
3098 $hookmanager->initHooks(array(
'emailcolector'));
3099 $parameters = array(
'arrayobject' => $arrayobject);
3100 $reshook = $hookmanager->executeHooks(
'addmoduletoeamailcollectorjoinpiece', $parameters);
3102 $arrayobject = $hookmanager->resArray;
3105 $resultobj = array();
3107 foreach ($arrayobject as $key => $objectdesc) {
3108 $sql =
'SELECT DISTINCT t.rowid ';
3109 $sql .=
' FROM ' . MAIN_DB_PREFIX . $this->db->sanitize($objectdesc[
'table']) .
' AS t';
3111 foreach ($objectdesc[
'fields'] as $field) {
3112 $sql .=
"('" .$this->db->escape($subject) .
"' LIKE CONCAT('%', t." . $this->db->sanitize($field) .
", '%') AND t." . $this->db->sanitize($field) .
" <> '') OR ";
3114 $sql = substr($sql, 0, -4);
3116 $ressqlobj = $this->db->query($sql);
3118 while ($obj = $this->db->fetch_object($ressqlobj)) {
3119 $resultobj[$key][] = $obj->rowid;
3124 foreach ($resultobj as $mod => $ids) {
3125 $moddesc = $arrayobject[$mod];
3126 $elementpath = $mod;
3128 $objectmanaged =
new $moddesc[
'object']($this->db);
3129 '@phan-var-force CommonObject $objectmanaged';
3130 foreach ($ids as $val) {
3131 $res = $objectmanaged->fetch($val);
3133 $path = ($objectmanaged->entity > 1 ?
"/" . $objectmanaged->entity :
'');
3134 $dirs[] = DOL_DATA_ROOT . $path .
"/" . $elementpath .
'/' .
dol_sanitizeFileName($objectmanaged->ref) .
'/';
3136 $this->errors[] =
'object not found';
3140 foreach ($dirs as $target) {
3141 $prefix = $this->actions[$this->id][
'actionparam'];
3142 foreach ($data as $filename => $content) {
3143 $resr =
saveAttachment($target, $prefix .
'_' . $filename, $content);
3145 $this->errors[] =
'Doc not saved';
3150 $operationslog .=
'<br>Save attachment files on disk';
3152 $this->errors[] =
'no joined piece';
3154 $operationslog .=
'<br>No joinded files';
3156 } elseif ($operation[
'type'] ==
'project') {
3158 $projecttocreate =
new Project($this->db);
3159 $alreadycreated = $projecttocreate->fetch(0,
'',
'', $msgid);
3160 if ($alreadycreated == 0) {
3161 if ($thirdpartystatic->id > 0) {
3162 $projecttocreate->socid = $thirdpartystatic->id;
3163 if ($thirdpartyfoundby) {
3164 $descriptionmeta =
dol_concatdesc($descriptionmeta,
'Third party found from '.$thirdpartyfoundby);
3167 if ($contactstatic->id > 0) {
3168 $projecttocreate->contact_id = $contactstatic->id;
3169 if ($contactfoundby) {
3170 $descriptionmeta =
dol_concatdesc($descriptionmeta,
'Contact/address found from '.$contactfoundby);
3174 $description = $descriptiontitle;
3180 $descriptionfull = $description;
3182 $descriptionfull =
dol_concatdesc($descriptionfull,
"----- Header");
3186 $id_opp_status =
dol_getIdFromCode($this->db,
'PROSP',
'c_lead_status',
'code',
'rowid');
3187 $percent_opp_status =
dol_getIdFromCode($this->db,
'PROSP',
'c_lead_status',
'code',
'percent');
3189 $projecttocreate->title = $subject;
3190 $projecttocreate->date_start = $dateemail;
3191 $projecttocreate->date_end = 0;
3192 $projecttocreate->opp_status = $id_opp_status;
3193 $projecttocreate->opp_percent = $percent_opp_status;
3195 $projecttocreate->note_private = $descriptionfull;
3196 $projecttocreate->entity =
$conf->entity;
3198 $projecttocreate->email_date = $dateemail;
3199 $projecttocreate->email_msgid = $msgid;
3200 $projecttocreate->email_from = $fromstring;
3201 $projecttocreate->email_sender = $sender;
3202 $projecttocreate->email_to = $to;
3203 $projecttocreate->email_tocc = $sendtocc;
3204 $projecttocreate->email_tobcc = $sendtobcc;
3205 $projecttocreate->email_subject = $subject;
3206 $projecttocreate->errors_to =
'';
3208 $savesocid = $projecttocreate->socid;
3212 $errorforthisaction = $this->
overwritePropertiesOfObject($projecttocreate, $operation[
'actionparam'], $messagetext, $subject, $header, $operationslog);
3216 if (empty($projecttocreate->ref)) {
3225 $dirmodels = array_merge(array(
'/'), (array)
$conf->modules_parts[
'models']);
3226 foreach ($dirmodels as $reldir) {
3227 $file =
dol_buildpath($reldir.
"core/modules/project/".$modele.
'.php', 0);
3228 if (file_exists($file)) {
3229 $classname = $modele;
3234 if ($classname !==
'') {
3235 if ($savesocid > 0) {
3236 if ($savesocid != $projecttocreate->socid) {
3238 setEventMessages(
'You loaded a thirdparty (id='.$savesocid.
') and you force another thirdparty id (id='.$projecttocreate->socid.
') by setting socid in operation with a different value',
null,
'errors');
3241 if ($projecttocreate->socid > 0) {
3242 $thirdpartystatic->fetch($projecttocreate->socid);
3246 $result =
dol_include_once($reldir.
"core/modules/project/".$modele.
'.php');
3247 $modModuleToUseForNextValue =
new $classname();
3248 '@phan-var-force ModeleNumRefProjects $modModuleToUseForNextValue';
3249 $defaultref = $modModuleToUseForNextValue->getNextValue(($thirdpartystatic->id > 0 ? $thirdpartystatic : null), $projecttocreate);
3251 $projecttocreate->ref = $defaultref;
3255 if ($errorforthisaction) {
3258 if (empty($projecttocreate->ref) || (is_numeric($projecttocreate->ref) && $projecttocreate->ref <= 0)) {
3260 $this->error =
'Failed to create project: Can\'t get a valid value for the field ref with numbering template = '.$modele.
', thirdparty id = '.$thirdpartystatic->id;
3262 $operationslog .=
'<br>'.$this->error;
3265 $result = $projecttocreate->create($user);
3268 $this->error =
'Failed to create project: '.$langs->trans($projecttocreate->error);
3269 $this->errors = $projecttocreate->errors;
3271 $operationslog .=
'<br>'.$this->error;
3274 $destdir =
$conf->project->dir_output.
'/'.$projecttocreate->ref;
3279 foreach ($attachments as $attachment) {
3281 $typeattachment = (string) $attachment->getDisposition();
3282 $filename = $attachment->getFilename();
3283 $content = $attachment->getContent();
3287 $this->
getmsg($connection, $imapemail, $destdir);
3290 $operationslog .=
'<br>Project created with attachments -> id='.dol_escape_htmltag($projecttocreate->id);
3292 $operationslog .=
'<br>Project created without attachments -> id='.dol_escape_htmltag($projecttocreate->id);
3300 $operationslog .=
'<br>Project already exists for msgid ='.dol_escape_htmltag($msgid);
3302 } elseif ($operation[
'type'] ==
'ticket') {
3304 $tickettocreate =
new Ticket($this->db);
3305 if ($ticketalreadyexists == 0) {
3306 if ($thirdpartystatic->id > 0) {
3307 $tickettocreate->socid = $thirdpartystatic->id;
3308 $tickettocreate->fk_soc = $thirdpartystatic->id;
3309 if ($thirdpartyfoundby) {
3310 $descriptionmeta =
dol_concatdesc($descriptionmeta,
'Third party found from '.$thirdpartyfoundby);
3313 if ($contactstatic->id > 0) {
3314 $tickettocreate->contact_id = $contactstatic->id;
3315 if ($contactfoundby) {
3316 $descriptionmeta =
dol_concatdesc($descriptionmeta,
'Contact/address found from '.$contactfoundby);
3320 $description = $descriptiontitle;
3326 $descriptionfull = $description;
3328 $descriptionfull =
dol_concatdesc($descriptionfull,
"----- Header");
3332 $tickettocreate->subject = $subject;
3333 $tickettocreate->message = $description;
3335 $tickettocreate->category_code = (
getDolGlobalString(
'MAIN_EMAILCOLLECTOR_TICKET_CATEGORY_CODE',
dol_getIdFromCode($this->db, 1,
'c_ticket_category',
'use_default',
'code', 1)));
3336 $tickettocreate->severity_code = (
getDolGlobalString(
'MAIN_EMAILCOLLECTOR_TICKET_SEVERITY_CODE',
dol_getIdFromCode($this->db, 1,
'c_ticket_severity',
'use_default',
'code', 1)));
3337 $tickettocreate->origin_email = $from;
3338 $tickettocreate->origin_replyto = (!empty($replyto) ? $replyto :
null);
3339 $tickettocreate->origin_references = (!empty($headers[
'References']) ? $headers[
'References'] :
null);
3340 $tickettocreate->fk_user_create = $user->id;
3341 $tickettocreate->datec =
dol_now();
3342 $tickettocreate->fk_project = $projectstatic->id;
3343 $tickettocreate->notify_tiers_at_create =
getDolGlobalInt(
'TICKET_CHECK_NOTIFY_THIRDPARTY_AT_CREATION');
3344 $tickettocreate->note_private = $descriptionfull;
3345 $tickettocreate->entity =
$conf->entity;
3347 $tickettocreate->email_date = $dateemail;
3348 $tickettocreate->email_msgid = $msgid;
3349 $tickettocreate->email_from = $fromstring;
3350 $tickettocreate->email_sender = $sender;
3351 $tickettocreate->email_to = $to;
3352 $tickettocreate->email_tocc = $sendtocc;
3353 $tickettocreate->email_tobcc = $sendtobcc;
3354 $tickettocreate->email_subject = $subject;
3355 $tickettocreate->errors_to =
'';
3359 $savesocid = $tickettocreate->socid;
3363 $errorforthisaction = $this->
overwritePropertiesOfObject($tickettocreate, $operation[
'actionparam'], $messagetext, $subject, $header, $operationslog);
3365 $modele =
'UNDEFINED';
3367 if (empty($tickettocreate->ref)) {
3376 $dirmodels = array_merge(array(
'/'), (array)
$conf->modules_parts[
'models']);
3377 foreach ($dirmodels as $reldir) {
3378 $file =
dol_buildpath($reldir.
"core/modules/ticket/".$modele.
'.php', 0);
3379 if (file_exists($file)) {
3380 $classname = $modele;
3385 if ($classname !==
'') {
3386 if ($savesocid > 0) {
3387 if ($savesocid != $tickettocreate->socid) {
3389 setEventMessages(
'You loaded a thirdparty (id='.$savesocid.
') and you force another thirdparty id (id='.$tickettocreate->socid.
') by setting socid in operation with a different value',
null,
'errors');
3392 if ($tickettocreate->socid > 0) {
3393 $thirdpartystatic->fetch($tickettocreate->socid);
3398 $modModuleToUseForNextValue =
new $classname();
3399 '@phan-var-force ModeleNumRefTicket $modModuleToUseForNextValue';
3400 $defaultref = $modModuleToUseForNextValue->getNextValue(($thirdpartystatic->id > 0 ? $thirdpartystatic : null), $tickettocreate);
3402 $tickettocreate->ref = $defaultref;
3405 if ($errorforthisaction) {
3408 if (is_numeric($tickettocreate->ref) && $tickettocreate->ref <= 0) {
3410 $this->error =
'Failed to create ticket: Can\'t get a valid value for the field ref with numbering template = '.$modele.
', thirdparty id = '.$thirdpartystatic->id;
3413 $tickettocreate->context[
'actionmsg2'] = $langs->trans(
"ActionAC_EMAIL_IN").
' - '.$langs->trans(
"TICKET_CREATEInDolibarr");
3414 $tickettocreate->context[
'actionmsg'] = $langs->trans(
"ActionAC_EMAIL_IN").
' - '.$langs->trans(
"TICKET_CREATEInDolibarr");
3417 $result = $tickettocreate->create($user);
3420 $this->error =
'Failed to create ticket: '.$langs->trans($tickettocreate->error);
3421 $this->errors = $tickettocreate->errors;
3424 $destdir =
$conf->ticket->dir_output.
'/'.$tickettocreate->ref;
3429 foreach ($attachments as $attachment) {
3431 $typeattachment = (string) $attachment->getDisposition();
3432 $filename = $attachment->getFilename();
3433 $content = $attachment->getContent();
3437 $this->
getmsg($connection, $imapemail, $destdir);
3440 $operationslog .=
'<br>Ticket created with attachments -> id='.dol_escape_htmltag($tickettocreate->id);
3442 $operationslog .=
'<br>Ticket created without attachments -> id='.dol_escape_htmltag($tickettocreate->id);
3448 } elseif ($operation[
'type'] ==
'candidature') {
3452 $alreadycreated = $candidaturetocreate->fetch(0,
'', $msgid);
3453 if ($alreadycreated == 0) {
3454 $description = $descriptiontitle;
3460 $descriptionfull = $description;
3461 $descriptionfull =
dol_concatdesc($descriptionfull,
"----- Header");
3464 $candidaturetocreate->subject = $subject;
3465 $candidaturetocreate->message = $description;
3466 $candidaturetocreate->type_code = 0;
3467 $candidaturetocreate->category_code =
null;
3468 $candidaturetocreate->severity_code =
null;
3469 $candidaturetocreate->email = $from;
3471 $candidaturetocreate->fk_user_creat = $user->id;
3472 $candidaturetocreate->date_creation =
dol_now();
3473 $candidaturetocreate->fk_project = $projectstatic->id;
3474 $candidaturetocreate->description = $description;
3475 $candidaturetocreate->note_private = $descriptionfull;
3476 $candidaturetocreate->entity =
$conf->entity;
3477 $candidaturetocreate->email_msgid = $msgid;
3478 $candidaturetocreate->email_date = $dateemail;
3479 $candidaturetocreate->status = $candidaturetocreate::STATUS_DRAFT;
3484 $errorforthisaction = $this->
overwritePropertiesOfObject($candidaturetocreate, $operation[
'actionparam'], $messagetext, $subject, $header, $operationslog);
3527 if ($errorforthisaction) {
3531 $result = $candidaturetocreate->create($user);
3534 $this->error =
'Failed to create candidature: '.implode(
', ', $candidaturetocreate->errors);
3535 $this->errors = $candidaturetocreate->errors;
3538 $operationslog .=
'<br>Candidature created without attachments -> id='.dol_escape_htmltag($candidaturetocreate->id);
3541 } elseif (substr($operation[
'type'], 0, 4) ==
'hook') {
3544 if (!is_object($hookmanager)) {
3545 include_once DOL_DOCUMENT_ROOT.
'/core/class/hookmanager.class.php';
3548 $hookmanager->initHooks([
'emailcolector']);
3550 $parameters = array(
3551 'connection' => $connection,
3552 'imapemail' => $imapemail,
3553 'overview' => $overview,
3556 'fromtext' => $fromtext,
3558 'actionparam' => $operation[
'actionparam'],
3560 'thirdpartyid' => $thirdpartyid,
3561 'objectid' => $objectid,
3562 'objectemail' => $objectemail,
3564 'messagetext' => $messagetext,
3565 'subject' => $subject,
3566 'header' => $header,
3567 'attachments' => $attachments,
3569 $reshook = $hookmanager->executeHooks(
'doCollectImapOneCollector', $parameters, $this, $operation[
'type']);
3572 $errorforthisaction++;
3573 $this->error = $hookmanager->resPrint;
3575 if ($errorforthisaction) {
3577 $operationslog .=
'<br>Hook doCollectImapOneCollector executed with error';
3579 $operationslog .=
'<br>Hook doCollectImapOneCollector executed without error';
3583 if (!$errorforactions) {
3584 $nbactiondoneforemail++;
3590 if (!$errorforactions) {
3591 if (!empty($targetdir)) {
3594 dol_syslog(
"EmailCollector::doCollectOneCollector move message ".($imapemail->getHeader()->get(
'subject')).
" to ".$targetdir, LOG_DEBUG);
3595 $operationslog .=
'<br>Move mail '.($this->uidAsString($imapemail)).
' - '.$msgid.
' - '.$imapemail->getHeader()->get(
'subject').
' to '.$targetdir;
3597 $arrayofemailtodelete[$this->
uidAsString($imapemail)] = $imapemail;
3600 dol_syslog(
"EmailCollector::doCollectOneCollector move message ".($this->
uidAsString($imapemail)).
" to ".$connectstringtarget, LOG_DEBUG);
3601 $operationslog .=
'<br>Move mail '.($this->uidAsString($imapemail)).
' - '.$msgid;
3603 $arrayofemailtodelete[$imapemail] = $msgid;
3608 dol_syslog(
"EmailCollector::doCollectOneCollector message ".($this->
uidAsString($imapemail)).
" '".($imapemail->getHeader()->get(
'subject')).
"' using this->host=".$this->host.
", this->access_type=".$this->acces_type.
" was set to read", LOG_DEBUG);
3610 dol_syslog(
"EmailCollector::doCollectOneCollector message ".($this->
uidAsString($imapemail)).
" to ".$connectstringtarget.
" was set to read", LOG_DEBUG);
3618 unset($objectemail);
3619 unset($projectstatic);
3620 unset($thirdpartystatic);
3621 unset($contactstatic);
3623 $nbemailprocessed++;
3625 if (!$errorforemail) {
3626 $nbactiondone += $nbactiondoneforemail;
3630 $this->db->commit();
3632 $this->db->rollback();
3636 if ($this->maxemailpercollect > 0 && $nbemailok >= $this->maxemailpercollect) {
3637 dol_syslog(
"EmailCollect::doCollectOneCollector We reach maximum of ".$nbemailok.
" collected with success, so we stop this collector now.");
3643 $this->db->rollback();
3647 $output = $langs->trans(
'XEmailsDoneYActionsDone', $nbemailprocessed, $nbemailok, $nbactiondone);
3649 dol_syslog(
"End of loop on emails", LOG_INFO, -1);
3651 $langs->load(
"admin");
3652 $output = $langs->trans(
'NoNewEmailToProcess');
3653 $output .=
' (defaultlang='.$langs->defaultlang.
')';
3659 krsort($arrayofemailtodelete, SORT_NUMERIC);
3661 foreach ($arrayofemailtodelete as $imapemailnum => $imapemail) {
3662 dol_syslog(
"EmailCollect::doCollectOneCollector delete email ".$imapemailnum);
3664 $operationslog .=
"<br> move email ".$imapemailnum.($mode > 0 ?
' (test)' :
'');
3666 if (empty($mode) && empty($error)) {
3667 $tmptargetdir = $targetdir;
3674 $result = $imapemail->move($tmptargetdir,
false);
3677 $operationslog .=
'<br>Exception !!!! '.$e->getMessage();
3679 if (empty($result)) {
3680 dol_syslog(
"Failed to move email into target directory ".$targetdir);
3681 $operationslog .=
'<br>Failed to move email into target directory '.$targetdir;
3687 if (empty($mode) && empty($error)) {
3689 $operationslog .=
"<br>Expunge";
3694 $client->disconnect();
3696 foreach ($arrayofemailtodelete as $imapemail => $msgid) {
3697 dol_syslog(
"EmailCollect::doCollectOneCollector delete email ".$imapemail.
" ".$msgid);
3699 $operationslog .=
"<br> delete email ".$imapemail.
" ".$msgid.($mode > 0 ?
' (test)' :
'');
3701 if (empty($mode) && empty($error)) {
3702 $res = imap_mail_move($connection, $imapemail, $targetdir, CP_UID);
3705 $this->error = imap_last_error();
3706 $this->errors[] = $this->error;
3708 $operationslog .=
'<br>Error in move '.$this->error;
3715 if (empty($mode) && empty($error)) {
3717 $operationslog .=
"<br>Expunge";
3719 imap_expunge($connection);
3721 imap_close($connection);
3724 $this->datelastresult = $now;
3725 $this->lastresult = $output;
3727 $this->debuginfo .=
'IMAP search array used : '.$search;
3729 $this->debuginfo .=
'IMAP search string used : '.$search;
3732 $this->debuginfo .=
'<br>Then search string into email header : '.dol_escape_htmltag($searchhead);
3734 if ($operationslog) {
3735 $this->debuginfo .= $operationslog;
3738 if (empty($error) && empty($mode)) {
3739 $this->datelastok = $now;
3742 if (!empty($this->errors)) {
3743 $this->lastresult .=
"<br>".implode(
"<br>", $this->errors);
3745 $this->codelastresult = ($error ?
'KO' :
'OK');
3751 dol_syslog(
"EmailCollector::doCollectOneCollector end", LOG_INFO);
3753 return $error ? -1 : 1;
3768 private function getmsg($mbox, $mid, $destdir =
'')
3772 global $charset, $htmlmsg, $plainmsg, $attachments;
3773 $htmlmsg = $plainmsg = $charset =
'';
3774 $attachments = array();
3781 $s = imap_fetchstructure($mbox, $mid, FT_UID);
3786 $this->
getpart($mbox, $mid, $s,
'0');
3789 foreach ($s->parts as $partno0 => $p) {
3790 $this->
getpart($mbox, $mid, $p, $partno0 + 1, $destdir);
3821 private function getpart($mbox, $mid, $p, $partno, $destdir =
'')
3824 global $htmlmsg, $plainmsg, $charset, $attachments;
3828 imap_fetchbody($mbox, $mid, $partno, FT_UID) :
3829 imap_body($mbox, $mid, FT_UID);
3831 if ($p->encoding == 4) {
3832 $data = quoted_printable_decode($data);
3833 } elseif ($p->encoding == 3) {
3834 $data = base64_decode($data);
3840 if ($p->parameters) {
3841 foreach ($p->parameters as $x) {
3842 $params[strtolower($x->attribute)] = $x->value;
3845 if (!empty($p->dparameters)) {
3846 foreach ($p->dparameters as $x) {
3847 $params[strtolower($x->attribute)] = $x->value;
3850 '@phan-var-force array{filename?:string,name?:string,charset?:string} $params';
3855 if (!empty($params[
'filename']) || !empty($params[
'name'])) {
3857 $filename = $params[
'filename'] ?? $params[
'name'];
3859 $attachments[$filename] = $data;
3861 if (strlen($destdir)) {
3862 if (substr($destdir, -1) !=
'/') {
3867 $file_name_complete = $filename;
3868 $destination = $destdir.$file_name_complete;
3871 $extension = pathinfo($file_name_complete, PATHINFO_EXTENSION);
3874 $file_name = pathinfo($file_name_complete, PATHINFO_FILENAME);
3877 $file_name_original = $file_name;
3886 while (file_exists($destdir.$file_name.
".".$extension)) {
3887 $file_name = $file_name_original .
' (' . $num .
')';
3888 $file_name_complete = $file_name .
"." . $extension;
3889 $destination = $destdir.$file_name_complete;
3895 file_put_contents($destination, $data);
3900 if ($p->type == 0 && $data) {
3901 if (!empty($params[
'charset'])) {
3906 if (strtolower($p->subtype) ==
'plain') {
3907 $plainmsg .= trim($data).
"\n\n";
3909 $htmlmsg .= $data.
"<br><br>";
3911 $charset = $params[
'charset'];
3912 } elseif ($p->type == 2 && $data) {
3918 if (!empty($params[
'charset'])) {
3921 $plainmsg .= $data.
"\n\n";
3925 if (!empty($p->parts)) {
3926 foreach ($p->parts as $partno0 => $p2) {
3927 $this->
getpart($mbox, $mid, $p2, $partno.
'.'.($partno0 + 1), $destdir);
3943 if (!$string || $fromEncoding == $toEncoding) {
3946 $convertedString = function_exists(
'iconv') ? @iconv($fromEncoding, $toEncoding.
'//IGNORE', $string) :
null;
3947 if (!$convertedString && extension_loaded(
'mbstring')) {
3948 $convertedString = @mb_convert_encoding($string, $toEncoding, $fromEncoding);
3950 if (!$convertedString) {
3951 throw new Exception(
'Mime string encoding conversion failed');
3953 return $convertedString;
3972 if (function_exists(
'imap_mime_header_decode') && function_exists(
'iconv_mime_decode')) {
3973 $elements = imap_mime_header_decode($subject);
3975 if (!empty($elements)) {
3976 $num = count($elements);
3977 for ($i = 0; $i < $num; $i++) {
3978 $stringinutf8 = (in_array(strtoupper($elements[$i]->charset), array(
'DEFAULT',
'UTF-8')) ? $elements[$i]->text : iconv_mime_decode($elements[$i]->text, ICONV_MIME_DECODE_CONTINUE_ON_ERROR, $elements[$i]->charset));
3979 $newstring .= $stringinutf8;
3981 $subject = $newstring;
3983 } elseif (!function_exists(
'mb_decode_mimeheader')) {
3984 $subject = mb_decode_mimeheader($subject);
3985 } elseif (function_exists(
'iconv_mime_decode')) {
3986 $subject = iconv_mime_decode($subject, ICONV_MIME_DECODE_CONTINUE_ON_ERROR,
'UTF-8');
4002 require_once DOL_DOCUMENT_ROOT .
'/core/lib/images.lib.php';
4005 $maxwidthsmall = $tmparraysize[
'maxwidthsmall'];
4006 $maxheightsmall = $tmparraysize[
'maxheightsmall'];
4007 $maxwidthmini = $tmparraysize[
'maxwidthmini'];
4008 $maxheightmini = $tmparraysize[
'maxheightmini'];
4009 $quality = $tmparraysize[
'quality'];
4011 file_put_contents($destdir.
'/'.$filename, $content);
4014 vignette($destdir.
'/'.$filename, $maxwidthsmall, $maxheightsmall,
'_small', $quality,
"thumbs");
4016 vignette($destdir.
'/'.$filename, $maxwidthmini, $maxheightmini,
'_mini', $quality,
"thumbs");
4029 if (is_object($imapemail)) {
4030 return $imapemail->getAttributes()[
"uid"];
4032 return (
string) $imapemail;