/**
  * Connect to an IMAP inbox.
  *
  * @return resource|bool The IMAP resource on success. Boolean false on failure.
  */
 protected function connect()
 {
     // stop if IMAP module does not exist
     if (!function_exists('imap_open')) {
         return false;
     }
     $mailbox = $this->get_mailbox();
     //
     if ($this->is_reconnection()) {
         // if PHP is 5.2+, use extra parameter to only try connecting once
         if (!empty($this->args['retries']) && version_compare(PHP_VERSION, '5.2.0') >= 0) {
             $resource = imap_reopen($this->connection, $mailbox, 0, (int) $this->args['retries']);
             // PHP is older, so use the default retry value of 3
         } else {
             $resource = imap_reopen($this->connection, $mailbox);
         }
     } else {
         // if PHP is 5.2+, use extra parameter to only try connecting once
         if (!empty($this->args['retries']) && version_compare(PHP_VERSION, '5.2.0') >= 0) {
             $resource = imap_open($mailbox, $this->args['username'], $this->args['password'], 0, (int) $this->args['retries']);
             // PHP is older, so use the default retry value of 3
         } else {
             $resource = imap_open($mailbox, $this->args['username'], $this->args['password']);
         }
     }
     return $resource;
 }
Ejemplo n.º 2
0
 /**
  * select given folder
  *
  * @return bool successfull opened folder
  * @param $folder name
  */
 public function selectFolder($folder)
 {
     $result = imap_reopen($this->imap, $this->mailbox . $folder);
     if ($result === true) {
         $this->folder = $folder;
     }
     return $result;
 }
Ejemplo n.º 3
0
 /**
  * Open a connection with the defined server.
  *
  * @return <bool> true/false according to success
  */
 public function connect()
 {
     //TODO: in the future, we can add an option for POP3 access as well
     $success = true;
     $mailbox_str = '{' . $this->hostname . ':' . $this->port . $this->options . '}';
     if ($this->connection == null) {
         $this->connection = @imap_open($mailbox_str, $this->username, $this->password);
         $success = $this->connection != null && $this->connection != false;
     } else {
         //reopen with a new mailbox name
         $success = imap_reopen($this->connection, $mailbox_str);
     }
     return $success;
 }
Ejemplo n.º 4
0
 function open_mailbox($folder = "", $ops = OP_HALFOPEN, $fatal = true)
 {
     if ($this->connection && is_resource($this->connection)) {
         imap_close($this->connection);
     }
     $this->connect_string = '{' . $this->host . ':' . $this->port . '/' . $this->protocol . config::get_config_item("allocEmailExtra") . '}';
     $this->connection = imap_open($this->connect_string, $this->username, $this->password, $ops);
     if (!$this->connection && $fatal) {
         alloc_error("Unable to access mail folder(1).");
     }
     $list = imap_list($this->connection, $this->connect_string, "*");
     if (!is_array($list) || !count($list)) {
         // || !in_array($connect_string.$folder,$list)) {
         $this->unlock();
         imap_close($this->connection);
         if ($fatal) {
             alloc_error("Unable to access mail folder(2).");
         }
     } else {
         $rtn = imap_reopen($this->connection, $this->connect_string . $folder);
         $errs = print_r(imap_errors(), 1);
         if (!$rtn || preg_match("/Invalid mailbox name/i", $errs) || preg_match("/Mailbox does not exist/i", $errs)) {
             $rtn = imap_reopen($this->connection, $this->connect_string . str_replace("/", ".", $folder));
         }
         if (!$rtn) {
             imap_close($this->connection);
             if ($fatal) {
                 alloc_error("Unable to access mail folder(3).");
             }
         }
     }
     if (!$rtn && $fatal) {
         alloc_error("<pre>IMAP errors: " . print_r(imap_errors(), 1) . print_r(imap_alerts(), 1) . "</pre>");
     }
     return $rtn;
 }
