当前位置: 首页>>代码示例>>PHP>>正文


PHP imap_search函数代码示例

本文整理汇总了PHP中imap_search函数的典型用法代码示例。如果您正苦于以下问题:PHP imap_search函数的具体用法?PHP imap_search怎么用?PHP imap_search使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了imap_search函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: readEmails

 public function readEmails($sentTo = null, $bodyPart = null)
 {
     $host = '{imap.gmail.com:993/imap/ssl}INBOX';
     $spinner = new Spinner('Could not connect to Imap server.', 60, 10000);
     $inbox = $spinner->assertBecomesTrue(function () use($host) {
         return @imap_open($host, $this->email, $this->password);
     });
     $emails = imap_search($inbox, 'TO ' . ($sentTo ? $sentTo : $this->email));
     if ($emails) {
         $messages = [];
         foreach ($emails as $n) {
             $structure = imap_fetchstructure($inbox, $n);
             if (!$bodyPart) {
                 $part = $this->findPart($structure, function ($part) {
                     return $part->subtype === 'HTML';
                 });
             } elseif (is_callable($bodyPart)) {
                 $part = $this->findPart($structure, $bodyPart);
             } else {
                 $part = $bodyPart;
             }
             $hinfo = imap_headerinfo($inbox, $n);
             $subject = $hinfo->subject;
             $message = ['subject' => $subject, 'body' => imap_fetchbody($inbox, $n, $part)];
             $messages[] = $message;
         }
         return $messages;
     } else {
         return [];
     }
 }
开发者ID:NathanGiesbrecht,项目名称:PrestaShopAutomationFramework,代码行数:31,代码来源:GmailReader.php

示例2: inbox

 function inbox()
 {
     $this->msg_cnt = imap_num_msg($this->conn);
     echo "Number of emails read = " . $this->msg_cnt . "\n";
     /*$in = array();
     		for($i = 1; $i <= $this->msg_cnt; $i++) {
     			$in[] = array(
     				'index'     => $i,
     				'header'    => imap_headerinfo($this->conn, $i),
     				'body'      => imap_body($this->conn, $i),
     				'structure' => imap_fetchstructure($this->conn, $i)
     			); */
     $output = '<table>';
     $output .= '<tr><th>Subject</th><th>voucher</th><th>From</th><th>seen</th><th>type</th></tr>';
     $mails = imap_search($this->conn, 'FROM "hotelpartners@goibibo.com" SUBJECT "Confirm Hotel Booking"');
     //print_r($mails);
     for ($i = 0; $i <= sizeof($mails); $i++) {
         $header = imap_fetch_overview($this->conn, $mails[$i], 0);
         $body = imap_fetchbody($this->conn, $mails[$i], 1.1);
         $output .= '<tr>';
         $output .= '<td><span class="subject">' . $header[0]->subject . '</span> </td>';
         $output .= '<td><span class="from">' . $header[0]->from . '</span></td>';
         $output .= '<td><span class="voucher">' . $mails[0]->voucher . '</span></td>';
         $output .= '<td><span class="date">' . $header[0]->date . '</span></td>>';
         $output .= '<td><span class="toggler">' . ($header[0]->seen ? 'read' : 'unread') . '"></span></td>';
         $structure = imap_fetchstructure($this->conn, $mails[$i]);
         $output .= '<td><span class="type">' . $structure->type . '</span> </td>';
         $output .= '</tr>';
     }
     $output .= '</table>';
     echo $output . "\n";
 }
开发者ID:jyotsnabuddha,项目名称:vistaram,代码行数:32,代码来源:Email_reader.php

示例3: get_messages

 /**
 * Get messages according to a search criteria
 * 
 * @param	string	search criteria (RFC2060, sec. 6.4.4). Set to "UNSEEN" by default
 					NB: Search criteria only affects IMAP mailboxes.
 * @param	string	date format. Set to "Y-m-d H:i:s" by default
 * @return	mixed	array containing messages
 */
 public function get_messages($search_criteria = "UNSEEN", $date_format = "Y-m-d H:i:s")
 {
     $msgs = imap_search($this->imap_stream, $search_criteria);
     $no_of_msgs = $msgs ? count($msgs) : 0;
     $messages = array();
     for ($i = 0; $i < $no_of_msgs; $i++) {
         $header = imap_header($this->imap_stream, $msgs[$i]);
         $date = date($date_format, $header->udate);
         $from = $this->_mime_decode($header->fromaddress);
         $subject = $this->_mime_decode($header->subject);
         $structure = imap_fetchstructure($this->imap_stream, $msgs[$i]);
         if (!empty($structure->parts)) {
             for ($j = 0, $k = count($structure->parts); $j < $k; $j++) {
                 $part = $structure->parts[$j];
                 if ($part->subtype == 'PLAIN') {
                     $body = imap_fetchbody($this->imap_stream, $msgs[$i], $j + 1);
                 }
             }
         } else {
             $body = imap_body($this->imap_stream, $msgs[$i]);
         }
         // Convert quoted-printable strings (RFC2045)
         $body = imap_qprint($body);
         array_push($messages, array('msg_no' => $msgs[$i], 'date' => $date, 'from' => $from, 'subject' => $subject, 'body' => $body));
     }
     return $messages;
 }
