Exemple #1
0
 /**
  * Returns the internal header array in array format.
  *
  * @param array $opts  Optional parameters:
  *   - canonical: (boolean) Use canonical (RFC 822/2045) line endings?
  *                DEFAULT: Uses $this->_eol
  *   - charset: (string) Encodes the headers using this charset. If empty,
  *              encodes using internal charset (UTF-8).
  *              DEFAULT: No encoding.
  *   - defserver: (string) The default domain to append to mailboxes.
  *                DEFAULT: No default name.
  *   - nowrap: (integer) Don't wrap the headers.
  *             DEFAULT: Headers are wrapped.
  *
  * @return array  The headers in array format.
  */
 public function toArray(array $opts = array())
 {
     $address_keys = $this->addressFields();
     $charset = array_key_exists('charset', $opts) ? empty($opts['charset']) ? 'UTF-8' : $opts['charset'] : null;
     $eol = empty($opts['canonical']) ? $this->_eol : "\r\n";
     $mime = $this->mimeParamFields();
     $ret = array();
     foreach ($this->_headers as $header => $ob) {
         $val = is_array($ob['v']) ? $ob['v'] : array($ob['v']);
         foreach (array_keys($val) as $key) {
             if (in_array($header, $address_keys)) {
                 /* Address encoded headers. */
                 $rfc822 = new Horde_Mail_Rfc822();
                 $text = $rfc822->parseAddressList($val[$key], array('default_domain' => empty($opts['defserver']) ? null : $opts['defserver']))->writeAddress(array('encode' => $charset, 'idn' => true));
             } elseif (in_array($header, $mime) && !empty($ob['p'])) {
                 /* MIME encoded headers (RFC 2231). */
                 $text = $val[$key];
                 foreach ($ob['p'] as $name => $param) {
                     foreach (Horde_Mime::encodeParam($name, $param, array('charset' => $charset, 'escape' => true)) as $name2 => $param2) {
                         $text .= '; ' . $name2 . '=' . $param2;
                     }
                 }
             } else {
                 $text = is_null($charset) ? $val[$key] : Horde_Mime::encode($val[$key], $charset);
             }
             if (empty($opts['nowrap'])) {
                 /* Remove any existing linebreaks and wrap the line. */
                 $header_text = $ob['h'] . ': ';
                 $text = ltrim(substr(wordwrap($header_text . strtr(trim($text), array("\r" => '', "\n" => '')), 76, $eol . ' '), strlen($header_text)));
             }
             $val[$key] = $text;
         }
         $ret[$ob['h']] = count($val) == 1 ? reset($val) : $val;
     }
     return $ret;
 }
Exemple #2
0
 public function testBug12127()
 {
     Horde_Mime::$brokenRFC2231 = true;
     $this->assertEquals(array('foo' => 'test'), Horde_Mime::encodeParam('foo', 'test', array('charset' => 'UTF-16LE')));
     $this->assertEquals(array('foo*' => "utf-16le''%01%01", 'foo' => '"=?utf-16le?b?AQE=?="'), Horde_Mime::encodeParam('foo', 'ā', array('charset' => 'UTF-16LE')));
 }