コード例 #1
2
 public function fetch($delete = false)
 {
     $oImap = imap_open('{' . $this->mail_server . ':993/imap/ssl/notls/novalidate-cert}', $this->username, $this->password);
     $oMailboxStatus = imap_check($oImap);
     $aMessages = imap_fetch_overview($oImap, "1:{$oMailboxStatus->Nmsgs}");
     $validMessages = array();
     foreach ($aMessages as $oMessage) {
         print "Trying message '" . $oMessage->subject . "'";
         $fileContent = $fileType = '';
         $geocoder = factory::create('geocoder');
         $postCode = $geocoder->extract_postcode($oMessage->subject);
         $fromName = null;
         $fromEmail = null;
         if (strpos($oMessage->from, '<')) {
             $split = split('<', $oMessage->from);
             //name - make sure name not an email address
             $fromName = trim($split[0]);
             if (valid_email($fromName)) {
                 $fromName = null;
             }
             //email
             $fromEmail = trim(str_replace('>', '', $split[1]));
         } else {
             $fromEmail = $oMessage->from;
         }
         $images = array();
         $messageStructure = imap_fetchstructure($oImap, $oMessage->msgno);
         if (isset($messageStructure->parts)) {
             $partNumber = 0;
             foreach ($messageStructure->parts as $oPart) {
                 $partNumber++;
                 if ($oPart->subtype == 'PLAIN' && !$postCode) {
                     $messageContent = imap_fetchbody($oImap, $oMessage->msgno, $partNumber);
                     if ($oPart->encoding == 4) {
                         $messageContent = quoted_printable_decode($messageContent);
                     }
                     $postCode = geocoder::extract_postcode($messageContent);
                 } elseif ($oPart->encoding == 3 && in_array($oPart->subtype, array('JPEG', 'PNG'))) {
                     $oImage = null;
                     $encodedBody = imap_fetchbody($oImap, $oMessage->msgno, $partNumber);
                     $fileContent = base64_decode($encodedBody);
                     $oImage = imagecreatefromstring($fileContent);
                     if (imagesx($oImage) > $this->min_import_size && imagesy($oImage) > $this->min_import_size) {
                         array_push($images, $oImage);
                     }
                     $fileType = strtolower($oPart->subtype);
                 }
             }
         }
         //add to the messages array
         array_push($validMessages, array('postcode' => $postCode, 'images' => $images, 'file_type' => $fileType, 'from_address' => $fromAddress, 'from_email' => $fromEmail, 'from_name' => $fromName));
         if ($delete) {
             imap_delete($oImap, $oMessage->msgno);
         }
     }
     imap_close($oImap, CL_EXPUNGE);
     $this->messages = $validMessages;
 }
コード例 #2
1
ファイル: ImapController.php プロジェクト: gAb09/NetP
 public function free($util)
 {
     $stream = imap_open("{imap.club-internet.fr:993/imap/SSL}", $util, "wrasuxwr");
     var_dump($stream);
     $check = imap_check($stream);
     $list = imap_list($stream, "{imap.club-internet.fr}", "*");
     imap_createmailbox($stream, '{imap.club-internet.fr}brubru');
     $getmailboxes = imap_getmailboxes($stream, "{imap.club-internet.fr}", "*");
     $headers = imap_headers($stream);
     $num_msg = imap_num_msg($stream);
     $status = imap_status($stream, "{imap.club-internet.fr:993/imap/SSL}INBOX", SA_ALL);
     $messages = imap_fetch_overview($stream, "1:" . $num_msg);
     $structure = imap_fetchstructure($stream, 2);
     $body = utf8_encode(quoted_printable_decode(imap_body($stream, '2')));
     // imap_delete($stream, '1');
     // imap_expunge($stream);
     return view('Imap.Imap')->with(compact('resource'))->with(compact('check'))->with(compact('list'))->with(compact('getmailboxes'))->with(compact('headers'))->with(compact('num_msg'))->with(compact('status'))->with(compact('errors'))->with(compact('messages'))->with(compact('structure'))->with(compact('body'));
 }