开发者ID:ajturner,项目名称:ushahidi,代码行数:35,代码来源:Imap.php

示例4: messages

 /**
  * @param string $criteria
  * @return $this
  */
 public function messages($criteria)
 {
     $this->messages = array_map(function ($messageNumber) {
         return array('id' => $messageNumber, 'header' => imap_header($this->mailbox, $messageNumber), 'struct' => imap_fetchstructure($this->mailbox, $messageNumber));
     }, imap_search($this->mailbox, $criteria));
     return $this;
 }
开发者ID:jochenJa,项目名称:mailstuff,代码行数:11,代码来源:Mailbox.php

示例5: BuscarMails

 public function BuscarMails($from, $readCommand)
 {
     $emails = null;
     if ($this->Open()) {
         $command = $readCommand . " FROM '" . $from . "'";
         $emails = imap_search($this->imap_client, $command);
     }
     return $emails;
 }
开发者ID:sistemasiblu,项目名称:correoApp,代码行数:9,代码来源:EmailReader.php

示例6: GetIMAPContent

 /**
  * Gets IMAP content
  *
  * @param string $imapHost
  * @param string $imapUser
  * @param string $imapPassword
  * @param \Swiftriver\Core\ObjectModel\Channel $channel
  *
  * @return $contentItems[]
  */
 private function GetIMAPContent($imapHost, $imapUser, $imapPassword, $channel)
 {
     $imapResource = imap_open("{" . $imapHost . "}INBOX", $imapUser, $imapPassword);
     //Open up unseen messages
     $imapEmails = imap_search($imapResource, strtoupper($channel->subType));
     $contentItems = array();
     if ($imapEmails) {
         //Put newest emails on top
         rsort($imapEmails);
         foreach ($imapEmails as $Email) {
             //Loop through each email and return the content
             $email_overview = imap_fetch_overview($imapResource, $Email, 0);
             $email_message = imap_fetchbody($imapResource, $Email, 2);
             $source_name = $imapUser;
             $source = \Swiftriver\Core\ObjectModel\ObjectFactories\SourceFactory::CreateSourceFromIdentifier($source_name);
             $source->name = $source_name;
             $source->parent = $channel->id;
             $source->type = $channel->type;
             $source->subType = $channel->subType;
             $item = \Swiftriver\Core\ObjectModel\ObjectFactories\ContentFactory::CreateContent($source);
             $item->text[] = new \Swiftriver\Core\ObjectModel\LanguageSpecificText(null, $email_overview[0]->subject, array($email_message));
             //the message
             $item->link = null;
             $item->date = $email_overview[0]->date;
             $contentItems[] = $item;
         }
         imap_close($imapResource);
         return $contentItems;
     }
     imap_close($imapResource);
     return null;
 }
开发者ID:Bridgeborn,项目名称:Swiftriver,代码行数:42,代码来源:IMAPParser.php

示例7: readImapStatus

function readImapStatus($config, $savedStatus, $db)
{
    $mbox = imap_open($config["imap_server"], $config["imap_user"], $config["imap_password"]);
    $imapStatus = imap_status($mbox, $config["imap_server"], SA_ALL);
    // Read message IDs of UNSEEN mails
    $unseen = [];
    if ($imapStatus->unseen > 0) {
        $messages = imap_search($mbox, "UNSEEN");
        foreach ($messages as $msgID) {
            $msg = imap_headerinfo($mbox, $msgID);
            $unseen[] = $msg->message_id;
        }
    }
    imap_close($mbox);
    //
    $last_unseen = json_decode($savedStatus->unseen);
    $new_message_found = false;
    foreach ($unseen as $key => $value) {
        // Does 'unseen' contain msgID we haven't seen before?
        if (array_search($value, $last_unseen) === FALSE) {
            $new_message_found = true;
        }
    }
    // Current unseen list doesn't match saved one
    if (count($unseen) != count($last_unseen) || $new_message_found) {
        saveStatusToSqlite($db, "unseen", json_encode($unseen));
    }
    return $new_message_found;
}
开发者ID:McFizh,项目名称:hackster-cc3200-email,代码行数:29,代码来源:common.php

