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; }
function findMails($name, $mailbox) { if (strlen($name) === 0 || $name == "_") { return array(); } $mailsIds = imap_sort($mailbox->getImapStream(), SORTARRIVAL, true, SE_UID, 'TO "' . $name . '@"'); return $mailsIds; }
public function getAllMessages($imap, $dsn) { $status = imap_status($imap, $dsn, SA_ALL); $msgs = imap_sort($imap, SORTDATE, 1, SE_UID); foreach ($msgs as $msguid) { $msgno = imap_msgno($imap, $msguid); $messages[$msgno] = imap_headerinfo($imap, $msgno); } return $messages; }
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; }
function read_inbox($params) { $sort = $params['sort'] == 'DESC' ? 1 : 0; switch ($params['order']) { case 'message_date': $idlist = imap_sort($this->imap, SORTARRIVAL, $sort, SE_UID); break; case 'message_from': $idlist = imap_sort($this->imap, SORTFROM, $sort, SE_UID); break; case 'message_subject': $idlist = imap_sort($this->imap, SORTSUBJECT, $sort, SE_UID); break; default: $idlist = imap_sort($this->imap, SORTARRIVAL, 1, SE_UID); } foreach ($idlist as $uid) { $msg = imap_headerinfo($this->imap, imap_msgno($this->imap, $uid)); $messages[] = array('id' => $uid, 'from' => $msg->from[0]->mailbox, 'status' => $this->_msg_status($msg), 'date' => $msg->udate, 'subject' => $msg->Subject); } return $messages; }
/** * @param int|null $limit * @param User $user */ public function import($limit = 3, User $user) { // making the work of Fetch package $messages = imap_sort($this->imap->getImapStream(), SORTARRIVAL, 1, SE_UID, $this->getImapSearch($user)); if ($limit != null) { $messages = array_slice($messages, 0, $limit); } foreach ($messages as &$message) { $message = new Message($message, $this->imap); } unset($message); foreach ($messages as $message) { $data = $this->parseData($message); foreach ($data as $purchase) { try { $this->purchase_service->save($purchase, $user); } catch (\Exception $e) { continue; } } } }
} $boxinfo = imap_check($mbox); if (!is_object($boxinfo) || !isset($boxinfo->Nmsgs)) { die("COULD NOT GET MAILBOX INFO\r\n"); } if ($boxinfo->Driver != 'imap') { die("THIS SCRIPT HAS ONLY BEEN TESTED WITH IMAP MAILBOXES\r\n"); } if ($boxinfo->Nmsgs < 1) { die("NO NEW MESSAGES\r\n"); } echo "Fetching {$boxinfo->Mailbox}\r\n"; echo "{$boxinfo->Nmsgs} messages, {$boxinfo->Recent} recent\r\n"; // Helps clean up the mailbox, especially if a desktop client is interracting with it also imap_expunge($mbox); foreach ((array) imap_sort($mbox, SORTARRIVAL, 1) as $message_id) { // Detect a disconnect... if (!imap_ping($mbox)) { die("REMOTE IMAP SERVER HAS GONE AWAY\r\n"); } // Fetch this message, fix the line endings, this makes a 1:1 copy of the message in ram // that, in my tests, matches the filesystem copy of the message on the imap server // ( tested with debian / postfix / dovecot ) $r = processmail(str_replace("\r\n", "\n", imap_fetchheader($mbox, $message_id, FT_INTERNAL) . imap_body($mbox, $message_id))); // stop when we reach the first duplicate if (!$r) { break; } echo '.'; imap_setflag_full($mbox, $message_id, '\\SEEN'); continue;
function aff_mail($servr, $user, $passwd, $folder, $mail, $verbose, $lang, $sort, $sortdir) { $mailhost = $servr; require 'conf.php'; require 'check_lang.php'; global $attach_tab; // GLOBAL $PHP_SELF; $glob_body = ''; $subject = $from = $to = $cc = ''; if (setlocale(LC_TIME, $lang_locale) != $lang_locale) { $default_date_format = $no_locale_date_format; } $current_date = strftime($default_date_format, time()); $pop = @imap_open('{' . $mailhost . '}' . $folder, $user, $passwd); // Finding the next and previous message number $sorted = imap_sort($pop, $sort, $sortdir); for ($i = 0; $i < sizeof($sorted); $i++) { if ($mail == $sorted[$i]) { $prev_msg = $sorted[$i - 1]; $next_msg = $sorted[$i + 1]; break; } } // END finding the next and previous message number $num_messages = @imap_num_msg($pop); $ref_contenu_message = @imap_header($pop, $mail); $struct_msg = @imap_fetchstructure($pop, $mail); if (sizeof($struct_msg->parts) > 0) { GetPart($struct_msg, NULL, $display_rfc822); } else { GetSinglePart($struct_msg, htmlspecialchars(imap_fetchheader($pop, $mail)), @imap_body($pop, $mail)); } if ($verbose == 1 && $use_verbose == 1) { $header = htmlspecialchars(imap_fetchheader($pop, $mail)); } else { $header = ''; } $tmp = array_pop($attach_tab); if (preg_match('/text/html/i', $tmp['mime']) || preg_match('/text/plain/i', $tmp['mime'])) { if ($tmp['transfer'] == 'QUOTED-PRINTABLE') { $glob_body = imap_qprint(imap_fetchbody($pop, $mail, $tmp['number'])); } elseif ($tmp['transfer'] == 'BASE64') { $glob_body = base64_decode(imap_fetchbody($pop, $mail, $tmp['number'])); } else { $glob_body = imap_fetchbody($pop, $mail, $tmp['number']); } $glob_body = remove_stuff($glob_body, $lang, $tmp['mime']); } else { array_push($attach_tab, $tmp); } @imap_close($pop); if ($struct_msg->subtype != 'ALTERNATIVE' && $struct_msg->subtype != 'RELATED') { switch (sizeof($attach_tab)) { case 0: $link_att = ''; break; case 1: $link_att = '<tr><td align="right" valign="top" class="mail">' . $html_att . '</td><td bgcolor="' . $glob_theme->mail_properties . '" class="mail">' . link_att($mailhost, $mail, $attach_tab, $display_part_no) . '</td></tr>'; break; default: $link_att = '<tr><td align="right" valign="top" class="mail">' . $html_atts . '</td><td bgcolor="' . $glob_theme->mail_properties . '" class="mail">' . link_att($mailhost, $mail, $attach_tab, $display_part_no) . '</td></tr>'; break; } } $subject_array = imap_mime_header_decode($ref_contenu_message->subject); for ($j = 0; $j < count($subject_array); $j++) { $subject .= $subject_array[$j]->text; } $from_array = imap_mime_header_decode($ref_contenu_message->fromaddress); for ($j = 0; $j < count($from_array); $j++) { $from .= $from_array[$j]->text; } $to_array = imap_mime_header_decode($ref_contenu_message->toaddress); for ($j = 0; $j < count($to_array); $j++) { $to .= $to_array[$j]->text; } $cc_array = imap_mime_header_decode($ref_contenu_message->ccaddress); for ($j = 0; $j < count($cc_array); $j++) { $cc .= $cc_array[$j]->text; } $content = array('from' => htmlspecialchars($from), 'to' => htmlspecialchars($to), 'cc' => htmlspecialchars($cc), 'subject' => htmlspecialchars($subject), 'date' => change_date(chop($ref_contenu_message->udate), $lang), 'att' => $link_att, 'body' => $glob_body, 'body_mime' => $tmp['mime'], 'body_transfer' => $tmp['transfer'], 'header' => $header, 'verbose' => $verbose, 'prev' => $prev_msg, 'next' => $next_msg); return $content; }
} $homedisplay = intval($homedisplay); $prev_currentapp = $GLOBALS['phpgw_info']['flags']['currentapp']; $GLOBALS['phpgw_info']['flags']['currentapp'] = $current_app; if (intval($homedisplay)) { $boemailadmin = CreateObject('emailadmin.bo'); $emailadmin_profile = $boemailadmin->getProfileList(); $_SESSION['phpgw_info']['expressomail']['email_server'] = $boemailadmin->getProfile($emailadmin_profile[0]['profileID']); $_SESSION['phpgw_info']['expressomail']['user'] = $GLOBALS['phpgw_info']['user']; $_SESSION['phpgw_info']['expressomail']['server'] = $GLOBALS['phpgw_info']['server']; $expressoMail = CreateObject($current_app . '.imap_functions'); $mbox_stream = $expressoMail->open_mbox(False, false); if (!$mbox_stream) { $portalbox = CreateObject('phpgwapi.listbox', array('title' => "<font color=red>" . lang('Connection failed with %1 Server. Try later.', lang('Mail')) . "</font>", 'primary' => $GLOBALS['phpgw_info']['theme']['navbar_bg'], 'secondary' => $GLOBALS['phpgw_info']['theme']['navbar_bg'], 'tertiary' => $GLOBALS['phpgw_info']['theme']['navbar_bg'], 'width' => '100%', 'outerborderwidth' => '0', 'header_background_image' => $GLOBALS['phpgw']->common->image('phpgwapi/templates/phpgw_website', 'bg_filler'))); } else { $messages = imap_sort($mbox_stream, SORTARRIVAL, true, SE_UID, UNSEEN); $num_new_messages = count($messages); $subjects = array(); foreach ($messages as $idx => $message) { if ($idx == 10) { break; } $header = @imap_headerinfo($mbox_stream, imap_msgno($mbox_stream, $message), 80, 255); if (!is_object($header)) { return false; } $date_msg = date("d/m/Y", $header->udate); if (date("d/m/Y") == $date_msg) { $date = date("H:i", $header->udate); } else { $date = $date_msg;
public function getSortedMessages($path) { $result = array(); if ($mailbox = $this->openMailbox($path)) { if ($sortedMessages = imap_sort($mailbox, SORTDATE, 0, SE_UID)) { for ($i = 0; $i < count($sortedMessages); $i++) { if ($messages = imap_fetch_overview($mailbox, $sortedMessages[$i], FT_UID)) { if (!@$messages[$i]->deleted) { $result[] = new BrIMAPMailMessage($this, $path, $messages[0]); } } } } } return $result; }
/** * Gets mails ids sorted by some criteria * * Criteria can be one (and only one) of the following constants: * SORTDATE - mail Date * SORTARRIVAL - arrival date (default) * SORTFROM - mailbox in first From address * SORTSUBJECT - mail subject * SORTTO - mailbox in first To address * SORTCC - mailbox in first cc address * SORTSIZE - size of mail in octets * * @param int $criteria * @param bool $reverse * @return array Mails ids */ public function sortMails($criteria = SORTARRIVAL, $reverse = true) { return imap_sort($this->getImapStream(), $criteria, $reverse, SE_UID); }
/** * Function to delete messages in a mailbox, based on date * NOTE: this is global ... will affect all mailboxes except any that have 'sent' in the mailbox name */ public function globalDelete() { $dateArr = split('-', $this->deleteMsgDate); // date format is yyyy-mm-dd $delDate = mktime(0, 0, 0, $dateArr[1], $dateArr[2], $dateArr[0]); $port = $this->port . '/' . $this->service . '/' . $this->serviceOption; $mboxt = imap_open('{' . $this->mailhost . ":" . $port . '}', $this->mailboxUserName, $this->mailboxPassword, OP_HALFOPEN); $list = imap_getmailboxes($mboxt, '{' . $this->mailhost . ":" . $port . '}', "*"); $mailboxFound = false; if (is_array($list)) { foreach ($list as $key => $val) { // get the mailbox name only $nameArr = split('}', imap_utf7_decode($val->name)); $nameRaw = $nameArr[count($nameArr) - 1]; if (!stristr($nameRaw, 'sent')) { $mboxd = imap_open('{' . $this->mailhost . ":" . $port . '}' . $nameRaw, $this->mailboxUserName, $this->mailboxPassword, CL_EXPUNGE); $messages = imap_sort($mboxd, SORTDATE, 0); $i = 0; $check = imap_mailboxmsginfo($mboxd); foreach ($messages as $message) { $header = imap_header($mboxd, $message); $fdate = date("F j, Y", $header->udate); // purge if prior to global delete date if ($header->udate < $delDate) { imap_delete($mboxd, $message); } $i++; } imap_expunge($mboxd); imap_close($mboxd); } } } }
/** * Returns the emails in the current mailbox as an array of ImapMessage objects * ordered by some ordering * * @see http://php.net/manual/en/function.imap-sort.php * @param int $orderBy * @param bool $reverse * @param int $limit * @return Message[] */ public function getOrderedMessages($orderBy, $reverse, $limit) { $msgIds = imap_sort($this->getImapStream(), $orderBy, $reverse ? 1 : 0, SE_UID); return array_map(array($this, 'getMessageByUid'), array_slice($msgIds, 0, $limit)); }
function sort($stream, $criteria, $reverse = '', $options = '', $msg_info = '') { return imap_sort($stream, $criteria, $reverse, $options); }
/** * Recuperation UID * * @param int $sort SORTDATE | SORTARRIVAL |.. * @return void **/ public function getMessageNumbers(SearchExpression $search = null, $sort = \SORTARRIVAL, $reverse = false, $charset = null) { $this->init(); $query = $search ? (string) $search : 'ALL'; $messageNumbers = imap_sort($this->connection->getResource(), $sort, (int) $reverse, \SE_UID | \SE_NOPREFETCH, $query, $charset); if (false == $messageNumbers) { // imap_search can also return false $messageNumbers = array(); } return $messageNumbers; }
public function sort($mode, $reverse = 0) { return imap_sort($this->_mailbox_link, $mode, $reverse, SE_UID); }
function sort($stream, $criteria, $reverse = '', $flags = 0) { // do we force use of msg UID's if ($this->force_msg_uids == True && !($flags & SE_UID)) { $flags |= SE_UID; } return imap_sort($stream, $criteria, $reverse, $flags); }
print "[\n"; sort($folders); // rsk kyll, aga inbox peaks ju ikka ja alati olema esimene ja mitte teisiti foreach ($folders as $folder) { $realname = substr($folder, strlen($server)); $caption = get_folder_caption($realname); $status = imap_status($mbox, $folder, SA_ALL); // dunno, sometimes that shit is in the folder name $caption = str_replace(chr(0), "", $caption); printf("{'type': 'mbox', 'caption': '%s', 'name': '%s', 'total': %d, 'unread': %d},\n", $caption, $realname, $status->messages, $status->unseen); } print "];"; } else { $msgpage = isset($_POST["msgpage"]) ? $_POST["msgpage"] : 0; $onpage = 50; $fo = imap_sort($mbox, SORTARRIVAL, 1, SE_UID && SE_NOPREFETCH); $_from = $msgpage * $onpage; $interesting = array_slice($fo, $_from, $onpage); $msgids = array(); print "[\n"; $flagsonly = array(); // asterisk is used as a separator for msgids //$_POST["msgids"] = "333*334*335*29330*29316"; //$_POST["msgids"] = "333*334*335*29330"; //$_POST["msgids"] = "333*334*335*"; //$_POST["msgids"] = "333*334*335*29469"; if (!empty($_REQUEST["msgids"])) { $msgstr = $_REQUEST["msgids"]; // cut the last char if it's a separator, this simplifies things later. // why is it at the end anyway? because that makes client side code easier. if ("," == substr($msgstr, -1)) {
$path = "INBOX"; //$imap_search ='SUBJECT "SMS from"'; $hostname = "{" . $MAIL_HOST . ":" . $MAIL_PORT . "/" . strtolower($MAIL_TYPE) . "/ssl/novalidate-cert}"; // $hostname = "{".$MAIL_HOST.":".$MAIL_PORT."}$path"; //$hostname = '{imap.gmail.com:993/imap/ssl}INBOX'; /* try to connect */ $USERNAME = substr($EMAIL, 0, strpos($EMAIL, "@")); if ($DEBUG) { logEntry("Username extracted from email: " . $USERNAME); } $mbox = imap_open($hostname, $USERNAME, $PASSWORD) or die('Cannot connect to Imap Server: ' . imap_last_error()); $imap_search = "ALL"; } //Message body Format: $messageFormat = 1.1; $sorted_mbox = imap_sort($mbox, SORTARRIVAL, 1); $totalrows = imap_num_msg($mbox); logEntry("total mesages: " . $totalrows); $emails = imap_search($mbox, $imap_search); //$emails = imap_search($mbox,'SUBJECT "SMS from"'); //$emails = imap_search($mbox,'ALL'); //$emails = imap_search($mbox,'UNSEEN'); // $emails = imap_search($inbox,'ALL', SE_UID); if ($emails) { if ($DEBUG) { logEntry("got emails"); } /* begin output var */ $output = ''; /* put the newest emails on top */ //rsort($emails);
$db->query($sql);*/ } } define('IN_NEWSLETTER', true); define('WA_ROOTDIR', '..'); require WA_ROOTDIR . '/start.php'; $process = false; foreach ($_SERVER['argv'] as $arg) { if ($arg == '--process' || $arg == 'process=true') { $process = true; } } if ($process == true) { if (extension_loaded('imap')) { $cid = imap_open("\\{{$pop_server}:{$pop_port}/service=pop3}INBOX", $pop_user, $pop_passwd); $mail_box = imap_sort($cid, SORTDATE, 1); foreach ($mail_box as $mail_id) { $email = imap_fetchstructure($cid, $mail_id); if ($email->type == TYPEMULTIPART && isset($email->parts[1]) && $email->parts[1]->type == TYPEMESSAGE && $email->parts[1]->ifsubtype == true && $email->parts[1]->subtype == 'DELIVERY-STATUS') { $body = imap_fetchbody($cid, $mail_id, 2, FT_PEEK); plain_error($body); $deleted_mails[] = process_bounce($body); // // On supprime l'email maintenant devenu inutile // //imap_delete($cid, $mail_id); } } imap_close($cid, CL_EXPUNGE); } else { require 'Mail/mimeDecode.php';
<?php $emailAddress = '*****@*****.**'; $password = '******'; $server = 'localhost'; $folder = 'Inbox'; $dsn = sprintf('{%s}%s', $server, $folder); $mbox = imap_open($dsn, $emailAddress, $password); if (!$mbox) { die('Unable to connect'); } $status = imap_status($mbox, $dsn, SA_ALL); $msgs = imap_sort($mbox, SORTDATE, 1, SE_UID); foreach ($msgs as $msguid) { $msgno = imap_msgno($mbox, $msguid); $headers = imap_headerinfo($mbox, $msgno); $structure = imap_fetchstructure($mbox, $msguid, FT_UID); var_dump($headers); var_dump($structure); }
/** * Returns the sorted results * @param string|array $criteria * @param int $sortBy * @param bool $reverse * @param int $options * @return array */ public function sort($criteria, $sortBy, $reverse, $options = 0) { return imap_sort($this->connection->getConnection(), $sortBy, $reverse, $options, $criteria); }
function searchSieveRule($params) { $imap = $this->open_mbox($params['folder']['criteria'] ? $params['folder']['criteria'] : 'INBOX'); $msgs = imap_sort($imap, SORTDATE, 0, SE_UID); $rr = array(); if (isset($params['from'])) { $rr['from'] = array(); } if (isset($params['to'])) { $rr['to'] = array(); } if (isset($params['subject'])) { $rr['subject'] = array(); } if (isset($params['body'])) { $rr['body'] = array(); } if (isset($params['size'])) { $rr['size'] = array(); } //$params['search'] = mb_convert_encoding($params['search'], 'UTF-8',mb_detect_encoding($params['search'].'x', 'UTF-8, ISO-8859-1')); foreach ($msgs as $i => $v) { $msg = imap_headerinfo($imap, imap_msgno($imap, $v)); if (isset($params['from'])) { $from['from'] = array(); $from['from']['name'] = $this->decode_string($msg->from[0]->personal); $from['from']['email'] = $this->decode_string($msg->from[0]->mailbox . "@" . $msg->from[0]->host); if ($from['from']['name']) { if (substr($from['from']['name'], 0, 1) == '"') { $from['from']['full'] = $from['from']['name'] . ' ' . '<' . $from['from']['email'] . '>'; } else { $from['from']['full'] = '"' . $from['from']['name'] . '" ' . '<' . $from['from']['email'] . '>'; } } else { $from['from']['full'] = $from['from']['email']; } if ($this->filterCheck($from['from']['full'], $params['from']['criteria'], $params['from']['filter'])) { $rr['from'][] = $v; } } if (isset($params['to'])) { $tos = $msg->to; $val = ''; foreach ($tos as $to) { $tmp = imap_mime_header_decode($to->personal); $val .= '"' . $tmp[0]->text . '" ' . '<' . $to->mailbox . "@" . $to->host . '>'; } if ($this->filterCheck($val, $params['to']['criteria'], $params['to']['filter'])) { $rr['to'][] = $v; } $tos = $msg->cc; $val = ''; foreach ($tos as $to) { $tmp = imap_mime_header_decode($to->personal); $val .= '"' . $tmp[0]->text . '" ' . '<' . $to->mailbox . "@" . $to->host . '>'; } if ($this->filterCheck($val, $params['to']['criteria'], $params['to']['filter'])) { $rr['to'][] = $v; } } if (isset($params['subject'])) { $ss = ''; $subject = imap_mime_header_decode($msg->subject); foreach ($subject as $tmp) { $ss .= $tmp->charset == "default" ? $tmp->text : utf8_encode($tmp->text); } if ($this->filterCheck($ss, $params['subject']['criteria'], $params['subject']['filter'])) { $rr['subject'][] = $v; } } if (isset($params['body'])) { $this->mbox = $this->open_mbox($params['folder']['criteria'] ? $params['folder']['criteria'] : 'INBOX'); $b = $this->get_body_msg($v, $params['folder']['criteria'] ? $params['folder']['criteria'] : 'INBOX'); if ($this->filterCheck(mb_convert_encoding(html_entity_decode($b['body']), 'UTF-8', mb_detect_encoding(html_entity_decode($b['body']) . 'x', 'UTF-8, ISO-8859-1')), $params['body']['criteria'], $params['body']['filter'])) { $rr['body'][] = $v; } unset($b); } if (isset($params['size'])) { if ($this->filterCheck($msg->Size, $params['size']['criteria'], $params['size']['filter'])) { $rr['size'][] = $v; } } } $rrr = array(); $init = true; foreach ($rr as $i => $v) { if (count($rrr) == 0 && $init === true) { $rrr = $v; } else { if ($params['isExact'] == 'yes') { $rrr = array_intersect($rrr, $v); } else { $rrr = array_unique(array_merge($rrr, $v)); } } } // if($params['page'] && $params['rows']) // { // // $end = ( $params['rows'] * $params['page'] ); // $ini = $end - $params['rows'] ; // // //Pegando os do range da paginação // $k = -1; // $r = array(); // foreach ($rrr as $v) // { // ++$k; // if( $k < $ini || $k >= $end ) continue; // $r[] = $v; // } // ////////////////////////////////////// // } // else $r = $rrr; return $r; }
</script> <style type="text/css" media="screen">@import "css/basic.css";</style> <style type="text/css" media="screen">@import "css/tabs.css";</style> </head> <body> <? include('config.inc.php'); if($config['check_bounces']) { $mbox = imap_open("{localhost:143}", $config[bounce_mailbox], $config[bounce_password]); $headers = imap_sort($mbox,SORTDATE,1); while (list ($key, $val) = each ($headers)) { $body = imap_body ($mbox, $val); preg_match("/[A-z0-9][\w.-]*@[A-z0-9][\w\-\.]+\.[A-z0-9]{2,6}/i",$body,$matches); $bounce_query = "UPDATE mailinglist_subscribers SET bounce_count = bounce_count + 1 WHERE address = '$matches[0]'"; $bounce_result = mysql_query($bounce_query) or die("Query failed : " . mysql_error()); imap_delete($mbox,$val); } imap_expunge($mbox); imap_close($mbox); }
/** * undocumented function * * @return void * @author gwoo */ public function read(&$model, $queryData = array(), $recursive = null) { $queryData = $this->__scrubQueryData($queryData); if ($this->connected) { $mc = imap_check($this->connection); $mc = min($mc->Nmsgs, $queryData['limit']); if (!isset($queryData['options'])) { $queryData['options'] = 0; } if (!isset($queryData['search'])) { $queryData['search'] = null; } $imapOrder = array(); list($imapOrder['criteria'], $imapOrder['reverse']) = $this->_imapOrderFormat($queryData['order']); $resultSet = imap_sort($this->connection, $imapOrder['criteria'], $imapOrder['reverse'], $queryData['options'], $queryData['search'], $this->charset); $result = array(); for ($i = 0; $i < $mc; $i++) { $result_tmp = imap_fetch_overview($this->connection, $resultSet[$i]); $result[] = $result_tmp[0]; } $result = $this->_imapFormat($model, $queryData, $result); return $result; } else { return false; } return $resultSet; }
public function fetchAll() { return imap_sort($this->connection, SORTARRIVAL, 0); }
/** * read data * * this is the main method that reads data from the datasource and * formats it according to the request from the model. * * @param mixed $model the model that is requesting data * @param mixed $query the qurey that was sent * * @return the data requested by the model */ public function read($Model, $query) { if (!$this->connect($Model, $query)) { return $this->err($Model, 'Cannot connect to server'); } $searchCriteria = $this->_makeSearch($Model, $query); $uids = $this->_uidsByCriteria($searchCriteria); if ($uids === false) { // Perform Search & Order. Returns list of ids list($orderReverse, $orderCriteria) = $this->_makeOrder($Model, $query); $uids = imap_sort($this->Stream, $orderCriteria, $orderReverse, SE_UID, join(' ', $searchCriteria)); } // Nothing was found if (empty($uids)) { return array(); } // Trim resulting ids based on pagination / limitation if (@$query['start'] && @$query['end']) { $uids = array_slice($uids, @$query['start'], @$query['end'] - @$query['start']); } elseif (@$query['limit']) { $uids = array_slice($uids, @$query['start'] ? @$query['start'] : 0, @$query['limit']); } elseif ($Model->findQueryType === 'first') { $uids = array_slice($uids, 0, 1); } // Format output depending on findQueryType if ($Model->findQueryType === 'list') { return $uids; } else { if ($Model->findQueryType === 'count') { return array(array($Model->alias => array('count' => count($uids)))); } else { if ($Model->findQueryType === 'all' || $Model->findQueryType === 'first') { $attachments = @$query['recursive'] > 0; $mails = array(); foreach ($uids as $uid) { if ($mail = $this->_getFormattedMail($Model, $uid, $attachments)) { $mails[] = $mail; } } return $mails; } } } return $this->err($Model, 'Unknown find type %s for query %s', $Model->findQueryType, $query); }
function board_sync_run($pLog = FALSE) { global $gBitUser, $gBitSystem; $gBitUser->setPermissionOverride('p_users_bypass_captcha', TRUE); $connectionString = '{' . $gBitSystem->getConfig('boards_sync_mail_server', 'imap') . ':' . $gBitSystem->getConfig('boards_sync_mail_port', '993') . '/' . $gBitSystem->getConfig('boards_sync_mail_protocol', 'imap') . '/ssl/novalidate-cert}'; // Can we open the mailbox? if ($mbox = imap_open($connectionString, $gBitSystem->getConfig('boards_sync_user'), $gBitSystem->getConfig('boards_sync_password'))) { $MC = imap_check($mbox); // Fetch an overview for all messages in INBOX of mailbox has messages if ($MC->Nmsgs) { // print($MC->Nmsgs); $result = imap_fetch_overview($mbox, "1:{$MC->Nmsgs}", 0); if ($messageNumbers = imap_sort($mbox, SORTDATE, 0)) { foreach ($messageNumbers as $msgNum) { if ($pLog) { print "Processing Msg#: " . $msgNum . "\n"; } $deleteMsg = FALSE; $header = imap_headerinfo($mbox, $msgNum); // Is this a moderation message? if (preg_match('/.*? post from .*? requires approval/', $header->subject)) { if ($pLog) { print "Is Moderation Request.\n"; } // moderated messages nest the orginal message in another part // php imap functions dont give us easy access to part header info, so... // to easily get to the headers of those message we open the part as a new imap stream // fetch the original message $body = imap_fetchbody($mbox, $msgNum, 2); // add a spoof time marker to the first line to make imap_open happy $body = "From dummy@localhost Sat Jan 1 00:00:00 1970\n" . $body; // write the org msg to a temp file $filename = 'orginal_email.eml'; srand(time()); $filestore = TEMP_PKG_PATH . BOARDS_PKG_NAME . '/boardsync/' . rand(999, 999999999) . '/' . $filename; mkdir_p(dirname($filestore)); $fp = fopen($filestore, "w+"); fwrite($fp, $body); fclose($fp); // open the temp file as an imap stream so we can use imap_headerinfo() to parse the org msg header $mbox2 = imap_open($filestore, "", ""); $msgHeader = imap_headerinfo($mbox2, 1); // moderation validation is also in a part, extract it $replyBody = imap_fetchbody($mbox, $msgNum, 3); $replyHeaders = board_sync_raw_headers($replyBody); $approveSubj = board_sync_get_header('Subject', $replyHeaders); $confirmCode = substr($approveSubj, strlen('confirm ')); if ($pLog) { print "Confirm code: " . $confirmCode . "\n"; } $deliveredTo = board_sync_delivered_to($replyHeaders); $deleteMsg = board_sync_process_message($mbox, $msgNum, $msgHeader, imap_fetchstructure($mbox, $msgNum, 2), $confirmCode, $pLog, $deliveredTo); // Is this a reminder message that we just skip? } elseif (preg_match('/[0-9]+ .*? moderator request.* waiting/', $header->subject)) { if ($pLog) { print "Deleting reminder.\n"; } $deleteMsg = TRUE; } elseif (preg_match('/Welcome to the .* mailing list/', $header->subject)) { if ($pLog) { print "Deleting welcome message.\n"; } $deleteMsg = TRUE; } else { // imap_headerinfo acts retarded on these emails and improperly parses the header unless we call fetchstructure first - so do it. // note this problem does not occure above when parsing the temp email in a moderated msg - god damn spooky $msgStructure = imap_fetchstructure($mbox, $msgNum); $msgHeader = imap_headerinfo($mbox, $msgNum); // With multiple To: recipients it is often handy to know who the message is "Delivered-To" by the MTA $raw_headers = imap_fetchheader($mbox, $msgNum); $deliveredTo = board_sync_delivered_to($raw_headers); $deleteMsg = board_sync_process_message($mbox, $msgNum, $msgHeader, $msgStructure, FALSE, $pLog, $deliveredTo); // vd($deleteMsg); } if ($deleteMsg && empty($gDebug) && empty($gArgs['test'])) { // vd("DELETE!"); if ($pLog) { print "Deleted msg {$msgNum}\n"; } imap_delete($mbox, $msgNum); } } } } // final cleanup imap_expunge($mbox); imap_close($mbox); // clear everything we've written to the temp directory $dir = TEMP_PKG_PATH . BOARDS_PKG_NAME . '/boardsync'; if (is_dir($dir) && strpos($dir, BIT_ROOT_PATH) === 0) { if (!unlink_r($dir)) { bit_error_log("Failed to clear directory: " . $dir . " in boards package mailinglist synchronization."); } } } else { bit_error_log(__FILE__ . " failed imap_open {$connectionString} " . imap_last_error()); } }
/* Receve Mail */ <?php $user = "******"; $pass = "******"; $host = "{yb-in-f108.1e100.net:993/ssl/novalidate-cert}INBOX"; $mailboxes = imap_list($connection, $host, '*'); if ($mbox = imap_open($host, $user, $pass, NULL, 1)) { $sorted_mbox = imap_sort($mbox, SORTDATE, 0); $totalrows = imap_num_msg($mbox); $invoce = $totalrows * 6; $imap_obj = imap_check($mbox); $row10 = $totalrows - 50; if ($totalrows < 50) { $sort = "1:{$imap_obj->Nmsgs}"; } else { $sort = $totalrows . ":" . $row10; } $result = imap_fetch_overview($mbox, $sort, 0); usort($result, function ($a, $b) { return $b->udate - $a->udate; }); $email = imap_search($mbox, 'UNSEEN'); foreach ($result as $overview) { $start = "{$overview->date}"; $newdate = date("F j, Y, g:i a", strtotime($start)); $from = "{$overview->from}"; $mail_id = "{$overview->msgno}"; $subject = "{$overview->subject}"; if ($email) {
/** * Function to delete messages in a mailbox, based on date * * NOTE: this is global ... will affect all mailboxes except any that have 'sent' in the mailbox name */ public function globalDelete() { $dateArr = explode('-', $this->deleteMsgDate); // date format is yyyy-mm-dd $delDate = mktime(0, 0, 0, $dateArr[1], $dateArr[2], $dateArr[0]); $port = $this->port . '/' . $this->service . '/' . $this->serviceOption; $mboxt = imap_open('{' . $this->mailhost . ':' . $port . '}', $this->mailboxUserName, $this->mailboxPassword, OP_HALFOPEN); if ($mboxt === false) { return false; } $list = imap_getmailboxes($mboxt, '{' . $this->mailhost . ':' . $port . '}', '*'); if (is_array($list)) { foreach ($list as $key => $val) { // get the mailbox name only $nameArr = explode('}', imap_utf7_decode($val->name)); $nameRaw = $nameArr[count($nameArr) - 1]; if (false === stripos($nameRaw, 'sent')) { $mboxd = imap_open('{' . $this->mailhost . ':' . $port . '}' . $nameRaw, $this->mailboxUserName, $this->mailboxPassword, CL_EXPUNGE); $messages = imap_sort($mboxd, SORTDATE, 0); $i = 0; foreach ($messages as $message) { $header = imap_header($mboxd, $message); // purge if prior to global delete date if ($header->udate < $delDate) { imap_delete($mboxd, $message); } $i++; } imap_expunge($mboxd); imap_close($mboxd); } } imap_close($mboxt); return true; } else { imap_close($mboxt); return false; } }