示例#1
1
 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'));
 }
 private function checkProcessedFolder($mailbox)
 {
     $list = imap_getmailboxes($mailbox, '{' . $this->host . '}', $this->processedFolder);
     if (count($list) == 0) {
         throw new \Exception("You need to create imap folder '{$this->processedFolder}'");
     }
 }
示例#3
0
 public function saveGmailDetails($parameters)
 {
     $username = $parameters["gmailusername"];
     $password = $parameters["gmailpassword"];
     $userid = $_SESSION["userid"];
     try {
         $inbox = $this->getImapConnection($username, $password, "INBOX");
     } catch (Exception $e) {
         error_log("Errror Caugt!!!");
         return self::$responder->constructErrorResponse("I could not connect to Gmail. Make sure your login details are correct.");
     }
     try {
         self::$gmailDAO->saveGmailDetails($userid, $username, $password);
     } catch (Exception $e) {
     }
     $folderList = array();
     $emailFolderList = imap_getmailboxes($inbox, self::INBOX, "*");
     error_log("list size: " . sizeof($emailFolderList));
     if (is_array($emailFolderList)) {
         $count = 0;
         foreach ($emailFolderList as $key => $val) {
             $temp = imap_utf7_decode($val->name);
             $folder = str_replace(self::INBOX, "", $temp);
             if (!strstr($folder, "[Gmail]")) {
                 $folderList["folder" . ++$count] = $folder;
             }
         }
     } else {
         return self::$responder->constructErrorResponse("Could not get the list of folder from your account, please try again.");
     }
     imap_close($inbox);
     return self::$responder->constructResponseForKeyValue(array_reverse($folderList));
 }
 /**
  * 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;
 }
示例#5
0
 public function getMailboxes($server, $str = "*")
 {
     $boxes = array();
     foreach (imap_getmailboxes($this->mbox, $server, $str) as $box) {
         $boxes[] = new Mailbox($box);
     }
     return $boxes;
 }
function getServerDelimiter()
{
    $list = @imap_getmailboxes($mbox, $server, "*");
    if (is_array($list) && count($list) > 0) {
        // get the delimiter from the first folder
        $delimiter = $list[0]->delimiter;
    } else {
        // default
        $delimiter = ".";
    }
    return $delimiter;
}
示例#7
0
 public function getMailboxes()
 {
     if (empty($this->mailboxes)) {
         $mailboxes = imap_getmailboxes($this->connection, $this->resource, '*');
         foreach ($mailboxes as $item) {
             preg_match('#\\{(.*)\\}(.*)#', $item->name, $name);
             $mailbox = $name[0];
             $name = $name[2];
             $this->mailboxes[$name] = new Mailbox($this, $mailbox, $name);
         }
     }
     return $this->mailboxes;
 }
示例#8
0
 /**
  * Vrati pole vsetkych najdenych mailboxov na emailovom konte
  *
  * @return array
  * @throws Exception
  */
 public function getFolders()
 {
     $mbox = $this->openMailServerConnection();
     $result = array();
     $boxes = imap_getmailboxes($mbox, '{' . IMAP_HOST . '}', '*');
     if (is_array($boxes)) {
         foreach ($boxes as $key => $val) {
             $result[$key]['name'] = str_replace('{' . IMAP_HOST . '}', '', imap_utf7_decode($val->name));
             $result[$key]['delimiter'] = $val->delimiter;
             $result[$key]['attribs'] = $val->attributes;
             $Status = imap_status($mbox, $val->name, SA_ALL);
             $result[$key]['msgNum'] = $Status->messages;
             $result[$key]['newNum'] = isset($Status->recent) ? $Status->recent : 0;
             $result[$key]['unreadNum'] = isset($Status->unseen) ? $Status->unseen : 0;
         }
     } else {
         Logger::error("imap_getmailboxes() failed: " . imap_last_error());
     }
     //        imap_close($mbox);
     return $result;
 }
 /**
  * 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);
             }
         }
     }
 }
示例#10
0
 /**
  * Reads mail box folders
  * @param string $ref Optional -
  */
 public function folders($ref = "{folder}")
 {
     if ($this->mFolders) {
         return $this->mFolders;
     }
     $result = imap_getmailboxes($this->mBox, $ref, "*");
     if ($this->isError()) {
         return false;
     }
     $folders = array();
     foreach ($result as $row) {
         $folderName = str_replace($ref, "", $row->name);
         $folder = $this->convertCharacterEncoding($folderName, "UTF-8", "UTF7-IMAP");
         //Decode folder name
         $folders[] = $this->folderInstance($folder);
     }
     $this->mFolders = $folders;
     return $folders;
 }