コード例 #3
0
 public function get_mails(Request $request)
 {
     $mbox = imap_open("{email.mindfiresolutions.com:143}INBOX", "*****@*****.**", "1mfmail2016#") or die("can't connect: " . imap_last_error());
     $MC = imap_check($mbox);
     $count = 0;
     $count_total = $MC->Nmsgs;
     $last_page = $count_total % 10;
     $this->number_of_pages = ($count_total - $last_page) / 10;
     $this->result = imap_fetch_overview($mbox, "1:{$MC->Nmsgs}", 0);
     $i = 0;
     foreach ($this->result as $overview) {
         $message = imap_fetchbody($mbox, $overview->msgno, 1.1);
         $this->msg[$i] = $message;
         $i++;
         \Cache::put($overview->msgno, $overview->subject, 5);
     }
     krsort($this->result);
     /*This sorting does not help.Please use only rsort.*/
     $str[0] = 'success';
     $result_json = array();
     $result_json['val'] = $this->result;
     $result_json['num'] = $this->number_of_pages;
     $result_json['total'] = $count_total;
     return response()->json($result_json);
 }
コード例 #4
0
ファイル: Imapx.php プロジェクト: nahidz/imapx
 public function getInbox($page = 1, $perPage = 25, $sort = null)
 {
     if (!$this->isConnect) {
         return false;
     }
     $start = $page == 1 ? 0 : $page * $perPage - ($perPage - 1);
     $order = 0;
     $by = SORTDATE;
     if (is_array($sort)) {
         $order = $this->sortBy['order'][$sort[0]];
         $by = $this->sortBy['by'][$sort[1]];
     }
     $sorted = imap_sort($this->stream, $by, $order);
     $mails = array_chunk($sorted, $perPage);
     $mails = $mails[$page - 1];
     $mbox = imap_check($this->stream);
     $inbox = imap_fetch_overview($this->stream, implode($mails, ','), 0);
     if (!is_array($inbox)) {
         return false;
     }
     if (is_array($inbox)) {
         $temp_inbox = [];
         foreach ($inbox as $msg) {
             $temp_inbox[$msg->msgno] = $msg;
         }
         foreach ($mails as $msgno) {
             $this->inbox[$msgno] = $temp_inbox[$msgno];
         }
     }
     return $this->inbox;
 }
