示例#1
0
 /**
  * Take a set of headers and make sure they are encoded properly.
  *
  * @param array $headers The headers to encode.
  * @param string $charset The character set to use.
  *
  * @return array  The array of encoded headers.
  */
 public function encode($headers, $charset)
 {
     $addressKeys = array('To', 'Cc', 'Bcc', 'From');
     $asciikeys = array('MIME-Version', 'Received', 'Message-ID', 'Date', 'Content-Disposition', 'Content-Transfer-Encoding', 'Content-ID', 'Content-Type', 'Content-Description');
     foreach ($headers as $key => $val) {
         if (is_array($val)) {
             foreach ($val as $key2 => $val2) {
                 $headers[$key][$key2] = Horde_MIME::wrapHeaders($key, $val2, $this->getEOL());
             }
         } else {
             if (in_array($key, $addressKeys)) {
                 $text = Horde_MIME::encodeAddress($val, $charset, $this->_defaultServer);
             } else {
                 $text = Horde_MIME::encode($val, in_array($key, $asciikeys) ? 'US-ASCII' : $charset);
             }
             $headers[$key] = Horde_MIME::wrapHeaders($key, $text, $this->getEOL());
         }
     }
     return $headers;
 }
示例#2
0
 /**
  * Encodes a string containing email addresses according to RFC 2047.
  *
  * This differs from MIME::encode() because it keeps email addresses legal,
  * only encoding the personal information.
  *
  * @param string $addresses The email addresses to encode.
  * @param string $charset The character set of the text.
  * @param string $defserver The default domain to append to mailboxes.
  *
  * @return string  The text, encoded only if it contains non-ascii
  *                 characters
  */
 public function encodeAddress($addresses, $charset = null, $defserver = null)
 {
     if (is_array($addresses)) {
         $addr_arr = $addresses;
     } else {
         /* parseAddressList() does not process the null entry
          * 'undisclosed-recipients:;' correctly. */
         if (preg_match('/undisclosed-recipients:\\s*;/i', trim($addresses))) {
             return $addresses;
         }
         $parser =& new Mail_RFC822();
         $addr_arr = $parser->parseAddressList($addresses, $defserver, true, false);
     }
     $text = '';
     if (is_array($addr_arr)) {
         foreach ($addr_arr as $addr) {
             // Check for groups.
             if (!empty($addr->groupname)) {
                 $text .= Horde_MIME::encode($addr->groupname, $charset) . ': ' . Horde_MIME::encodeAddress($addr->addresses) . '; ';
             } else {
                 if (empty($addr->personal)) {
                     $personal = '';
                 } else {
                     if (substr($addr->personal, 0, 1) == '"' && substr($addr->personal, -1) == '"') {
                         $addr->personal = stripslashes(substr($addr->personal, 1, -1));
                     }
                     $personal = Horde_MIME::encode($addr->personal, $charset);
                 }
                 $text .= Horde_MIME::trimEmailAddress(Horde_MIME::rfc822WriteAddress($addr->mailbox, $addr->host, $personal)) . ', ';
             }
         }
     }
     return rtrim($text, ' ,');
 }