function getdata($host, $login, $password, $savedirpath) { $mbox = imap_open($host, $login, $password) or die("can't connect: " . imap_last_error()); $message = array(); $message["attachment"]["type"][0] = "text"; $message["attachment"]["type"][1] = "multipart"; $message["attachment"]["type"][2] = "message"; $message["attachment"]["type"][3] = "application"; $message["attachment"]["type"][4] = "audio"; $message["attachment"]["type"][5] = "image"; $message["attachment"]["type"][6] = "video"; $message["attachment"]["type"][7] = "other"; $buzon_destino = "cfdi"; echo imap_createmailbox($mbox, imap_utf7_encode("{$buzon_destino}")); echo imap_num_msg($mbox); for ($jk = 1; $jk <= imap_num_msg($mbox); $jk++) { $structure = imap_fetchstructure($mbox, $jk); $parts = $structure->parts; $fpos = 2; for ($i = 1; $i < count($parts); $i++) { $message["pid"][$i] = $i; $part = $parts[$i]; if (strtolower($part->disposition) == "attachment") { $message["type"][$i] = $message["attachment"]["type"][$part->type] . "/" . strtolower($part->subtype); $message["subtype"][$i] = strtolower($part->subtype); $ext = $part->subtype; $params = $part->dparameters; $filename = $part->dparameters[0]->value; if (!($ext == 'xml' or $ext == 'XML' or $ext == 'PDF' or $ext == 'pdf')) { continue; } $mege = ""; $data = ""; $mege = imap_fetchbody($mbox, $jk, $fpos); $data = $this->getdecodevalue($mege, $part->type); $fp = fopen($filename, 'w'); fputs($fp, $data); fclose($fp); $fpos += 1; /* Se mueve el archiv descargado al directorio de recibidos */ // rename($filename, $savedirpath.$filename); // printf("\nSe movio el archivo $filename"); } } $result = imap_fetch_overview($mbox, $jk); echo $result[0]->from; // imap_mail_move($mbox, $jk, $buzon_destino); //imap_delete tags a message for deletion // imap_delete($mbox,$jk); } // imap_expunge deletes all tagged messages // imap_expunge($mbox); imap_close($mbox); }
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 "*****@*****.**" 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"; }
function inbox() { $this->msg_cnt = imap_num_msg($this->conn); $in = array(); for ($i = 1; $i <= 20; $i++) { $in[] = array('index' => $i, 'header' => imap_headerinfo($this->conn, $i), 'body' => imap_body($this->conn, $i), 'structure' => imap_fetchstructure($this->conn, $i)); } $this->inbox = $in; }
/** * 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_num_msg($this->imap_stream); $no_of_msgs = imap_num_msg($this->imap_stream); $messages = array(); for ($i = 1; $i <= $no_of_msgs; $i++) { $header = imap_headerinfo($this->imap_stream, $i); $message_id = $header->message_id; $date = date($date_format, $header->udate); if (isset($header->from)) { $from = $header->from; } else { $from = FALSE; } $fromname = ""; $fromaddress = ""; $subject = ""; if ($from != FALSE) { 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); } // Read the message structure $structure = imap_fetchstructure($this->imap_stream, $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, $i, $j + 1); } } } else { $body = imap_body($this->imap_stream, $i); } // Convert quoted-printable strings (RFC2045) $body = imap_qprint($body); // Convert to valid UTF8 $body = htmlentities($body); $subject = htmlentities($subject); array_push($messages, array('message_id' => $message_id, 'date' => $date, 'from' => $fromname, 'email' => $fromaddress, 'subject' => $subject, 'body' => $body)); // Mark Message As Read imap_setflag_full($this->imap_stream, $i, "\\Seen"); } return $messages; }
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); }
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')); }
/** * @return integer */ protected function countMessages($inbox = null) { if (!$inbox) { $inbox = $this->inbox; } return imap_num_msg($inbox); }
function get_fbl_messages($fbl_array, $fbl_log) { $msgpack = array(); $fblname = $fbl_array['name']; $hostname = $fbl_array['hostname']; $hostname = "{" . $hostname . "}"; $username = $fbl_array['username']; $password = $fbl_array['password']; sendLog($fbl_log, "Connecting to {$fblname} FBL IMAP : {$username}@{$hostname}."); $mailbox = imap_open($hostname, $username, "{$password}", OP_READONLY); if ($mailbox) { $num_msg = imap_num_msg($mailbox); if ($num_msg > 0) { sendLog($fbl_log, "Fetching {$num_msg} FBL message(s)."); for ($i = $num_msg; $i > 0; $i--) { $fblhdr = imap_fetchheader($mailbox, $i); $fblhdr = str_replace("\r", "", $fblhdr); $fblbody = imap_body($mailbox, $i); $fblbody = str_replace("\r", "", $fblbody); $fblmsg = $fblhdr . "\n" . $fblbody; array_push($msgpack, $fblmsg); imap_delete($mailbox, $i); } return $msgpack; } imap_close($mailbox); } else { sendLog($fbl_log, "Error opening mailbox {$hostname}, {$username}."); } }
/** * Make a connect with a imap or pop3 mail server * * @param array $params Parameters for making connection */ function connect($params) { # Storing server type $server_type = $params['type']; # Determine port to use $port = $params['type'] == "pop3" ? $params['secure'] ? 995 : 110 : ($params['secure'] ? 993 : 143); # Form server string $server = "{" . $params['server'] . ":{$port}/" . $params['type']; $server .= $params['secure'] ? "/ssl" : ""; $server .= "}"; # Attempt connection $this->conn = @imap_open($server . $params['mailbox'], $params['username'], $params['password']); # If failure also try with "notls" and "novalidate-cert" option if (!$this->conn) { $server = str_replace("}", "/notls}", $server); $this->conn = @imap_open($server . $params['mailbox'], $params['username'], $params['password']); } if (!$this->conn) { $server = str_replace("/notls}", "/novalidate-cert}", $server); $this->conn = @imap_open($server . $params['mailbox'], $params['username'], $params['password']); } # Connection made if ($this->conn) { # Keep track of server string $this->server = $server; # Retrieve number of messages in mailbox $this->num_msgs = imap_num_msg($this->conn); return true; } else { # If connection not made then log error return false; } }
public function getNumMessages() { if ($this->can_receive && $this->initialized) { $this->num_messages_available = imap_num_msg($this->box); return $this->num_messages_available; } }
public function __construct($email_addr, $host, $user, $pass, $exitifnoemails = 1) { error_reporting(0); if (!function_exists('imap_mail')) { echo '<p class="error">IMAP MAIL EXTENSION IS NOT AVAILABLE ON THIS SERVER!</p>'; //exit; return false; # No need to exit entire page as other things might be there. } // End function. //$this->conn = imap_open ("{{$host}:143/notls}Inbox", $email_addr, $pass); $this->conn = imap_open("{{$host}:143/notls}Inbox", $user, $pass); //$this->conn = imap_open ("{{$host}:143}", $user, $pass); if (!$this->conn) { // Error occurred while try to connect: echo '<p class="error">Could not access mailbox</p>'; //var_dump(imap_errors()); imap_close($this->conn); exit; } // End if. // Get the number of mails on the server: $this->num_emails = imap_num_msg($this->conn); if ($this->num_emails == 0) { echo '<p class="error">No emails in mailbox</p>'; imap_close($this->conn); if ($exitifnoemails) { exit; } } // End if. }
/** * Count number of messages not in any mailbox * * @return int */ public function count() { if ($this->closed) { return true; } return imap_num_msg($this->resource); }
public function totalEmail() { if (!$this->isConnect) { return false; } return imap_num_msg($this->stream); }
/** * 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'] = '******'; // 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'] = '******'; // 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; }
/** Fetch all the messages from the mailbox. @return array(weeFetchMailMessage) All the messages from the mailbox. */ public function fetchAll() { $aResults = array(); $iTotal = imap_num_msg($this->rLink); for ($iMsg = 1; $iMsg <= $iTotal; $iMsg++) { $aResults[] = new weeFetchMailMessage($this->rLink, $iMsg); } return $aResults; }
function getmails($conn) { $num = imap_num_msg($conn); $mail = array(); for ($i = 1; $i <= $num; $i++) { $mail[$i - 1][] = parseheader($conn, $i); $mail[$i - 1][] = parsebody($conn, $i); } return $mail; }
/** * Get count all messages * @access public * @return integer|boolean */ public function getCount() { $a = $this->connection->getImapCheck(); if ($a) { return $a->Nmsgs; } if ($this->connection->isAuth()) { return imap_num_msg($this->connection->getResource()); } return false; }
public function __construct($mailbox, $username, $password, $timeout = 30) { imap_timeout(IMAP_OPENTIMEOUT, $timeout); imap_timeout(IMAP_READTIMEOUT, $timeout); imap_timeout(IMAP_WRITETIMEOUT, $timeout); try { $this->count = imap_num_msg($this->imap = imap_open(\Zeyon\convert($mailbox, 'UTF7-IMAP'), \Zeyon\convert($username, 'UTF7-IMAP'), \Zeyon\convert($password, 'UTF7-IMAP'), OP_SILENT, 1)); } catch (\Exception $e) { throw new \Exception('IMAP: ' . (($error = imap_last_error()) === false ? $e->getMessage() : $error)); } }
function get_all_mail() { $this->email_open(); $number_of_messages = imap_num_msg($this->connection); //echo $number_of_messages; $counter = 1; while ($number_of_messages >= $counter) { $this->get_one_mail($counter); $counter++; } $this->email_close(); }
function get_imap_connection() { $mbox = imap_open("{xxx.xxx.xxx.xxx:xxx/pop3/novalidate-cert}INBOX", "xml", "password") or die("can't connect: " . imap_last_error()); if ($mbox) { // call this to avoid the mailbox is empty error message if (imap_num_msg($mbox) == 0) { $errors = imap_errors(); if ($errors) { die("can't connect: " . imap_last_error()); } } } return $mbox; }
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); }
function __construct($host, $user, $password, $port, $flags, $mailbox) { $this->total_messages = false; $this->current_message_index = false; $portstring = ""; if ($port) { $portstring = ":" . $port; } $flagstring = ""; foreach ($flags as $flag) { $flagstring .= "/{$flag}"; } $this->imap_stream = imap_open("{" . $host . $portstring . $flagstring . "}" . $mailbox, $user, $password); if ($this->imap_stream) { $this->current_message_index = 0; $this->total_messages = imap_num_msg($this->imap_stream); } }
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; }
static function fetch($options) { if ($mbox = imap_open(sprintf('{%1$s:%2$s/%3$s}INBOX', $options['server'], $options['port'], implode('/', $options['settings'])), $options['user'], $options['pass'])) { $ret = array(); if (($messages = imap_num_msg($mbox)) > 0) { for ($message = 1; $message < $messages + 1; $message++) { $eml = imap_fetchheader($mbox, $message) . imap_body($mbox, $message); $data = array('Task' => array()); $email_data = LilTasksParseEmail::__parseEmailHeader($mbox, $message); $data['Task']['title'] = $email_data['subject']; $data['Task']['happened'] = strftime('%Y-%m-%d', strtotime($email_data['date'])); list($sender, $domain) = explode('@', $email_data['from']); if ($sender == 'today') { $data['Task']['deadline'] = strftime('%Y-%m-%d'); } else { if ($sender == 'tomorrow') { $data['Task']['deadline'] = strftime('%Y-%m-%d', time() + 24 * 60 * 60); } else { if (in_array(strtolower($sender), array('monday', 'tuesday', 'wednesday', 'thursday', 'saturday', 'sunday'))) { $data['Task']['deadline'] = strftime('%Y-%m-%d', strtotime('next ' . ucfirst($sender))); } } } $hash = sha1($data['Task']['happened'] . '_' . $email_data['subject']); $parts = array(); $data['Task']['descript'] = LilTasksParseEmail::__parseEmailBody($mbox, $message, $hash, $parts); file_put_contents(TMP . $hash . '.eml', $eml); $data['Attachment'][0] = array('model' => 'Task', 'filename' => array('name' => $hash . '.eml', 'tmp_name' => TMP . $hash . '.eml'), 'title' => 'SOURCE: ' . $data['Task']['title']); App::uses('Sanitize', 'Utility'); foreach ($parts as $part) { if (!empty($part['attachment'])) { $data['Attachment'][] = array('model' => 'Task', 'filename' => array('name' => Sanitize::paranoid($part['attachment']['filename']), 'tmp_name' => $part['attachment']['tmp']), 'title' => $part['attachment']['filename']); } } $ret[$message] = $data; imap_delete($mbox, $message); } } return $ret; imap_close($mbox, CL_EXPUNGE); } else { var_dump(imap_errors()); } }
/** * 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; }
public function showEmails() { $connect_to = '{imap.gmail.com:993/imap/ssl/novalidate-cert}INBOX'; $user = '******'; $password = '******'; $inbox = imap_open($connect_to, $user, $password) or die("Can't connect to '{$connect_to}': " . imap_last_error()); $folders = imap_list($inbox, "{imap.gmail.com:993/imap/ssl}", "*"); //return dd($folders); //return $message_count = imap_num_msg($inbox); $emails = imap_search($inbox, 'SINCE ' . date('d-M-Y', strtotime("-2 week"))); $output = []; $emailCount = imap_num_msg($inbox); rsort($emails); $i = 0; foreach ($emails as $mail) { $headerInfo = imap_headerinfo($inbox, $mail); //return var_dump(dd($headerInfo)); $message = ""; $output[$i]['subject'] = isset($headerInfo->Subject) ? imap_utf8($headerInfo->Subject) : "0"; $output[$i]['from'] = imap_utf8($headerInfo->from[0]->personal); $output[$i]['toaddress'] = $headerInfo->toaddress; $output[$i]['to'] = array_shift($headerInfo->to); $output[$i]['date'] = $headerInfo->date[0]; $output[$i]['fromaddress'] = $headerInfo->fromaddress[0]; $output[$i]['reply_toaddress'] = $headerInfo->reply_toaddress[0]; $output[$i]['date'] = date('d-m-Y ' . '[' . 'H:i' . ']', strtotime($headerInfo->date) + 3600); $output[$i]['unseen'] = $headerInfo->Unseen; $output[$i]['flagged'] = $headerInfo->Flagged; $message = imap_fetchbody($inbox, $mail, 2); if (base64_decode($message, true)) { //message body if base64 encoded $message = base64_decode($message); } else { //message body is not base64 encoded $message = imap_fetchbody($inbox, $mail, 1); } $output[$i]['body'] = $message; $i++; } return dd($output); //return view('aßdministration.email.showEmails')->with('output', $output); }
public function getMails() { /*echo '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> </head><body>';*/ $message_count = imap_num_msg($this->MailBoxHandle); for ($counter = 1; $counter <= $message_count; $counter++) { // echo "<h1>Headers in INBOX</h1>\n"; $headers = imap_headerinfo($this->MailBoxHandle,$counter); $structure = imap_fetchstructure($this->MailBoxHandle,$counter); $ttype = $structure->type; $tcode = $structure->encoding; $body = imap_body($this->MailBoxHandle,$counter,1); if ( $tcode == 3 ) { $body = base64_decode($body); $value= $body; if (isset($structure->parameters[0]->attribute) && $structure->parameters[0]->attribute=='CHARSET'); { if ($structure->parameters[0]->value=='iso-8859-1') { $body = str_replace("\r\n", "<br />",iconv("ISO-8859-1", "UTF-8",$body)); } } } if ( $tcode == 4 ) { $body = quoted_printable_decode($body); $body = str_replace("\r\n", "<br />",iconv("ISO-8859-1", "UTF-8",$body)); } // echo "<br />".$body; } imap_close($this->MailBoxHandle); }
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; }
function imap_get_url($u) { if (!($c = imap_open_url($u))) { return FALSE; } extract(parse_url($u)); extract(imap_parse_path($path)); if ($mailbox) { if ($uid) { $msgno = imap_msgno($c, $uid); $o = imap_fetchstructure($c, $msgno); } else { $o = array(); $n = imap_num_msg($c); while ($i++ < $n) { $o[] = imap_fetchheader($c, $i); } } } else { $o = imap_list($c, '{}', '*'); } return $o; }
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); }