示例8: emailDeliverFailBySubject

 public static function emailDeliverFailBySubject($subject)
 {
     $mailcnf = "outlook.office365.com:993/imap/ssl/novalidate-cert";
     $username = MAILACCOUNT;
     $pw = MAILPASSWORD;
     $conn_str = "{" . $mailcnf . "}INBOX";
     $inbox = imap_open($conn_str, $username, $pw) or die('Cannot connect to mail: ' . imap_last_error());
     /* grab emails */
     $emails = imap_search($inbox, 'SUBJECT "Undeliverable: ' . $subject . '"');
     $failedInfo = [];
     /* if emails are returned, cycle through each... */
     if ($emails) {
         /* for every email... */
         foreach ($emails as $email_number) {
             /* get information specific to this email */
             $body = imap_fetchbody($inbox, $email_number, 2);
             $list = split('; ', $body);
             $sender = $list[2];
             $sender_email = explode("\n", $sender)[0];
             array_push($failedInfo, trim($sender_email));
         }
     }
     /* close the connection */
     imap_close($inbox);
     return $failedInfo;
 }
开发者ID:aanyun,项目名称:PHP-Sample-Code,代码行数:26,代码来源:EmailController.php

示例9: GetIMAPContent

 /**
  * Gets IMAP content
  *
  * @param string $imapHost
  * @param string $imapUser
  * @param string $imapPassword
  * @param \Swiftriver\Core\ObjectModel\Channel $channel
  *
  * @return $contentItems[]
  */
 private function GetIMAPContent($imapHost, $imapUser, $imapPassword, $channel)
 {
     $imapResource = imap_open("{" . $imapHost . "}INBOX", $imapUser, $imapPassword);
     //Open up unseen messages
     $search = $channel->lastSuccess == null ? "UNSEEN" : "UNSEEN SINCE " . \date("Y-m-d", $channel->lastSuccess);
     $imapEmails = imap_search($imapResource, $search);
     $contentItems = array();
     if ($imapEmails) {
         //Put newest emails on top
         rsort($imapEmails);
         foreach ($imapEmails as $Email) {
             //Loop through each email and return the content
             $email_overview = imap_fetch_overview($imapResource, $Email, 0);
             if (strtotime(reset($email_overview)->date) < $channel->lastSuccess) {
                 continue;
             }
             $email_header_info = imap_header($imapResource, $Email);
             $email_message = imap_fetchbody($imapResource, $Email, 1);
             $source_name = \reset($email_overview)->from;
             $source = \Swiftriver\Core\ObjectModel\ObjectFactories\SourceFactory::CreateSourceFromIdentifier($source_name);
             $source->name = $source_name;
             $source->parent = $channel->id;
             $source->type = $channel->type;
             $source->subType = $channel->subType;
             $item = \Swiftriver\Core\ObjectModel\ObjectFactories\ContentFactory::CreateContent($source);
             $item->text[] = new \Swiftriver\Core\ObjectModel\LanguageSpecificText(null, $email_overview[0]->subject, array($email_message));
             //the message
             $item->link = null;
             $item->date = $email_header_info->udate;
             $contentItems[] = $item;
         }
     }
     imap_close($imapResource);
     return $contentItems;
 }
开发者ID:Bridgeborn,项目名称:Swiftriver,代码行数:45,代码来源:IMAPParser.php

示例10: emailListener

function emailListener()
{
    $connection = establishConnection();
    $dbConn = establishDBConnection();
    $messagestatus = "UNSEEN";
    $emails = imap_search($connection, $messagestatus);
    if ($emails) {
        rsort($emails);
        foreach ($emails as $email_number) {
            // echo "in email loop";
            $header = imap_headerinfo($connection, $email_number);
            $message = imap_fetchbody($connection, $email_number, 1.1);
            if ($message == "") {
                $message = imap_fetchbody($connection, $email_number, 1);
            }
            $emailaddress = substr($header->senderaddress, stripos($header->senderaddress, "<") + 1, stripos($header->senderaddress, ">") - (stripos($header->senderaddress, ">") + 1));
            if (!detectOOOmessage($header->subject, $message, $emailaddress)) {
                detectBIOmessage($header->subject, $emailaddress);
            }
            imap_delete($connection, 1);
            //this might bug out but should delete the top message that was just parsed
        }
    }
    $dbConn->query("DELETE FROM away_mentor WHERE tiStamp <= DATE_ADD(NOW(), INTERVAL -1 DAY) limit 1");
    //delete mentors that have been away for more than 24 hours from the away list
}
开发者ID:acuba001,项目名称:Collaborative-Platform,代码行数:26,代码来源:AutoBackendOutOfTimeShow.php

