Work on emailcollector
This commit is contained in:
parent
773e2da4cc
commit
f1287578f3
@ -103,25 +103,6 @@ if (empty($reshook))
|
|||||||
include DOL_DOCUMENT_ROOT.'/core/actions_printing.inc.php';
|
include DOL_DOCUMENT_ROOT.'/core/actions_printing.inc.php';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if ($action == 'confirm_collect')
|
|
||||||
{
|
|
||||||
dol_include_once('/emailcollector/class/emailcollector.class.php');
|
|
||||||
|
|
||||||
$res = $object->doCollect();
|
|
||||||
|
|
||||||
if ($res == 0)
|
|
||||||
{
|
|
||||||
setEventMessages($object->output, null, 'mesgs');
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
setEventMessages($object->error, null, 'errors');
|
|
||||||
}
|
|
||||||
|
|
||||||
$action = '';
|
|
||||||
}
|
|
||||||
|
|
||||||
if (GETPOST('addfilter','alpha'))
|
if (GETPOST('addfilter','alpha'))
|
||||||
{
|
{
|
||||||
$emailcollectorfilter = new EmailCollectorFilter($db);
|
$emailcollectorfilter = new EmailCollectorFilter($db);
|
||||||
@ -190,6 +171,25 @@ if ($action == 'deleteoperation')
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ($action == 'confirm_collect')
|
||||||
|
{
|
||||||
|
dol_include_once('/emailcollector/class/emailcollector.class.php');
|
||||||
|
|
||||||
|
$res = $object->doCollect();
|
||||||
|
|
||||||
|
if ($res == 0)
|
||||||
|
{
|
||||||
|
setEventMessages($object->output, null, 'mesgs');
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
setEventMessages($object->error, null, 'errors');
|
||||||
|
}
|
||||||
|
|
||||||
|
$action = '';
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -373,7 +373,29 @@ if ($object->id > 0 && (empty($action) || ($action != 'edit' && $action != 'crea
|
|||||||
*/
|
*/
|
||||||
$morehtmlref .= '</div>';
|
$morehtmlref .= '</div>';
|
||||||
|
|
||||||
dol_banner_tab($object, 'ref', $linkback, 1, 'ref', 'ref', $morehtmlref);
|
$morehtml = $langs->trans("NbOfEmailsInInbox").' : ';
|
||||||
|
|
||||||
|
$sourcedir = $object->source_directory;
|
||||||
|
$targetdir = ($object->target_directory ? $object->target_directory : ''); // Can be '[Gmail]/Trash' or 'mytag'
|
||||||
|
|
||||||
|
$connectstringserver = $object->getConnectStringIMAP();
|
||||||
|
$connectstringsource = $connectstringserver.imap_utf7_encode($sourcedir);
|
||||||
|
$connectstringtarget = $connectstringserver.imap_utf7_encode($targetdir);
|
||||||
|
|
||||||
|
$connection = imap_open($connectstringsource, $object->user, $object->password);
|
||||||
|
if (! $connection)
|
||||||
|
{
|
||||||
|
$morehtml .= 'Failed to open IMAP connection '.$connectstringsource;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
//$morehtmlstatus .= imap_num_msg($connection).'</div><div class="statusref">';
|
||||||
|
$morehtml .= imap_num_msg($connection);
|
||||||
|
}
|
||||||
|
|
||||||
|
imap_close($connection);
|
||||||
|
|
||||||
|
dol_banner_tab($object, 'ref', $linkback, 1, 'ref', 'ref', $morehtmlref.'<div class="refidno">'.$morehtml.'</div>', '', 0, '', '', 0, '');
|
||||||
|
|
||||||
print '<div class="fichecenter">';
|
print '<div class="fichecenter">';
|
||||||
print '<div class="fichehalfleft">';
|
print '<div class="fichehalfleft">';
|
||||||
@ -474,7 +496,7 @@ if ($object->id > 0 && (empty($action) || ($action != 'edit' && $action != 'crea
|
|||||||
print '</form>';
|
print '</form>';
|
||||||
|
|
||||||
print '</div>';
|
print '</div>';
|
||||||
print '</div>';
|
print '</div>'; // End <div class="fichecenter">
|
||||||
|
|
||||||
|
|
||||||
print '<div class="clearboth"></div><br>';
|
print '<div class="clearboth"></div><br>';
|
||||||
|
|||||||
@ -90,7 +90,8 @@ class EmailCollector extends CommonObject
|
|||||||
//'actiontodo' => array('type'=>'varchar(255)', 'label'=>'ActionToDo', 'visible'=>1, 'enabled'=>1, 'position'=>106),
|
//'actiontodo' => array('type'=>'varchar(255)', 'label'=>'ActionToDo', 'visible'=>1, 'enabled'=>1, 'position'=>106),
|
||||||
'target_directory' => array('type'=>'varchar(255)', 'label'=>'MailboxTargetDirectory', 'visible'=>1, 'enabled'=>1, 'position'=>110, 'notnull'=>0, 'comment'=>"Where to store messages once processed"),
|
'target_directory' => array('type'=>'varchar(255)', 'label'=>'MailboxTargetDirectory', 'visible'=>1, 'enabled'=>1, 'position'=>110, 'notnull'=>0, 'comment'=>"Where to store messages once processed"),
|
||||||
'datelastresult' => array('type'=>'datetime', 'label'=>'DateLastResult', 'visible'=>1, 'enabled'=>'$action != "create" && $action != "edit"', 'position'=>121, 'notnull'=>-1,),
|
'datelastresult' => array('type'=>'datetime', 'label'=>'DateLastResult', 'visible'=>1, 'enabled'=>'$action != "create" && $action != "edit"', 'position'=>121, 'notnull'=>-1,),
|
||||||
'lastresult' => array('type'=>'varchar(255)', 'label'=>'LastResult', 'visible'=>1, 'enabled'=>'$action != "create" && $action != "edit"', 'position'=>122, 'notnull'=>-1,),
|
'codelastresult' => array('type'=>'varchar(16)', 'label'=>'CodeLastResult', 'visible'=>1, 'enabled'=>'$action != "create" && $action != "edit"', 'position'=>122, 'notnull'=>-1,),
|
||||||
|
'lastresult' => array('type'=>'varchar(255)', 'label'=>'LastResult', 'visible'=>1, 'enabled'=>'$action != "create" && $action != "edit"', 'position'=>123, 'notnull'=>-1,),
|
||||||
'note_public' => array('type'=>'html', 'label'=>'NotePublic', 'visible'=>0, 'enabled'=>1, 'position'=>61, 'notnull'=>-1,),
|
'note_public' => array('type'=>'html', 'label'=>'NotePublic', 'visible'=>0, 'enabled'=>1, 'position'=>61, 'notnull'=>-1,),
|
||||||
'note_private' => array('type'=>'html', 'label'=>'NotePrivate', 'visible'=>0, 'enabled'=>1, 'position'=>62, 'notnull'=>-1,),
|
'note_private' => array('type'=>'html', 'label'=>'NotePrivate', 'visible'=>0, 'enabled'=>1, 'position'=>62, 'notnull'=>-1,),
|
||||||
'date_creation' => array('type'=>'datetime', 'label'=>'DateCreation', 'visible'=>-2, 'enabled'=>1, 'position'=>500, 'notnull'=>1,),
|
'date_creation' => array('type'=>'datetime', 'label'=>'DateCreation', 'visible'=>-2, 'enabled'=>1, 'position'=>500, 'notnull'=>1,),
|
||||||
@ -717,23 +718,16 @@ class EmailCollector extends CommonObject
|
|||||||
$this->fetchActions();
|
$this->fetchActions();
|
||||||
|
|
||||||
$sourcedir = $this->source_directory;
|
$sourcedir = $this->source_directory;
|
||||||
$targetdir = ($this->target_directory ? $server.$this->target_directory : ''); // Can be '[Gmail]/Trash' or 'mytag'
|
$targetdir = ($this->target_directory ? $this->target_directory : ''); // Can be '[Gmail]/Trash' or 'mytag'
|
||||||
|
|
||||||
// Connect to IMAP
|
$connectstringserver = $this->getConnectStringIMAP();
|
||||||
$flags ='/service=imap'; // IMAP
|
$connectstringsource = $connectstringserver.imap_utf7_encode($sourcedir);
|
||||||
$flags.='/ssl'; // '/tls'
|
|
||||||
$flags.='/novalidate-cert';
|
|
||||||
//$flags.='/readonly';
|
|
||||||
//$flags.='/debug';
|
|
||||||
|
|
||||||
$connectstringserver = '{'.$this->host.':993'.$flags.'}';
|
|
||||||
$connectstring = $connectstringserver.imap_utf7_encode($sourcedir);
|
|
||||||
$connectstringtarget = $connectstringserver.imap_utf7_encode($targetdir);
|
$connectstringtarget = $connectstringserver.imap_utf7_encode($targetdir);
|
||||||
|
|
||||||
$connection = imap_open($connectstring, $this->user, $this->password);
|
$connection = imap_open($connectstringsource, $this->user, $this->password);
|
||||||
if (! $connection)
|
if (! $connection)
|
||||||
{
|
{
|
||||||
$this->error = 'Failed to open IMAP connection '.$connectstring;
|
$this->error = 'Failed to open IMAP connection '.$connectstringsource;
|
||||||
return -3;
|
return -3;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -743,23 +737,24 @@ class EmailCollector extends CommonObject
|
|||||||
{
|
{
|
||||||
if (empty($rule['status'])) continue;
|
if (empty($rule['status'])) continue;
|
||||||
|
|
||||||
if ($rule['key'] == 'to') $search=($search?' ':'').'TO "'.str_replace('"', '', $rule['rulevalue']).'"';
|
if ($rule['type'] == 'to') $search.=($search?' ':'').'TO "'.str_replace('"', '', $rule['rulevalue']).'"';
|
||||||
if ($rule['key'] == 'bcc') $search=($search?' ':'').'BCC';
|
if ($rule['type'] == 'bcc') $search.=($search?' ':'').'BCC';
|
||||||
if ($rule['key'] == 'cc') $search=($search?' ':'').'CC';
|
if ($rule['type'] == 'cc') $search.=($search?' ':'').'CC';
|
||||||
if ($rule['key'] == 'from') $search=($search?' ':'').'FROM "'.str_replace('"', '', $rule['rulevalue']).'"';
|
if ($rule['type'] == 'from') $search.=($search?' ':'').'FROM "'.str_replace('"', '', $rule['rulevalue']).'"';
|
||||||
if ($rule['key'] == 'subject') $search=($search?' ':'').'SUBJECT "'.str_replace('"', '', $rule['rulevalue']).'"';
|
if ($rule['type'] == 'subject') $search.=($search?' ':'').'SUBJECT "'.str_replace('"', '', $rule['rulevalue']).'"';
|
||||||
if ($rule['key'] == 'body') $search=($search?' ':'').'BODY "'.str_replace('"', '', $rule['rulevalue']).'"';
|
if ($rule['type'] == 'body') $search.=($search?' ':'').'BODY "'.str_replace('"', '', $rule['rulevalue']).'"';
|
||||||
if ($rule['key'] == 'seen') $search=($search?' ':'').'SEEN';
|
if ($rule['type'] == 'seen') $search.=($search?' ':'').'SEEN';
|
||||||
if ($rule['key'] == 'unseen') $search=($search?' ':'').'UNSEEN';
|
if ($rule['type'] == 'unseen') $search.=($search?' ':'').'UNSEEN';
|
||||||
}
|
}
|
||||||
|
|
||||||
if (empty($targetdir)) // Use last date as filter if there is no targetdir defined.
|
if (empty($targetdir)) // Use last date as filter if there is no targetdir defined.
|
||||||
{
|
{
|
||||||
$fromdate=0;
|
$fromdate=0;
|
||||||
if ($this->datelastresult) $fromdate = $this->datelastresult;
|
if ($this->datelastresult && $this->codelastresult == 'OK') $fromdate = $this->datelastresult;
|
||||||
if ($fromdate > 0) $search.=($search?' ':'').'SINCE '.dol_print_date($fromdate - 1,'dayhourrfc');
|
if ($fromdate > 0) $search.=($search?' ':'').'SINCE '.dol_print_date($fromdate - 1,'dayhourrfc');
|
||||||
}
|
}
|
||||||
dol_syslog("search string = ".$search);
|
dol_syslog("search string = ".$search);
|
||||||
|
//var_dump($search);exit;
|
||||||
|
|
||||||
$nbemailprocessed=0; $nbactiondone=0;
|
$nbemailprocessed=0; $nbactiondone=0;
|
||||||
|
|
||||||
@ -841,4 +836,23 @@ class EmailCollector extends CommonObject
|
|||||||
|
|
||||||
return $error;
|
return $error;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return the connectstring to use with IMAP connection function
|
||||||
|
*
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
function getConnectStringIMAP()
|
||||||
|
{
|
||||||
|
// Connect to IMAP
|
||||||
|
$flags ='/service=imap'; // IMAP
|
||||||
|
$flags.='/ssl'; // '/tls'
|
||||||
|
$flags.='/novalidate-cert';
|
||||||
|
//$flags.='/readonly';
|
||||||
|
//$flags.='/debug';
|
||||||
|
|
||||||
|
$connectstringserver = '{'.$this->host.':993'.$flags.'}';
|
||||||
|
|
||||||
|
return $connectstringserver;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -153,6 +153,7 @@ CREATE TABLE llx_emailcollector_emailcollector(
|
|||||||
source_directory varchar(255) NOT NULL,
|
source_directory varchar(255) NOT NULL,
|
||||||
target_directory varchar(255),
|
target_directory varchar(255),
|
||||||
datelastresult datetime,
|
datelastresult datetime,
|
||||||
|
codelastresult varchar(16),
|
||||||
lastresult varchar(255),
|
lastresult varchar(255),
|
||||||
note_public text,
|
note_public text,
|
||||||
note_private text,
|
note_private text,
|
||||||
|
|||||||
@ -27,6 +27,7 @@ CREATE TABLE llx_emailcollector_emailcollector(
|
|||||||
source_directory varchar(255) NOT NULL,
|
source_directory varchar(255) NOT NULL,
|
||||||
target_directory varchar(255),
|
target_directory varchar(255),
|
||||||
datelastresult datetime,
|
datelastresult datetime,
|
||||||
|
codelastresult varchar(16),
|
||||||
lastresult varchar(255),
|
lastresult varchar(255),
|
||||||
note_public text,
|
note_public text,
|
||||||
note_private text,
|
note_private text,
|
||||||
|
|||||||
@ -1827,11 +1827,13 @@ DateLastResult=Date last collect
|
|||||||
LastResult=Last result
|
LastResult=Last result
|
||||||
EmailCollectorConfirmCollectTitle=Email collect confirmation
|
EmailCollectorConfirmCollectTitle=Email collect confirmation
|
||||||
EmailCollectorConfirmCollect=Do you want to run the collect for this collector now ?
|
EmailCollectorConfirmCollect=Do you want to run the collect for this collector now ?
|
||||||
NoNewEmailToProcess=No new email to process
|
NoNewEmailToProcess=No new email (matching filters) to process
|
||||||
NothingProcessed=Nothing done
|
NothingProcessed=Nothing done
|
||||||
XEmailsDoneYActionsDone=%s emails analyzed, %s record/actions done by collector
|
XEmailsDoneYActionsDone=%s emails analyzed, %s record/actions done by collector
|
||||||
RecordEvent=Record event
|
RecordEvent=Record event
|
||||||
CreateLeadAndThirdParty=Create lead (and thirdparty if necessary)
|
CreateLeadAndThirdParty=Create lead (and thirdparty if necessary)
|
||||||
|
CodeLastResult=Result code of last collect
|
||||||
|
NbOfEmailsInInbox=Number of email in source directory
|
||||||
##### Resource ####
|
##### Resource ####
|
||||||
ResourceSetup=Configuration du module Resource
|
ResourceSetup=Configuration du module Resource
|
||||||
UseSearchToSelectResource=Use a search form to choose a resource (rather than a drop-down list).
|
UseSearchToSelectResource=Use a search form to choose a resource (rather than a drop-down list).
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user