示例#11
0
 /**
  * Reads mail box folders
  * @param string $ref Optional - 
  */
 function folders($ref = "{folder}")
 {
     if ($this->mFolders) {
         return $this->mFolders;
     }
     $result = imap_getmailboxes($this->mBox, $ref, "*");
     if ($this->isError()) {
         return false;
     }
     $folders = array();
     foreach ($result as $row) {
         $folders[] = $this->folderInstance(str_replace($ref, "", $row->name));
     }
     $this->mFolders = $folders;
     return $folders;
 }
示例#12
0
文件: Server.php 项目: kamaroly/Fetch
 /**
  * Return information about the mailbox or mailboxes
  *
  * @param $mailbox
  *
  * @return array
  */
 public function getMailBoxDetails($mailbox)
 {
     return imap_getmailboxes($this->getImapStream(), $this->getServerString(), $this->getServerSpecification() . $mailbox);
 }
示例#13
0
 protected function getMailBoxList()
 {
     if (!is_null($this->mailboxList)) {
         return $this->mailboxList;
     }
     $mailboxes = imap_getmailboxes($this->resource, $this->server, '*');
     $this->mailboxList = array();
     foreach ($mailboxes as $mailbox) {
         $name = str_replace($this->server, '', $mailbox->name);
         $this->mailboxList[$name] = $mailbox;
     }
     return $this->mailboxList;
 }
示例#14
0
文件: lib.php 项目: Rikisha/proj
 /**
  * Function to check if a mailbox exists
  * - if not found, it will create it
  * @param string  $mailbox        (the mailbox name, must be in 'INBOX.checkmailbox' format)
  * @param boolean $create         (whether or not to create the checkmailbox if not found, defaults to true)
  * @return boolean
  */
 function isMailboxExist($mailbox)
 {
     if (trim($mailbox) == '' || !strstr($mailbox, 'INBOX.')) {
         // this is a critical error with either the mailbox name blank or an invalid mailbox name
         // need to stop processing and exit at this point
         //echo "Invalid mailbox name for move operation. Cannot continue.<br />\n";
         //echo "TIP: the mailbox you want to move the message to must include 'INBOX.' at the start.<br />\n";
         return false;
     }
     $port = $this->port . '/' . $this->service . ($this->service_option != 'none' ? '/' . $this->service_option : '');
     $mbox = imap_open('{' . $this->mailhost . ":" . $port . '}', $this->mailbox_username, $this->mailbox_password, OP_HALFOPEN);
     $list = imap_getmailboxes($mbox, '{' . $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 ($mailbox == $nameRaw) {
                 $mailboxFound = true;
             }
         }
         //      if ( ($mailboxFound === false) && $create ) {
         //        @imap_createmailbox($mbox, imap_utf7_encode('{'.$this->mailhost.":".$port.'}' . $mailbox));
         //        imap_close($mbox);
         //        return true;
         //      } else {
         //        imap_close($mbox);
         //        return false;
         //      }
     } else {
         imap_close($mbox);
         return false;
     }
 }
示例#15
0
 /**
  * Gets the folder list
  *
  * @access private
  * @return array
  */
 private function get_folder_list()
 {
     $folders = array();
     $list = @imap_getmailboxes($this->mbox, $this->server, "*");
     if (is_array($list)) {
         $list = array_reverse($list);
         foreach ($list as $l) {
             $folders[] = $l->name;
         }
     }
     return $folders;
 }
示例#16
0
 /**
  * Caches/returns cached results for child instances
  *
  * @return array
  */
 function listSources()
 {
     if ($this->cacheSources === false) {
         return null;
     }
     if ($this->_sources !== null) {
         return $this->_sources;
     }
     $sources = imap_getmailboxes($this->connection, "{{$config['host']}}", "*");
     $this->_sources = $sources;
     return $sources;
 }
