- Posts: 57
- Thank you received: 0
Please Log in or Create an account to join the conversation.
No. Reply ùessage is not analysed, just stored as note.Bonus question : is it possible to approve or refuse a ticket or any element received by email simply by replying to the mail ?
Please Log in or Create an account to join the conversation.
babynus wrote: IMAP seems to be correctly configured.
What was in the reply message ?
Please take care to add at least 2 blank lines between new message and original message.
Bonus question : is it possible to approve or refuse a ticket or any element received by email simply by replying to the mail ?
No. Reply message is not analysed, just stored as note.
Please Log in or Create an account to join the conversation.
public static function checkEmails() {
self::init();
global $globalCronMode, $globalCatchErrors;
$globalCronMode=true;
$globalCatchErrors=true;
require_once("../model/ImapMailbox.php"); // Imap management Class
if (! ImapMailbox::checkImapEnabled()) {
traceLog("ERROR - Cron::checkEmails() - IMAP extension not enabled in your PHP config. Cannot connect to IMAP Mailbox.");
return;
}
// IMAP must be enabled in Google Mail Settings
$emailEmail=Parameter::getGlobalParameter('cronCheckEmailsUser');
$emailPassword=Parameter::getGlobalParameter('cronCheckEmailsPassword');
$emailAttachmentsDir=dirname(__FILE__) . '/../files/attach';
$emailHost=Parameter::getGlobalParameter('cronCheckEmailsHost'); // {imap.gmail.com:993/imap/ssl}INBOX';
if (! $emailHost) {
traceLog("IMAP connection string not defined");
return;
}
$mailbox = new ImapMailbox($emailHost, $emailEmail, $emailPassword, $emailAttachmentsDir, 'utf-8');
$mails = array();
// Get some mail
$mailsIds = $mailbox->searchMailBox('UNSEEN UNDELETED');
if(!$mailsIds) {
debugTraceLog('Mailbox is empty'); // Will be a debug level trace
return;
}
include_once '../external/html2text/html2text.php';
foreach ($mailsIds as $mailId) {
$mail = $mailbox->getMail($mailId);
$mailbox->markMailAsUnread($mailId);
$body=$mail->textPlain;
traceLog('body='.$body);
$bodyHtml=$mail->textHtml;
traceLog('bodyHtml='.$bodyHtml);
if (! $body and $bodyHtml) {
$body=str_replace(array("</div>","</p>","<br>","<br/>","<br />"),
array("</div>\n","</p>\n","\n","\n","\n"), $bodyHtml);
$body=strip_tags($bodyHtml);
}
$class=null;
$id=null;
$msg=null;
$senderId=null;
// Class and Id of object
$posClass=strpos($body,'directAccess=true&objectClass=');
if ($posClass) { // It is a ProjeQtor mail
$posId=strpos($body,'&objectId=',$posClass);
$posEnd=strpos($body,'>',$posId);
$class=substr($body,$posClass+30,$posId-$posClass-30);
$id=substr($body,$posId+10,$posEnd-$posId-10);
} else {
continue;
}
// Message
$posEndMsg=strpos($body,"\r\n\r\n\r\n");
if ($posEndMsg) {
$msg=substr($body,0,$posEndMsg);
traceLog('msg='.$msg);
}
// Sender
$sender=$mail->fromAddress;
$crit=array('email'=>$sender);
$usr=new Affectable();
$usrList=$usr->getSqlElementsFromCriteria($crit,false,null,'idle asc, isUser desc, isResource desc');
if (count($usrList)) {
$senderId=$usrList[0]->id;
}
if (! $senderId) {
traceLog("Email message received from '$sender', not recognized as resource or user or contact : message not stored as note to avoid spamming");
$mailbox->markMailAsUnread($mailId);
continue;
}
$arrayFrom=array("\n","\r"," ");
$arrayTo=array("","","");
$class=str_replace($arrayFrom, $arrayTo, $class);
$id=str_replace($arrayFrom, $arrayTo, $id);
$obj=null;
if (SqlElement::class_exists($class) and is_numeric($id)) {
$obj=new $class($id);
}
if ($obj and $obj->id and $senderId) {
$note=new Note();
$note->refType=$class;
$note->refId=$id;
$note->idPrivacy=1;
$note->note=nl2br($msg);
$note->idUser=$senderId;
$note->creationDate=date('Y-m-d H:i:s');
$note->fromEmail=1;
$note->save();
$mailbox->markMailAsRead($mailId);
debugTraceLog("Note from '$sender' added on $class #$id");
} else {
$mailbox->markMailAsUnread($mailId);
}
}
}
Please Log in or Create an account to join the conversation.
Please Log in or Create an account to join the conversation.
En poursuivant votre navigation, vous acceptez le dépôt de cookies tiers destinés au bon fonctionnement et à la sécurisation du site (gestion de session, reCaptcha) et à une analyse statistique anonymisée des accès sur notre site (Google Analytics). Si vous vous inscrivez, les informations que vous fournirez ne seront jamais divulguées à un tiers sous quelque forme que ce soit. En savoir plus
Ce site utilise des cookies pour assurer son bon fonctionnement et ne peuvent pas être désactivés de nos systèmes. Nous ne les utilisons pas à des fins publicitaires. Si ces cookies sont bloqués, certaines parties du site ne pourront pas fonctionner.
Ce site web utilise un certain nombre de cookies pour gérer, par exemple, les sessions utilisateurs.