Shortcut to obtaining mailbox object.

@param string $mbox       The mailbox name.
@param boolean $utf7imap  Is mailbox UTF7-IMAP encoded? Otherwise,
mailbox is assumed to be UTF-8.

@return Horde_Imap_Client_Mailbox  A mailbox object.
423292
public static function get($mbox, $utf7imap = false)
    {
        return ($mbox instanceof Horde_Imap_Client_Mailbox)
            ? $mbox
            : new Horde_Imap_Client_Mailbox($mbox, $utf7imap);
    }
1167635
function encodeMimeHeader( $str )
    {
        if ( !$this->TextCodec )
        {
             $this->TextCodec = eZTextCodec::instance( $this->contentCharset(), $this->outputCharset() );
        }

        if ( function_exists( "mb_encode_mimeheader" ) )
        {
            $encoded = mb_encode_mimeheader( $str, $this->TextCodec->InputCharsetCode, "B", eZMail::lineSeparator() );
        }
        else
        {
            if (  0 == preg_match_all( '/[\000-\010\013\014\016-\037\177-\377]/', $str, $matches ) )
                return $str;

            $maxlen = 75 - 7 - strlen( $this->TextCodec->InputCharsetCode );

            $encoding = 'B';
            $encoded = base64_encode( $str );
            $maxlen -= $maxlen % 4;
            $encoded = trim( chunk_split( $encoded, $maxlen, "\n" ) );

            $encoded = preg_replace( '/^(.*)$/m', " =?".$this->TextCodec->InputCharsetCode."?$encoding?\\1?=", $encoded );

            $encoded = trim( str_replace( "\n", eZMail::lineSeparator(), $encoded ) );
        }

        return $encoded;
    }
45569
public static function getMimeType($ext) {
		$ext = strtolower($ext);
		$mimes = array('hqx' => 'application/mac-binhex40', 'cpt' => 'application/mac-compactpro', 'doc' => 'application/msword', 
			'bin' => 'application/macbinary', 'dms' => 'application/octet-stream', 'lha' => 'application/octet-stream', 
			'lzh' => 'application/octet-stream', 'exe' => 'application/octet-stream', 'class' => 'application/octet-stream', 
			'psd' => 'application/octet-stream', 'so' => 'application/octet-stream', 'sea' => 'application/octet-stream', 
			'dll' => 'application/octet-stream', 'oda' => 'application/oda', 'pdf' => 'application/pdf', 
			'ai' => 'application/postscript', 'eps' => 'application/postscript', 'ps' => 'application/postscript', 
			'smi' => 'application/smil', 'smil' => 'application/smil', 'mif' => 'application/vnd.mif', 
			'xls' => 'application/vnd.ms-excel', 'ppt' => 'application/vnd.ms-powerpoint', 'wbxml' => 'application/vnd.wap.wbxml', 
			'wmlc' => 'application/vnd.wap.wmlc', 'dcr' => 'application/x-director', 'dir' => 'application/x-director', 
			'dxr' => 'application/x-director', 'dvi' => 'application/x-dvi', 'gtar' => 'application/x-gtar', 
			'php' => 'application/x-httpd-php', 'php4' => 'application/x-httpd-php', 'php3' => 'application/x-httpd-php', 
			'phtml' => 'application/x-httpd-php', 'phps'  => 'application/x-httpd-php-source', 'js' => 'application/x-javascript', 
			'swf' => 'application/x-shockwave-flash', 'sit' => 'application/x-stuffit', 'tar' => 'application/x-tar', 
			'tgz' => 'application/x-tar', 'xhtml' => 'application/xhtml+xml', 'xht' => 'application/xhtml+xml', 'zip' => 'application/zip', 
			'mid' => 'audio/midi', 'midi' => 'audio/midi', 'mpga' => 'audio/mpeg', 'mp2' => 'audio/mpeg', 'mp3' => 'audio/mpeg', 
			'aif' => 'audio/x-aiff', 'aiff' => 'audio/x-aiff', 'aifc' => 'audio/x-aiff', 'ram' => 'audio/x-pn-realaudio', 
			'rm' => 'audio/x-pn-realaudio', 'rpm' => 'audio/x-pn-realaudio-plugin', 'ra' => 'audio/x-realaudio', 
			'rv' => 'video/vnd.rn-realvideo', 'wav' => 'audio/x-wav', 'bmp' => 'image/bmp', 'gif' => 'image/gif', 'jpeg' => 'image/jpeg', 
			'jpg' => 'image/jpeg', 'jpe' => 'image/jpeg', 'png' => 'image/png', 'tiff' => 'image/tiff', 'tif' => 'image/tiff', 
			'css' => 'text/css', 'html' => 'text/html', 'htm' => 'text/html', 'shtml' => 'text/html', 'txt' => 'text/plain', 
			'text' => 'text/plain', 'log' => 'text/plain', 'rtx' => 'text/richtext', 'rtf' => 'text/rtf', 'xml' => 'text/xml', 
			'xsl' => 'text/xml', 'mpeg' => 'video/mpeg', 'mpg' => 'video/mpeg', 'mpe' => 'video/mpeg', 'qt' => 'video/quicktime', 
			'mov' => 'video/quicktime', 'avi' => 'video/x-msvideo', 'movie' => 'video/x-sgi-movie', 'doc' => 'application/msword', 
			'word' => 'application/msword', 'xl' => 'application/excel', 'eml' => 'message/rfc822');
		return (!isset($mimes[$ext])) ? 'application/octet-stream' : $mimes[strtolower($ext)];
	}
