Work on email collector
This commit is contained in:
parent
4a25317f10
commit
15dd2b3e35
@ -713,7 +713,7 @@ class EmailCollector extends CommonObject
|
|||||||
$this->fetch_actions();
|
$this->fetch_actions();
|
||||||
|
|
||||||
$sourcedir = $this->source_directory;
|
$sourcedir = $this->source_directory;
|
||||||
$targetdir = ($this->target_directory ? $server.$this->target_directory : '');
|
$targetdir = ($this->target_directory ? $server.$this->target_directory : ''); // Can be '[Gmail]/Trash' or 'mytag'
|
||||||
|
|
||||||
// Connect to IMAP
|
// Connect to IMAP
|
||||||
$flags ='/service=imap'; // IMAP
|
$flags ='/service=imap'; // IMAP
|
||||||
@ -722,8 +722,9 @@ class EmailCollector extends CommonObject
|
|||||||
//$flags.='/readonly';
|
//$flags.='/readonly';
|
||||||
//$flags.='/debug';
|
//$flags.='/debug';
|
||||||
|
|
||||||
$connectstring = '{'.$this->host.':993'.$flags.'}';
|
$connectstringserver = '{'.$this->host.':993'.$flags.'}';
|
||||||
$connectstring.=imap_utf7_encode($sourcedir);
|
$connectstring = $connectstringserver.imap_utf7_encode($sourcedir);
|
||||||
|
$connectstringtarget = $connectstringserver.imap_utf7_encode($targetdir);
|
||||||
|
|
||||||
$connection = imap_open($connectstring, $this->user, $this->password);
|
$connection = imap_open($connectstring, $this->user, $this->password);
|
||||||
if (! $connection)
|
if (! $connection)
|
||||||
@ -765,10 +766,23 @@ class EmailCollector extends CommonObject
|
|||||||
{
|
{
|
||||||
foreach($arrayofemail as $imapemail)
|
foreach($arrayofemail as $imapemail)
|
||||||
{
|
{
|
||||||
|
if ($nbemailprocessed > 100) break; // Do not process more than 100 email per launch
|
||||||
|
|
||||||
$errorforactions = 0;
|
$errorforactions = 0;
|
||||||
|
|
||||||
$this->db->begin();
|
$this->db->begin();
|
||||||
|
|
||||||
|
$overview = imap_fetch_overview($connection, $imapemail, 0);
|
||||||
|
$header = imap_fetchheader($connection ,$imapemail, 0);
|
||||||
|
$message = imap_body($connection, $imapemail, 0);
|
||||||
|
// imap_fetchstructure($connection, $imapemail, 0);
|
||||||
|
// imap_fetchbody($connection, $imapemail, 1) may be text/plain, 2 may be text/html
|
||||||
|
|
||||||
|
/*var_dump($overview);
|
||||||
|
var_dump($header);
|
||||||
|
var_dump($message);
|
||||||
|
*/
|
||||||
|
|
||||||
// Record email
|
// Record email
|
||||||
foreach($this->actions as $actionkey => $actionvalue)
|
foreach($this->actions as $actionkey => $actionvalue)
|
||||||
{
|
{
|
||||||
@ -786,7 +800,13 @@ class EmailCollector extends CommonObject
|
|||||||
// Move email
|
// Move email
|
||||||
if (! $errorforactions && $targetdir)
|
if (! $errorforactions && $targetdir)
|
||||||
{
|
{
|
||||||
//imap_mail_move($connection, $sourcedir, $targetdir);
|
dol_syslog("EmailCollector::doCollect move message ".$imapemail." to ".$connectstringtarget, LOG_DEBUG);
|
||||||
|
$res = imap_mail_move($connection, $imapemail, $targetdir, 0);
|
||||||
|
if ($res == false) {
|
||||||
|
$error++;
|
||||||
|
$this->errors = imap_last_error();
|
||||||
|
dol_syslog(imap_last_error());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$nbemailprocessed++;
|
$nbemailprocessed++;
|
||||||
@ -801,7 +821,8 @@ class EmailCollector extends CommonObject
|
|||||||
$this->output=$langs->trans('NoNewEmailToProcess');
|
$this->output=$langs->trans('NoNewEmailToProcess');
|
||||||
}
|
}
|
||||||
|
|
||||||
//imap_expunge($connection);
|
imap_expunge($connection); // To validate any move
|
||||||
|
|
||||||
imap_close($connection);
|
imap_close($connection);
|
||||||
|
|
||||||
$this->datelastresult = $now;
|
$this->datelastresult = $now;
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user