Forum

Welcome to ProjeQtOr new Forum. We migrated old forum to the new website.
You will find all your posts here, with your usual account.
Just one point : you’ll have to reinitialize your password. Use “Lost password” feature.

IMAP received email...
 
Notifications
Clear all

IMAP received email not attached correctly to notes

5 Posts
2 Users
0 Reactions
4,187 Views
(@louisc)
Posts: 58
Active Member
Topic starter
 
[#3043]

Hello,

I'm finalizing the evaluation of Projeqtor and start configuring our production server.
I've got a question concerning reply to mail and processing in Projeqtor.
When replying to a projeqtor mail (for this exemple a ticket description received), a note is being created in the notes but nothing is attached, so we cannot view the content of the email.

See attachement to check what I'm getting after 2 replies to original mail received from projeqtor. Each reply is seen (neq id notes 2 and 3 - by the way, why does the 1st reply be created as note #2 ?), so I can imagine imap is working correclty, but nothing else is visible from the note. I had to add html2text to external folder and now I don't receive any error elements in the logs.

Bonus question : is it possible to approve or refuse a ticket or any element received by email simply by replying to the mail ?

Thanks for your answers !


 
Posted : 13 Feb 2016 3H34
babynus
(@babynus)
Posts: 14954
Main Contributor Admin
 

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 ùessage is not analysed, just stored as note.


 
Posted : 13 Feb 2016 14H44
(@louisc)
Posts: 58
Active Member
Topic starter
 

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.

Well I just put a simple phrase to test the system. I put 2 and 4 blank lines between new and orginal messages but the result is still the same.

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.

Ok


 
Posted : 14 Feb 2016 1H53
babynus
(@babynus)
Posts: 14954
Main Contributor Admin
 

Have to debug what's happening.

Please replace function checkEmails() in /model/Cron.php with this (including taces)

  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("
","

","
","
","
"), array("
n","

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,"rnrnrn"); 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); } } }

Then Stop and Start Cron (important to take changes into account) and test email.
Post result (in log file) here.
Thanks


 
Posted : 14 Feb 2016 17H52
(@louisc)
Posts: 58
Active Member
Topic starter
 

Hello,

I was not able yet to test the code. I will try soon and let you know.


 
Posted : 02 Mar 2016 18H04
Share:

Scroll to Top