From f9860e1425c738ca3c8218023446fe3d42a5adae Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Tue, 9 Apr 2019 13:23:30 +0200 Subject: [PATCH] Work on email collector --- htdocs/admin/emailcollector_card.php | 10 +++--- htdocs/core/tpl/ajaxrow.tpl.php | 4 +-- .../class/emailcollector.class.php | 35 +++++++++++++------ htdocs/langs/en_US/admin.lang | 2 +- 4 files changed, 34 insertions(+), 17 deletions(-) diff --git a/htdocs/admin/emailcollector_card.php b/htdocs/admin/emailcollector_card.php index 0ce530aea9f..cbf544bcad3 100644 --- a/htdocs/admin/emailcollector_card.php +++ b/htdocs/admin/emailcollector_card.php @@ -554,10 +554,7 @@ if ($object->id > 0 && (empty($action) || ($action != 'edit' && $action != 'crea } print ''; print ''.$ruleaction['actionparam'].''; - print ''; - //print $ruleactionobj->getLibStatut(3); - print ' '.img_delete().''; - print ''; + // Move up/down print ''; if ($i > 0) { @@ -567,6 +564,10 @@ if ($object->id > 0 && (empty($action) || ($action != 'edit' && $action != 'crea print ''.img_down('default', 0, 'imgdownforline').''; } print ''; + // Delete + print ''; + print ' '.img_delete().''; + print ''; print ''; $i++; } @@ -575,6 +576,7 @@ if ($object->id > 0 && (empty($action) || ($action != 'edit' && $action != 'crea print ''; if (! empty($conf->use_javascript_ajax)) { + $urltorefreshaftermove = DOL_URL_ROOT.'/admin/emailcollector_card.php?id='.$id; include DOL_DOCUMENT_ROOT . '/core/tpl/ajaxrow.tpl.php'; } diff --git a/htdocs/core/tpl/ajaxrow.tpl.php b/htdocs/core/tpl/ajaxrow.tpl.php index 761d5e52e11..8971dc2a919 100644 --- a/htdocs/core/tpl/ajaxrow.tpl.php +++ b/htdocs/core/tpl/ajaxrow.tpl.php @@ -77,8 +77,8 @@ $(document).ready(function(){ function() { console.log("tableDND end of ajax call"); if (reloadpage == 1) { - //console.log(''); - location.href = ''; + //console.log(''); + location.href = ''; } else { $("# .drag").each( function( intIndex ) { diff --git a/htdocs/emailcollector/class/emailcollector.class.php b/htdocs/emailcollector/class/emailcollector.class.php index 1975a16c9ea..1d41d1c9f33 100644 --- a/htdocs/emailcollector/class/emailcollector.class.php +++ b/htdocs/emailcollector/class/emailcollector.class.php @@ -734,9 +734,10 @@ class EmailCollector extends CommonObject * @param string $actionparam Action parameters * @param string $messagetext Body * @param string $subject Subject + * @param string $header Header * @return int 0=OK, Nb of error if error */ - private function overwritePropertiesOfObject(&$object, $actionparam, $messagetext, $subject) + private function overwritePropertiesOfObject(&$object, $actionparam, $messagetext, $subject, $header) { $errorforthisaction = 0; @@ -776,21 +777,35 @@ class EmailCollector extends CommonObject $sourcefield=$regforregex[1]; $regexstring=$regforregex[2]; } - if (! empty($sourcefield) && ! empty($regexstring)) { if (strtolower($sourcefield) == 'body') $sourcestring=$messagetext; elseif (strtolower($sourcefield) == 'subject') $sourcestring=$subject; + elseif (strtolower($sourcefield) == 'header') $sourcestring=$header; - $regforval=array(); - if (preg_match('/'.preg_quote($regexstring, '/').'/', $sourcestring, $regforval)) + if ($sourcestring) { - // Overwrite param $tmpproperty - $object->$tmpproperty = $regforval[1]; + $regforval=array(); + //var_dump($regexstring);var_dump($sourcestring); + if (preg_match('/'.$regexstring.'/ms', $sourcestring, $regforval)) + { + //var_dump($regforval[1]);exit; + // Overwrite param $tmpproperty + $object->$tmpproperty = isset($regforval[1])?trim($regforval[1]):null; + } + else + { + // Regex not found + $object->$tmpproperty = null; + } + //var_dump($object->$tmpproperty);exit; } else { // Nothing can be done for this param + $errorforthisaction++; + $this->errors = 'The extract rule to use has on an unknown source (must be HEADER, SUBJECT or BODY)'; + $this->errors[] = $this->error; } } elseif (preg_match('/^SET:(.*)$/', $valueforproperty, $reg)) @@ -1360,7 +1375,7 @@ class EmailCollector extends CommonObject $thirdpartystatic->email = $from; // Overwrite values with values extracted from source email - $errorforthisaction = $this->overwritePropertiesOfObject($thirdpartystatic, $operation['actionparam'], $messagetext, $subject); + $errorforthisaction = $this->overwritePropertiesOfObject($thirdpartystatic, $operation['actionparam'], $messagetext, $subject, $header); if ($errorforthisaction) { @@ -1441,7 +1456,7 @@ class EmailCollector extends CommonObject //$actioncomm->extraparams = $extraparams; // Overwrite values with values extracted from source email - $errorforthisaction = $this->overwritePropertiesOfObject($actioncommn, $operation['actionparam'], $messagetext, $subject); + $errorforthisaction = $this->overwritePropertiesOfObject($actioncommn, $operation['actionparam'], $messagetext, $subject, $header); if ($errorforthisaction) { @@ -1513,7 +1528,7 @@ class EmailCollector extends CommonObject $projecttocreate->ref = $defaultref; // Overwrite values with values extracted from source email - $errorforthisaction = $this->overwritePropertiesOfObject($projecttocreate, $operation['actionparam'], $messagetext, $subject); + $errorforthisaction = $this->overwritePropertiesOfObject($projecttocreate, $operation['actionparam'], $messagetext, $subject, $header); if ($errorforthisaction) { @@ -1597,7 +1612,7 @@ class EmailCollector extends CommonObject $tickettocreate->ref = $defaultref; // Overwrite values with values extracted from source email - $errorforthisaction = $this->overwritePropertiesOfObject($tickettocreate, $operation['actionparam'], $messagetext, $subject); + $errorforthisaction = $this->overwritePropertiesOfObject($tickettocreate, $operation['actionparam'], $messagetext, $subject, $header); if ($errorforthisaction) { diff --git a/htdocs/langs/en_US/admin.lang b/htdocs/langs/en_US/admin.lang index 9620a16d144..af5ead68a26 100644 --- a/htdocs/langs/en_US/admin.lang +++ b/htdocs/langs/en_US/admin.lang @@ -1849,7 +1849,7 @@ WithoutDolTrackingID=Dolibarr Tracking ID not found FormatZip=Zip MainMenuCode=Menu entry code (mainmenu) ECMAutoTree=Show automatic ECM tree -OperationParamDesc=Define values to use for action, or how to extract values. For example:
objproperty1=SET:abc
objproperty2=EXTRACT:HEADER:X-Myheaderkey.*[^\s]+(.*)
objproperty3=EXTRACT:SUBJECT:([^\s]*)
object.objproperty4=EXTRACT:BODY:My company name is\s([^\s]*)

Use a ; char as separator to extract or set several properties. +OperationParamDesc=Define values to use for action, or how to extract values. For example:
objproperty1=SET:abc
objproperty2=EXTRACT:HEADER:X-Myheaderkey.*[^\s]+(.*)
options_myextrafield=EXTRACT:SUBJECT:([^\s]*)
object.objproperty4=EXTRACT:BODY:My company name is\s([^\s]*)

Use a ; char as separator to extract or set several properties. OpeningHours=Opening hours OpeningHoursDesc=Enter here the regular opening hours of your company. ResourceSetup=Configuration of Resource module