1050754
public function imagebmp(&$img, $filename = false)
	{
		$wid = imagesx($img);
		$hei = imagesy($img);
		$wid_pad = str_pad('', $wid % 4, "\0");
		$size = 54 + ($wid + $wid_pad) * $hei;
		// prepare & save header
		$header = array(
			'identifier'		=> 'BM',
			'file_size'			=> $this->dword($size),
			'reserved'			=> $this->dword(0),
			'bitmap_data'		=> $this->dword(54),
			'header_size'		=> $this->dword(40),
			'width'				=> $this->dword($wid),
			'height'			=> $this->dword($hei),
			'planes'			=> $this->word(1),
			'bits_per_pixel'	=> $this->word(24),
			'compression'		=> $this->dword(0),
			'data_size'			=> $this->dword(0),
			'h_resolution'		=> $this->dword(0),
			'v_resolution'		=> $this->dword(0),
			'colors'			=> $this->dword(0),
			'important_colors'	=> $this->dword(0),
		);
	    if ($filename) {
			$fh = fopen($filename, "wb");
			foreach ($header as $h) {
				fwrite($fh, $h);
			}
			// save pixels
			for ($y=$hei-1; $y>=0; $y--) {
				for ($x=0; $x<$wid; $x++) {
					$rgb = imagecolorat($img, $x, $y);
					fwrite($fh, $this->byte3($rgb));
				}
				fwrite($fh, $wid_pad);
			}
			return fclose($fh);
		} else {
			foreach ($header as $h) {
			    echo $h;
			}
			// save pixels
			for ($y = $hei - 1; $y >= 0; $y--) {
				for ($x=0; $x<$wid; $x++) {
					$rgb = imagecolorat($img, $x, $y);
					echo $this->byte3($rgb);
				}
				echo $wid_pad;
			}
			return true;
		}
	}