Ejemplo n.º 5
0
 /**
  * This function creates or reopens an imap_stream when called.
  *
  */
 protected function set_imap_stream()
 {
     if (isset($this->imap_stream)) {
         if (!imap_reopen($this->imap_stream, $this->mailbox, $this->options, 1)) {
             throw new Imap_Exception(imap_last_error());
         }
     } else {
         $imap_stream = imap_open($this->get_server_string(), $this->username, $this->password, $this->options, 1);
         if ($imap_stream === FALSE) {
             throw new Imap_Exception(imap_last_error());
         }
         $this->imap_stream = $imap_stream;
     }
 }
 /**
  * Função que importa arquivos .eml exportados pelo expresso para a caixa do usuário. Testado apenas
  * com .emls gerados pelo expresso, e o arquivo pode ser um zip contendo vários emls ou um .eml.
  */
 function import_msgs($params)
 {
     if (!$this->mbox) {
         $this->mbox = $this->open_mbox();
     }
     if (preg_match('/local_/', $params["folder"])) {
         // PLEASE, BE CAREFULL!!! YOU SHOULD USE EMAIL CONFIGURATION VALUES (EMAILADMIN MODULE)
         //$tmp_box = mb_convert_encoding('INBOX'.$this->folders['trash'].$this->imap_delimiter.'tmpMoveToLocal', "UTF7-IMAP", "UTF-8");
         $tmp_box = mb_convert_encoding($this->mount_url_folder(array("INBOX", $this->folders['trash'], "tmpMoveToLocal")), "UTF7-IMAP", "UTF-8");
         if (!imap_createmailbox($this->mbox, "{" . $this->imap_server . "}{$tmp_box}")) {
             return $this->functions->getLang('Import to Local : fail...');
         }
         imap_reopen($this->mbox, "{" . $this->imap_server . ":" . $this->imap_port . $this->imap_options . "}" . $tmp_box);
         $params["folder"] = $tmp_box;
     }
     $errors = array();
     $invalid_format = false;
     $filename = $params['FILES'][0]['name'];
     $params["folder"] = mb_convert_encoding($params["folder"], "UTF7-IMAP", "ISO-8859-1, UTF-8");
     $quota = imap_get_quotaroot($this->mbox, $params["folder"]);
     if (($quota['limit'] - $quota['usage']) * 1024 <= $params['FILES'][0]['size']) {
         return array('error' => $this->functions->getLang("fail in import:") . " " . $this->functions->getLang("Over quota"));
     }
     if (substr($filename, strlen($filename) - 4) == ".zip") {
         $zip = zip_open($params['FILES'][0]['tmp_name']);
         if ($zip) {
             while ($zip_entry = zip_read($zip)) {
                 if (zip_entry_open($zip, $zip_entry, "r")) {
                     $email = zip_entry_read($zip_entry, zip_entry_filesize($zip_entry));
                     /*Caso mensagens vierem com quebras de linha diferentes do esperado, como por exemplo,
                     		mensagens exportadas pelo MailArchiver, é preciso corrigir.*/
                     $email = str_replace("\r\n", "\n", $email);
                     $email = str_replace("\n", "\r\n", $email);
                     $status = @imap_append($this->mbox, "{" . $this->imap_server . ":" . $this->imap_port . $this->imap_options . "}" . $params["folder"], $email);
                     if (!$status) {
                         array_push($errors, zip_entry_name($zip_entry));
                     }
                     zip_entry_close($zip_entry);
                 }
             }
             zip_close($zip);
         }
         if (isset($tmp_box) && !sizeof($errors)) {
             $mc = imap_check($this->mbox);
             $result = imap_fetch_overview($this->mbox, "1:{$mc->Nmsgs}", 0);
             $ids = array();
             foreach ($result as $overview) {
                 $ids[] = $overview->uid;
             }
             return implode(',', $ids);
         }
     } else {
         if (substr($filename, strlen($filename) - 4) == ".eml") {
             $email = implode("", file($params['FILES'][0]['tmp_name']));
             /*Caso mensagens vierem com quebras de linha diferentes do esperado, como por exemplo,
             		mensagens exportadas pelo MailArchiver, é preciso corrigir.*/
             $email = str_replace("\r\n", "\n", $email);
             $email = str_replace("\n", "\r\n", $email);
             $status = imap_append($this->mbox, "{" . $this->imap_server . ":" . $this->imap_port . $this->imap_options . "}" . $params["folder"], $email);
             if (!$status) {
                 return "Error importing";
             }
             if (isset($tmp_box) && !sizeof($errors)) {
                 $mc = imap_check($this->mbox);
                 $result = imap_fetch_overview($this->mbox, "1:{$mc->Nmsgs}", 0);
                 $ids = array();
                 foreach ($result as $overview) {
                     $ids[] = $overview->uid;
                 }
                 return implode(',', $ids);
             }
         } else {
             if (isset($tmp_box)) {
                 imap_deletemailbox($this->mbox, "{" . $this->imap_server . "}{$tmp_box}");
             }
             return array("error" => $this->functions->getLang("wrong file format"));
             $invalid_format = true;
         }
     }
     if (!$invalid_format) {
         if (count($errors) > 0) {
             $message = $this->functions->getLang("fail in import:") . "\n";
             foreach ($errors as $arquivo) {
                 $message .= $arquivo . "\n";
             }
             return array("error" => $message);
         } else {
             return $this->functions->getLang("The import was executed successfully.");
         }
     }
 }