示例#17
0
    		echo "<blockquote>".substr(str_replace("<", "&lt;", $thisBody), 0, 400)."</blockquote>";
    	
    	}
    	
    	echo "</blockquote>";
    */
}
die("protected");
//mysql_query("TRUNCATE TABLE winamp_emails");
//mysql_query("TRUNCATE TABLE winamp_email_bodies");
$mailboxRoot = '{64.15.252.17:143}';
$mailUsername = '******';
$mailPassword = '******';
// get mailboxes
$imap = imap_open($mailboxRoot, $mailUsername, $mailPassword, OP_HALFOPEN) or die("Can't connect: " . imap_last_error());
$mailboxes = imap_getmailboxes($imap, "{64.15.252.17:143}", "*");
imap_close($imap);
$total_added = 0;
$total_time = 0;
//go through each mailbox
if (is_array($mailboxes)) {
    foreach ($mailboxes as $key => $val) {
        $thisBox = imap_utf7_decode($val->name);
        $boxName = substr($thisBox, strlen($mailboxRoot));
        if ($boxName == "Inbox") {
            $startTime = time();
            $imap = imap_open($mailboxRoot . $boxName, $mailUsername, $mailPassword) or die("Can't open {$boxName} box! " . imap_last_error());
            $added = 0;
            $num_msg = imap_num_msg($imap);
            //if ($num_msg > 40) $num_msg = 40;
            // go through each message
示例#18
0
            $output .= sprintf("<input size=40 type=text name=subject value=\"%s\" />", $subject);
            $output .= "<hr />";
            $msgBody = get_body($mb, $_REQUEST['num'], False);
            if (strstr(strtolower($msgBody), "<html>") !== False) {
                $msgBody .= "<html>\n\n\n<hr />";
            } else {
                $msgBody = "\n\n\n>" . str_replace("\n", "\n>", $msgBody);
            }
            $output .= "<textarea name=body rows=10 cols=40>";
            $output .= $msgBody;
            $output .= "</textarea>";
            $output .= "<hr />";
            $output .= "<input type=submit name=send value=Send />";
            $output .= sprintf("<input type=hidden name=mbox value=\"%s\" />", $_REQUEST['mbox']);
            $output .= "</form>";
        } else {
            $folders = imap_getmailboxes($mb, $server, "*");
            $output .= "<a href=index.php?folder=INBOX>INBOX</a><br />";
            foreach ($folders as $f) {
                $name = substr($f->name, strlen($server));
                if ($name == "INBOX") {
                    continue;
                }
                $output .= sprintf("<a href=\"index.php?folder=%s\">%s</a><br />", $name, $name);
            }
        }
    }
}
$output .= "<hr />";
$output .= "<a href=index.php?logout=yes>Logout</a>";
echo $output;
示例#19
0
 function getServerDelimiter()
 {
     $list = @imap_getmailboxes($this->_mbox, $this->_server, "*");
     if (is_array($list)) {
         $val = $list[0];
         return $val->delimiter;
     }
     return ".";
     // default "."
 }
 function getFolderList($_subscribedOnly = false)
 {
     $folders = array();
     if (!is_resource($this->mbox)) {
         return $folders;
     }
     $mailboxString = ExecMethod('emailadmin.bo.getMailboxString', $this->imapBaseDir, 3, $this->profileID);
     if ($_subscribedOnly == 'true') {
         $list = imap_getsubscribed($this->mbox, $mailboxString, "*");
     } else {
         $list = imap_getmailboxes($this->mbox, $mailboxString, "*");
     }
     if (is_array($list)) {
         #_debug_array($list);
         reset($list);
         $folders = array();
         while (list($key, $val) = each($list)) {
             // remove the {host:port/imap/...} part
             $folderNameIMAP = $this->decodeFolderName(preg_replace("/{.*}/", '', $val->name));
             $folderParts = explode(".", $folderNameIMAP);
             reset($folderParts);
             $displayName = "";
             #print_r($folderParts);print"<br>";
             for ($i = 0; $i < count($folderParts); $i++) {
                 if ($i + 1 == count($folderParts)) {
                     $displayName .= $folderParts[$i];
                 } else {
                     $displayName .= ". . ";
                 }
             }
             $folders["{$folderNameIMAP}"] = $displayName;
         }
         #exit;
         ksort($folders, SORT_STRING);
         // return always the inbox
         $folders = array_merge(array('INBOX' => 'INBOX'), $folders);
         reset($folders);
         return $folders;
     } else {
         if ($_subscribedOnly == 'true' && is_array(imap_list($this->mbox, $mailboxString, 'INBOX'))) {
             $folders['INBOX'] = 'INBOX';
         }
         return $folders;
     }
 }
