|
@@ -745,13 +745,13 @@ class EmailCollector extends CommonObject
|
|
|
$sourcestring='';
|
|
|
$sourcefield='';
|
|
|
$regexstring='';
|
|
|
- $transformationstring='';
|
|
|
+ //$transformationstring='';
|
|
|
$regforregex=array();
|
|
|
if (preg_match('/^REGEX:([a-zA-Z0-9]+):(.*):([^:])$/', $valueforproperty, $regforregex))
|
|
|
{
|
|
|
$sourcefield=$regforregex[0];
|
|
|
$regexstring=$regforregex[1];
|
|
|
- $transofrmationstring=$regforregex[2];
|
|
|
+ //$transofrmationstring=$regforregex[2];
|
|
|
}
|
|
|
elseif (preg_match('/^REGEX:([a-zA-Z0-9]+):(.*)$/', $valueforproperty, $regforregex))
|
|
|
{
|
|
@@ -759,7 +759,7 @@ class EmailCollector extends CommonObject
|
|
|
$regexstring=$regforregex[1];
|
|
|
}
|
|
|
|
|
|
- if (! empty($sourcestring) && ! empty($regexstring))
|
|
|
+ if (! empty($sourcefield) && ! empty($regexstring))
|
|
|
{
|
|
|
if (strtolower($sourcefield) == 'body') $sourcestring=$messagetext;
|
|
|
elseif (strtolower($sourcefield) == 'subject') $sourcestring=$subject;
|
|
@@ -902,14 +902,28 @@ class EmailCollector extends CommonObject
|
|
|
$headers = array_combine($matches[1], $matches[2]);
|
|
|
//var_dump($headers);
|
|
|
|
|
|
+ // $conf->global->MAIL_PREFIX_FOR_EMAIL_ID must be defined
|
|
|
+ $host=dol_getprefix('email');
|
|
|
+
|
|
|
// If there is a filter on trackid
|
|
|
+ //var_dump($host);exit;
|
|
|
if ($searchfilterdoltrackid > 0)
|
|
|
{
|
|
|
- if (empty($headers['X-Dolibarr-TRACKID'])) continue;
|
|
|
+ //if (empty($headers['X-Dolibarr-TRACKID'])) continue;
|
|
|
+ if (empty($headers['References']) || ! preg_match('/@'.preg_quote($host,'/').'/', $headers['References']))
|
|
|
+ {
|
|
|
+ $nbemailprocessed++;
|
|
|
+ continue;
|
|
|
+ }
|
|
|
}
|
|
|
if ($searchfilternodoltrackid > 0)
|
|
|
{
|
|
|
- if (! empty($headers['X-Dolibarr-TRACKID'])) continue;
|
|
|
+ if (! empty($headers['References']) && preg_match('/@'.preg_quote($host,'/').'/', $headers['References']))
|
|
|
+ {
|
|
|
+ $nbemailprocessed++;
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ //if (! empty($headers['X-Dolibarr-TRACKID']) continue;
|
|
|
}
|
|
|
|
|
|
$thirdpartystatic=new Societe($this->db);
|
|
@@ -967,10 +981,11 @@ class EmailCollector extends CommonObject
|
|
|
|
|
|
$contactid = 0; $thirdpartyid = 0; $projectid = 0;
|
|
|
|
|
|
- // Analyze TrackId
|
|
|
+ // Analyze TrackId in field References
|
|
|
+ // For example: References: <1542377954.SMTPs-dolibarr-thi649@8f6014fde11ec6cdec9a822234fc557e>
|
|
|
$trackid = '';
|
|
|
$reg=array();
|
|
|
- if (! empty($headers['X-Dolibarr-TRACKID']) && preg_match('/:\s*([a-z]+)([0-9]+)$/', $headers['X-Dolibarr-TRACKID'], $reg))
|
|
|
+ if (! empty($headers['References']) && preg_match('/dolibarr-([a-z]+)([0-9]+)@'.preg_quote($host,'/').'/', $headers['References'], $reg))
|
|
|
{
|
|
|
$trackid = $reg[0].$reg[1];
|
|
|
|
|
@@ -1002,17 +1017,20 @@ class EmailCollector extends CommonObject
|
|
|
$objectemail = new User($this->db);
|
|
|
}
|
|
|
|
|
|
- $result = $objectemail->fetch($objectid);
|
|
|
- if ($result > 0)
|
|
|
+ if (is_object($objectemail))
|
|
|
{
|
|
|
- $fk_element_id = $objectemail->id;
|
|
|
- $fk_element_type = $objectemail->element;
|
|
|
- // Fix fk_element_type
|
|
|
- if ($fk_element_type == 'facture') $fk_element_type = 'invoice';
|
|
|
-
|
|
|
- $thirdpartyid = $objectemail->fk_soc;
|
|
|
- $contactid = $objectemail->fk_socpeople;
|
|
|
- $projectid = isset($objectemail->fk_project)?$objectemail->fk_project:$objectemail->fk_projet;
|
|
|
+ $result = $objectemail->fetch($objectid);
|
|
|
+ if ($result > 0)
|
|
|
+ {
|
|
|
+ $fk_element_id = $objectemail->id;
|
|
|
+ $fk_element_type = $objectemail->element;
|
|
|
+ // Fix fk_element_type
|
|
|
+ if ($fk_element_type == 'facture') $fk_element_type = 'invoice';
|
|
|
+
|
|
|
+ $thirdpartyid = $objectemail->fk_soc;
|
|
|
+ $contactid = $objectemail->fk_socpeople;
|
|
|
+ $projectid = isset($objectemail->fk_project)?$objectemail->fk_project:$objectemail->fk_projet;
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
// Project
|
|
@@ -1087,14 +1105,115 @@ class EmailCollector extends CommonObject
|
|
|
if (empty($operation['status'])) continue;
|
|
|
|
|
|
// Make Operation
|
|
|
+ dol_syslog("Execute action ".$operation['type']." actionparam=".$operation['actionparam'].' thirdpartystatic->id='.$thirdpartystatic->id.' contactstatic->id='.$contactstatic->id.' projectstatic->id='.$projectstatic->id);
|
|
|
|
|
|
// Search and create thirdparty
|
|
|
- if ($operation['type'] == 'searchandcreatethirdparty')
|
|
|
+ if ($operation['type'] == 'loadthirdparty' && $operation['type'] == 'loadandcreatethirdparty')
|
|
|
{
|
|
|
+ if (empty($operation['actionparam']))
|
|
|
+ {
|
|
|
+ $errorforactions++;
|
|
|
+ $this->errors = "Action loadthirdparty or loadandcreatethirdparty has empty parameter. Must be 'VALUE:xxx' or 'REGEX:(body|subject):regex' to extract";
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ $actionparam = $operation['actionparam'];
|
|
|
+ $nametouseforthirdparty='';
|
|
|
|
|
|
+ // $this->actionparam = 'VALUE:aaa' or 'REGEX:BODY:....'
|
|
|
+ $arrayvaluetouse = dolExplodeIntoArray($actionparam, ';', '=');
|
|
|
+ foreach($arrayvaluetouse as $propertytooverwrite => $valueforproperty)
|
|
|
+ {
|
|
|
+ $tmpclass=''; $tmpproperty='';
|
|
|
+ $tmparray=explode('.', $propertytooverwrite);
|
|
|
+ if (count($tmparray) == 2)
|
|
|
+ {
|
|
|
+ $tmpclass=$tmparray[0];
|
|
|
+ $tmpproperty=$tmparray[1];
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ $tmpproperty=$tmparray[0];
|
|
|
+ }
|
|
|
+ //if ($tmpclass && ($tmpclass != $object->element)) continue; // Property is for another type of object
|
|
|
|
|
|
+ $sourcestring='';
|
|
|
+ $sourcefield='';
|
|
|
+ $regexstring='';
|
|
|
+ $regforregex=array();
|
|
|
+ if (preg_match('/^REGEX:([a-zA-Z0-9]+):(.*)$/', $valueforproperty, $regforregex))
|
|
|
+ {
|
|
|
+ $sourcefield=$regforregex[0];
|
|
|
+ $regexstring=$regforregex[1];
|
|
|
+ }
|
|
|
|
|
|
+ if (! empty($sourcefield) && ! empty($regexstring))
|
|
|
+ {
|
|
|
+ if (strtolower($sourcefield) == 'body') $sourcestring=$messagetext;
|
|
|
+ elseif (strtolower($sourcefield) == 'subject') $sourcestring=$subject;
|
|
|
+
|
|
|
+ $regforval=array();
|
|
|
+ if (preg_match('/'.preg_quote($regexstring, '/').'/', $sourcestring, $regforval))
|
|
|
+ {
|
|
|
+ // Overwrite param $tmpproperty
|
|
|
+ $nametouseforthirdparty = $regforval[0];
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ // Nothing can be done for this param
|
|
|
+ }
|
|
|
+ }
|
|
|
+ elseif (preg_match('/^VALUE:(.*)$/', $valueforproperty, $reg))
|
|
|
+ {
|
|
|
+ $nametouseforthirdparty = $reg[0];
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ $errorforactions++;
|
|
|
+ $this->error = 'Bad syntax for description of action parameters: '.$actionparam;
|
|
|
+ $this->errors[] = $this->error;
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
+ if (! $errorforactions && $nametouseforthirdparty)
|
|
|
+ {
|
|
|
+ $result = $thirdpartystatic->fetch(0, $nametouseforthirdparty);
|
|
|
+ if ($result < 0)
|
|
|
+ {
|
|
|
+ $errorforactions++;
|
|
|
+ $this->error = 'Error when getting thirdparty with name '.$nametouseforthirdparty.' (may be 2 record exists with same name ?)';
|
|
|
+ $this->errors[] = $this->error;
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ elseif ($result == 0)
|
|
|
+ {
|
|
|
+ if ($operation['type'] == 'loadandcreatethirdparty')
|
|
|
+ {
|
|
|
+ // Create thirdparty
|
|
|
+ $thirdpartystatic->name = $nametouseforthirdparty;
|
|
|
+
|
|
|
+ // Overwrite values with values extracted from source email
|
|
|
+ $errorforthisaction = $this->overwritePropertiesOfObject($thirdpartystatic, $operation['actionparam'], $messagetext, $subject);
|
|
|
+
|
|
|
+ if ($errorforthisaction)
|
|
|
+ {
|
|
|
+ $errorforactions++;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ $result = $thirdpartystatic->create($user);
|
|
|
+ if ($result <= 0)
|
|
|
+ {
|
|
|
+ $errorforactions++;
|
|
|
+ $this->error = $thirdpartystatic->error;
|
|
|
+ $this->errors = $thirdpartystatic->errors;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
// Create event
|
|
|
elseif ($operation['type'] == 'recordevent')
|