Ejemplo n.º 7
0
 /**
  * Helper to re-initialize the folder to speed things up
  * Remember what folder is currently open and only change if necessary
  *
  * @param string        $folderid       id of the folder
  * @param boolean       $force          re-open the folder even if currently opened
  *
  * @access protected
  * @return boolean      if folder is opened
  */
 protected function imap_reopen_folder($folderid, $force = false)
 {
     // if the stream is not alive, we open it again
     if (!@imap_ping($this->mbox)) {
         $this->mbox = @imap_open($this->server, $this->username, $this->password, OP_HALFOPEN);
         $this->mboxFolder = "";
     }
     // to see changes, the folder has to be reopened!
     if ($this->mboxFolder != $folderid || $force) {
         $s = @imap_reopen($this->mbox, $this->server . $folderid);
         // TODO throw status exception
         if (!$s) {
             ZLog::Write(LOGLEVEL_WARN, sprintf("BackendIMAP->imap_reopen_folder('%s'): failed to change folder: %s", $folderid, implode(", ", imap_errors())));
             return false;
         }
         $this->mboxFolder = $folderid;
     }
     return true;
 }
Ejemplo n.º 8
0
 function pathOpen($p, $stat = 'stat')
 {
     // Open a Folder
     if (is_object($p)) {
         //$x = $f;
         //$f = new stdClass();
         //$f->name = $this->_c_host . $x;
         $p = $this->_c_host . self::folderName($p->name);
     }
     // prepend host if not found
     if (strpos($p, $this->_c_host) === false) {
         $p = $this->_c_host . self::folderName($p);
     }
     // Reset
     $this->_folder_stat = null;
     $this->_message_cur = 1;
     $this->_message_max = 0;
     // Open
     imap_check($this->_c);
     imap_reopen($this->_c, $p, 0, 1);
     //$this->_c_stat = imap_status($this->_c);
     $x = $this->stat();
     if (empty($x)) {
         $this->_folder_name = $p;
         $this->_message_cur = 1;
         // switch ($stat) {
         // case 'count':
         // 	$this->_message_max = imap_num_msg($this->_c);
         // 	return $this->_message_max;
         // case 'stat':
         // 	$this->_folder_stat = imap_status($this->_c, $p, SA_ALL);
         // 	print_r($this->_folder_stat);
         // 	die('stat');
         // 	return $this->_folder_stat;
         // case 'info':
         // 	$this->_folder_stat = imap_mailboxmsginfo($this->_c);
         // 	$this->_message_max = $this->_folder_stat->Nmsgs;
         // }
         // return $this->_folder_stat;
         // $x0 = self::folderName($p);
         // $x1 = self::folderName($this->_folder_stat->Mailbox);
         // if ($x0 == $x1) {
         // 	return $this->_folder_stat;
         // }
     } else {
         if (preg_match('/no such mailbox/', $x)) {
             return self::E_NO_MAILBOX;
         }
         if (preg_match('/Unknown Mailbox/', $x)) {
             return self::E_NO_MAILBOX;
         }
         die("\nimap_reopen({$this->_c_host}, {$p}) failed: {$x}\n");
     }
 }
Ejemplo n.º 9
0
 function reopen($mailbox, $flags)
 {
     if (version_compare(PHP_VERSION, '5.2.1') != -1) {
         $result = @imap_reopen($this->_stream, $this->getServerString($mailbox), $flags, $this->_config['login_tries']);
     } else {
         $result = @imap_reopen($this->_stream, $this->getServerString($mailbox), $flags);
     }
     return $result;
 }