示例#21
0
 /**
  * Gets the folders matching the given pattern
  * @param $mailbox
  * @param $pattern
  * @return array
  */
 public function getFolders($mailbox, $pattern)
 {
     return imap_getmailboxes($this->connection->getConnection(), $mailbox, $pattern);
 }
示例#22
0
 public function dir_opendir($path, $options)
 {
     // Reset
     self::$attachmentsMetadata = null;
     $st = '';
     $stream = $this->stream_open($path, 'np', $options, $st);
     if (!$stream) {
         return false;
     }
     if (empty($this->mailbox)) {
         // We are browsing root, we want the list of mailboxes
         $this->mailboxes = imap_getmailboxes($this->ih, self::$currentRef, "*");
         $this->dir = count($this->mailboxes);
         self::$currentCount = count($this->mailboxes);
         $this->pos = $this->dir - 1;
     } else {
         if ($this->fragment == "attachments") {
             require_once AJXP_INSTALL_PATH . '/plugins/editor.eml/class.EmlParser.php';
             $parser = new EmlParser("", "");
             $ar = explode("#", $path);
             $path = array_shift($ar);
             // remove fragment
             self::$attachmentsMetadata = array();
             $parser->listAttachments($path, true, self::$attachmentsMetadata);
             $this->dir = count(self::$attachmentsMetadata);
             $this->pos = $this->dir - 1;
             self::$currentCount = $this->dir;
         } else {
             // We are in a mailbox, we want the messages number
             $this->dir = imap_num_msg($this->ih);
             self::$currentCount = $this->dir;
             $this->pos = $this->dir;
         }
     }
     $this->stream_close();
     return true;
 }
示例#23
0
文件: Connection.php 项目: Kofel/imap
 /**
  * Get mailbox names
  * 
  * @return array
  */
 private function getMailboxNames()
 {
     if (null === $this->mailboxNames) {
         $mailboxes = imap_getmailboxes($this->resource, $this->server, '*');
         foreach ($mailboxes as $mailbox) {
             $this->mailboxNames[] = imap_utf7_decode(str_replace($this->server, '', $mailbox->name));
         }
     }
     return $this->mailboxNames;
 }
示例#24
0
 /**
  * Checks if the given mailbox exists.
  *
  * @param $mailbox
  *
  * @return bool
  */
 public function hasMailBox($mailbox)
 {
     return (bool) imap_getmailboxes($this->getImapStream(), $this->getServerString(), $this->getServerSpecification() . $mailbox);
 }
示例#25
0
文件: IMAP.php 项目: edoceo/radix
 /**
 	@param $pat '*' for all folders, '%' for current folder and below
 	@return array of folder names
 */
 function pathList($pat = '*')
 {
     // $this->_open();
     $ret = array();
     $list = imap_getmailboxes($this->_c, $this->_c_host, $pat);
     foreach ($list as $x) {
         $ret[] = array('name' => $x->name, 'attribute' => $x->attributes, 'delimiter' => $x->delimiter);
     }
     return $ret;
 }
