00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00018 final class MimeMail implements MailBuilder
00019 {
00020 private $parts = array();
00021
00022
00023 private $body = null;
00024 private $headers = null;
00025
00029 public function addPart(MimePart $part)
00030 {
00031 $this->parts[] = $part;
00032
00033 return $this;
00034 }
00035
00036 public function build()
00037 {
00038 if (!$this->parts)
00039 throw new UnimplementedFeatureException();
00040
00041 $boundary = '=_'.md5(microtime(true));
00042
00043 $mail =
00044 MimePart::create()->
00045 setContentType('multipart/mixed')->
00046 setBoundary($boundary);
00047
00048 $this->headers =
00049 "MIME-Version: 1.0\n"
00050 .$mail->getHeaders();
00051
00052 foreach ($this->parts as $part)
00053 $this->body .=
00054 '--'.$boundary."\n"
00055 .$part->getHeaders()
00056 ."\n\n"
00057 .$part->getEncodedBody()."\n";
00058
00059 $this->body .= '--'.$boundary."--"."\n\n";
00060 }
00061
00062 public function getEncodedBody()
00063 {
00064 Assert::isTrue(
00065 $this->body && $this->headers
00066 );
00067
00068 return $this->body;
00069 }
00070
00071 public function getHeaders()
00072 {
00073 Assert::isTrue(
00074 $this->body && $this->headers
00075 );
00076
00077 return $this->headers;
00078 }
00079 }
00080 ?>