Debug v14
Fix email collector (Creation of thirparty, set of extrafields)
This commit is contained in:
parent
1e93a3f8f4
commit
ce27feda84
@ -6521,11 +6521,11 @@ abstract class CommonObject
|
||||
} elseif (in_array($type, array('int', 'integer'))) {
|
||||
$tmp = explode(',', $size);
|
||||
$newsize = $tmp[0];
|
||||
$out = '<input type="text" class="flat '.$morecss.'" name="'.$keyprefix.$key.$keysuffix.'" id="'.$keyprefix.$key.$keysuffix.'" maxlength="'.$newsize.'" value="'.dol_escape_htmltag($value).'"'.($moreparam ? $moreparam : '').($autofocusoncreate ? ' autofocus' : '').'>';
|
||||
$out = '<input type="text" class="flat '.$morecss.'" name="'.$keyprefix.$key.$keysuffix.'" id="'.$keyprefix.$key.$keysuffix.'"'.($newsize > 0 ? ' maxlength="'.$newsize.'"' : '').' value="'.dol_escape_htmltag($value).'"'.($moreparam ? $moreparam : '').($autofocusoncreate ? ' autofocus' : '').'>';
|
||||
} elseif (in_array($type, array('real'))) {
|
||||
$out = '<input type="text" class="flat '.$morecss.'" name="'.$keyprefix.$key.$keysuffix.'" id="'.$keyprefix.$key.$keysuffix.'" value="'.dol_escape_htmltag($value).'"'.($moreparam ? $moreparam : '').($autofocusoncreate ? ' autofocus' : '').'>';
|
||||
} elseif (preg_match('/varchar/', $type)) {
|
||||
$out = '<input type="text" class="flat '.$morecss.'" name="'.$keyprefix.$key.$keysuffix.'" id="'.$keyprefix.$key.$keysuffix.'" maxlength="'.$size.'" value="'.dol_escape_htmltag($value).'"'.($moreparam ? $moreparam : '').($autofocusoncreate ? ' autofocus' : '').'>';
|
||||
$out = '<input type="text" class="flat '.$morecss.'" name="'.$keyprefix.$key.$keysuffix.'" id="'.$keyprefix.$key.$keysuffix.'"'.($size > 0 ? ' maxlength="'.$size.'"' : '').' value="'.dol_escape_htmltag($value).'"'.($moreparam ? $moreparam : '').($autofocusoncreate ? ' autofocus' : '').'>';
|
||||
} elseif (in_array($type, array('mail', 'phone', 'url'))) {
|
||||
$out = '<input type="text" class="flat '.$morecss.'" name="'.$keyprefix.$key.$keysuffix.'" id="'.$keyprefix.$key.$keysuffix.'" value="'.dol_escape_htmltag($value).'" '.($moreparam ? $moreparam : '').($autofocusoncreate ? ' autofocus' : '').'>';
|
||||
} elseif (preg_match('/^text/', $type)) {
|
||||
|
||||
@ -324,6 +324,9 @@ class EmailCollector extends CommonObject
|
||||
// Clear fields
|
||||
$object->ref = "copy_of_".$object->ref;
|
||||
$object->title = $langs->trans("CopyOf")." ".$object->title;
|
||||
if (empty($object->host)) {
|
||||
$object->host = 'imap.example.com';
|
||||
}
|
||||
// ...
|
||||
// Clear extrafields that are unique
|
||||
if (is_array($object->array_options) && count($object->array_options) > 0) {
|
||||
@ -849,11 +852,11 @@ class EmailCollector extends CommonObject
|
||||
$regexstring = '';
|
||||
//$transformationstring='';
|
||||
$regforregex = array();
|
||||
if (preg_match('/^EXTRACT:([a-zA-Z0-9]+):(.*):([^:])$/', $valueforproperty, $regforregex)) {
|
||||
if (preg_match('/^EXTRACT:([a-zA-Z0-9_]+):(.*):([^:])$/', $valueforproperty, $regforregex)) {
|
||||
$sourcefield = $regforregex[1];
|
||||
$regexstring = $regforregex[2];
|
||||
//$transofrmationstring=$regforregex[3];
|
||||
} elseif (preg_match('/^EXTRACT:([a-zA-Z0-9]+):(.*)$/', $valueforproperty, $regforregex)) {
|
||||
} elseif (preg_match('/^EXTRACT:([a-zA-Z0-9_]+):(.*)$/', $valueforproperty, $regforregex)) {
|
||||
$sourcefield = $regforregex[1];
|
||||
$regexstring = $regforregex[2];
|
||||
}
|
||||
@ -1199,15 +1202,20 @@ class EmailCollector extends CommonObject
|
||||
$iforemailloop = 0;
|
||||
foreach ($arrayofemail as $imapemail) {
|
||||
if ($nbemailprocessed > 1000) {
|
||||
break; // Do not process more than 1000 email per launch (this is a different protection than maxnbcollectedpercollect
|
||||
break; // Do not process more than 1000 email per launch (this is a different protection than maxnbcollectedpercollect)
|
||||
}
|
||||
|
||||
$iforemailloop++;
|
||||
|
||||
// GET header and overview datas
|
||||
|
||||
$header = imap_fetchheader($connection, $imapemail, 0);
|
||||
$overview = imap_fetch_overview($connection, $imapemail, 0);
|
||||
|
||||
/* print $header; var_dump($overview); */
|
||||
|
||||
// Process $header of email
|
||||
$header = preg_replace('/\r\n\s+/m', ' ', $header); // When a header line is on several lines, merge lines
|
||||
/*print $header;
|
||||
print $header;*/
|
||||
|
||||
$matches = array();
|
||||
preg_match_all('/([^: ]+): (.+?(?:\r\n\s(?:.+?))*)\r\n/m', $header, $matches);
|
||||
@ -1297,9 +1305,6 @@ class EmailCollector extends CommonObject
|
||||
$this->db->begin();
|
||||
|
||||
|
||||
// GET Email meta datas
|
||||
$overview = imap_fetch_overview($connection, $imapemail, 0);
|
||||
|
||||
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);
|
||||
|
||||
$overview[0]->subject = $this->decodeSMTPSubject($overview[0]->subject);
|
||||
@ -1309,10 +1314,14 @@ class EmailCollector extends CommonObject
|
||||
// Removed emojis
|
||||
$overview[0]->subject = preg_replace('/[\x{10000}-\x{10FFFF}]/u', "\xEF\xBF\xBD", $overview[0]->subject);
|
||||
|
||||
// Parse IMAP email structure
|
||||
// GET IMAP email structure/content
|
||||
|
||||
global $htmlmsg, $plainmsg, $charset, $attachments;
|
||||
|
||||
$this->getmsg($connection, $imapemail);
|
||||
|
||||
//print $plainmsg; var_dump($plainmsg); exit;
|
||||
|
||||
//$htmlmsg,$plainmsg,$charset,$attachments
|
||||
$messagetext = $plainmsg ? $plainmsg : dol_string_nohtmltag($htmlmsg, 0);
|
||||
// Removed emojis
|
||||
@ -1640,13 +1649,15 @@ class EmailCollector extends CommonObject
|
||||
if ($operation['type'] == 'loadthirdparty' || $operation['type'] == 'loadandcreatethirdparty') {
|
||||
if (empty($operation['actionparam'])) {
|
||||
$errorforactions++;
|
||||
$this->error = "Action loadthirdparty or loadandcreatethirdparty has empty parameter. Must be a rule like 'SET:xxx' or 'EXTRACT:(body|subject):regex' to define how to set or extract data";
|
||||
$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;";
|
||||
$this->errors[] = $this->error;
|
||||
} else {
|
||||
$actionparam = $operation['actionparam'];
|
||||
$idtouseforthirdparty = '';
|
||||
$nametouseforthirdparty = '';
|
||||
$emailtouseforthirdparty = '';
|
||||
|
||||
// $this->actionparam = 'SET:aaa' or 'EXTRACT:BODY:....'
|
||||
// $actionparam = 'param=SET:aaa' or 'param=EXTRACT:BODY:....'
|
||||
$arrayvaluetouse = dolExplodeIntoArray($actionparam, ';', '=');
|
||||
foreach ($arrayvaluetouse as $propertytooverwrite => $valueforproperty) {
|
||||
$sourcestring = '';
|
||||
@ -1654,7 +1665,7 @@ class EmailCollector extends CommonObject
|
||||
$regexstring = '';
|
||||
$regforregex = array();
|
||||
|
||||
if (preg_match('/^EXTRACT:([a-zA-Z0-9]+):(.*)$/', $valueforproperty, $regforregex)) {
|
||||
if (preg_match('/^EXTRACT:([a-zA-Z0-9_]+):(.*)$/', $valueforproperty, $regforregex)) {
|
||||
$sourcefield = $regforregex[1];
|
||||
$regexstring = $regforregex[2];
|
||||
}
|
||||
@ -1674,10 +1685,18 @@ class EmailCollector extends CommonObject
|
||||
if (preg_match('/'.$regexstring.'/ms', $sourcestring, $regforval)) {
|
||||
//var_dump($regforval[count($regforval)-1]);exit;
|
||||
// Overwrite param $tmpproperty
|
||||
$nametouseforthirdparty = isset($regforval[count($regforval) - 1]) ? trim($regforval[count($regforval) - 1]) : null;
|
||||
if ($propertytooverwrite == 'id') {
|
||||
$idtouseforthirdparty = isset($regforval[count($regforval) - 1]) ? trim($regforval[count($regforval) - 1]) : null;
|
||||
} elseif ($propertytooverwrite == 'email') {
|
||||
$emailtouseforthirdparty = isset($regforval[count($regforval) - 1]) ? trim($regforval[count($regforval) - 1]) : null;
|
||||
} else {
|
||||
$nametouseforthirdparty = isset($regforval[count($regforval) - 1]) ? trim($regforval[count($regforval) - 1]) : null;
|
||||
}
|
||||
} else {
|
||||
// Regex not found
|
||||
$idtouseforthirdparty = null;
|
||||
$nametouseforthirdparty = null;
|
||||
$emailtouseforthirdparty = null;
|
||||
}
|
||||
//var_dump($object->$tmpproperty);exit;
|
||||
} else {
|
||||
@ -1689,7 +1708,13 @@ class EmailCollector extends CommonObject
|
||||
} elseif (preg_match('/^(SET|SETIFEMPTY):(.*)$/', $valueforproperty, $reg)) {
|
||||
//if (preg_match('/^options_/', $tmpproperty)) $object->array_options[preg_replace('/^options_/', '', $tmpproperty)] = $reg[1];
|
||||
//else $object->$tmpproperty = $reg[1];
|
||||
$nametouseforthirdparty = $reg[2];
|
||||
if ($propertytooverwrite == 'id') {
|
||||
$idtouseforthirdparty = $reg[2];
|
||||
} elseif ($propertytooverwrite == 'email') {
|
||||
$emailtouseforthirdparty = $reg[2];
|
||||
} else {
|
||||
$nametouseforthirdparty = $reg[2];
|
||||
}
|
||||
} else {
|
||||
$errorforactions++;
|
||||
$this->error = 'Bad syntax for description of action parameters: '.$actionparam;
|
||||
@ -1698,8 +1723,8 @@ class EmailCollector extends CommonObject
|
||||
}
|
||||
}
|
||||
|
||||
if (!$errorforactions && $nametouseforthirdparty) {
|
||||
$result = $thirdpartystatic->fetch(0, $nametouseforthirdparty);
|
||||
if (!$errorforactions && ($idtouseforthirdparty || $emailtouseforthirdparty || $nametouseforthirdparty)) {
|
||||
$result = $thirdpartystatic->fetch($idtouseforthirdparty, $nametouseforthirdparty, '', '', '', '', '', '', '', '', $emailtouseforthirdparty);
|
||||
if ($result < 0) {
|
||||
$errorforactions++;
|
||||
$this->error = 'Error when getting thirdparty with name '.$nametouseforthirdparty.' (may be 2 record exists with same name ?)';
|
||||
@ -1707,20 +1732,20 @@ class EmailCollector extends CommonObject
|
||||
break;
|
||||
} elseif ($result == 0) {
|
||||
if ($operation['type'] == 'loadthirdparty') {
|
||||
dol_syslog("Third party with name ".$nametouseforthirdparty." was not found");
|
||||
dol_syslog("Third party with id=".$idtouseforthirdparty." email=".$emailtouseforthirdparty." name=".$nametouseforthirdparty." was not found");
|
||||
|
||||
$errorforactions++;
|
||||
$this->error = 'ErrorFailedToLoadThirdParty';
|
||||
$this->errors[] = 'ErrorFailedToLoadThirdParty';
|
||||
} elseif ($operation['type'] == 'loadandcreatethirdparty') {
|
||||
dol_syslog("Third party with name ".$nametouseforthirdparty." was not found. We try to create it.");
|
||||
dol_syslog("Third party with id=".$idtouseforthirdparty." email=".$emailtouseforthirdparty." name=".$nametouseforthirdparty." was not found. We try to create it.");
|
||||
|
||||
// Create thirdparty
|
||||
$thirdpartystatic->name = $nametouseforthirdparty;
|
||||
if ($fromtext != $nametouseforthirdparty) {
|
||||
$thirdpartystatic->name_alias = $fromtext;
|
||||
}
|
||||
$thirdpartystatic->email = $from;
|
||||
$thirdpartystatic->email = ($emailtouseforthirdparty ? $emailtouseforthirdparty : $from);
|
||||
|
||||
// Overwrite values with values extracted from source email
|
||||
$errorforthisaction = $this->overwritePropertiesOfObject($thirdpartystatic, $operation['actionparam'], $messagetext, $subject, $header);
|
||||
|
||||
@ -2090,7 +2090,7 @@ LargerThan=Larger than
|
||||
IfTrackingIDFoundEventWillBeLinked=Note that If a tracking ID of an object is found into email, or if the email is an answer of an email aready collected and linked to an object, the created event will be automatically linked to the known related object.
|
||||
WithGMailYouCanCreateADedicatedPassword=With a GMail account, if you enabled the 2 steps validation, it is recommanded to create a dedicated second password for the application instead of using your own account passsword from https://myaccount.google.com/.
|
||||
EmailCollectorTargetDir=It may be a desired behaviour to move the email into another tag/directory when it was processed successfully. Just set name of directory here to use this feature (Do NOT use special characters in name). Note that you must also use a read/write login account.
|
||||
EmailCollectorLoadThirdPartyHelp=You can use this action to use the email content to find and load an existing thirdparty in your database. The found (or created) thirdparty will be used for following actions that need it. In the parameter field you can use for example 'EXTRACT:BODY:Name:\s([^\s]*)' if you want to extract the name of the thirdparty from a string 'Name: name to find' found into the body.
|
||||
EmailCollectorLoadThirdPartyHelp=You can use this action to use the email content to find and load an existing thirdparty in your database. The found (or created) thirdparty will be used for following actions that need it.<br>For example, if you want to create a thirdparty with a name extracted a string 'Name: name to find' found into the body, use sender email as email, you can set the parameter field like this:<br>'email=HEADER:^From:(.*);name=EXTRACT:BODY:Name:\s([^\s]*);client=SET:2;'<br>
|
||||
EndPointFor=End point for %s : %s
|
||||
DeleteEmailCollector=Delete email collector
|
||||
ConfirmDeleteEmailCollector=Are you sure you want to delete this email collector?
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
<?php
|
||||
/* Copyright (C) 2002-2006 Rodolphe Quiedeville <rodolphe@quiedeville.org>
|
||||
* Copyright (C) 2004-2019 Laurent Destailleur <eldy@users.sourceforge.net>
|
||||
* Copyright (C) 2004-2021 Laurent Destailleur <eldy@users.sourceforge.net>
|
||||
* Copyright (C) 2004 Eric Seigne <eric.seigne@ryxeo.com>
|
||||
* Copyright (C) 2003 Brian Fraval <brian@fraval.org>
|
||||
* Copyright (C) 2006 Andre Cianfarani <acianfa@free.fr>
|
||||
@ -4265,21 +4265,6 @@ class Societe extends CommonObject
|
||||
return $lib;
|
||||
}
|
||||
|
||||
|
||||
// phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
|
||||
/**
|
||||
* Set prospect level
|
||||
*
|
||||
* @param User $user User who sets the discount
|
||||
* @return int <0 if KO, >0 if OK
|
||||
* @deprecated Use update function instead
|
||||
*/
|
||||
public function set_prospect_level(User $user)
|
||||
{
|
||||
// phpcs:enable
|
||||
return $this->update($this->id, $user);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return status of prospect
|
||||
*
|
||||
@ -4359,20 +4344,6 @@ class Societe extends CommonObject
|
||||
return "Error, mode/status not found";
|
||||
}
|
||||
|
||||
// phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
|
||||
/**
|
||||
* Set outstanding value
|
||||
*
|
||||
* @param User $user User making change
|
||||
* @return int <0 if KO, >0 if OK
|
||||
* @deprecated Use update function instead
|
||||
*/
|
||||
public function set_OutstandingBill(User $user)
|
||||
{
|
||||
// phpcs:enable
|
||||
return $this->update($this->id, $user);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return amount of order not paid and total
|
||||
*
|
||||
|
||||
Loading…
Reference in New Issue
Block a user