示例#26
0
文件: func.inc.php 项目: hggh/cpves
function list_imap_folders($imap_server, $email, $password, $stati)
{
    if (!function_exists('imap_open')) {
        die("CpVES needs PHP IMAP Support. Please install php-imap!");
    }
    $mbox = @imap_open("{" . $imap_server . ":143/imap/notls}", $email, $password);
    if (!$mbox) {
        return false;
    }
    $list = imap_getmailboxes($mbox, "{ffo}", "*");
    if (is_array($list)) {
        $imap_folders = array();
        sort($list);
        foreach ($list as $key => $val) {
            $trenner = $val->delimiter;
            $name = ereg_replace("{ffo}", "", $val->name);
            $folder = ereg_replace("{ffo}", "", $val->name);
            $name = ereg_replace("INBOX{$trenner}", "", $name);
            $name_display = mb_convert_encoding($name, "UTF-8", "UTF7-IMAP");
            $name_display = str_replace($trenner, "/", $name_display);
            if (!preg_match('/^drafts$/i', $name) && !preg_match("/^Trash{$trenner}/i", $name)) {
                if ($stati == 1) {
                    $status = imap_status($mbox, "{" . $imap_server . "}" . $folder, SA_ALL);
                    if ($status) {
                        $messages = $status->messages;
                        $unseen = $status->unseen;
                    } else {
                        $messages = 0;
                        $unseen = 0;
                    }
                }
                if (preg_match('/SPAM/i', $name) || preg_match('/JUNK/i', $name)) {
                    $type = "spam";
                } else {
                    if (preg_match('/^INBOX$/i', $name)) {
                        $type = "inbox";
                    } else {
                        $type = "normal";
                    }
                }
                array_push($imap_folders, array('name_display' => $name_display, 'name' => $name, 'type' => $type, 'messages' => $messages, 'unseen' => $unseen));
            }
            $type = "";
        }
        if (count($imap_folders) > 0) {
            return $imap_folders;
        } else {
            return false;
        }
    } else {
        return false;
    }
}
示例#27
0
function getImapFolders($server, $user, $password)
{
    #$port =  "993/imap/ssl/novalidate-cert";
    $port = "143/imap/notls";
    $mbox = @imap_open("{" . $server . ":" . $port . "}", $user, $password, OP_HALFOPEN);
    if (!$mbox) {
        Fatal_Error($GLOBALS['I18N']->get("can't connect") . ": " . imap_last_error());
        return 0;
    }
    $list = imap_getmailboxes($mbox, "{" . $server . "}", "*");
    if (is_array($list)) {
        return $list;
    } else {
        Fatal_Error($GLOBALS['I18N']->get("imap_getmailboxes failed") . ": " . imap_last_error() . "\n");
        return 0;
    }
    imap_close($mbox);
}
示例#28
0
    }
    flush();
    // MAIN LOOP
    // Main loop to create listview entries
}
$search_html = '<select name="optionSel" class="importBox" id="search_type">';
foreach ($search_fields as $searchfield) {
    if ($_REQUEST['search_type'] == $searchfield) {
        $search_html .= '<option selected value="' . $searchfield . '">' . $mod_strings["IN"] . ' ' . $mod_strings[$searchfield] . '</option>';
    } else {
        $search_html .= '<option value="' . $searchfield . '">' . $mod_strings["IN"] . ' ' . $mod_strings[$searchfield] . '</option>';
    }
}
$search_html .= '</select>';
// Build folder list and move_to dropdown box
$list = imap_getmailboxes($MailBox->mbox, "{" . $MailBox->imapServerAddress . "}", "*");
sort($list);
$i = 0;
if (is_array($list)) {
    $boxes = '<select name="mailbox" id="mailbox_select" onChange="move_messages();">';
    $boxes .= '<option value="move_to" SELECTED>' . $mod_strings['LBL_MOVE_TO'] . '</option>';
    foreach ($list as $key => $val) {
        $tmpval = preg_replace(array("/\\{.*?\\}/i"), array(""), $val->name);
        if (preg_match("/trash/i", $tmpval)) {
            $img = "webmail_trash.gif";
        } elseif ($_REQUEST["mailbox"] == $tmpval) {
            $img = "opened_folder.gif";
        } else {
            $img = "folder.gif";
        }
        $i++;
 /**
  * Programatically determines best-case settings for imap_open()
  */
 function findOptimumSettings($useSsl = false, $user = '', $pass = '', $server = '', $port = '', $prot = '', $mailbox = '')
 {
     global $mod_strings;
     $serviceArr = array();
     $returnService = array();
     $badService = array();
     $goodService = array();
     $errorArr = array();
     $raw = array();
     $retArray = array('good' => $goodService, 'bad' => $badService, 'err' => $errorArr);
     if (!function_exists('imap_open')) {
         $retArray['err'][0] = $mod_strings['ERR_NO_IMAP'];
         return $retArray;
     }
     imap_errors();
     // clearing error stack
     error_reporting(0);
     // turn off notices from IMAP
     if (isset($_REQUEST['ssl']) && $_REQUEST['ssl'] == 1) {
         $useSsl = true;
     }
     $exServ = explode('::', $this->service);
     $service = '/' . $exServ[1];
     $nonSsl = array('both-secure' => '/notls/novalidate-cert/secure', 'both' => '/notls/novalidate-cert', 'nocert-secure' => '/novalidate-cert/secure', 'nocert' => '/novalidate-cert', 'notls-secure' => '/notls/secure', 'secure' => '/secure', 'notls' => '/notls', 'none' => '');
     $ssl = array('ssl-both-on-secure' => '/ssl/tls/validate-cert/secure', 'ssl-both-on' => '/ssl/tls/validate-cert', 'ssl-cert-secure' => '/ssl/validate-cert/secure', 'ssl-cert' => '/ssl/validate-cert', 'ssl-tls-secure' => '/ssl/tls/secure', 'ssl-tls' => '/ssl/tls', 'ssl-both-off-secure' => '/ssl/notls/novalidate-cert/secure', 'ssl-both-off' => '/ssl/notls/novalidate-cert', 'ssl-nocert-secure' => '/ssl/novalidate-cert/secure', 'ssl-nocert' => '/ssl/novalidate-cert', 'ssl-notls-secure' => '/ssl/notls/secure', 'ssl-notls' => '/ssl/notls', 'ssl-secure' => '/ssl/secure', 'ssl-none' => '/ssl');
     if (isset($user) && !empty($user) && isset($pass) && !empty($pass)) {
         $this->email_password = $pass;
         $this->email_user = $user;
         $this->server_url = $server;
         $this->port = $port;
         $this->protocol = $prot;
         $this->mailbox = $mailbox;
     }
     // in case we flip from IMAP to POP3
     if ($this->protocol == 'pop3') {
         $this->mailbox = 'INBOX';
     }
     //If user has selected multiple mailboxes, we only need to test the first mailbox for the connection string.
     $a_mailbox = explode(",", $this->mailbox);
     $tmpMailbox = isset($a_mailbox[0]) ? $a_mailbox[0] : "";
     if ($useSsl == true) {
         foreach ($ssl as $k => $service) {
             $returnService[$k] = 'foo' . $service;
             $serviceArr[$k] = '{' . $this->server_url . ':' . $this->port . '/service=' . $this->protocol . $service . '}' . $tmpMailbox;
         }
     } else {
         foreach ($nonSsl as $k => $service) {
             $returnService[$k] = 'foo' . $service;
             $serviceArr[$k] = '{' . $this->server_url . ':' . $this->port . '/service=' . $this->protocol . $service . '}' . $tmpMailbox;
         }
     }
     $GLOBALS['log']->debug('---------------STARTING FINDOPTIMUMS LOOP----------------');
     $l = 1;
     //php imap library will capture c-client library warnings as errors causing good connections to be ignored.
     //Check against known warnings to ensure good connections are used.
     $acceptableWarnings = array("SECURITY PROBLEM: insecure server advertised AUTH=PLAIN", "Mailbox is empty");
     $login = $this->email_user;
     $passw = $this->email_password;
     $foundGoodConnection = false;
     foreach ($serviceArr as $k => $serviceTest) {
         $errors = '';
         $alerts = '';
         $GLOBALS['log']->debug($l . ': I-E testing string: ' . $serviceTest);
         // open the connection and try the test string
         $this->conn = imap_open($serviceTest, $login, $passw);
         if (($errors = imap_last_error()) || ($alerts = imap_alerts())) {
             if ($errors == 'Too many login failures' || $errors == '[CLOSED] IMAP connection broken (server response)') {
                 // login failure means don't bother trying the rest
                 $GLOBALS['log']->debug($l . ': I-E failed using [' . $serviceTest . ']');
                 $retArray['err'][$k] = $mod_strings['ERR_BAD_LOGIN_PASSWORD'];
                 $retArray['bad'][$k] = $serviceTest;
                 $GLOBALS['log']->debug($l . ': I-E ERROR: $ie->findOptimums() failed due to bad user credentials for user login: '******'log']->debug($l . ': I-E found good connection but with warnings [' . $serviceTest . '] Errors:' . $errors);
                 $retArray['good'][$k] = $returnService[$k];
                 $foundGoodConnection = true;
             } else {
                 $GLOBALS['log']->debug($l . ': I-E failed using [' . $serviceTest . '] - error: ' . $errors);
                 $retArray['err'][$k] = $errors;
                 $retArray['bad'][$k] = $serviceTest;
             }
         } else {
             $GLOBALS['log']->debug($l . ': I-E found good connect using [' . $serviceTest . ']');
             $retArray['good'][$k] = $returnService[$k];
             $foundGoodConnection = true;
         }
         if (is_resource($this->conn)) {
             if (!$this->isPop3Protocol()) {
                 $serviceTest = str_replace("INBOX", "", $serviceTest);
                 $boxes = imap_getmailboxes($this->conn, $serviceTest, "*");
                 $delimiter = '.';
                 // clean MBOX path names
                 foreach ($boxes as $k => $mbox) {
                     $raw[] = $mbox->name;
                     if ($mbox->delimiter) {
                         $delimiter = $mbox->delimiter;
                     }
                     // if
                 }
                 // foreach
                 $this->setSessionInboundDelimiterString($this->server_url, $this->email_user, $this->port, $this->protocol, $delimiter);
             }
             // if
             if (!imap_close($this->conn)) {
                 $GLOBALS['log']->debug('imap_close() failed!');
             }
         }
         $GLOBALS['log']->debug($l . ': I-E clearing error and alert stacks.');
         imap_errors();
         // clear stacks
         imap_alerts();
         // If you find a good connection, then don't do any further testing to find URL
         if ($foundGoodConnection) {
             break;
         }
         // if
         $l++;
     }
     $GLOBALS['log']->debug('---------------end FINDOPTIMUMS LOOP----------------');
     if (!empty($retArray['good'])) {
         $newTls = '';
         $newCert = '';
         $newSsl = '';
         $newNotls = '';
         $newNovalidate_cert = '';
         $good = array_pop($retArray['good']);
         // get most complete string
         $exGood = explode('/', $good);
         foreach ($exGood as $v) {
             switch ($v) {
                 case 'ssl':
                     $newSsl = 'ssl';
                     break;
                 case 'tls':
                     $newTls = 'tls';
                     break;
                 case 'notls':
                     $newNotls = 'notls';
                     break;
                 case 'cert':
                     $newCert = 'validate-cert';
                     break;
                 case 'novalidate-cert':
                     $newNovalidate_cert = 'novalidate-cert';
                     break;
                 case 'secure':
                     $secure = 'secure';
                     break;
             }
         }
         $goodStr['serial'] = $newTls . '::' . $newCert . '::' . $newSsl . '::' . $this->protocol . '::' . $newNovalidate_cert . '::' . $newNotls . '::' . $secure;
         $goodStr['service'] = $good;
         $testConnectString = str_replace('foo', '', $good);
         $testConnectString = '{' . $this->server_url . ':' . $this->port . '/service=' . $this->protocol . $testConnectString . '}';
         $this->setSessionConnectionString($this->server_url, $this->email_user, $this->port, $this->protocol, $goodStr);
         $i = 0;
         foreach ($raw as $mbox) {
             $raw[$i] = str_replace($testConnectString, "", $GLOBALS['locale']->translateCharset($mbox, "UTF7-IMAP", "UTF8"));
             $i++;
         }
         // foreach
         sort($raw);
         $this->setSessionInboundFoldersString($this->server_url, $this->email_user, $this->port, $this->protocol, implode(",", $raw));
         return $goodStr;
     } else {
         return false;
     }
 }
<?php

// $server = "{imap.example.org:993/ssl/novalidate-cert}";
// $username = "******";
// $password = "******";
$mbox = imap_open($server, $username, $password, OP_HALFOPEN) or die("unable to connect: " . imap_last_error());
$list = imap_getmailboxes($mbox, $server, "*");
if (is_array($list)) {
    foreach ($list as $val) {
        echo imap_utf7_decode($val->name) . "\n";
    }
} else {
    echo "imap_list failed: " . imap_last_error() . "\n";
}
imap_close($mbox);