.

AttachmentsBuilder Class Reference

Build message body for a message containing attachments. More...

Inheritance diagram for AttachmentsBuilder:
IMailMessageBuilder AlternativeMessageBuilder

List of all members.

Public Member Functions

  __construct (IMailMessageBuilder $msg_builder, $attachments)
  Constructors.
  get_additional_headers ()
  Return additional mail headers.
  get_body ()
  Return mail body.
  get_boundary ()
  Returns generated boundary.
  get_mail_mime ()
  Return mime type of mail as a whole.

Protected Member Functions

  create_attachment_block ($name, $file)
  Create a block for an attachment.
  create_block ($mime_type, $encoding, $content, $more_headers=array())
  Create a block in the body.
  end_seperator ($boundary)
  Return seperator.
  start_seperator ($boundary)
  Return seperator.

Protected Attributes

  $attachments
  $boundary
  $message_builder

Detailed Description

Build message body for a message containing attachments.

Definition at line 7 of file attachments.builder.php.


Constructor & Destructor Documentation

AttachmentsBuilder::__construct ( IMailMessageBuilder msg_builder,
attachments  
)

Constructors.

Parameters:
IMailMessageBuiler  $msg_builder Builder for the message body
array  $attachments Attachments as associative array of name to filename

Definition at line 35 of file attachments.builder.php.

00035                                                                                     {
00036                 $this->message_builder = $msg_builder;
00037                 $this->attachments = $attachments;
00038                 $this->boundary = 'GYROMAILSEP-' . Common::create_token();
00039         }

Member Function Documentation

AttachmentsBuilder::create_attachment_block ( name,
file  
) [protected]

Create a block for an attachment.

Definition at line 95 of file attachments.builder.php.

00095                                                                  {
00096                 return $this->create_block(
00097                         $this->get_attachment_mime($file) . '; name=' . ConverterFactory::encode($name, ConverterFactory::MIMEHEADER),
00098                         'base64',
00099                         base64_encode(file_get_contents($file))
00100                 );              
00101         }       
AttachmentsBuilder::create_block ( mime_type,
encoding,
content,
more_headers = array()  
) [protected]

Create a block in the body.

Definition at line 106 of file attachments.builder.php.

00106                                                                                                   {
00107                 $ret = '';
00108                 $header = $more_headers;
00109                 $header['Content-Type'] = $mime_type;
00110                 if ($encoding) {
00111                         $header['Content-Transfer-Encoding'] = $encoding;
00112                 }       
00113                 
00114                 $ret = Arr::implode("\n", $header, ': ') . "\n\n" . $content;
00115                 return $ret;
00116         }
AttachmentsBuilder::end_seperator ( boundary  )  [protected]

Return seperator.

Definition at line 88 of file attachments.builder.php.

00088                                                     {
00089                 return "\n--" . $boundary . "--\n";
00090         }
AttachmentsBuilder::get_additional_headers (  ) 

Return additional mail headers.

Attention:
Content-Type header is already added
Returns:
$headers Associative array with header name as key

Implements IMailMessageBuilder.

Definition at line 138 of file attachments.builder.php.

00138                                                  {
00139                 return array();
00140         }       
AttachmentsBuilder::get_body (  ) 

Return mail body.

Returns:
string

Implements IMailMessageBuilder.

Reimplemented in AlternativeMessageBuilder.

Definition at line 55 of file attachments.builder.php.

00055                                    {
00056                 $blocks = array();
00057                 $blocks[] = $this->create_block(
00058                         $this->message_builder->get_mail_mime(), false, $this->message_builder->get_body(), $this->message_builder->get_additional_headers()
00059                 );
00060                 foreach($this->attachments as $name => $file) {
00061                         $blocks[] = $this->create_attachment_block($name, $file);
00062                 }               
00063                 return 
00064                         $this->start_seperator($this->boundary) .
00065                         implode("\n" . $this->start_seperator($this->boundary), $blocks) .
00066                         $this->end_seperator($this->boundary);
00067         }
AttachmentsBuilder::get_boundary (  ) 

Returns generated boundary.

Returns:
string

Definition at line 74 of file attachments.builder.php.

00074                                        {
00075                 return $this->boundary;
00076         }
AttachmentsBuilder::get_mail_mime (  ) 

Return mime type of mail as a whole.

Returns:
string

Implements IMailMessageBuilder.

Reimplemented in AlternativeMessageBuilder.

Definition at line 46 of file attachments.builder.php.

00046                                         {
00047                 return  'multipart/mixed; boundary="' . $this->boundary . '"';
00048         }
AttachmentsBuilder::start_seperator ( boundary  )  [protected]

Return seperator.

Definition at line 81 of file attachments.builder.php.

00081                                                       {
00082                 return "--" . $boundary . "\n";
00083         }

Member Data Documentation

AttachmentsBuilder::$attachments [protected]

Definition at line 20 of file attachments.builder.php.

AttachmentsBuilder::$boundary [protected]

Definition at line 27 of file attachments.builder.php.

AttachmentsBuilder::$message_builder [protected]

Definition at line 13 of file attachments.builder.php.


The documentation for this class was generated from the following file: