本文整理汇总了PHP中imap_reopen函数的典型用法代码示例。如果您正苦于以下问题:PHP imap_reopen函数的具体用法?PHP imap_reopen怎么用?PHP imap_reopen使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了imap_reopen函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: connect
/**
* 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;
}
示例2: selectFolder
/**
* 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;
}
示例3: connect
/**
* 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;
}
示例4: open_mailbox
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;
}
示例5: set_imap_stream
/**
* 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;
}
}
示例6: import_msgs
/**
* 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.");
}
}
}
示例7: imap_reopen_folder
/**
* 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;
}
示例8: pathOpen
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");
}
}
示例9: reopen
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;
}
示例10: setImapStream
/**
* 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;
}
}
示例11: init
/**
* 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);
}
}
示例12: setActiveMailbox
public function setActiveMailbox($mailbox)
{
imap_reopen($this->con, $mailbox, 0, 3);
}
示例13: url_stat
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;
}
}
示例14: init
/**
* 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);
}
}
示例15: reopen
public function reopen($mailbox)
{
if (!imap_reopen($this->mbox, $mailbox)) {
throw new \ConnectionException('cannot set mailbox');
}
}