Ejemplo n.º 10
0
 /**
  * This function creates or reopens an imapStream when called.
  *
  */
 protected function setImapStream()
 {
     if (!empty($this->imapStream)) {
         if (!imap_reopen($this->imapStream, $this->getServerString(), $this->options, 1)) {
             throw new \RuntimeException(imap_last_error());
         }
     } else {
         $imapStream = @imap_open($this->getServerString(), $this->username, $this->password, $this->options, 1, $this->params);
         if ($imapStream === false) {
             throw new \RuntimeException(imap_last_error());
         }
         $this->imapStream = $imapStream;
     }
 }
Ejemplo n.º 11
0
 /**
  * If connection is not currently in this mailbox, switch it to this mailbox
  */
 protected function init()
 {
     $check = \imap_check($this->connection->getResource());
     if ($check->Mailbox != $this->mailbox) {
         \imap_reopen($this->connection->getResource(), $this->mailbox);
     }
 }
Ejemplo n.º 12
0
 public function setActiveMailbox($mailbox)
 {
     imap_reopen($this->con, $mailbox, 0, 3);
 }
Ejemplo n.º 13
0
 public function url_stat($path, $flags)
 {
     $emptyString = '';
     if ($this->stream_open($path, 'np', $flags, $emptyString)) {
         if (!empty($this->path) && empty($this->currentAttachmentData)) {
             // Mail
             //$stats = array();
             if (empty($this->size) && empty($this->time)) {
                 list($stats, ) = imap_fetch_overview($this->ih, $this->path);
                 $this->size = $stats->size;
                 $this->time = strtotime($stats->date);
             }
             $keys = array('dev' => 0, 'ino' => 0, 'mode' => 33216, 'nlink' => 0, 'uid' => 0, 'gid' => 0, 'rdev' => 0, 'size' => $this->size, 'atime' => $this->time, 'mtime' => $this->time, 'ctime' => $this->time, 'blksize' => 0, 'blocks' => 0);
         } else {
             // BOX
             if (empty($this->currentAttachmentData) && !empty($this->mailbox) && !$this->pop3) {
                 // GET LAST MESSAGE
                 imap_reopen($this->ih, self::$currentRef . $this->mailbox);
                 $last = imap_num_msg($this->ih);
                 //AJXP_Logger::debug(__CLASS__,__FUNCTION__,"Should get mailbox data ".self::$currentRef.$this->mailbox . $last);
                 list($stats, ) = imap_fetch_overview($this->ih, $last);
                 $this->size = $stats->size;
                 $this->time = strtotime($stats->date);
             }
             $keys = array('dev' => 0, 'ino' => 0, 'mode' => empty($this->currentAttachmentData) ? 33216 | 040000 : 33216, 'nlink' => 0, 'uid' => 0, 'gid' => 0, 'rdev' => 0, 'size' => !empty($this->currentAttachmentData) ? $this->currentAttachmentData["size"] : 0, 'atime' => !empty($this->time) ? $this->time : 0, 'mtime' => !empty($this->time) ? $this->time : 0, 'ctime' => !empty($this->time) ? $this->time : 0, 'blksize' => 0, 'blocks' => 0);
         }
         $this->stream_close();
         return $keys;
     } else {
         return false;
     }
 }
Ejemplo n.º 14
0
 /**
  * If connection is not currently in this mailbox, switch it to this mailbox
  */
 private function init()
 {
     $check = imap_check($this->connection->getResource());
     if ($check === false || $check->Mailbox != $this->mailbox) {
         imap_reopen($this->connection->getResource(), $this->mailbox);
     }
 }
Ejemplo n.º 15
0
 public function reopen($mailbox)
 {
     if (!imap_reopen($this->mbox, $mailbox)) {
         throw new \ConnectionException('cannot set mailbox');
     }
 }
Ejemplo n.º 16
0
 function imap_reopenFolder($folderid, $force = false)
 {
     // to see changes, the folder has to be reopened!
     if ($this->_mboxFolder != $folderid || $force) {
         $s = @imap_reopen($this->_mbox, $this->_server . imap_utf7_encode(str_replace(".", $this->_serverdelimiter, $folderid)));
         $this->_mboxFolder = $folderid;
     }
 }
