Ejemplo n.º 1
0
 /**
  * Parses the body parts of the provided message
  * @param zibo\library\mail\Message $message The message to parse the parts of
  * @param array $variables Array with variables to replace in the body
  * @return null
  */
 private function parseParts(Message $message, array $variables)
 {
     $attachments = $message->getParts();
     $numParts = count($attachments);
     $body = null;
     if (isset($attachments[Message::PART_BODY])) {
         $body = $attachments[Message::PART_BODY];
         unset($attachments[Message::PART_BODY]);
     }
     $alternative = null;
     if (isset($attachments[Message::PART_ALTERNATIVE])) {
         $alternative = $attachments[Message::PART_ALTERNATIVE];
         unset($attachments[Message::PART_ALTERNATIVE]);
     }
     if (!$alternative && $numParts == 1) {
         $this->headers[self::HEADER_CONTENT_TYPE] = self::HEADER_CONTENT_TYPE . ': ' . $body->getMimeType() . '; charset=' . $body->getCharset();
         $this->headers[self::HEADER_CONTENT_TRANSFER_ENCODING] = self::HEADER_CONTENT_TRANSFER_ENCODING . ': ' . $body->getTransferEncoding();
         $this->addPartToBody($body, $variables, true);
         return;
     }
     $salt = $this->generateSalt();
     if ($alternative && $numParts == 2) {
         $this->headers[self::HEADER_CONTENT_TYPE] = self::HEADER_CONTENT_TYPE . ': ' . self::MIME_MULTIPART_ALTERNATIVE . '; boundary=' . $salt;
         $this->addPartsToBody($body, $alternative, $variables, $salt);
         return;
     }
     $this->headers[self::HEADER_CONTENT_TYPE] = self::HEADER_CONTENT_TYPE . ': ' . self::MIME_MULTIPART_MIXED . '; boundary=' . $salt;
     if ($alternative) {
         $messageSalt = $this->generateSalt('message');
         $this->body .= '--' . $salt . "\n";
         $this->body .= self::HEADER_CONTENT_TYPE . ': ' . self::MIME_MULTIPART_ALTERNATIVE . '; boundary=' . $messageSalt . "\n\n";
         $this->addPartsToBody($body, $alternative, $variables, $messageSalt);
     } elseif ($body) {
         $this->body .= '--' . $salt . "\n";
         $this->addPartToBody($body, $variables);
     }
     if (isset($attachments) && is_array($attachments)) {
         foreach ($attachments as $name => $attachment) {
             $this->body .= '--' . $salt . "\n";
             $this->addAttachmentToBody($attachment, $name);
         }
     }
     $this->body .= '--' . $salt . '--' . "\n";
 }