original_string: 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;
      }
code: 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;
      }
code_tokens: 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 ; }
docstring: 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.
docstring_tokens: Builds a Horde_Mime_Headers object from header text .