/**
  * Cast a given value
  *
  * @see     xp://scriptlet.xml.workflow.casters.ParamCaster
  * @param   array value
  * @return  array value
  */
 public function castValue($value)
 {
     $return = [];
     foreach ($value as $k => $v) {
         try {
             $addr = InternetAddress::fromString($v);
         } catch (\lang\FormatException $e) {
             return $e->getMessage();
         }
         $return[$k] = $addr;
     }
     return $return;
 }
 public function parse_from_string_without_personal()
 {
     $address = InternetAddress::fromString('*****@*****.**');
     $this->assertEquals('kiesel', $address->localpart);
     $this->assertEquals('example.com', $address->domain);
 }
Exemplo n.º 3
0
 /**
  * Set headers from string
  *
  * @param   string str
  */
 public function setHeaderString($str)
 {
     $this->subject = $this->contenttype = '';
     $t = strtok($str, "\n\r");
     while ($t) {
         if ("\t" === $t[0] || ' ' === $t[0]) {
             $value = substr($t, 1);
         } else {
             $value = null;
             sscanf($t, "%[^:]: %[^\r]", $k, $value);
         }
         switch (strtolower($k)) {
             case 'from':
                 if ('' === $value) {
                     break;
                 }
                 try {
                     $this->setFrom(InternetAddress::fromString($value));
                 } catch (\lang\FormatException $e) {
                     $this->setFrom(new InternetAddress([null, null], $value));
                 }
                 break;
             case 'to':
             case 'cc':
             case 'bcc':
                 if ('' === $value) {
                     break;
                 }
                 $k = strtolower($k);
                 $offset = 0;
                 do {
                     if ('"' === $value[$offset]) {
                         $quote = strpos($value, '"', $offset + 1);
                         $span = strcspn($value, ',', $offset + $quote) + $quote;
                     } else {
                         $span = strcspn($value, ',', $offset);
                     }
                     $recipient = substr($value, $offset, $span);
                     try {
                         $this->addRecipient($k, InternetAddress::fromString($recipient));
                     } catch (\lang\FormatException $e) {
                         $this->addRecipient($k, new InternetAddress([null, null], $value));
                     }
                     $offset += $span + strspn($value, ', ', $offset + $span);
                 } while ($offset < strlen($value));
                 break;
             case 'mime-version':
                 $this->mimever = $value;
                 break;
             case 'subject':
                 $this->subject .= ($this->subject ? ' ' : '') . $this->decode($value);
                 break;
             case 'content-type':
                 $this->contenttype .= $value;
                 break;
             case 'content-transfer-encoding':
                 $this->encoding = $value;
                 break;
             case 'date':
                 $this->setDate($value);
                 break;
             case 'x-priority':
                 $this->priority = (int) $value;
                 break;
             case 'message-id':
                 $this->message_id = $value;
                 break;
             default:
                 $this->_setHeader($k, $this->decode($value), ' ');
                 break;
         }
         $t = strtok("\n\r");
     }
 }