コード例 #5
0
function store_email_into_folder($msg, $folder = 'SentFromDolibarr')
{
    global $user, $db;
    $mailboxconfig = new Usermailboxconfig($db);
    $mailboxconfig->fetch_from_user($user->id);
    $user->mailbox_imap_login = $mailboxconfig->mailbox_imap_login;
    $user->mailbox_imap_password = $mailboxconfig->mailbox_imap_password;
    $user->mailbox_imap_host = $mailboxconfig->mailbox_imap_host;
    $user->mailbox_imap_port = $mailboxconfig->mailbox_imap_port;
    $user->mailbox_imap_ssl = $mailboxconfig->mailbox_imap_ssl;
    $user->mailbox_imap_ssl_novalidate_cert = $mailboxconfig->mailbox_imap_ssl_novalidate_cert;
    $user->mailbox_imap_ref = $mailboxconfig->get_ref();
    $user->mailbox_imap_connector_url = $mailboxconfig->get_connector_url();
    $mbox = imap_open($user->mailbox_imap_connector_url . $folder, $user->mailbox_imap_login, $user->mailbox_imap_password);
    $check = imap_check($mbox);
    $before = $check->Nmsgs;
    $result = imap_append($mbox, $user->mailbox_imap_connector_url . $folder, $msg);
    $check = imap_check($mbox);
    $after = $check->Nmsgs;
    if ($result == FALSE) {
        if (imap_createmailbox($mbox, imap_utf7_encode($user->mailbox_imap_ref . $folder))) {
            $mbox = imap_open($user->mailbox_imap_connector_url . $folder, $user->mailbox_imap_login, $user->mailbox_imap_password);
            $check = imap_check($mbox);
            $before = $check->Nmsgs;
            $result = imap_append($mbox, $user->mailbox_imap_connector_url . $folder, $msg);
            $check = imap_check($mbox);
            $after = $check->Nmsgs;
        }
    }
    imap_close($mbox);
}
コード例 #6
0
function pop3_list($connection, $message = "")
{
    if (!isset($result)) {
        $result = array();
    }
    if ($message) {
        $range = $message;
    } else {
        $MC = @imap_check($connection);
        if ($MC) {
            $range = "1:" . $MC->Nmsgs;
        } else {
            $range = "1:0";
        }
    }
    $response = @imap_fetch_overview($connection, $range);
    if ($response) {
        $result = array();
        foreach ($response as $msg) {
            $result[$msg->msgno] = (array) $msg;
        }
    } else {
        $result = array();
    }
    return $result;
}
コード例 #7
0
ファイル: MailCheckGUI.class.php プロジェクト: nemiah/fheME
 public function check($touch = false)
 {
     $mbox = $this->connection();
     #echo "<h1>Nachrichten in INBOX</h1><div style=\"overflow:auto;max-height:400px;\"><pre>";
     $MC = imap_check($mbox);
     $T = new HTMLTable(1, $touch ? "Mails" : "");
     $T->setTableStyle("font-size:11px;");
     $T->useForSelection();
     $start = $MC->Nmsgs - 10;
     if ($start < 1) {
         $start = 1;
     }
     $result = imap_fetch_overview($mbox, "{$start}:{$MC->Nmsgs}", 0);
     $result = array_reverse($result);
     foreach ($result as $overview) {
         #print_r($overview);
         $T->addRow(array("\n\t\t\t\t<small style=\"color:grey;float:right;\">" . Util::CLDateParser($overview->udate) . "</small>\n\t\t\t\t" . str_replace("\"", "", $this->decodeBlubb($overview->from)) . "<br />\n\t\t\t\t<small style=\"color:grey;\">" . substr($this->decodeBlubb($overview->subject), 0, 50) . "</small>"));
         $T->addCellEvent(1, "click", "\$j('#MailFrame').attr('src', './interface/rme.php?class=MailCheck&constructor=" . $this->getID() . "&method=showMailBody&parameters=\\'{$overview->uid}\\'');");
     }
     imap_close($mbox);
     #echo "</pre></div>";
     $BC = "";
     if ($touch) {
         $BC = new Button("Fenster\nschließen", "stop");
         $BC->style("float:right;margin:10px;");
         $BC->onclick(OnEvent::closePopup("MailCheck"));
     }
     echo "<div style=\"float:right;width:300px;\">";
     echo $BC;
     echo "<p>{$MC->Nmsgs} Nachricht" . ($MC->Nmsgs == 1 ? "" : "en") . "</p><div style=\"clear:both;\"></div>";
     echo $T;
     echo "</div>";
     echo "\n\t\t\t<div style=\"border-right-style:solid;border-right-width:1px;width:699px;\" class=\"borderColor1\">\n\t\t\t\t<iframe id=\"MailFrame\" style=\"border:0px;width:699px;height:520px;\" src=\"./fheME/MailCheck/Home/index.html\"></iframe>\n\t\t\t</div>";
     echo "<div style=\"clear:both;\"></div>";
 }
コード例 #8
0
 /**
  * Checkt die Anzahl Messages in einer Mailbox
  * return array
  */
 public function imapCheck()
 {
     if ($this->imap === null) {
         throw new IMAPException(__METHOD__ . ' not connected');
     }
     $this->imapPing(true);
     return imap_check($this->imap);
 }
コード例 #9
0
ファイル: imap.php プロジェクト: kamaroly/kigalilifeapp
 /**
  * @return stdClass
  */
 public function check()
 {
     $info = imap_check($this->stream);
     if (FALSE === $info) {
         throw new Exception('Check failed: ' . imap_last_error());
     }
     return $info;
 }
コード例 #10
0
ファイル: messages.php プロジェクト: ClixLtd/pccupload
 /**
  * Returns a unified count of unread e-mails.
  * 
  * @access public
  * @static
  * @return void
  */
 public static function imap_count_unread()
 {
     $total_messages = 0;
     foreach (static::$_imap_connections as $connection) {
         $imap_object = imap_check($connection);
         $total_messages = $total_messages + (int) $imap_object->Nmsgs;
     }
     return $total_messages;
 }
コード例 #11
0
ファイル: imap.class.php プロジェクト: Git-Host/sms
 public function check()
 {
     debug::output("Starting Check...");
     $object = imap_check($this->imap);
     if (!is_object($object)) {
         throw new emailException(imap_last_error($this->imap), imap_errors($this->imap));
     } else {
         return $object;
     }
 }
