Exemplo n.º 1
0
 function syncInbox()
 {
     $this->msg_cnt = imap_num_msg($this->conn);
     $unseen_messages = imap_search($this->conn, 'UNSEEN');
     if ($this->msg_cnt === 0) {
     }
     echo "no unseen mails\n";
     $in = array();
     for ($i = 1; $i <= $this->msg_cnt; $i++) {
         if ($unseen_messages && in_array($i, $unseen_messages)) {
             $body = imap_body($this->conn, $i, FT_PEEK);
             $header = imap_headerinfo($this->conn, $i);
             $structure = imap_fetchstructure($this->conn, $i);
             echo $structure->encoding;
             if ($structure->encoding == 4) {
                 $body = imap_qprint($body);
             }
             echo 'faschismus';
             $in[] = array('index' => $i, 'header' => $header, 'body' => $body, 'structure' => imap_fetchstructure($this->conn, $i));
             //check if msg is from iridium msg service
             if (true) {
                 echo 'got unseen mail from msg.iridium.com:';
                 echo $body;
                 //create case
                 if (strpos($body, 'safepassage -create') !== FALSE) {
                     $body = trim($body);
                     //remove syntax from beginn
                     $json_string = str_replace('safepassage -create ', '', $body);
                     //the iridium go replaces the "{" and "}" at the end and beginning of the json string
                     //with "(" and ")" so it has to be rereplaced again
                     $json_string = '{' . substr($json_string, 1);
                     $json_string = substr($json_string, 0, -2) . '}';
                     $json_string = str_replace('":("', '":{"', $json_string);
                     $json_string = str_replace(')}', '}}', $json_string);
                     echo "\n";
                     echo $json_string;
                     echo "f**k\n";
                     $case_array = json_decode($json_string, true);
                     var_dump($case_array);
                     //$case_array['location_data'] = json_encode($case_array['location_data']);
                     /*var_dump($case_array);*/
                     $case_id = \App\Http\Controllers\ApiController::createCase($case_array);
                     echo $case_id;
                     self::sendMail($header->fromaddress, 'Re: ' . $header->subject, "Your case has been submitted. Case-ID: " . $case_id);
                     imap_setflag_full($this->conn, $i, "\\Seen", ST_UID);
                 }
                 /*if(\App\Http\Controllers\Admin\VehicleController::addLocationFromIridiumMail($header, $body)){
                       
                       echo 'adding location from'.$header->fromaddress;
                       imap_setflag_full($this->conn, $i, "\\Seen", ST_UID);
                       
                       $body = imap_body($this->conn, $i);
                   }else{
                       
                       echo 'not now';
                       /*$status = imap_clearflag_full($this->conn, $i, "\\Seen \\Flagged");
                       
                       imap_close($this->conn, CL_EXPUNGE);
                   }*/
             }
         }
     }
     //var_dump($in);
     $this->inbox = $in;
 }