Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Public Member Functions | Static Public Member Functions | Static Protected Member Functions | Protected Attributes
Zend_Mime_Message Class Reference
Inheritance diagram for Zend_Mime_Message:
Zend_Mail

Public Member Functions

 getParts ()
 
 setParts ($parts)
 
 addPart (Zend_Mime_Part $part)
 
 isMultiPart ()
 
 setMime (Zend_Mime $mime)
 
 getMime ()
 
 generateMessage ($EOL=Zend_Mime::LINEEND)
 
 getPartHeadersArray ($partnum)
 
 getPartHeaders ($partnum, $EOL=Zend_Mime::LINEEND)
 
 getPartContent ($partnum, $EOL=Zend_Mime::LINEEND)
 

Static Public Member Functions

static createFromMessage ( $message, $boundary, $EOL=Zend_Mime::LINEEND)
 

Static Protected Member Functions

static _disassembleMime ($body, $boundary)
 

Protected Attributes

 $_parts = array()
 
 $_mime = null
 

Detailed Description

Definition at line 38 of file Message.php.

Member Function Documentation

◆ _disassembleMime()

static _disassembleMime (   $body,
  $boundary 
)
staticprotected

Explode MIME multipart string into seperate parts

Parts consist of the header and the body of each MIME part.

Parameters
string$body
string$boundary
Exceptions
Zend_Exception
Returns
array

Definition at line 213 of file Message.php.

214  {
215  $start = 0;
216  $res = array();
217  // find every mime part limiter and cut out the
218  // string before it.
219  // the part before the first boundary string is discarded:
220  $p = strpos($body, '--' . $boundary . "\n", $start);
221  if ($p === false) {
222  // no parts found!
223  return array();
224  }
225 
226  // position after first boundary line
227  $start = $p + 3 + strlen($boundary);
228 
229  while (($p = strpos($body, '--' . $boundary . "\n", $start))
230  !== false) {
231  $res[] = substr($body, $start, $p - $start);
232  $start = $p + 3 + strlen($boundary);
233  }
234 
235  // no more parts, find end boundary
236  $p = strpos($body, '--' . $boundary . '--', $start);
237  if ($p === false) {
238  throw new Zend_Exception('Not a valid Mime Message: End Missing');
239  }
240 
241  // the remaining part also needs to be parsed:
242  $res[] = substr($body, $start, $p - $start);
243 
244  return $res;
245  }
$start
Definition: listing.phtml:18

◆ addPart()

addPart ( Zend_Mime_Part  $part)

Append a new Zend_Mime_Part to the current message

Parameters
Zend_Mime_Part$part
Todo:
check for duplicate object handle

Definition at line 79 of file Message.php.

80  {
84  $this->_parts[] = $part;
85  }

◆ createFromMessage()

static createFromMessage (   $message,
  $boundary,
  $EOL = Zend_Mime::LINEEND 
)
static

Decodes a MIME encoded string and returns a Zend_Mime_Message object with all the MIME parts set according to the given string

Parameters
string$message
string$boundary
string$EOLEOL string; defaults to Zend_Mime::LINEEND
Exceptions
Zend_Exception
Returns
Zend_Mime_Message
Todo:
check for characterset and filename

Definition at line 257 of file Message.php.

260  {
261  #require_once 'Zend/Mime/Decode.php';
262  $parts = Zend_Mime_Decode::splitMessageStruct($message, $boundary, $EOL);
263 
264  $res = new self();
265  foreach ($parts as $part) {
266  // now we build a new MimePart for the current Message Part:
267  $newPart = new Zend_Mime_Part($part['body']);
268  foreach ($part['header'] as $key => $value) {
272  switch (strtolower($key)) {
273  case 'content-type':
274  $newPart->type = $value;
275  break;
276  case 'content-transfer-encoding':
277  $newPart->encoding = $value;
278  break;
279  case 'content-id':
280  $newPart->id = trim($value, '<>');
281  break;
282  case 'content-disposition':
283  $newPart->disposition = $value;
284  break;
285  case 'content-description':
286  $newPart->description = $value;
287  break;
288  case 'content-location':
289  $newPart->location = $value;
290  break;
291  case 'content-language':
292  $newPart->language = $value;
293  break;
294  default:
295  throw new Zend_Exception(
296  'Unknown header ignored for MimePart:' . $key
297  );
298  }
299  }
300  $res->addPart($newPart);
301  }
302 
303  return $res;
304  }
$message
static splitMessageStruct( $message, $boundary, $EOL=Zend_Mime::LINEEND)
Definition: Decode.php:91
$value
Definition: gender.phtml:16