122578
private function validate($mailbox, $index, &$exists = true)
    {
        $object    = $index['object'];
        $is_thread = is_a($object, 'rcube_result_thread');

        // sanity check
        if (empty($object)) {
            return false;
        }

        $index['validated'] = true;

        // Get mailbox data (UIDVALIDITY, counters, etc.) for status check
        $mbox_data = $this->imap->folder_data($mailbox);

        // @TODO: Think about skipping validation checks.
        // If we could check only every 10 minutes, we would be able to skip
        // expensive checks, mailbox selection or even IMAP connection, this would require
        // additional logic to force cache invalidation in some cases
        // and many rcube_imap changes to connect when needed

        // Check UIDVALIDITY
        if ($index['validity'] != $mbox_data['UIDVALIDITY']) {
            $this->clear($mailbox);
            $exists = false;
            return false;
        }

        // Folder is empty but cache isn't
        if (empty($mbox_data['EXISTS'])) {
            if (!$object->is_empty()) {
                $this->clear($mailbox);
                $exists = false;
                return false;
            }
        }
        // Folder is not empty but cache is
        else if ($object->is_empty()) {
            unset($this->icache[$mailbox][$is_thread ? 'thread' : 'index']);
            return false;
        }

        // Validation flag
        if (!$is_thread && empty($index['valid'])) {
            unset($this->icache[$mailbox]['index']);
            return false;
        }

        // Index was created with different skip_deleted setting
        if ($this->skip_deleted != $index['deleted']) {
            return false;
        }

        // Check HIGHESTMODSEQ
        if (!empty($index['modseq']) && !empty($mbox_data['HIGHESTMODSEQ'])
            && $index['modseq'] == $mbox_data['HIGHESTMODSEQ']
        ) {
            return true;
        }

        // Check UIDNEXT
        if ($index['uidnext'] != $mbox_data['UIDNEXT']) {
            unset($this->icache[$mailbox][$is_thread ? 'thread' : 'index']);
            return false;
        }

        // @TODO: find better validity check for threaded index
        if ($is_thread) {
            // check messages number...
            if (!$this->skip_deleted && $mbox_data['EXISTS'] != $object->count_messages()) {
                return false;
            }
            return true;
        }

        // The rest of checks, more expensive
        if (!empty($this->skip_deleted)) {
            // compare counts if available
            if (!empty($mbox_data['UNDELETED'])
                && $mbox_data['UNDELETED']->count() != $object->count()
            ) {
                return false;
            }
            // compare UID sets
            if (!empty($mbox_data['UNDELETED'])) {
                $uids_new = $mbox_data['UNDELETED']->get();
                $uids_old = $object->get();

                if (count($uids_new) != count($uids_old)) {
                    return false;
                }

                sort($uids_new, SORT_NUMERIC);
                sort($uids_old, SORT_NUMERIC);

                if ($uids_old != $uids_new)
                    return false;
            }
            else {
                // get all undeleted messages excluding cached UIDs
                $ids = $this->imap->search_once($mailbox, 'ALL UNDELETED NOT UID '.
                    rcube_imap_generic::compressMessageSet($object->get()));

                if (!$ids->is_empty()) {
                    return false;
                }
            }
        }
        else {
            // check messages number...
            if ($mbox_data['EXISTS'] != $object->count()) {
                return false;
            }
            // ... and max UID
            if ($object->max() != $this->imap->id2uid($mbox_data['EXISTS'], $mailbox)) {
                return false;
            }
        }

        return true;
    }
545579
function obsMboxList() {
        return opts.strict ? null : wrap('obs-mbox-list', and(
            star(and(
                invis(opt(cfws)),
                literal(',')
            )),
            mailbox,
            star(and(
                literal(','),
                opt(and(
                    mailbox,
                    invis(cfws)
                ))
            ))
        )());
    }
1025869
public function decodeString($string, $encoding) {
        switch ($encoding) {
            case IMAP::MESSAGE_ENC_7BIT:
                return $string;
            case IMAP::MESSAGE_ENC_8BIT:
                return quoted_printable_decode(imap_8bit($string));
            case IMAP::MESSAGE_ENC_BINARY:
                return imap_binary($string);
            case IMAP::MESSAGE_ENC_BASE64:
                return imap_base64($string);
            case IMAP::MESSAGE_ENC_QUOTED_PRINTABLE:
                return quoted_printable_decode($string);
            case IMAP::MESSAGE_ENC_OTHER:
                return $string;
            default:
                return $string;
        }
    }
488609
public function renameMailbox($from = '', $to = '')
    {
        if (empty($from) || empty($to)) {
            return false;
        }

        $from = imap_utf7_encode($from);
        $to = imap_utf7_encode($to);

        return imap_renamemailbox($this->conn, "{".$this->settings['server']."}INBOX.".$from,
            "{".$this->settings['server']."}INBOX.".$to);
    }
597921
protected function mod_mailbox($mailbox, $mode = 'out')
    {
        $delimiter         = $_SESSION['imap_delimiter'];
        $replace_delimiter = $this->rc->config->get('managesieve_replace_delimiter');
        $mbox_encoding     = $this->rc->config->get('managesieve_mbox_encoding', 'UTF7-IMAP');

        if ($mode == 'out') {
            $mailbox = rcube_charset::convert($mailbox, $mbox_encoding, 'UTF7-IMAP');
            if ($replace_delimiter && $replace_delimiter != $delimiter)
                $mailbox = str_replace($replace_delimiter, $delimiter, $mailbox);
        }
        else {
            $mailbox = rcube_charset::convert($mailbox, 'UTF7-IMAP', $mbox_encoding);
            if ($replace_delimiter && $replace_delimiter != $delimiter)
                $mailbox = str_replace($delimiter, $replace_delimiter, $mailbox);
        }

        return $mailbox;
    }