示例11: get_exchange

function get_exchange($imap_box)
{
    $emails = imap_search($imap_box, "FROM 'e-mail address'");
    //ищем письма от
    //$emails = imap_search($imap_box, "FROM 'e-mail address'");  //ищем письма от
    //echo "<br>";
    //if ($emails) echo "Найдено:" . sizeof($emails) . " писем.<br>";  // сколько нашли и какие их номера начиная с 0
    //else echo "Писем удовлетворяющих условию не найдено.";
    $result = false;
    if ($emails) {
        /* put the newest emails on top */
        rsort($emails);
        /* for every email... */
        foreach ($emails as $email_number) {
            $message = get_msg($imap_box, $email_number, "PLAIN");
            //  PLAIN or  HTML  or ...
            $message = preg_replace('/\\r\\n|\\r|\\n/u', '', $message);
            // удаляем символы перевода строки
            preg_match("/Курс виписки рахунків- \\d\\d\\,\\d\\dГотівковий- \\d\\d\\,\\d\\d/", $message, $output_array);
            //ищем паттерн
            if ($output_array[0]) {
                // Если нашли паттерн
                if (!$result) {
                    preg_match_all('/\\d\\d\\,\\d\\d/', $output_array[0], $result);
                }
                //нашли свежак и сохраняем его
                imap_delete($imap_box, $email_number);
                //помечаем письмо на удаление
            }
        }
    }
    imap_expunge($imap_box);
    return $result[0];
}
开发者ID:qwant50,项目名称:email-s-parser,代码行数:34,代码来源:get_exchange_v2.1.php

示例12: search

 function search($criteria, $options = SE_FREE)
 {
     if ($this->mbox) {
         return imap_search($this->mbox, $criteria, $options);
     }
     return false;
 }
开发者ID:ateliee,项目名称:php_lib,代码行数:7,代码来源:class_imap.php

示例13: getMail

 /**
  * Gets the mail from the inbox
  * Reads all the messages there, and adds posts based on them. Then it deletes the entire mailbox.
  */
 function getMail()
 {
     $config = Config::current();
     if (time() - 60 * $config->emailblog_minutes >= $config->emailblog_mail_checked) {
         $hostname = '{' . $config->emailblog_server . '}INBOX';
         # this isn't working well on localhost
         $username = $config->emailblog_address;
         $password = $config->emailblog_pass;
         $subjpass = $config->emailblog_subjpass;
         $inbox = imap_open($hostname, $username, $password) or exit("Cannot connect to Gmail: " . imap_last_error());
         $emails = imap_search($inbox, 'SUBJECT "' . $subjpass . '"');
         if ($emails) {
             rsort($emails);
             foreach ($emails as $email_number) {
                 $message = imap_body($inbox, $email_number);
                 $overview = imap_headerinfo($inbox, $email_number);
                 imap_delete($inbox, $email_number);
                 $title = htmlspecialchars($overview->Subject);
                 $title = preg_replace($subjpass, "", $title);
                 $clean = strtolower($title);
                 $body = htmlspecialchars($message);
                 # The subject of the email is used as the post title
                 # the content of the email is used as the body
                 # not sure about compatibility with images or audio feathers
                 Post::add(array("title" => $title, "body" => $message), $clean, Post::check_url($clean), "text");
             }
         }
         # close the connection
         imap_close($inbox, CL_EXPUNGE);
         $config->set("emailblog_mail_checked", time());
     }
 }
开发者ID:betsyzhang,项目名称:chyrp,代码行数:36,代码来源:emailblog.php

