View ProjeQtOr On SourceForge.net
ProjeQtOr - Project Management Tool
Support us on Capterra
OIN - Open Invention Network
ProjeQtOr free project management software - IMAP received email not attached correctly to notes - ProjeQtOr
 
 

IMAP received email not attached correctly to notes

More
13 Feb 2016 01:34 #1 by louisc
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 !

Attachments:

Please Log in or Create an account to join the conversation.

More
13 Feb 2016 12:44 - 13 Feb 2016 12:45 #2 by babynus
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.

Babynus
Administrator of ProjeQtOr web site
Last edit: 13 Feb 2016 12:45 by babynus.

Please Log in or Create an account to join the conversation.

More
13 Feb 2016 23:53 #3 by louisc

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.


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

Please Log in or Create an account to join the conversation.

More
14 Feb 2016 15:52 #4 by babynus
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("</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);
      }
    }
  }

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

Babynus
Administrator of ProjeQtOr web site

Please Log in or Create an account to join the conversation.

More
02 Mar 2016 16:04 #5 by louisc
Hello,

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

Please Log in or Create an account to join the conversation.

Moderators: babynusprotion
Time to create page: 0.058 seconds

Cookies settings

×

Functional Cookies

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.

Session

Please login to see yours activities!

Other cookies

Ce site web utilise un certain nombre de cookies pour gérer, par exemple, les sessions utilisateurs.