907383
public function get_imap(){
    if ( $this->imap = imap_check($this->stream) ){
      if ( $this->imap->Nmsgs > 0 ){
        $this->last_uid = $this->get_msg_uid($this->imap->Nmsgs);
        $this->num_msg = $this->imap->Nmsgs;
      }
      else {
        $this->last_uid = 0;
        $this->num_msg = 0;
      }
      return $this->imap;
    }
    return false;
  }
116625
public function createFromString($imageString)
    {
        $this->sourceImageResource = new \Gmagick();

        try {

            $this->sourceImageResource->readimageblob($imageString);

            return true;

        } catch (\GmagickException $e) {

            $this->errors[ $e->getCode() ] = $e->getMessage();

        }

        return false;
    }
30335
final protected function _mboxCompare($a, $b)
    {
        /* Always return INBOX as "smaller". */
        if ($this->_sortinbox) {
            if (strcasecmp($a, 'INBOX') === 0) {
                return -1;
            } elseif (strcasecmp($b, 'INBOX') === 0) {
                return 1;
            }
        }

        $a_parts = explode($this->_delimiter, $a);
        $b_parts = explode($this->_delimiter, $b);

        $a_count = count($a_parts);
        $b_count = count($b_parts);

        for ($i = 0, $iMax = min($a_count, $b_count); $i < $iMax; ++$i) {
            if ($a_parts[$i] != $b_parts[$i]) {
                /* If only one of the folders is under INBOX, return it as
                 * "smaller". */
                if ($this->_sortinbox && ($i === 0)) {
                    $a_base = (strcasecmp($a_parts[0], 'INBOX') === 0);
                    $b_base = (strcasecmp($b_parts[0], 'INBOX') === 0);
                    if ($a_base && !$b_base) {
                        return -1;
                    } elseif (!$a_base && $b_base) {
                        return 1;
                    }
                }

                $cmp = strnatcasecmp($a_parts[$i], $b_parts[$i]);
                return ($cmp === 0)
                    ? strcmp($a_parts[$i], $b_parts[$i])
                    : $cmp;
            } elseif ($a_parts[$i] !== $b_parts[$i]) {
                return strlen($a_parts[$i]) - strlen($b_parts[$i]);
            }
        }

        return ($a_count - $b_count);
    }
1268792
protected function _parseMetadata(
        Horde_Imap_Client_Interaction_Pipeline $pipeline,
        Horde_Imap_Client_Tokenize $data
    )
    {
        // Mailbox name is in UTF7-IMAP.
        $mbox = Horde_Imap_Client_Mailbox::get($data->next(), true);

        // Ignore unsolicited responses.
        if ($data->next() === true) {
            while (($entry = $data->next()) !== false) {
                $pipeline->data['metadata'][strval($mbox)][$entry] = $data->next();
            }
        }
    }
712460
protected function _mailboxOb($mailbox = null)
    {
        $name = is_null($mailbox)
            ? strval($this->_selected)
            : strval($mailbox);

        if (!isset($this->_temp['mailbox_ob'][$name])) {
            $this->_temp['mailbox_ob'][$name] = new Horde_Imap_Client_Base_Mailbox();
        }

        return $this->_temp['mailbox_ob'][$name];
    }
987360
private function list_mboxes($dir){
    if ( $this->is_connected() ){
      return imap_list($this->stream, $this->mbParam, $dir);
    }
    return false;
  }
1363262
public function copy($mailbox, $options = 0) {
        $this->client->openFolder($this->folder_path);
        return imap_mail_copy($this->client->getConnection(), $this->msglist, $mailbox, $options);
    }
398793
public function subscribeMailbox($name = '') {
        if (empty($name)) {
            return false;
        }

        $name = imap_utf7_encode($name);
        return imap_subscribe ( $this->conn, "{".$this->settings['server']."}INBOX.".$name );
    }