コード例 #12
0
 /**
  * Get information about authorization
  * @access public
  * @return object|bool
  */
 public function getImapCheck()
 {
     if ($this->_connectionCheck != null) {
         return $this->_connectionCheck;
     }
     if ($this->isAuth()) {
         return imap_check($this->_connection);
     }
     return false;
 }
コード例 #13
0
ファイル: mailfeed.php プロジェクト: Tixp/aaron
 public function update()
 {
     if (isset($this->feed)) {
         $this->infoUpdate = imap_check($this->feed);
         if (!$this->infoUpdate) {
             throw new Exception('Error on update', 20003);
         }
         $this->postsOverview = imap_fetch_overview($this->feed, "1:{$this->infoUpdate->Nmsgs}", 0);
     }
 }
コード例 #14
0
ファイル: Connection.php プロジェクト: nsbucky/pop3
 /**
  * @return array
  */
 public function getMessages()
 {
     $messages = array();
     $info = imap_check($this->connect());
     $range = "1:" . $info->Nmsgs;
     $responses = imap_fetch_overview($this->connect(), $range);
     foreach ($responses as $message) {
         $messages[$message->msgno] = new Message($this, $message->msgno, $message);
     }
     return $messages;
 }
コード例 #15
0
 function getMails($email, $passw, $numRegs)
 {
     global $arrLang;
     $counter = 0;
     if ($email != '' && $passw != '') {
         $imap = imap_open("{localhost:143/notls}INBOX", $email, $passw);
     } else {
         return $arrLang["You don't have a webmail account"];
     }
     if (!$imap) {
         return $arrLang["Imap: Connection error"];
     }
     $tmp = imap_check($imap);
     if ($tmp->Nmsgs == 0) {
         return $arrLang["You don't recibed emails"];
     }
     $result = imap_fetch_overview($imap, "1:{$tmp->Nmsgs}", 0);
     $mails = array();
     //print_r($result);
     foreach ($result as $overview) {
         $mails[] = array("seen" => $overview->seen, "recent" => $overview->recent, "answered" => $overview->answered, "date" => $overview->date, "from" => $overview->from, "subject" => $overview->subject);
     }
     imap_close($imap);
     $mails = array_slice($mails, -$numRegs, $numRegs);
     krsort($mails);
     $content = "";
     /*
             foreach($mails as $value){
                 $temp = $arrLang["mail recived"];
                 $temp = str_replace("{source}",$value["from"],$temp);
                 $temp = str_replace("{date}",$value["date"],$temp);
                 $temp = str_replace("{subject}",$value["subject"],$temp);
             
                 $b = ($value["seen"] or $value["answered"])?false:true;
                 if($b)
                     $temp = "<b>$temp</b>";
                 $content.=$temp."<br>";
             }
     
             return $content;*/
     //print_r($mails);
     $temp = '';
     foreach ($mails as $index => $value) {
         $b = ($value["seen"] or $value["answered"]) ? false : true;
         if ($b) {
             $temp .= "<font color='#000080' size='1'>" . $value['date'] . "</font>&nbsp;&nbsp;&nbsp;";
             $temp .= "<font  size='1'>" . "From: " . substr($value['from'], 0, 50) . "</font>&nbsp;&nbsp;&nbsp;";
             $temp .= "<font  size='1'>" . "Subject: " . substr($value['subject'], 0, 30) . "</font><br>";
         }
     }
     return "<b>" . $temp . "</b>";
 }
コード例 #16
0
ファイル: imap.php プロジェクト: rrecurse/IntenseCart
function pop3_list($connection, $message = "")
{
    if ($message) {
        $range = $message;
    } else {
        $MC = imap_check($mbox);
        $range = "1:" . $MC->Nmsgs;
    }
    $response = imap_fetch_overview($mbox, $range);
    foreach ($response as $msg) {
        $result[$msg->msgno] = (array) $msg;
    }
}
コード例 #17
0
ファイル: Server.php プロジェクト: ctalbot/imap
 /**
  * Authenticate connection
  *
  * @param string $username Username
  * @param string $password Password
  *
  * @return \Ddeboer\Imap\Connection
  * @throws AuthenticationFailedException
  */
 public function authenticate($username, $password)
 {
     $resource = @\imap_open($this->getServerString(), $username, $password, null, 1);
     if (false === $resource) {
         throw new AuthenticationFailedException($username);
     }
     $check = imap_check($resource);
     $mailbox = $check->Mailbox;
     $this->connection = substr($mailbox, 0, strpos($mailbox, '}') + 1);
     // These are necessary to get rid of PHP throwing IMAP errors
     imap_errors();
     imap_alerts();
     return new Connection($resource, $this->connection);
 }