Ejemplo n.º 17
0
    if ($debug) {
        print "creating {$dest_mailbox} on {$dest_server} {$dest_mbox}\n";
    }
    createmailbox($dest_mbox, $dest_server, $dest_mailbox);
}
/*
// Create TEMP folder to back up INBOX messages from src_server not being 'archived'
if ($inbox && !folderExists($dest_mbox, $dest_server, $backup_inbox_folder)) {
  if ($debug) print "creating $backup_inbox_folder on $dest_server $dest_mbox\n";
  createmailbox($dest_mbox, $dest_server, $backup_inbox_folder);
}
*/
// And then reopen dest_server to $dest_mailbox so we can count before and afters
// NOTE - the use of foo is a cludge to fix the imap_reopen bug!!
$foo = $dest_mbox;
$dest_mbox = imap_reopen($dest_mbox, $dst_imap_string . $dest_mailbox);
$dest_mbox = $foo;
if ($debug) {
    print "\$dest_mbox = {$dest_mbox}\n";
}
// Print out number of messages from source server
$da_no_msgs = imap_num_msg($src_mbox);
print "Msg Count on {$src_server} - {$mailbox}: " . $da_no_msgs . "\n";
// Print out number of message from dest server before running append()s
$no_msgs = imap_num_msg($dest_mbox);
print "Msg Count on {$dest_server} - {$dest_mailbox} before migration: " . $no_msgs . "\n";
// Get each message from src_mbox (connected to the correct mailbox)
//  and append it to {$dest_server}$mailbox IF it's older
//  than $archive_date, which is set based on $folder_date_weeks
// Then mark message deleted on src_server IF $delete_src_msg is true
for ($i = 1; $i <= $da_no_msgs; $i++) {
Ejemplo n.º 18
0
 public function to_folder($folder)
 {
     imap_reopen($this->mbox, $folder);
 }
Ejemplo n.º 19
0
 /**
  * Reopens the IMAP connection pointing at a different mailbox
  * Accepts name or full server spec string
  * (like the one that is returned by imap_list())
  *
  */
 public function change_to_mailbox($mailbox_name_or_full_server_spec_string)
 {
     // should check if it is a valid mailbox
     // but for now, just see if it starts with curly bracket
     if (strncmp('{', $mailbox_name_or_full_server_spec_string, 1) === 0) {
         // it is (probably) a spec string
         // but, maybe mailbox names can start with {?
         // set the local mailbox property by splitting on curly brackets
         // use strtok twice to get the end of the string because it is surper fast
         strtok($mailbox_name_or_full_server_spec_string, '}');
         $this->mailbox = strtok($mailbox_name_or_full_server_spec_string);
         // reopen the connection using the new server spec string
         $bool = imap_reopen($this->resource, $mailbox_name_or_full_server_spec_string);
     } else {
         $this->mailbox = $mailbox_name_or_full_server_spec_string;
         $new_sss_with_mb = $this->_generate_server_spec_string();
         $bool = imap_reopen($this->resource, $new_sss_with_mb);
     }
 }
Ejemplo n.º 20
0
 /**
  * If connection is not currently in this mailbox, switch it to this mailbox
  */
 private function init()
 {
     $check = imap_check($this->connection->getResource());
     if ($check === false || $check->Mailbox != $this->mailbox->name) {
         set_error_handler([$this, 'errorHandler']);
         $this->setLastException(null);
         $result = imap_reopen($this->connection->getResource(), $this->mailbox->name);
         restore_error_handler();
         if (!$result) {
             throw new MailboxOpenException($this->mailbox->name);
         }
         $ex = $this->getLastException();
         if ($ex) {
             throw $ex;
         }
     }
 }
Ejemplo n.º 21
0
 /**
  * Helper to re-initialize the folder to speed things up
  * Remember what folder is currently open and only change if necessary
  *
  * @param string        $folderid       id of the folder
  * @param boolean       $force          re-open the folder even if currently opened
  *
  * @access protected
  * @return
  */
 protected function imap_reopenFolder($folderid, $force = false)
 {
     // to see changes, the folder has to be reopened!
     if ($this->mboxFolder != $folderid || $force) {
         $s = @imap_reopen($this->mbox, $this->server . $folderid);
         // TODO throw status exception
         if (!$s) {
             ZLog::Write(LOGLEVEL_WARN, "BackendIMAP->imap_reopenFolder('%s'): failed to change folder: ", $folderid, implode(", ", imap_errors()));
             return false;
         }
         $this->mboxFolder = $folderid;
     }
 }
Ejemplo n.º 22
0
 public function openMailbox(Mailbox $mailbox)
 {
     $this->currentMailbox = $mailbox;
     $options = $this->read_only ? OP_READONLY : 0;
     imap_reopen($this->connection, $mailbox->getMailbox(), $options, 3);
 }
Ejemplo n.º 23
0
 /**
  * @param $folder
  * @return string
  *
  * @Then /^(?:|I )can read messages from "(?P<folder>[^"]*)"$/
  */
 public function iCanReadMessagesFromFolder($folder)
 {
     \imap_reopen($this->imapConnection, $this->imapDsn . $folder);
     $this->printDebug(print_r(\imap_headers($this->imapConnection), TRUE));
 }
Ejemplo n.º 24
0
 /**
  * Change current mailbox
  *
  * @param string $mailbox
  * @return void
  * @access private
  */
 function _changeMailbox($mailbox)
 {
     if ($this->protocol == 'POP3') {
         return;
     }
     $this->select($mailbox);
     return;
     $this->cid++;
     if ($this->use_native) {
         imap_reopen($this->mailer, $mailbox);
     } else {
         $this->mailer->select($mailbox);
     }
     $this->cur_mailbox = $mailbox;
 }
Ejemplo n.º 25
0
 function imap_reopenFolder($folderid, $force = false)
 {
     // to see changes, the folder has to be reopened!
     if ($this->_mboxFolder != $folderid || $force) {
         $s = @imap_reopen($this->_mbox, $this->_server . str_replace(".", $this->_serverdelimiter, $folderid));
         if (!$s) {
             debugLog("failed to change folder: " . implode(", ", imap_errors()));
         }
         $this->_mboxFolder = $folderid;
     }
 }
Ejemplo n.º 26
0
 /**
     Sets the Current Mailfolder, Creates if Needed
 */
 function setPath($p)
 {
     if (substr($p, 0, 1) != '{') {
         $p = $this->_c_host . trim($p, '/');
     }
     $ret = imap_reopen($this->_c, $p);
     // Always returns true :(
     $buf = imap_errors();
     if (empty($buf)) {
         return true;
     }
     $buf = implode(', ', $buf);
     if (preg_match('/EXIST/i', $buf)) {
         // Couldn't Open on Target Side, So Create
         $ret = imap_createmailbox($this->_c, $p);
         $buf = imap_errors();
         if (empty($buf)) {
             // Reopen Again
             imap_reopen($this->_c, $p);
             return true;
         }
         die(print_r($buf, true) . "\nFailed to Create setPath({$p})\n");
     }
     die(print_r($buf, true) . "\nFailed to Switch setPath({$p})\n");
 }
Ejemplo n.º 27
0
 /**
  * per imap_reopen die aktuelle Connection auf eine andere mbox umstellen
  * @param string $mbox
  * @return boolean
  */
 public function imapSwitchMbox($mbox)
 {
     if ($this->imap === null) {
         throw new IMAPException(__METHOD__ . ' not connected');
     }
     $this->imapPing(true);
     if (imap_reopen($this->imap, $this->server . $mbox) === false) {
         throw new IMAPException(__METHOD__ . ' reopen failed');
     }
     $this->mbox = $mbox;
     return true;
 }
Ejemplo n.º 28
0
 /**
  * Get IMAP mailbox connection stream
  *
  * @return null|resource
  */
 public function getImapStream()
 {
     if (!$this->isConnected()) {
         $this->imapStream = $this->initImapStream();
     } else {
         @imap_reopen($this->imapStream, $this->imapFullPath);
     }
     return $this->imapStream;
 }
Ejemplo n.º 29
0
 /**
  * Connects to mailserver.  If an existing IMAP resource is available, it
  * will attempt to reuse the connection, updating the mailbox path.
  *
  * @param bool test Flag to test connection
  * @param bool force Force reconnect
  * @return string "true" on success, "false" or $errorMessage on failure
  */
 function connectMailserver($test = false, $force = false)
 {
     global $mod_strings;
     if (!function_exists("imap_open")) {
         $GLOBALS['log']->debug('------------------------- IMAP libraries NOT available!!!! die()ing thread.----');
         return $mod_strings['LBL_WARN_NO_IMAP'];
     }
     imap_errors();
     // clearing error stack
     error_reporting(0);
     // turn off notices from IMAP
     // tls::ca::ssl::protocol::novalidate-cert::notls
     $useSsl = $_REQUEST['ssl'] == 'true' ? true : false;
     if ($test) {
         imap_timeout(1, 15);
         // 60 secs is the default
         imap_timeout(2, 15);
         imap_timeout(3, 15);
         $opts = $this->findOptimumSettings($useSsl);
         if (isset($opts['good']) && empty($opts['good'])) {
             return array_pop($opts['err']);
         } else {
             $service = $opts['service'];
             $service = str_replace('foo', '', $service);
             // foo there to support no-item explodes
         }
     } else {
         $service = $this->getServiceString();
     }
     $connectString = $this->getConnectString($service, $this->mailbox);
     /*
      * Try to recycle the current connection to reduce response times
      */
     if (is_resource($this->conn)) {
         if ($force) {
             // force disconnect
             imap_close($this->conn);
         }
         if (imap_ping($this->conn)) {
             // we have a live connection
             imap_reopen($this->conn, $connectString, CL_EXPUNGE);
         }
     }
     // final test
     if (!is_resource($this->conn) && !$test) {
         $this->conn = imap_open($connectString, $this->email_user, $this->email_password, CL_EXPUNGE);
     }
     if ($test) {
         if ($opts == false && !is_resource($this->conn)) {
             $this->conn = imap_open($connectString, $this->email_user, $this->email_password, CL_EXPUNGE);
         }
         $errors = '';
         $alerts = '';
         $successful = false;
         if (($errors = imap_last_error()) || ($alerts = imap_alerts())) {
             if ($errors == 'Mailbox is empty') {
                 // false positive
                 $successful = true;
             } else {
                 $msg .= $errors;
                 $msg .= '<p>' . $alerts . '<p>';
                 $msg .= '<p>' . $mod_strings['ERR_TEST_MAILBOX'];
             }
         } else {
             $successful = true;
         }
         if ($successful) {
             if ($this->protocol == 'imap') {
                 $msg .= $mod_strings['LBL_TEST_SUCCESSFUL'];
                 /*
                 $testConnectString = '{'.$this->server_url.':'.$this->port.'/service='.$this->protocol.$service.'}';
                 if (!is_resource($this->conn)) {
                 	$this->conn = imap_open($connectString, $this->email_user, $this->email_password, CL_EXPUNGE);
                 }
                 $list = imap_getmailboxes($this->conn, $testConnectString, "*");
                 if(isset($_REQUEST['personal']) && $_REQUEST['personal'] == 'true') {
                 	$msg .= $mod_strings['LBL_TEST_SUCCESSFUL'];
                 } elseif (is_array($list)) {
                 	sort($list);
                 	_ppd($boxes);
                 
                 	$msg .= '<b>'.$mod_strings['LBL_FOUND_MAILBOXES'].'</b><p>';
                 	foreach ($list as $key => $val) {
                 		$mb = imap_utf7_decode(str_replace($testConnectString,'',$val->name));
                 		$msg .= '<a onClick=\'setMailbox(\"'.$mb.'\"); window.close();\'>';
                 		$msg .= $mb;
                 		$msg .= '</a><br>';
                 	}
                 } else {
                 	$msg .= $errors;
                 	$msg .= '<p>'.$mod_strings['ERR_MAILBOX_FAIL'].imap_last_error().'</p>';
                 	$msg .= '<p>'.$mod_strings['ERR_TEST_MAILBOX'].'</p>';
                 }
                 */
             } else {
                 $msg .= $mod_strings['LBL_POP3_SUCCESS'];
             }
         }
         imap_errors();
         // collapse error stack
         imap_close($this->conn);
         return $msg;
     } elseif (!is_resource($this->conn)) {
         return "false";
     } else {
         return "true";
     }
 }
Ejemplo n.º 30
0
 public function switch_mailbox($mailbox = '')
 {
     if ($this->stream) {
         $this->mbox = '{' . $this->server;
         if ($this->port) {
             $this->mbox .= ':' . $this->port;
         }
         if ($this->flags) {
             $this->mbox .= $this->flags;
         }
         $this->mbox .= '/user="******"';
         $this->mbox .= '}';
         $this->mbox .= $this->default_mailbox;
         if ($mailbox) {
             $this->mbox .= '.' . $mailbox;
         }
         return @imap_reopen($this->stream, $this->mbox);
     }
     // Not connected
     return imap_last_error();
 }