public function getFieldValue($format = HeaderInterface::FORMAT_RAW)
 {
     $emails = [];
     $encoding = $this->getEncoding();
     foreach ($this->getAddressList() as $address) {
         $email = $address->getEmail();
         $name = $address->getName();
         if (empty($name)) {
             $emails[] = $email;
             continue;
         }
         if (false !== strstr($name, ',')) {
             $name = sprintf('"%s"', $name);
         }
         if ($format === HeaderInterface::FORMAT_ENCODED && 'ASCII' !== $encoding) {
             $name = HeaderWrap::mimeEncodeValue($name, $encoding);
         }
         $emails[] = sprintf('%s <%s>', $name, $email);
     }
     // Ensure the values are valid before sending them.
     if ($format !== HeaderInterface::FORMAT_RAW) {
         foreach ($emails as $email) {
             HeaderValue::assertValid($email);
         }
     }
     return implode(',' . Headers::FOLDING, $emails);
 }
Exemplo n.º 2
0
 /**
  * @group ZF2-359
  */
 public function testMimeEncoding()
 {
     $string = 'Umlauts: ä';
     $expected = '=?UTF-8?Q?Umlauts:=20=C3=A4?=';
     $test = HeaderWrap::mimeEncodeValue($string, 'UTF-8', 78);
     $this->assertEquals($expected, $test);
     $this->assertEquals($string, iconv_mime_decode($test, ICONV_MIME_DECODE_CONTINUE_ON_ERROR, 'UTF-8'));
 }
Exemplo n.º 3
0
 /**
  * Get the header value
  * 
  * @return string
  */
 public function getFieldValue()
 {
     $encoding = $this->getEncoding();
     if ($encoding == 'ASCII') {
         return HeaderWrap::wrap($this->subject, $this);
     }
     return HeaderWrap::mimeEncodeValue($this->subject, $encoding, true);
 }
Exemplo n.º 4
0
 public function setSubject($subject)
 {
     $subject = (string) $subject;
     if (!HeaderWrap::canBeEncoded($subject)) {
         throw new Exception\InvalidArgumentException('Subject value must be composed of printable US-ASCII or UTF-8 characters.');
     }
     $this->subject = $subject;
     $this->encoding = null;
     return $this;
 }
Exemplo n.º 5
0
 public static function fromString($headerLine)
 {
     list($name, $value) = Header\GenericHeader::splitHeaderLine($headerLine);
     $value = Header\HeaderWrap::mimeDecodeValue($value);
     if (strtolower($name) !== 'x-queue-item-id') {
         throw new Header\Exception\InvalidArgumentException('Invalid header line for Message-ID string');
     }
     $header = new static();
     $header->setId($value);
     return $header;
 }
Exemplo n.º 6
0
 public static function fromString($headerLine)
 {
     list($name, $value) = GenericHeader::splitHeaderLine($headerLine);
     $value = HeaderWrap::mimeDecodeValue($value);
     // check to ensure proper header type for this factory
     if (strtolower($name) !== 'received') {
         throw new Exception\InvalidArgumentException('Invalid header line for Received string');
     }
     $header = new static($value);
     return $header;
 }
Exemplo n.º 7
0
 public function getFieldValue($format = HeaderInterface::FORMAT_RAW)
 {
     if (!$this->address instanceof Mail\Address\AddressInterface) {
         return '';
     }
     $email = sprintf('<%s>', $this->address->getEmail());
     $name = $this->address->getName();
     if (!empty($name)) {
         $encoding = $this->getEncoding();
         if ($format == HeaderInterface::FORMAT_ENCODED && 'ASCII' !== $encoding) {
             $name = HeaderWrap::mimeEncodeValue($name, $encoding);
         }
         $email = sprintf('%s %s', $name, $email);
     }
     return $email;
 }
Exemplo n.º 8
0
 public function getFieldValue($format = HeaderInterface::FORMAT_RAW)
 {
     $emails = array();
     $encoding = $this->getEncoding();
     foreach ($this->getAddressList() as $address) {
         $email = $address->getEmail();
         $name = $address->getName();
         if (empty($name)) {
             $emails[] = $email;
         } else {
             if (false !== strstr($name, ',')) {
                 $name = sprintf('"%s"', $name);
             }
             if ($format == HeaderInterface::FORMAT_ENCODED && 'ASCII' !== $encoding) {
                 $name = HeaderWrap::mimeEncodeValue($name, $encoding);
             }
             $emails[] = sprintf('%s <%s>', $name, $email);
         }
     }
     return implode(',' . Headers::FOLDING, $emails);
 }
