/**
  * Returns the ezcMailText part corresponding to the parsed message.
  *
  * @return ezcMailText
  */
 public function finish()
 {
     $charset = "us-ascii";
     // RFC 2822 default
     if (isset($this->headers['Content-Type'])) {
         preg_match('/\\s*charset\\s?=\\s?"?([^;"\\s]*);?/', $this->headers['Content-Type'], $parameters);
         if (count($parameters) > 0) {
             $charset = strtolower(trim($parameters[1], '"'));
         }
     }
     $encoding = strtolower($this->headers['Content-Transfer-Encoding']);
     if ($encoding == ezcMail::QUOTED_PRINTABLE) {
         $this->text = quoted_printable_decode($this->text);
     } else {
         if ($encoding == ezcMail::BASE64) {
             $this->text = base64_decode($this->text);
         }
     }
     $this->text = ezcMailCharsetConverter::convertToUTF8($this->text, $charset);
     $part = new ezcMailText($this->text, 'utf-8', ezcMail::EIGHT_BIT, $charset);
     $part->subType = $this->subType;
     $part->setHeaders($this->headers->getCaseSensitiveArray());
     ezcMailPartParser::parsePartHeaders($this->headers, $part);
     $part->size = strlen($this->text);
     return $part;
 }
Exemple #2
0
 /**
  * Returns an ezcMailAddress object parsed from the address string $address.
  *
  * You can set the encoding of the name part with the $encoding parameter.
  * If $encoding is omitted or set to "mime" parseEmailAddress will asume that
  * the name part is mime encoded.
  *
  * This method does not perform validation. It will also accept slightly
  * malformed addresses.
  *
  * If the mail address given can not be decoded null is returned.
  *
  * Example:
  * <code>
  * ezcMailTools::parseEmailAddress( 'John Doe <*****@*****.**>' );
  * </code>
  *
  * @param string $address
  * @param string $encoding
  * @return ezcMailAddress
  */
 public static function parseEmailAddress($address, $encoding = "mime")
 {
     // we don't care about the "group" part of the address since this is not used anywhere
     $matches = array();
     $pattern = '/<?\\"?[a-zA-Z0-9!#\\$\\%\\&\'\\*\\+\\-\\/=\\?\\^_`{\\|}~\\.]+\\"?@[a-zA-Z0-9!#\\$\\%\\&\'\\*\\+\\-\\/=\\?\\^_`{\\|}~\\.]+>?$/';
     if (preg_match(trim($pattern), $address, $matches, PREG_OFFSET_CAPTURE) != 1) {
         return null;
     }
     $name = substr($address, 0, $matches[0][1]);
     // trim <> from the address and "" from the name
     $name = trim($name, '" ');
     $mail = trim($matches[0][0], '<>');
     // remove any quotes found in mail addresses like "bah,"@example.com
     $mail = str_replace('"', '', $mail);
     if ($encoding == 'mime') {
         // the name may contain interesting character encoding. We need to convert it.
         $name = ezcMailTools::mimeDecode($name);
     } else {
         $name = ezcMailCharsetConverter::convertToUTF8($name, $encoding);
     }
     $address = new ezcMailAddress($mail, $name, 'utf-8');
     return $address;
 }