private function PHPParseEmails(&$_reload, $_delete, $_test)
 {
     $list = array();
     $starttime = time();
     $executiontime = Server::SetTimeLimit(CALLER_TIMEOUT - 10);
     try {
         $ssl = $this->Mailbox->SSL == 0 ? "" : ($this->Mailbox->SSL == 1 ? '/ssl' : '/tls');
         $service = $this->Mailbox->Type == "IMAP" ? "imap" : "pop3";
         $mailbox = new ImapMailbox('{' . $this->Mailbox->Host . ':' . $this->Mailbox->Port . '/' . $service . $ssl . '}INBOX', $this->Mailbox->Username, $this->Mailbox->Password, "./uploads/", 'utf-8');
         $mails = $mailbox->searchMailBox('ALL');
         if ($_test) {
             return count($mails);
         }
         if (empty($mails)) {
             return array();
         }
         $counter = 0;
         foreach ($mails as $mailId) {
             $subject = "";
             try {
                 $temail = new TicketEmail();
                 $message = $mailbox->getMail($mailId);
                 $subject = $temail->Subject = $message->subject;
                 //$temail->Id = $message->id;
                 $temail->Id = $message->message_id;
                 $temail->Name = $message->fromName;
                 if (empty($temail->Id)) {
                     $temail->Id = getId(32);
                 }
                 if ($_delete) {
                     $delete[$mailId] = $temail->Id;
                 }
                 $temail->Email = trim($message->fromAddress);
                 reset($message->to);
                 $temail->ReceiverEmail = key($message->to);
                 if (!empty($message->replyTo)) {
                     reset($message->replyTo);
                     $temail->ReplyTo = key($message->replyTo);
                 }
                 $temail->BodyHTML = $message->textHtml;
                 $temail->Body = $message->textPlain;
                 if (empty($temail->Body) && !empty($temail->BodyHTML)) {
                     $temail->Body = MailSystem::DownConvertHTML($temail->BodyHTML);
                 }
                 $atts = $message->getAttachments();
                 foreach ($atts as $att) {
                     $filename = $att->name;
                     $fileid = getId(32);
                     $filesid = Server::$Configuration->File["gl_lzid"] . "_" . $fileid;
                     $content = file_get_contents($att->filePath);
                     $temail->Attachments[$fileid] = array($filesid, $filename, $content);
                     @unlink($att->filePath);
                 }
                 $temail->Created = strtotime($message->date);
                 if (!is_numeric($temail->Created) || empty($temail->Created)) {
                     $temail->Created = time();
                 }
                 $list[] = $temail;
                 if (time() - $starttime >= $executiontime / 2 || $counter++ > DATA_ITEM_LOADS) {
                     $_reload = true;
                     break;
                 }
             } catch (Exception $e) {
                 if ($_test) {
                     throw $e;
                 } else {
                     handleError("115", "Email Error: " . $e->getMessage() . ", email: " . $subject, "functions.global.inc.php", 0);
                 }
             }
         }
         try {
             krsort($delete);
             foreach ($delete as $num => $id) {
                 $mailbox->deleteMail($num);
             }
         } catch (Exception $e) {
             if ($_test) {
                 throw $e;
             } else {
                 handleError("114", "Email delete error: " . $e->getMessage() . ", email: " . $subject, "functions.global.inc.php", 0);
             }
         }
     } catch (Exception $e) {
         if ($_test) {
             throw $e;
         } else {
             handleError("113", "Email Error: " . $e->getMessage() . ", email: " . $subject, "functions.global.inc.php", 0);
         }
     }
     return $list;
 }
예제 #2
0
// See classes/ImapMailbox.php for some examples
define('MAIL_EMAIL', '*****@*****.**');
// Your e-mail username
define('MAIL_PASSWORD', 'password');
// Your e-mail password
// PushBullet settings
$PushBullet_API_key = 'pushbullet_api_key_goes_here';
$deviceIds = array('device_id_1', 'device_id_2', 'device_id_3');
// Start readin the mailbox
$mailbox = new ImapMailbox(MAIL_PATH, MAIL_EMAIL, MAIL_PASSWORD, false, 'utf-8');
// Get all e-mails from the mailbox
$mailsIds = $mailbox->searchMailBox('ALL');
if ($mailsIds) {
    // Read each mail individually
    foreach ($mailsIds as $mailId) {
        $mail = $mailbox->getMail($mailId);
        // Send the PushBullet notifications
        try {
            $p = new PushBullet($PushBullet_API_key);
            // Send a notification to each device
            foreach ($deviceIds as $deviceId) {
                $p->pushNote($deviceId, $mail->subject, $mail->textPlain);
            }
            // Delete the mail from the folder
            $mailbox->deleteMail($mailId);
        } catch (PushBulletException $e) {
            // Die() on error
            die($e->getMessage());
        }
    }
}
예제 #3
0
파일: Imap.php 프로젝트: rtsantos/mais
 /**
  * Remove uma mensagem da caixa postal
  *
  * @param string $mailId
  * @return bool
  * @throws Exception 
  */
 public function deleteMail($mailId)
 {
     @($result = parent::deleteMail($this->_getNumMessage($mailId)));
     if (!$result) {
         set_time_limit(3);
         throw new Exception('deleteMail Error: ' . imap_last_error());
     }
     return $result;
 }