Parse a LANGUAGE response (RFC 5255 [3.3]).

@param Horde_Imap_Client_Tokenize $data  The server response.
3999
protected function _parseLanguage(Horde_Imap_Client_Tokenize $data)
    {
        $lang_list = $data->flushIterator();

        if (count($lang_list) === 1) {
            // This is the language that was set.
            $this->_setInit('lang', reset($lang_list));
        } else {
            // These are the languages that are available.
            $this->_setInit('langavail', $lang_list);
        }
    }
93903
private function tokenFromResponse(array $data): Token
    {
        $token = Token::fromResponseData($data);
        // Save the token to the cache and return it.
        $this->tokenCachePool->setToken($this, $token);

        return $token;
    }
383467
protected function _parseLocalPart()
    {
        if (($curr = $this->_curr()) === false) {
            throw new Horde_Mail_Exception('Error when parsing local part.');
        }

        if ($curr == '"') {
            $this->_rfc822ParseQuotedString($str);
        } else {
            $this->_rfc822ParseDotAtom($str, ',;@');
        }

        return $str;
    }
96033
public function parse($data)
    {
        if ($data === null || !is_string($data)) {
            return array();
        }

        if (substr($data, 0, 1) !== '{' &&
            substr($data, 0, 1) !== '[') {
            return array();
        }

        return (array) json_decode($data, true);
    }
1034378
protected function parseClientList($data)
    {
        $clients = array();

        foreach (explode("\n", $data, -1) as $clientData) {
            $client = array();

            foreach (explode(' ', $clientData) as $kv) {
                @list($k, $v) = explode('=', $kv);
                $client[$k] = $v;
            }

            $clients[] = $client;
        }

        return $clients;
    }
529708
protected function _parseThreadLevel(&$thread,
                                         Horde_Imap_Client_Tokenize $data,
                                         $level = 0)
    {
        while (($curr = $data->next()) !== false) {
            if ($curr === true) {
                $this->_parseThreadLevel($thread, $data, $level);
            } elseif (!is_bool($curr)) {
                $thread[$curr] = $level++;
            }
        }
    }
559638
public function parseContentLength($data)
    {
        $this->buffer .= $data;
        if (strlen($this->buffer) >= $this->contentLength) {
            $this->completed();
        }
    }
299822
public function canParse($data)
	{
		$data = trim($data);

		try
		{
			// Parse config string
			$parsed = SymfonyYaml::parse($data, true);
		}
		catch (Exception $e)
		{
			return false;
		}

		return true;
	}
147746
public function parse(array $data, ParsingDispatcher $parsingDispatcher)
    {
        $contentUpdateStruct = $this->contentService->newContentUpdateStruct();

        // Missing initial language code

        if (array_key_exists('initialLanguageCode', $data)) {
            $contentUpdateStruct->initialLanguageCode = $data['initialLanguageCode'];
        }

        // @todo Where to set the user?
        // @todo Where to set modification date?

        if (array_key_exists('fields', $data)) {
            if (!is_array($data['fields']) || !array_key_exists('field', $data['fields']) || !is_array($data['fields']['field'])) {
                throw new Exceptions\Parser("Invalid 'fields' element for VersionUpdate.");
            }

            $contentId = $this->requestParser->parseHref($data['__url'], 'contentId');

            foreach ($data['fields']['field'] as $fieldData) {
                if (!array_key_exists('fieldDefinitionIdentifier', $fieldData)) {
                    throw new Exceptions\Parser("Missing 'fieldDefinitionIdentifier' element in field data for VersionUpdate.");
                }

                if (!array_key_exists('fieldValue', $fieldData)) {
                    throw new Exceptions\Parser("Missing 'fieldValue' element for '{$fieldData['fieldDefinitionIdentifier']}' identifier in VersionUpdate.");
                }

                $fieldValue = $this->fieldTypeParser->parseFieldValue(
                    $contentId,
                    $fieldData['fieldDefinitionIdentifier'],
                    $fieldData['fieldValue']
                );

                $languageCode = null;
                if (array_key_exists('languageCode', $fieldData)) {
                    $languageCode = $fieldData['languageCode'];
                }

                $contentUpdateStruct->setField($fieldData['fieldDefinitionIdentifier'], $fieldValue, $languageCode);
            }
        }

        return $contentUpdateStruct;
    }
675111
protected function parseGroup($data)
    {
        $set = $this->_parseDataItemToKeys($data);
        return empty($set) ? '' : 'GROUP BY ' . implode(',', array_unique($set));
    }
415072
private function parseIniString($data)
    {
        $config = $this->arr();
        $data = parse_ini_string($data, true);
        foreach ($data as $section => $value) {
            $config = $config->mergeRecursive($this->processValue($section, $value));
        }

        return $config;
    }