Exemplo n.º 9
0
 public static function fromString($headerLine)
 {
     list($name, $value) = GenericHeader::splitHeaderLine($headerLine);
     $value = HeaderWrap::mimeDecodeValue($value);
     // check to ensure proper header type for this factory
     if (strtolower($name) !== 'content-type') {
         throw new Exception\InvalidArgumentException('Invalid header line for Content-Type string');
     }
     $value = str_replace(Headers::FOLDING, ' ', $value);
     $values = preg_split('#\\s*;\\s*#', $value);
     $type = array_shift($values);
     $header = new static();
     $header->setType($type);
     // Remove empty values
     $values = array_filter($values);
     foreach ($values as $keyValuePair) {
         list($key, $value) = explode('=', $keyValuePair, 2);
         $value = trim($value, "'\" \t\n\r\v");
         $header->addParameter($key, $value);
     }
     return $header;
 }
Exemplo n.º 10
0
 /**
  * Get field value of this header
  *
  * @return string
  */
 public function getFieldValue()
 {
     $emails = array();
     $encoding = $this->getEncoding();
     foreach ($this->getAddressList() as $address) {
         $email = $address->getEmail();
         $name = $address->getName();
         if (empty($name)) {
             $emails[] = $email;
         } else {
             if (false !== strstr($name, ',')) {
                 $name = sprintf('"%s"', $name);
             }
             if ('ASCII' !== $encoding) {
                 $name = HeaderWrap::mimeEncodeValue($name, $encoding, false);
             }
             $emails[] = sprintf('%s <%s>', $name, $email);
         }
     }
     $string = implode(",\r\n ", $emails);
     return $string;
 }
Exemplo n.º 11
0
 public function getFieldValue($format = HeaderInterface::FORMAT_RAW)
 {
     if (HeaderInterface::FORMAT_ENCODED === $format) {
         return HeaderWrap::wrap($this->fieldValue, $this);
     }
     return $this->fieldValue;
 }
Exemplo n.º 12
0
 /**
  * Add a parameter pair
  *
  * @param  string $name
  * @param  string $value
  * @return ContentType
  * @throws Exception\InvalidArgumentException for parameter names that do not follow RFC 2822
  * @throws Exception\InvalidArgumentException for parameter values that do not follow RFC 2822
  */
 public function addParameter($name, $value)
 {
     $name = strtolower($name);
     $value = (string) $value;
     if (!HeaderValue::isValid($name)) {
         throw new Exception\InvalidArgumentException('Invalid content-type parameter name detected');
     }
     if (!HeaderWrap::canBeEncoded($value)) {
         throw new Exception\InvalidArgumentException('Parameter value must be composed of printable US-ASCII or UTF-8 characters.');
     }
     $this->parameters[$name] = $value;
     return $this;
 }
Exemplo n.º 13
0
 /**
  * Get header value
  *
  * @return string
  */
 public function getFieldValue()
 {
     if (!$this->address instanceof AddressDescription) {
         return '';
     }
     $email = sprintf('<%s>', $this->address->getEmail());
     $name = $this->address->getName();
     if (!empty($name)) {
         $encoding = $this->getEncoding();
         if ('ASCII' !== $encoding) {
             $name = HeaderWrap::mimeEncodeValue($name, $encoding, false);
         }
         $email = sprintf('%s %s', $name, $email);
     }
     return $email;
 }
 public function getFieldValue($format = HeaderInterface::FORMAT_RAW)
 {
     $emails = [];
     $encoding = $this->getEncoding();
     foreach ($this->getAddressList() as $address) {
         $email = $address->getEmail();
         $name = $address->getName();
         if (!empty($name) && false !== strstr($name, ',')) {
             $name = sprintf('"%s"', $name);
         }
         if ($format === HeaderInterface::FORMAT_ENCODED && 'ASCII' !== $encoding) {
             if (!empty($name)) {
                 $name = HeaderWrap::mimeEncodeValue($name, $encoding);
             }
             if (preg_match('/^(.+)@([^@]+)$/', $email, $matches)) {
                 $localPart = $matches[1];
                 $hostname = $this->idnToAscii($matches[2]);
                 $email = sprintf('%s@%s', $localPart, $hostname);
             }
         }
         if (empty($name)) {
             $emails[] = $email;
         } else {
             $emails[] = sprintf('%s <%s>', $name, $email);
         }
     }
     // Ensure the values are valid before sending them.
     if ($format !== HeaderInterface::FORMAT_RAW) {
         foreach ($emails as $email) {
             HeaderValue::assertValid($email);
         }
     }
     return implode(',' . Headers::FOLDING, $emails);
 }