示例14: getMails

 private function getMails()
 {
     $mails = array();
     if ($this->createConnection()) {
         $unseen = imap_search($this->connection, 'UNSEEN');
         // fetch only unseen mails... much faster
         $index = '';
         if ($unseen) {
             foreach ($unseen as $uMail) {
                 $index .= $uMail . ",";
             }
         }
         $mails = array_reverse(imap_fetch_overview($this->connection, "{$index}"));
     }
     $this->closeConnection();
     $cleanMails = array();
     foreach ($mails as $mail) {
         $tmp = array();
         $tmp['subject'] = $this->decodeSubject($mail->subject);
         $tmp['from'] = $this->decodeSubject($mail->from);
         $datetime = new DateTime($mail->date);
         $tmp['datetime'] = $datetime->getTimestamp() + $datetime->getOffset();
         $cleanMails[] = $tmp;
     }
     return $cleanMails;
 }
开发者ID:arnovr,项目名称:dashboard,代码行数:26,代码来源:mailcontroller.php

示例15: download_and_process_email_replies

 /**
  * Primary method for downloading and processing email replies
  */
 public function download_and_process_email_replies($connection_details)
 {
     imap_timeout(IMAP_OPENTIMEOUT, apply_filters('supportflow_imap_open_timeout', 5));
     $ssl = $connection_details['imap_ssl'] ? '/ssl' : '';
     $ssl = apply_filters('supportflow_imap_ssl', $ssl, $connection_details['imap_host']);
     $mailbox = "{{$connection_details['imap_host']}:{$connection_details['imap_port']}{$ssl}}";
     $inbox = "{$mailbox}{$connection_details['inbox']}";
     $archive_box = "{$mailbox}{$connection_details['archive']}";
     $imap_connection = imap_open($mailbox, $connection_details['username'], $connection_details['password']);
     $redacted_connection_details = $connection_details;
     $redacted_connection_details['password'] = '[redacted]';
     // redact the password to avoid unnecessarily exposing it in logs
     $imap_errors = imap_errors();
     SupportFlow()->extend->logger->log('email_retrieve', __METHOD__, $imap_connection ? __('Successfully opened IMAP connection.', 'supportflow') : __('Failed to open IMAP connection.', 'supportflow'), compact('redacted_connection_details', 'mailbox', 'imap_errors'));
     if (!$imap_connection) {
         return new WP_Error('connection-error', __('Error connecting to mailbox', 'supportflow'));
     }
     // Check to see if the archive mailbox exists, and create it if it doesn't
     $mailboxes = imap_getmailboxes($imap_connection, $mailbox, '*');
     if (!wp_filter_object_list($mailboxes, array('name' => $archive_box))) {
         imap_createmailbox($imap_connection, $archive_box);
     }
     // Make sure here are new emails to process
     $email_count = imap_num_msg($imap_connection);
     if ($email_count < 1) {
         SupportFlow()->extend->logger->log('email_retrieve', __METHOD__, __('No new messages to process.', 'supportflow'), compact('mailboxes'));
         return false;
     }
     $emails = imap_search($imap_connection, 'ALL', SE_UID);
     $email_count = min($email_count, apply_filters('supportflow_max_email_process_count', 20));
     $emails = array_slice($emails, 0, $email_count);
     $processed = 0;
     // Process each new email and put it in the archive mailbox when done.
     foreach ($emails as $uid) {
         $email = new stdClass();
         $email->uid = $uid;
         $email->msgno = imap_msgno($imap_connection, $email->uid);
         $email->headers = imap_headerinfo($imap_connection, $email->msgno);
         $email->structure = imap_fetchstructure($imap_connection, $email->msgno);
         $email->body = $this->get_body_from_connection($imap_connection, $email->msgno);
         if (0 === strcasecmp($connection_details['username'], $email->headers->from[0]->mailbox . '@' . $email->headers->from[0]->host)) {
             $connection_details['password'] = '[redacted]';
             // redact the password to avoid unnecessarily exposing it in logs
             SupportFlow()->extend->logger->log('email_retrieve', __METHOD__, __('Skipping message because it was sent from a SupportFlow account.', 'supportflow'), compact('email'));
             continue;
         }
         // @todo Confirm this a message we want to process
         $result = $this->process_email($imap_connection, $email, $email->msgno, $connection_details['username'], $connection_details['account_id']);
         // If it was successful, move the email to the archive
         if ($result) {
             imap_mail_move($imap_connection, $email->uid, $connection_details['archive'], CP_UID);
             $processed++;
         }
     }
     imap_close($imap_connection, CL_EXPUNGE);
     $status_message = sprintf(__('Processed %d emails', 'supportflow'), $processed);
     SupportFlow()->extend->logger->log('email_retrieve', __METHOD__, $status_message);
     return $status_message;
 }
开发者ID:nagyistoce,项目名称:supportflow,代码行数:62,代码来源:class-supportflow-email-replies.php


注:本文中的imap_search函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。