1013124
protected function parseHeader($data)
    {
        $leftover = '';

        $length = mb_strlen($data, '8bit');

        for ($i = 0; $i < $length; $i++) {
            switch ($this->cursor) {
            case 0x00:
                $char = $this->getChar($data, $i);

                $this->fin    = (($char & 0x80) === 0x80);
                $this->rsv1   = (($char & 0x40) === 0x40);
                $this->rsv2   = (($char & 0x20) === 0x20);
                $this->rsv3   = (($char & 0x10) === 0x10);
                $this->opcode = $char & 0x0f;

                break;

            case 0x01:
                $char = $this->getChar($data, $i);

                $this->isMasked = (($char & 0x80) === 0x80);
                $this->length    = $char & 0x7f;

                if ($this->isMasked) {
                    $this->headerLength += 4;
                }

                // extended length
                if ($this->length === 0x7e) {
                    $this->headerLength += 2;
                } elseif ($this->length === 0x7f) {
                    $this->headerLength += 6;
                }

                break;

            case 0x02:
            case 0x03:
                if ($this->length === 0x7e) {
                    $this->lengthData .= mb_substr($data, $i, 1, '8bit');
                    if ($this->cursor === 0x03) {
                        $this->length16 = $this->getShort($this->lengthData);
                    }
                } elseif ($this->length === 0x7f) {
                    $this->lengthData .= mb_substr($data, $i, 1, '8bit');
                } else {
                    $this->mask .= mb_substr($data, $i, 1, '8bit');
                }
                break;

            case 0x04:
            case 0x05:
            case 0x06:
            case 0x07:
                if ($this->length === 0x7f) {
                    $this->lengthData .= mb_substr($data, $i, 1, '8bit');
                } else {
                    $this->mask .= mb_substr($data, $i, 1, '8bit');
                }
                break;

            case 0x08:
            case 0x09:
                $this->lengthData .= mb_substr($data, $i, 1, '8bit');
                if ($this->cursor === 0x09) {
                    $this->length64 = $this->getLong($this->lengthData);
                }
                break;

            case 0x0a:
            case 0x0b:
                $this->mask .= mb_substr($data, $i, 1, '8bit');
                break;

            default:
                throw new Exception('Parsed frame header length incorrectly.');
            }

            $this->cursor++;

            // check if finished parsing header
            if ($this->cursor === $this->headerLength) {
                $this->isHeaderComplete = true;
                $this->state = self::STATE_HEADERS_RECEIVED;
                break;
            }
        }

        // we have more data
        if ($i < $length) {
            $data = mb_substr($data, $i + 1, $length - $i - 1, '8bit');
            $leftover = $this->parseData($data);
        }

        return $leftover;
    }
630601
protected function _parseEsearch(
        Horde_Imap_Client_Interaction_Pipeline $pipeline,
        Horde_Imap_Client_Tokenize $data
    )
    {
        // Ignore search correlator information
        if ($data->next() === true) {
            $data->flushIterator(false);
        }

        // Ignore UID tag
        $current = $data->next();
        if (Horde_String::upper($current) === 'UID') {
            $current = $data->next();
        }

        do {
            $val = $data->next();
            $tag = Horde_String::upper($current);

            switch ($tag) {
            case 'ALL':
                $this->_parseSearch($pipeline, $val);
                break;

            case 'COUNT':
            case 'MAX':
            case 'MIN':
            case 'MODSEQ':
            case 'RELEVANCY':
                $pipeline->data['esearchresp'][Horde_String::lower($tag)] = $val;
                break;

            case 'PARTIAL':
                // RFC 5267 [4.4]
                $partial = $val->flushIterator();
                $this->_parseSearch($pipeline, end($partial));
                break;
            }
        } while (($current = $data->next()) !== false);
    }
1205386
protected function _parseThread(
        Horde_Imap_Client_Interaction_Pipeline $pipeline,
        Horde_Imap_Client_Tokenize $data
    )
    {
        $out = array();

        while ($data->next() !== false) {
            $thread = array();
            $this->_parseThreadLevel($thread, $data);
            $out[] = $thread;
        }

        $pipeline->data['threadparse'] = $out;
    }
1279980
public function decode($data)
    {
        $out = array();

        $this->_data = $data;
        $this->_datalen = strlen($data);
        $this->_ptr = 0;

        while ($this->_curr() !== false) {
            $this->_rfc822SkipLwsp();

            $this->_rfc822ParseMimeToken($param);

            if (is_null($param) || ($this->_curr() != '=')) {
                break;
            }

            ++$this->_ptr;
            $this->_rfc822SkipLwsp();

            $value = '';

            if ($this->_curr() == '"') {
                try {
                    $this->_rfc822ParseQuotedString($value);
                } catch (Horde_Mail_Exception $e) {
                    break;
                }
            } else {
                $this->_rfc822ParseMimeToken($value);
                if (is_null($value)) {
                    break;
                }
            }

            $out[$param] = $value;

            $this->_rfc822SkipLwsp();
            if ($this->_curr() != ';') {
                break;
            }

            ++$this->_ptr;
        }

        return $out;
    }
1256095
protected function _parseEnabled(Horde_Imap_Client_Tokenize $data)
    {
        $c = $this->_capability();

        foreach ($data->flushIterator() as $val) {
            $c->enable($val);
        }
    }
188225
public function setEnvelope($data)
    {
        $this->_data[Horde_Imap_Client::FETCH_ENVELOPE] = is_array($data)
            ? new Horde_Imap_Client_Data_Envelope($data)
            : $data;
    }