◆ generateMessage()

generateMessage (   $EOL = Zend_Mime::LINEEND)

Generate MIME-compliant message from the current configuration

This can be a multipart message if more than one MIME part was added. If only one part is present, the content of this part is returned. If no part had been added, an empty string is returned.

Parts are seperated by the mime boundary as defined in Zend_Mime. If setMime() has been called before this method, the Zend_Mime object set by this call will be used. Otherwise, a new Zend_Mime object is generated and used.

Parameters
string$EOLEOL string; defaults to Zend_Mime::LINEEND
Returns
string

Definition at line 143 of file Message.php.

144  {
145  if (!$this->isMultiPart()) {
146  $body = array_shift($this->_parts);
147  $body = $body->getContent($EOL);
148  } else {
149  $mime = $this->getMime();
150 
151  $boundaryLine = $mime->boundaryLine($EOL);
152  $body = 'This is a message in Mime Format. If you see this, '
153  . "your mail reader does not support this format." . $EOL;
154 
155  foreach (array_keys($this->_parts) as $p) {
156  $body .= $boundaryLine
157  . $this->getPartHeaders($p, $EOL)
158  . $EOL
159  . $this->getPartContent($p, $EOL);
160  }
161 
162  $body .= $mime->mimeEnd($EOL);
163  }
164 
165  return trim($body);
166  }
getPartHeaders($partnum, $EOL=Zend_Mime::LINEEND)
Definition: Message.php:186
getPartContent($partnum, $EOL=Zend_Mime::LINEEND)
Definition: Message.php:198

◆ getMime()

getMime ( )

Returns the Zend_Mime object in use by the message

If the object was not present, it is created and returned. Can be used to determine the boundary used in this message.

Returns
Zend_Mime

Definition at line 119 of file Message.php.

120  {
121  if ($this->_mime === null) {
122  $this->_mime = new Zend_Mime();
123  }
124 
125  return $this->_mime;
126  }

◆ getPartContent()

getPartContent (   $partnum,
  $EOL = Zend_Mime::LINEEND 
)

Get the (encoded) content of a given part as a string

Parameters
int$partnum
string$EOL
Returns
string

Definition at line 198 of file Message.php.

199  {
200  return $this->_parts[$partnum]->getContent($EOL);
201  }

◆ getPartHeaders()

getPartHeaders (   $partnum,
  $EOL = Zend_Mime::LINEEND 
)

Get the headers of a given part as a string

Parameters
int$partnum
string$EOL
Returns
string

Definition at line 186 of file Message.php.

187  {
188  return $this->_parts[$partnum]->getHeaders($EOL);
189  }

◆ getPartHeadersArray()

getPartHeadersArray (   $partnum)

Get the headers of a given part as an array

Parameters
int$partnum
Returns
array

Definition at line 174 of file Message.php.

175  {
176  return $this->_parts[$partnum]->getHeadersArray();
177  }

◆ getParts()

getParts ( )

Returns the list of all Zend_Mime_Parts in the message

Returns
array of Zend_Mime_Part

Definition at line 59 of file Message.php.

60  {
61  return $this->_parts;
62  }

◆ isMultiPart()

isMultiPart ( )

Check if message needs to be sent as multipart MIME message or if it has only one part.

Returns
boolean

Definition at line 93 of file Message.php.

94  {
95  return (count($this->_parts) > 1);
96  }

◆ setMime()

setMime ( Zend_Mime  $mime)

Set Zend_Mime object for the message

This can be used to set the boundary specifically or to use a subclass of Zend_Mime for generating the boundary.

Parameters
Zend_Mime$mime

Definition at line 106 of file Message.php.

107  {
108  $this->_mime = $mime;
109  }

◆ setParts()

setParts (   $parts)

Sets the given array of Zend_Mime_Parts as the array for the message

Parameters
array$parts

Definition at line 69 of file Message.php.

70  {
71  $this->_parts = $parts;
72  }

Field Documentation

◆ $_mime

$_mime = null
protected

Definition at line 52 of file Message.php.

◆ $_parts

$_parts = array()
protected

Definition at line 45 of file Message.php.


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