public function parse($text)
{
$data = array();
$temp = array('type' => self::ARMOR_TEXT);
if ($text instanceof Horde_Stream) {
$stream = $text;
$stream->rewind();
} else {
$stream = new Horde_Stream_Temp();
$stream->add($text, true);
}
while (!$stream->eof()) {
$val = rtrim($stream->getToChar("\n", false), "\r");
if (strpos($val, '-----') === 0 && preg_match('/^-----(BEGIN|END) PGP ([^-]+)-----\\s*$/', $val, $matches)) {
if (isset($temp['data'])) {
$data[] = $temp;
}
$temp = array();
if ($matches[1] == 'BEGIN') {
$temp['type'] = $this->_armor[$matches[2]];
$temp['data'][] = $val;
} elseif ($matches[1] == 'END') {
$temp['type'] = self::ARMOR_TEXT;
$data[count($data) - 1]['data'][] = $val;
}
} else {
$temp['data'][] = $val;
}
}
if (isset($temp['data']) && (count($temp['data']) > 1 || !empty($temp['data'][0]))) {
$data[] = $temp;
}
return $data;
}