示例#1
0
文件: Parse.php 项目: raz0rsdge/horde
 /**
  * Parses a message into text and PGP components.
  *
  * @param mixed $text  Either the text to parse or a Horde_Stream object.
  *
  * @return array  An array with the parsed text, returned in blocks of
  *                text corresponding to their actual order. Keys:
  * <pre>
  *   - data: (array) The data for each section. Each line has been
  *           stripped of EOL characters.
  *   - type: (integer) The type of data contained in block. Valid types
  *           are the class ARMOR_* constants.
  * </pre>
  */
 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;
 }
示例#2
0
 /**
  * Builds a Horde_Mime_Headers object from header text.
  *
  * @param mixed $text  A text string (or, as of 2.3.0, a Horde_Stream
  *                     object or stream resource) containing the headers.
  *
  * @return Horde_Mime_Headers  A new Horde_Mime_Headers object.
  */
 public static function parseHeaders($text)
 {
     $curr = null;
     $headers = new Horde_Mime_Headers();
     $hdr_list = array();
     if ($text instanceof Horde_Stream) {
         $stream = $text;
         $stream->rewind();
     } else {
         $stream = new Horde_Stream_Temp();
         $stream->add($text, true);
     }
     while (!$stream->eof()) {
         if (!($val = rtrim($stream->getToChar("\n", false), "\r"))) {
             break;
         }
         if ($curr && ($val[0] == ' ' || $val[0] == "\t")) {
             $curr->text .= ' ' . ltrim($val);
         } else {
             $pos = strpos($val, ':');
             $curr = new stdClass();
             $curr->header = substr($val, 0, $pos);
             $curr->text = ltrim(substr($val, $pos + 1));
             $hdr_list[] = $curr;
         }
     }
     foreach ($hdr_list as $val) {
         /* When parsing, only keep the FIRST header seen for single value
          * text-only headers, since newer headers generally are appended
          * to the top of the message. */
         if (!($ob = $headers[$val->header]) || !$ob instanceof Horde_Mime_Headers_Element_Single || $ob instanceof Horde_Mime_Headers_Addresses) {
             $headers->addHeader($val->header, rtrim($val->text));
         }
     }
     if (!$text instanceof Horde_Stream) {
         $stream->close();
     }
     return $headers;
 }
示例#3
0
 /**
  * Builds a Horde_Mime_Headers object from header text.
  *
  * @param mixed $text  A text string (or, as of 2.3.0, a Horde_Stream
  *                     object or stream resource) containing the headers.
  *
  * @return Horde_Mime_Headers  A new Horde_Mime_Headers object.
  */
 public static function parseHeaders($text)
 {
     $currheader = $currtext = null;
     $mime = self::mimeParamFields();
     $to_process = array();
     if ($text instanceof Horde_Stream) {
         $stream = $text;
         $stream->rewind();
     } else {
         $stream = new Horde_Stream_Temp();
         $stream->add($text, true);
     }
     while (!$stream->eof()) {
         if (!($val = rtrim($stream->getToChar("\n", false), "\r"))) {
             break;
         }
         if ($val[0] == ' ' || $val[0] == "\t") {
             $currtext .= ' ' . ltrim($val);
         } else {
             if (!is_null($currheader)) {
                 $to_process[] = array($currheader, rtrim($currtext));
             }
             $pos = strpos($val, ':');
             $currheader = substr($val, 0, $pos);
             $currtext = ltrim(substr($val, $pos + 1));
         }
     }
     if (!is_null($currheader)) {
         $to_process[] = array($currheader, $currtext);
     }
     $headers = new Horde_Mime_Headers();
     reset($to_process);
     while (list(, $val) = each($to_process)) {
         /* Ignore empty headers. */
         if (!strlen($val[1])) {
             continue;
         }
         if (in_array(Horde_String::lower($val[0]), $mime)) {
             $res = Horde_Mime::decodeParam($val[0], $val[1]);
             $headers->addHeader($val[0], $res['val'], array('params' => $res['params'], 'sanity_check' => true));
         } else {
             $headers->addHeader($val[0], $val[1], array('sanity_check' => true));
         }
     }
     return $headers;
 }
示例#4
0
文件: Ids.php 项目: jubinpatel/horde
 /**
  * Split the sequence string at an approximate length.
  *
  * @since 2.7.0
  *
  * @param integer $length  Length to split.
  *
  * @return array  A list containing individual sequence strings.
  */
 public function split($length)
 {
     $id = new Horde_Stream_Temp();
     $id->add($this->tostring_sort, true);
     $out = array();
     do {
         $out[] = $id->substring(0, $length) . $id->getToChar(',');
     } while (!$id->eof());
     return $out;
 }
示例#5
0
 /**
  */
 public function eof()
 {
     return $this->_string ? $this->_string->eof() : parent::eof();
 }