コード例 #18
0
ファイル: POP3.php プロジェクト: hmc-soft/mvc
 public function getMessageList($message = "")
 {
     if ($message) {
         $range = $message;
     } else {
         $MC = imap_check($this->conn);
         $range = "1:" . $MC->Nmsgs;
     }
     $response = imap_fetch_overview($this->conn, $range);
     foreach ($response as $msg) {
         $result[$msg->msgno] = (array) $msg;
     }
     return $result;
 }
コード例 #19
0
 function pop3_list($connection = false, $message = "")
 {
     $connection = $this->getConnection($connection);
     if ($message) {
         $range = $message;
     } else {
         $MC = imap_check($connection);
         $range = "1:" . $MC->Nmsgs;
     }
     $response = imap_fetch_overview($connection, $range);
     foreach ($response as $msg) {
         $result[$msg->msgno] = (array) $msg;
     }
     return $result;
 }
コード例 #20
0
 /**
  * @name: addmail
  * Wenn die Mails nicht per imap geholt werden, fuege die Mail mit allen header-Daten aus $xarf als Mail ein.
  *
  * @param $xarf-report
  * @return Boolean
  */
 public function addmail($xarf)
 {
     $config = $this->config;
     preg_match('/subject: (.*)/im', $xarf, $subject);
     $this->subject = $subject[1];
     $xarf = str_replace("\n", "\r\n", $xarf);
     $check = imap_check($this->connection);
     $add = imap_append($this->connection, '{' . $config['server'] . ':' . $config['port'] . '/' . $config['conntyp'] . '/' . $config['extras'] . '}' . $config['ordner'], stripslashes($xarf));
     $check1 = imap_check($this->connection);
     if ($check < $check1 && $add == 1) {
         $return = 0;
     } else {
         $return = 1;
     }
     return $return;
 }
コード例 #21
0
ファイル: Inbox.php プロジェクト: kobabasu/rest-slim
 /**
  * POP3アカウントに接続
  *
  * @param String $host
  * @param String $port
  * @param String $user
  * @param String $pass
  * @return vold
  * @codeCoverageIgnore
  */
 public function __construct($host, $user, $pass, $port = '110')
 {
     try {
         $this->inbox = imap_open('{' . $host . ':' . $port . '/pop3}', $user, $pass);
         $check = imap_check($this->inbox);
         $this->count = $check->Nmsgs;
         $this->overview = imap_fetch_overview($this->inbox, "1:{$this->count}", 0);
         foreach ($this->overview as $item) {
             $this->ids[] = $item->msgno;
         }
     } catch (Exception $e) {
         $erros = implode("; ", imap_errors());
         $msg = $e->getMessage();
         $ms = $msg . "\nPOP3 Errors: {$errors}";
         throw new Exception($mes);
     }
 }
コード例 #22
0
ファイル: imapClass.php プロジェクト: charvoa/Epitech-2
 public function getUnreadMessages()
 {
     $emails = array();
     if ($headers = imap_check($this->mailbox)) {
         $lastnr = $headers->Nmsgs;
         if ($mails = imap_fetch_overview($this->mailbox, "1:" . $lastnr, 0)) {
             while (list($key, $val) = each($mails)) {
                 if (++$key >= 0 && ($header = imap_header($this->mailbox, $key))) {
                     if ($header->Unseen == 'U' || $header->Recent == 'R') {
                         $emails[] = array("date" => $val->date, "subject" => $val->subject, "msgno" => $val->msgno, "from" => $val->from);
                     }
                 }
             }
         }
     }
     return $emails;
 }
コード例 #23
0
ファイル: ImapMailer.php プロジェクト: hlag/svs
    public function getMails()
    {
        $this->open();

        $MC = imap_check($this->resource);
        $result = imap_fetch_overview($this->resource, "1:{$MC->Nmsgs}", 0);

        $mail = array();
        for ($x = 0; $x < $MC->Nmsgs; $x++)
        {
            $mail[$x] = imap_header($this->resource, $x + 1);
            $mail[$x]->body = utf8_encode(imap_body($this->resource, $x + 1));
        }
        $this->close();
        return $mail;

    }
