/** * 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++) { // Get Message Unique ID in case mail box changes // in the middle of this operation $message_id = imap_uid($this->imap_stream, $msgs[$i]); $header = imap_header($this->imap_stream, $message_id); $date = date($date_format, $header->udate); $from = $header->from; $fromname = ""; $fromaddress = ""; $subject = ""; foreach ($from as $id => $object) { if (isset($object->personal)) { $fromname = $object->personal; } $fromaddress = $object->mailbox . "@" . $object->host; if ($fromname == "") { // In case from object doesn't have Name $fromname = $fromaddress; } } if (isset($header->subject)) { $subject = $this->_mime_decode($header->subject); } $structure = imap_fetchstructure($this->imap_stream, $message_id); $body = ''; 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, $message_id, $j + 1); } } } else { $body = imap_body($this->imap_stream, $message_id); } // Convert quoted-printable strings (RFC2045) $body = imap_qprint($body); array_push($messages, array('msg_no' => $message_id, 'date' => $date, 'from' => $fromname, 'email' => $fromaddress, 'subject' => $subject, 'body' => $body)); // Mark Message As Read imap_setflag_full($this->imap_stream, $message_id, "\\Seen"); } return $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; }
public function readMessage($messageid) { $message = array(); $header = imap_header($this->mailbox, $messageid); $structure = imap_fetchstructure($this->mailbox, $messageid); $message['subject'] = $header->subject; $message['fromaddress'] = $header->fromaddress; $message['toaddress'] = $header->toaddress; //$message['ccaddress'] = $header->ccaddress; $message['date'] = $header->date; $message['id'] = $messageid; if ($this->check_type($structure)) { $message['body'] = imap_fetchbody($this->mailbox, $messageid, "2"); ## GET THE BODY OF MULTI-PART MESSAGE if (!$message['body']) { $message['body'] = '[NO TEXT ENTERED INTO THE MESSAGE]\\n\\n'; } } else { $message['body'] = imap_body($this->mailbox, $messageid); if (!$message['body']) { $message['body'] = '[NO TEXT ENTERED INTO THE MESSAGE]\\n\\n'; } } return $message; }
/** * @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; }
function pop3_body() { $imap = imap_open("{pop.163.com:110/pop3/notls}", "rong360credit01", "rong36000"); $message_count = imap_num_msg($imap); for ($i = 1; $i <= $message_count; ++$i) { $header = imap_header($imap, $i); $date = $header->date; echo "************msg no: {$i} \n {$date} \n"; $structure = imap_fetchstructure($imap, $i); // print_r($structure) ; } imap_close($imap); }
function retrieve_message($auth_user, $accountid, $messageid, $fullheaders) { $message = array(); if (!($auth_user && $messageid && $accountid)) { return false; } $imap = open_mailbox($auth_user, $accountid); if (!$imap) { return false; } $header = imap_header($imap, $messageid); if (!$header) { return false; } $message['body'] = imap_body($imap, $messageid); if (!$message['body']) { $message['body'] = "[This message has no body]\n\n\n\n\n\n"; } if ($fullheaders) { $message['fullheaders'] = imap_fetchheader($imap, $messageid); } else { $message['fullheaders'] = ''; } $message['subject'] = $header->subject; $message['fromaddress'] = $header->fromaddress; $message['toaddress'] = $header->toaddress; $message['ccaddress'] = $header->ccaddress; $message['date'] = $header->date; // note we can get more detailed information by using from and to // rather than fromaddress and toaddress, but these are easier imap_close($imap); return $message; }
function mp_header($mbox, $messageid) { $header = imap_header($mbox, $messageid); $h = array(); if (isset($header->Msgno)) { $h['Msgno'] = $header->Msgno; } if (isset($header->from[0])) { $h['from'] = mp_decode($header->fromaddress); } if (isset($header->to[0])) { $h['to'] = mp_decode($header->toaddress); } if (isset($header->cc[0])) { $h['cc'] = mp_decode($header->ccaddress); } if (isset($header->subject)) { $h['subject'] = mp_decode($header->subject); } if (isset($header->Date)) { $h['Date'] = $header->Date; } if (isset($header->Size)) { $h['Size'] = $header->Size; } $h['Deleted'] = $header->Deleted == 'D' ? 1 : 0; return $h; }
/** * 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; }
function getHeaders($mid) { if (!$this->marubox) { return false; } $mail_header = imap_header($this->marubox, $mid); $sender = $mail_header->from[0]; // var_dump(strtolower($sender->mailbox)); // return $this->marubox; $sender_replyto = $mail_header->reply_to[0]; $mail_details = array(); if (strtolower($sender->mailbox) != 'mailer-daemon' && strtolower($sender->mailbox) != 'postmaster') { date_default_timezone_set('PRC'); $subject = imap_mime_header_decode($mail_header->subject); $toaddress = imap_mime_header_decode($mail_header->toaddress); $mail_details = array('from' => strtolower($sender->mailbox) . '@' . $sender->host, 'fromName' => "", 'fromName_charset' => "", 'toOth' => strtolower($sender_replyto->mailbox) . '@' . $sender_replyto->host, 'toNameOth' => "", 'subject' => $subject[0]->text, 'subject_charset' => $subject[0]->charset, 'mailDate' => date("Y-m-d H:i:s", $mail_header->udate), 'udate' => $mail_header->udate, 'to' => $toaddress[0]->text); if (isset($sender->personal)) { $sPersonal = imap_mime_header_decode($sender->personal); $mail_details['fromName'] = $sPersonal[0]->text; $mail_details['fromName_charset'] = $sPersonal[0]->charset; } if (isset($sender_replyto->personal)) { $rePersonal = imap_mime_header_decode($sender_replyto->personal); $mail_details['toNameOth'] = $rePersonal[0]->text; } } return $mail_details; }
function getmsg($mid) { // the message may in $htmlmsg, $plainmsg, or both $this->htmlmsg = ""; $this->plainmsg = ""; $this->charset = ''; $this->attachments = array(); // HEADER $h = imap_header($this->mbox, $mid); // add code here to get date, from, to, cc, subject... // BODY $s = imap_fetchstructure($this->mbox, $mid); if (!isset($s->parts) || !$s->parts) { $this->getpart($mid, $s, 0); // no part-number, so pass 0 // multipart: iterate through each part } else { foreach ($s->parts as $partno0 => $p) { $this->getpart($mid, $p, $partno0 + 1); } } // データを返す $result = array(); $result["header"] = $h; $result["html"] = $this->htmlmsg; $result["plain"] = $this->plainmsg; $result["charset"] = $this->charset; $result["attachments"] = $this->attachments; return $result; }
function imap_read_mail($mail_id) { $mail_header = imap_header($this->conn, $mail_id); $mail_body = imap_body($this->conn, $mail_id); foreach ($mail_header as $mail_head) { $mail[] = $mail_head; } $mail['body'] = $mail_body; return $mail; }
function getHeaders($mid) { $mail_header = imap_header($this->marubox, $mid); $sender = $mail_header->from[0]; $sender_replyto = $mail_header->reply_to[0]; if (strtolower($sender->mailbox) != 'mailer-daemon' && strtolower($sender->mailbox) != 'postmaster') { $mail_details = array('from' => strtolower($sender->mailbox) . '@' . $sender->host, 'fromName' => $sender->personal, 'toOth' => strtolower($sender_replyto->mailbox) . '@' . $sender_replyto->host, 'toNameOth' => $sender_replyto->personal, 'subject' => $mail_header->subject, 'to' => strtolower($mail_header->toaddress)); } return $mail_details; }
function get_info($message_number) { $info = array(); $header = @imap_header($this->connect, $message_number); $info['from'] = @imap_rfc822_write_address($header->from[0]->mailbox, $header->from[0]->host, ""); $info['to'] = @$this->identifiant; $info['subject'] = $this->formate_subject(@$header->subject); $info['date'] = $this->formate_date(@$header->date); $info['message_id'] = @$header->message_id; return $info; }
function getHeaders($mid) { if (!$this->marubox) { return false; } $mail_header = imap_header($this->marubox, $mid); if (strtolower($sender->mailbox) != 'mailer-daemon' && strtolower($sender->mailbox) != 'postmaster') { $mail_details = $mail_header; } return $mail_details; }
function getHeaders($mid) { $mail_header = imap_header($this->mailResource, $mid); $sender = $mail_header->from[0]; $sender_replyto = $mail_header->reply_to[0]; $stat = strtolower($sender->mailbox) != 'mailer-daemon' && strtolower($sender->mailbox) != 'postmaster' ? FALSE : TRUE; if (strpos($mail_header->subject, "delayed")) { $stat = FALSE; } $mail_details = array('from' => strtolower($sender->mailbox) . '@' . $sender->host, 'fromName' => $sender->personal, 'toOth' => strtolower($sender_replyto->mailbox) . '@' . $sender_replyto->host, 'toNameOth' => $sender_replyto->personal, 'subject' => $mail_header->subject, 'to' => strtolower($mail_header->toaddress), 'bounce' => $stat, 'date' => $mail_header->date); return $mail_details; }
function getMessages() { $messages = imap_search($this->stream, 'UNSEEN', SE_UID); if (is_array($messages)) { $all = count($messages); $current = 0; $status = ''; $last_percent = -1; $message_id = 0; echo 'Messages found total : ' . count($messages) . "\n\n"; foreach ($messages as $uid) { $message_id++; echo 'Message: ' . $message_id . '/' . $all . "\n"; $msg = imap_fetchbody($this->stream, $uid, '', FT_UID | FT_PEEK); $header = imap_header($this->stream, $this->getMessageNumber($uid)); $fromInfo = $header->from[0]; $replyInfo = $header->reply_to[0]; if ($header->message_id) { $this->currentMessageId = $header->message_id; } else { $this->currentMessageId = mt_rand() . "---" . $fromInfo->mailbox . "@" . $fromInfo->host; } $this->fromAddr = isset($fromInfo->mailbox) && isset($fromInfo->host) ? $fromInfo->mailbox . "@" . $fromInfo->host : ""; $details = array("messageId" => $this->getCurrentMessageId(), "date" => $header->date, "fromAddr" => isset($fromInfo->mailbox) && isset($fromInfo->host) ? $fromInfo->mailbox . "@" . $fromInfo->host : "", "fromName" => isset($fromInfo->personal) ? $fromInfo->personal : "", "replyAddr" => isset($replyInfo->mailbox) && isset($replyInfo->host) ? $replyInfo->mailbox . "@" . $replyInfo->host : "", "replyName" => isset($replyTo->personal) ? $replyto->personal : "", "subject" => isset($header->subject) ? $header->subject : "", "udate" => isset($header->udate) ? $header->udate : "", "body" => '', "totalAttachments" => 0, "attachmentsDetail" => array()); $details['body'] = $this->getBody($uid); echo 'Date: ' . $details['date'] . "\n"; echo 'Message id: ' . $details['messageId'] . "\n"; echo 'From: ' . $details['fromAddr'] . "\n"; echo 'Name: ' . $details['fromName'] . "\n"; echo 'Reply add: ' . $details['replyAddr'] . "\n"; echo 'Reply name: ' . $details['replyName'] . "\n"; echo 'Subject: ' . $details['subject'] . "\n"; echo 'Body: ' . substr($details['body'], 0, 100) . "\n"; echo "\n\n"; $attachFlags = $this->hasAttachments($uid); echo "\n\n"; if ($attachFlags['attachmentsTotal'] > 0) { $details['totalAttachments'] = $attachFlags['attachmentsTotal']; $details['attachmentsDetail'] = $attachFlags; } echo 'Total attachments: ' . $details['totalAttachments'] . "\n\n"; array_push($this->content, $details); // Uncomment this line for archive the messages on the given folder // $this->archiveMessage($uid); } //end foreach return $this->content; } else { //fputs(STDERR, "\nError retrieving list of messages in folder: $folder_name. SKIPPED\n" . imap_last_error() . "\n"); echo "No messages were found \n\n\n"; } }
/** * Get the header data of a note and returns it as an associative array. * * @param int $ID_Num The numerical ID of the note. * * @return Array <u>Description:</u><br>An associative array containing note header data.<br>Common values are "Date", "Subject", and "Size". Other values may be present. These values differ based on iOS version that created the note. */ function Get_Note_Header_By_ID_Num($ID_Num) { //if we already have the header data, return the requested header if (isset($this->note_headers)) { return $this->note_headers[$ID_Num - 1]; //get all note header data and store it for future use } else { $this->note_headers = array(); for ($notenum_loop = 1; $notenum_loop <= $this->Get_Total_Notes_Count(); $notenum_loop++) { $this->note_headers[$notenum_loop - 1] = get_object_vars(imap_header($this->imap, $notenum_loop)); } return $this->note_headers[$ID_Num - 1]; } }
public function headers($token) { if (!$this->box) { return false; } $headers = imap_header($this->box, $token); $this->encode_subject($headers->subject); $this->message_id = $headers->message_id; $this->send_date($headers->date); $this->mail_to_address($headers->to); $this->mail_from_address($headers->fromaddress, $headers->from); $this->mail_cc_address($headers->cc); $this->mail_body($token); }
function getHeaders($mid) { if (!$this->mailbox) { return false; } $mail_header = imap_header($this->mailbox, $mid); $sender = $mail_header->from[0]; $sender_replyTo = $mail_header->reply_to[0]; if (strtolower($sender->mailbox) != 'mailer-daemon' && strtolower($sender->mailbox) != 'postmaster') { $subject = $this->decodeToUTF8($mail_header->subject); $toNameOth = $this->decodeToUTF8($sender_replyTo->personal); $fromName = $this->decodeToUTF8($sender->personal); $mail_details = array('from' => strtolower($sender->mailbox) . '@' . $sender->host, 'fromName' => $fromName, 'toOth' => strtolower($sender_replyTo->mailbox) . '@' . $sender_replyTo->host, 'toNameOth' => $toNameOth, 'subject' => $subject, 'to' => strtolower($mail_header->toaddress)); } return $mail_details; }
function go_mail(){ $username = ''; //Would store the email account username $password = ''; //Would store email password $mbox = imap_open ("{imap.gmail.com:993/imap/ssl}INBOX", $username, $password) or die("can't connect: " . imap_last_error()); $count = imap_num_msg($mbox); for($i = 1; $i<=$count; $i++){ $headers = imap_header($mbox,$i); $to = $headers->to[0]->mailbox; //The following it designed to match an address like rpi+g-123 preg_match('/(\w+)\+(\w)\-(\w+)/', $to, $res); $main = $res[1]; //Not used $type = $res[2]; $id = $res[3]; $subject = $headers->subject; $from = $headers->fromaddress; print_r(imap_fetchstructure($mbox, $i)); $body = strip_tags(imap_fetchbody($mbox, $i, 0)); echo $body; if($type == 'g1'){ $obj = new Group($id); if(!$obj->set || !$obj->id){ echo "Group $id doesnt exist. Mail is junk.\n"; return false; } else { echo "Shooting an email from $from to $obj->name about $subject\n"; //$obj->send_mail($subject, $body, $from, true); } }elseif($type == 'u'){ $obj = new User($id); if(!$obj->set || !$obj->id){ echo "User $id doesnt exist. Mail is junk.\n"; return false; } else { echo "Shooting an email from $from to $obj->name about $subject\n"; //$obj->send_mail($subject, $body, $from, true); } } // imap_delete($mbox, $i); } // imap_expunge($mbox); imap_close($mbox); }
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; }
function read_mail() { echo "Entering read mails function"; /* connect to gmail */ $hostname = '{imap.gmail.com:993/imap/ssl}inbox'; $username = '******'; $password = '******'; /* try to connect */ $inbox = imap_open($hostname, $username, $password) or die('cannot connect to gmail: ' . imap_last_error()); /* grab emails */ $emails = imap_search($inbox, 'unseen'); //$emails contain integer value acc to emails /* if emails are returned, cycle through each... */ if ($emails) { /* put the newest emails on top */ rsort($emails); /* for every email... */ foreach ($emails as $email_number) { $header = imap_header($inbox, $email_number); //Extarcting id from msgFROM $message['fromaddress'] = $header->fromaddress; $extractingID1 = explode('<', $message['fromaddress']); $extractingID2 = explode('>', $extractingID1[1]); $from = $extractingID2[0]; //Extarcting body of the msg $bodyText = imap_fetchbody($inbox, $email_number, 1); if (!strlen($bodyText) > 0) { $bodyText = imap_fetchbody($inbox, $email_number, 1); } //Displaying content // echo "<br> From - ".$from; // echo "<br>BOdy of email starts here--- "; // var_dump($bodyText); // echo "<br>Next msg will start from her________________________________---------------------________________________"; //Sql querry for inserting in data base $query_new_mails = "INSERT INTO new_mails \n\t\t\t\t\t\t\tVALUES ({$email_number}, '{$from}','{$bodyText}')"; $result = mysql_query($query_new_mails); $query_all_mails = "INSERT INTO all_mails \n\t\t\t\t\t\t\tVALUES ({$email_number}, '{$from}','{$bodyText}')"; $result = mysql_query($query_all_mails); //Proceeding to decoding of message decode_mail($from, $bodyText); } } }
public function getEmailInfo($messageNumber) { $body = nl2br(strip_tags(imap_body($this->conn, $messageNumber))); $header = imap_header($this->conn, $messageNumber); // For getting From and then display name/email address $from2 = $header->from; // Get display from name and email address: $fromname = $fromaddress = ''; foreach ($from2 as $id => $object) { $fromname = property_exists($object, 'personal') ? $object->personal : ''; $fromaddress = property_exists($object, 'mailbox') ? $object->mailbox . "@" . $object->host : ''; } // End foreach. $mailHeader = imap_headerinfo($this->conn, $messageNumber); // For gleaning subject and date. $subject = strip_tags($mailHeader->subject); $date = $mailHeader->date; return array($body, $fromname, $fromaddress, $subject, $date); }
/** * Return list of payments on the statement * * @return array */ public function getPayments() { $payments = array(); $messageCount = imap_num_msg($this->connection); for ($i = 1; $i <= $messageCount; $i++) { $headers = imap_header($this->connection, $i); if (strtotime($headers->date) < $this->checkToDate) { continue; } if ($p = $this->processEmail($i, $headers)) { if (is_array($p)) { $payments = array_merge($payments, $p); } else { $payments[] = $p; } } } return $payments; }
function getHeaders($mid) { if (!$this->marubox) { return false; } $mail_header = imap_header($this->marubox, $mid); $sender = $mail_header->from[0]; $sender_replyto = $mail_header->reply_to[0]; if (strtolower($sender->mailbox) != 'mailer-daemon' && strtolower($sender->mailbox) != 'postmaster') { /*解决主题乱码问题 jiangx date2013-09-03*/ $subject = imap_mime_header_decode($mail_header->subject); $title = iconv($subject[0]->charset, 'UTF-8', $subject[0]->text); /*唯一标识*/ /* $message_id = str_replace('<', '', $mail_header->message_id); $message_id = str_replace('>', '', $message_id); */ $mail_details = array('from' => strtolower($sender->mailbox) . '@' . $sender->host, 'fromName' => $sender->personal, 'toOth' => strtolower($sender_replyto->mailbox) . '@' . $sender_replyto->host, 'toNameOth' => $sender_replyto->personal, 'subject' => $title, 'to' => strtolower($mail_header->toaddress), 'message_id' => $mail_header->message_id, 'date' => $mail_header->udate); } return $mail_details; }
/** * 获取邮件头部信息 * @param $mid * @return array */ public function getHeaders($mid) { if (!$this->marubox) { return false; } else { // 获取邮件头信息 $mail_header = imap_header($this->marubox, $mid); $sender = $mail_header->from[0]; if (strtolower($sender->mailbox) != 'mailer-daemon' && strtolower($sender->mailbox) != 'postmaster') { // 对邮件标题进行解码 $obj = imap_mime_header_decode($mail_header->subject); // 如邮件标题不是UTF-8编码 则进行转码 if ($obj[0]->charset != 'UTF-8' && $obj[0]->charset != 'default') { $title = iconv($obj[0]->charset, 'utf-8//IGNORE', $obj[0]->text); } else { $title = $obj[0]->text; } } return $title; } }
function getdata($host, $login, $password, $savedirpath) { $this->savedDirPath = $savedirpath; $this->attachmenttype = array("text", "multipart", "message", "application", "audio", "image", "video", "other"); // create empty array to store message data $this->importedMessageDataArray = array(); // open the mailbox $mailbox = "{" . $host . ":143/imap/notls}INBOX"; $this->mbox = imap_open($mailbox, $login, $password); if ($this->mbox == FALSE) { return null; } $status = imap_status($this->mbox, $mailbox, SA_ALL); echo "Messages: ", $status->messages, "<BR>\n"; echo "Recent: ", $status->recent, "<BR>\n"; echo "Unseen: ", $status->unseen, "<BR>\n"; echo "UIDnext: ", $status->uidnext, "<BR>\n"; echo "UIDvalidity: ", $status->uidvalidity, "<BR>\n"; echo "Flags: ", $status->flags, "<BR>\n"; // now itterate through messages for ($mid = imap_num_msg($this->mbox); $mid >= 1; $mid--) { $header = imap_header($this->mbox, $mid); $this->importedMessageDataArray[$mid]["subject"] = property_exists($header, 'subject') ? $header->subject : ""; $this->importedMessageDataArray[$mid]["fromaddress"] = property_exists($header, 'fromaddress') ? $header->fromaddress : ""; $this->importedMessageDataArray[$mid]["date"] = property_exists($header, 'date') ? $header->date : ""; $this->importedMessageDataArray[$mid]["body"] = ""; $this->structureObject = imap_fetchstructure($this->mbox, $mid); $this->saveAttachments($mid); $this->getBody($mid); imap_delete($this->mbox, $mid); //imap_delete tags a message for deletion } // for multiple messages imap_expunge($this->mbox); // imap_expunge deletes all tagged messages imap_close($this->mbox); // now send the data to the server $this->exportEntries(); return $this->importedMessageDataArray; }
public function getNewMessages($imap, $limit) { $messages = imap_sort($imap, SORTARRIVAL, 1); $mails = array(); $i = 0; echo "<pre>"; foreach ($messages as $message) { $i++; $header = imap_header($imap, $message); $header = json_decode(json_encode($header), true); print_r($header); /* $prettydate = date("jS F Y", $header->udate); print "{$header->fromaddress} - $prettydate\n"; $mails[]['fromaddress'] = $header->fromaddress; */ if ($i == $limit) { die; } } //print_r($mails); }
private function getMessage($mbox, $mid) { // input $mbox = IMAP stream, $mid = message id // output all the following: $this->html_message = $this->plain_message = $this->charset = ''; $this->attachments = array(); // HEADER $h = imap_header($mbox, $mid); $this->headers = $h; // add code here to get date, from, to, cc, subject... // BODY $s = imap_fetchstructure($mbox, $mid); if (!isset($s->parts)) { // simple $this->getMessagePart($mbox, $mid, $s, 0); } else { // multipart: cycle through each part foreach ($s->parts as $partno0 => $p) { $this->getMessagePart($mbox, $mid, $p, $partno0 + 1); } } }
public function temp() { set_time_limit(4000); // Connect to gmail $imapPath = '{imap.gmail.com:993/imap/ssl}INBOX'; $username = '******'; $password = '******'; $imap = imap_open($imapPath, $username, $password) or die('Cannot connect to Gmail: ' . imap_last_error()); $numMessages = imap_num_msg($imap); for ($i = $numMessages; $i > $numMessages - 1; $i--) { $header = imap_header($imap, $i); $fromInfo = $header->from[0]; $replyInfo = $header->reply_to[0]; $details = array("fromAddr" => isset($fromInfo->mailbox) && isset($fromInfo->host) ? $fromInfo->mailbox . "@" . $fromInfo->host : "", "fromName" => isset($fromInfo->personal) ? $fromInfo->personal : "", "replyAddr" => isset($replyInfo->mailbox) && isset($replyInfo->host) ? $replyInfo->mailbox . "@" . $replyInfo->host : "", "subject" => isset($header->subject) ? $header->subject : "", "udate" => isset($header->udate) ? $header->udate : ""); $uid = imap_uid($imap, $i); } $body = get_part($imap, $uid, "TEXT/HTML"); // if HTML body is empty, try getting text body /* if ($body == "") { $body = get_part($imap, $uid, "TEXT/PLAIN"); } return $body;*/ // return view('messages.che')->with('body',$body); }