コード例 #24
0
ファイル: index.php プロジェクト: hardikk/HNH
 protected function leerInformacionImap($smarty, $module_name, $imap, &$respuesta)
 {
     $smarty->assign(array('NO_EMAILS' => _tr("You don't recibed emails")));
     $mails = array();
     $tmp = imap_check($imap);
     if ($tmp->Nmsgs > 0) {
         $result = imap_fetch_overview($imap, "1:{$tmp->Nmsgs}", 0);
         foreach ($result as $overview) {
             if (!($overview->seen || $overview->answered)) {
                 $mails[] = array('seen' => $overview->seen, 'recent' => $overview->recent, 'answered' => $overview->answered, 'date' => $overview->date, 'from' => $overview->from, 'subject' => $overview->subject);
             }
         }
         $mails = array_reverse(array_slice($mails, -1 * MAX_EMAIL_RECORDS, MAX_EMAIL_RECORDS));
     }
     $smarty->assign('mails', $mails);
     $local_templates_dir = dirname($_SERVER['SCRIPT_FILENAME']) . "/modules/{$module_name}/applets/Emails/tpl";
     $respuesta['html'] = $smarty->fetch("{$local_templates_dir}/emails.tpl");
 }
コード例 #25
0
 /**
  * Get mailbox info
  */
 function mailboxmsginfo()
 {
     //$mailbox = imap_mailboxmsginfo($this->link); #It's wery slow
     $mailbox = imap_check($this->link);
     if ($mailbox) {
         $mbox["Date"] = $mailbox->Date;
         $mbox["Driver"] = $mailbox->Driver;
         $mbox["Mailbox"] = $mailbox->Mailbox;
         $mbox["Messages"] = $this->num_message();
         $mbox["Recent"] = $this->num_recent();
         $mbox["Unread"] = $mailbox->Unread;
         $mbox["Deleted"] = $mailbox->Deleted;
         $mbox["Size"] = $mailbox->Size;
     } else {
         $this->error[] = imap_last_error();
     }
     return $mbox;
 }
コード例 #26
0
ファイル: mailbox.class.php プロジェクト: rafaldrive/ucaps
 function loadNaggers()
 {
     //$this->resetArrays();
     $imapcheck = imap_check($this->hconnection);
     $a = array();
     $n = 0;
     $overview = imap_fetch_overview($this->hconnection, "1:{$imapcheck->Nmsgs}", 0);
     foreach ($overview as $i => $ah) {
         $hi = imap_headerinfo($this->hconnection, $ah->msgno, 80, 80);
         $sfrom = trim(strtolower($hi->from[0]->mailbox . "@" . $hi->from[0]->host));
         if ($a[$sfrom] > 0) {
             $a[$sfrom] = $a[$sfrom] + 1;
         } else {
             $a[$sfrom] = 1;
         }
     }
     return $a;
 }
コード例 #27
0
ファイル: receivemail.class.php プロジェクト: tmlsoft/main
 function listMessages($page = 1, $per_page = 25, $sort = null)
 {
     $limit = $per_page * $page;
     $start = $limit - $per_page + 1;
     $start = $start < 1 ? 1 : $start;
     $limit = $limit - $start != $per_page - 1 ? $start + ($per_page - 1) : $limit;
     $info = imap_check($this->marubox);
     $limit = $info->Nmsgs < $limit ? $info->Nmsgs : $limit;
     if (true === is_array($sort)) {
         $sorting = array('direction' => array('asc' => 0, 'desc' => 1), 'by' => array('date' => SORTDATE, 'arrival' => SORTARRIVAL, 'from' => SORTFROM, 'subject' => SORTSUBJECT, 'size' => SORTSIZE));
         $by = true === is_int($by = $sorting['by'][$sort[0]]) ? $by : $sorting['by']['date'];
         $direction = true === is_int($direction = $sorting['direction'][$sort[1]]) ? $direction : $sorting['direction']['desc'];
         $sorted = imap_sort($this->marubox, $by, $direction);
         $msgs = array_chunk($sorted, $per_page);
         $msgs = $msgs[$page - 1];
     } else {
         $msgs = range($start, $limit);
         //just to keep it consistent
     }
     $result = imap_fetch_overview($this->marubox, implode($msgs, ','), 0);
     if (false === is_array($result)) {
         return false;
     }
     foreach ($result as $k => $r) {
         $result[$k]->subject = $this->_imap_utf8($r->subject);
         $result[$k]->from = $this->_imap_utf8($r->from);
         $result[$k]->to = $this->_imap_utf8($r->to);
         $result[$k]->body = $this->getBody($r->msgno);
     }
     //sorting!
     if (true === is_array($sorted)) {
         $tmp_result = array();
         foreach ($result as $r) {
             $tmp_result[$r->msgno] = $r;
         }
         $result = array();
         foreach ($msgs as $msgno) {
             $result[] = $tmp_result[$msgno];
         }
     }
     $return = array('res' => $result, 'start' => $start, 'limit' => $limit, 'sorting' => array('by' => $sort[0], 'direction' => $sort[1]), 'total' => imap_num_msg($this->marubox));
     $return['pages'] = ceil($return['total'] / $per_page);
     return $return;
 }
コード例 #28
0
ファイル: Server.php プロジェクト: voofy/imap
 /**
  * Authenticate connection
  *
  * @param string $username Username
  * @param string $password Password
  *
  * @return Connection
  * @throws AuthenticationFailedException
  */
 public function authenticate($username, $password)
 {
     // Wrap imap_open, which gives notices instead of exceptions
     set_error_handler(function ($nr, $message) use($username) {
         throw new AuthenticationFailedException($username, $message);
     });
     $resource = imap_open($this->getServerString(), $username, $password, null, 1, $this->parameters);
     if (false === $resource) {
         throw new AuthenticationFailedException($username);
     }
     restore_error_handler();
     $check = imap_check($resource);
     $mailbox = $check->Mailbox;
     $this->connection = substr($mailbox, 0, strpos($mailbox, '}') + 1);
     // These are necessary to get rid of PHP throwing IMAP errors
     imap_errors();
     imap_alerts();
     return new Connection($resource, $this->connection);
 }
コード例 #29
0
 function check_messages($options = "UNSEEN")
 {
     $client = open_all();
     $CG = get_instance();
     $mailcheck = imap_check($client);
     $srch = imap_search($client, $options);
     if ($srch !== FALSE) {
         $emails = imap_fetch_overview($client, implode(',', $srch), 0);
         foreach ($emails as $email) {
             $message_id = $email->message_id;
             $check_query = $CG->db->get_where('messages', array('message_id' => $message_id));
             if ($check_query->num_rows() == 0) {
                 $uid = $email->uid;
                 $body = fetch_message($client, $uid);
                 add_to_inbox($client, $email, $body);
             }
         }
     }
 }
コード例 #30
0
ファイル: SiteController.php プロジェクト: rocwang/incoming
 private function _getMails($provider)
 {
     $mailbox = Yii::app()->params['mailServerConfig'][$provider];
     $user = Yii::app()->params['credentials'][$provider]['username'];
     $password = Yii::app()->params['credentials'][$provider]['password'];
     $inbox = imap_open($mailbox, $user, $password);
     /*imap_check returns information about the mailbox
     		including mailbox name and number of messages*/
     $check = imap_check($inbox);
     /*imap_fetch_overview returns an overview for a message.
     		  An overview contains information such as message subject,
     		  sender, date, and if it has been seen. Note that it does
     		  not contain the body of the message. Setting the second
     		parameter to "1:n" will cause it to return a sequence of messages*/
     $overviews = imap_fetch_overview($inbox, "1:{$check->Nmsgs}");
     foreach ($overviews as &$mail) {
         $st = imap_fetchstructure($inbox, $mail->msgno);
         //CVarDumper::dump($st, 10, true);
         switch ($st->type) {
             case TYPETEXT:
                 $mail->body = $this->_decodeMail($st->encoding, imap_body($inbox, $mail->msgno, FT_PEEK));
                 break;
             case TYPEMULTIPART:
                 for ($i = 0, $j = count($st->parts); $i < $j; $i++) {
                     $part = $st->parts[$i];
                     if ($part->type === TYPETEXT) {
                         $mail->body = $this->_decodeMail($part->encoding, imap_fetchbody($inbox, $mail->msgno, $i + 1));
                         break;
                     }
                 }
                 break;
             default:
                 $mail->body = 'UNKNOWN MIME TYPE';
                 break;
         }
     }
     return $overviews;
 }