Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Public Member Functions | Protected Member Functions | Protected Attributes
Zend_Mail_Part Class Reference
Inheritance diagram for Zend_Mail_Part:
Zend_Mail_Part_Interface Zend_Mail_Message Zend_Mail_Part_File Zend_Mail_Message_File

Public Member Functions

 __construct (array $params)
 
 setPartClass ($class)
 
 getPartClass ()
 
 isMultipart ()
 
 getContent ()
 
 getSize ()
 
 getPart ($num)
 
 countParts ()
 
 getHeaders ()
 
 getHeader ($name, $format=null)
 
 headerExists ($name)
 
 getHeaderField ($name, $wantedPart=0, $firstName=0)
 
 __get ($name)
 
 __isset ($name)
 
 __toString ()
 
 hasChildren ()
 
 getChildren ()
 
 valid ()
 
 next ()
 
 key ()
 
 current ()
 
 rewind ()
 

Protected Member Functions

 _cacheContent ()
 
 _validateHeaders (array $headers, $assertNames=true)
 

Protected Attributes

 $_headers
 
 $_content
 
 $_topLines = ''
 
 $_parts = array()
 
 $_countParts
 
 $_iterationPos = 1
 
 $_mail
 
 $_messageNum = 0
 
 $_partClass
 

Detailed Description

Definition at line 50 of file Part.php.

Constructor & Destructor Documentation

◆ __construct()

__construct ( array  $params)

Public constructor

Zend_Mail_Part supports different sources for content. The possible params are:

  • handler a instance of Zend_Mail_Storage_Abstract for late fetch
  • id number of message for handler
  • raw raw content with header and body as string
  • headers headers as array (name => value) or string, if a content part is found it's used as toplines
  • noToplines ignore content found after headers in param 'headers'
  • content content as string
Parameters
array$paramsfull message with or without headers
Exceptions
Zend_Mail_Exception
See also
Zend_Mail_Exception
Zend_Mail_Exception

Definition at line 120 of file Part.php.

121  {
122  if (isset($params['handler'])) {
123  if (!$params['handler'] instanceof Zend_Mail_Storage_Abstract) {
127  #require_once 'Zend/Mail/Exception.php';
128  throw new Zend_Mail_Exception('handler is not a valid mail handler');
129  }
130  if (!isset($params['id'])) {
134  #require_once 'Zend/Mail/Exception.php';
135  throw new Zend_Mail_Exception('need a message id with a handler');
136  }
137 
138  $this->_mail = $params['handler'];
139  $this->_messageNum = $params['id'];
140  }
141 
142  if (isset($params['partclass'])) {
143  $this->setPartClass($params['partclass']);
144  }
145 
146  if (isset($params['raw'])) {
147  Zend_Mime_Decode::splitMessage($params['raw'], $this->_headers, $this->_content, "\r\n");
148  } else if (isset($params['headers'])) {
149  if (is_array($params['headers'])) {
150  $this->_headers = $params['headers'];
151  $this->_validateHeaders($this->_headers);
152  } else {
153  if (!empty($params['noToplines'])) {
154  Zend_Mime_Decode::splitMessage($params['headers'], $this->_headers, $null, "\r\n");
155  } else {
156  Zend_Mime_Decode::splitMessage($params['headers'], $this->_headers, $this->_topLines, "\r\n");
157  }
158  }
159 
160  if (isset($params['content'])) {
161  $this->_content = $params['content'];
162  }
163  }
164  }
static splitMessage( $message, &$headers, &$body, $EOL=Zend_Mime::LINEEND)
Definition: Decode.php:123
_validateHeaders(array $headers, $assertNames=true)
Definition: Part.php:588
setPartClass($class)
Definition: Part.php:171
$params[\Magento\Store\Model\StoreManager::PARAM_RUN_CODE]
Definition: website.php:18

Member Function Documentation

◆ __get()

__get (   $name)

Getter for mail headers - name is matched in lowercase

This getter is short for Zend_Mail_Part::getHeader($name, 'string')

See also
Zend_Mail_Part::getHeader()
Parameters
string$nameheader name
Returns
string value of header
Exceptions
Zend_Mail_Exception

Implements Zend_Mail_Part_Interface.

Definition at line 477 of file Part.php.

478  {
479  return $this->getHeader($name, 'string');
480  }
getHeader($name, $format=null)
Definition: Part.php:393
if(!isset($_GET['name'])) $name
Definition: log.php:14

◆ __isset()

__isset (   $name)

Isset magic method proxy to hasHeader

This method is short syntax for Zend_Mail_Part::hasHeader($name);

See also
Zend_Mail_Part::hasHeader
Parameters
string
Returns
boolean

Definition at line 492 of file Part.php.

493  {
494  return $this->headerExists($name);
495  }
headerExists($name)
Definition: Part.php:436
if(!isset($_GET['name'])) $name
Definition: log.php:14

◆ __toString()

__toString ( )

magic method to get content of part

Returns
string content

Implements Zend_Mail_Part_Interface.

Definition at line 502 of file Part.php.

503  {
504  return $this->getContent();
505  }

◆ _cacheContent()

_cacheContent ( )
protected

Cache content and split in parts if multipart

Returns
null
Exceptions
Zend_Mail_Exception
See also
Zend_Mail_Exception

Definition at line 262 of file Part.php.

263  {
264  // caching content if we can't fetch parts
265  if ($this->_content === null && $this->_mail) {
266  $this->_content = $this->_mail->getRawContent($this->_messageNum);
267  }
268 
269  if (!$this->isMultipart()) {
270  return;
271  }
272 
273  // split content in parts
274  $boundary = $this->getHeaderField('content-type', 'boundary');
275  if (!$boundary) {
279  #require_once 'Zend/Mail/Exception.php';
280  throw new Zend_Mail_Exception('no boundary found in content type to split message');
281  }
282  $parts = Zend_Mime_Decode::splitMessageStruct($this->_content, $boundary);
283  if ($parts === null) {
284  return;
285  }
286  $partClass = $this->getPartClass();
287  $counter = 1;
288  foreach ($parts as $part) {
289  $this->_parts[$counter++] = new $partClass(array('headers' => $part['header'], 'content' => $part['body']));
290  }
291  }
getHeaderField($name, $wantedPart=0, $firstName=0)
Definition: Part.php:461
static splitMessageStruct( $message, $boundary, $EOL=Zend_Mime::LINEEND)
Definition: Decode.php:91
getPartClass()
Definition: Part.php:196

◆ _validateHeaders()

_validateHeaders ( array  $headers,
  $assertNames = true 
)
protected

Ensure headers do not contain invalid characters

Parameters
array$headers
bool$assertNames

Definition at line 588 of file Part.php.

589  {
590  foreach ($headers as $name => $value) {
591  if ($assertNames) {
593  }
594 
595  if (is_array($value)) {
596  $this->_validateHeaders($value, false);
597  continue;
598  }
599 
601  }
602  }
_validateHeaders(array $headers, $assertNames=true)
Definition: Part.php:588
$value
Definition: gender.phtml:16
if(!isset($_GET['name'])) $name
Definition: log.php:14

◆ countParts()

countParts ( )

Count parts of a multipart part

Returns
int number of sub-parts

Implements Zend_Mail_Part_Interface.

Definition at line 337 of file Part.php.

338  {
339  if ($this->_countParts) {
340  return $this->_countParts;
341  }
342 
343  $this->_countParts = count($this->_parts);
344  if ($this->_countParts) {
345  return $this->_countParts;
346  }
347 
348  if ($this->_mail && $this->_mail->hasFetchPart) {
349  // TODO: fetch part
350  // return
351  }
352 
353  $this->_cacheContent();
354 
355  $this->_countParts = count($this->_parts);
356  return $this->_countParts;
357  }
_cacheContent()
Definition: Part.php:262

◆ current()

current ( )

implements Iterator::current()

Returns
Zend_Mail_Part current part

Definition at line 566 of file Part.php.

567  {
568  return $this->getPart($this->_iterationPos);
569  }
getPart($num)
Definition: Part.php:300

◆ getChildren()

getChildren ( )

implements RecursiveIterator::getChildren()

Returns
Zend_Mail_Part same as self::current()

Definition at line 523 of file Part.php.

524  {
525  return $this->current();
526  }

◆ getContent()

getContent ( )

Body of part

If part is multipart the raw content of this part with all sub parts is returned

Returns
string body
Exceptions
Zend_Mail_Exception
See also
Zend_Mail_Exception

Implements Zend_Mail_Part_Interface.

Definition at line 227 of file Part.php.

228  {
229  if ($this->_content !== null) {
230  return $this->_content;
231  }
232 
233  if ($this->_mail) {
234  return $this->_mail->getRawContent($this->_messageNum);
235  } else {
239  #require_once 'Zend/Mail/Exception.php';
240  throw new Zend_Mail_Exception('no content');
241  }
242  }

◆ getHeader()

getHeader (   $name,
  $format = null 
)

Get a header in specificed format

Internally headers that occur more than once are saved as array, all other as string. If $format is set to string implode is used to concat the values (with Zend_Mime::LINEEND as delim).

Parameters
string$namename of header, matches case-insensitive, but camel-case is replaced with dashes
string$formatchange type of return value to 'string' or 'array'
Returns
string|array value of header in wanted or internal format
Exceptions
Zend_Mail_Exception
See also
Zend_Mail_Exception

Implements Zend_Mail_Part_Interface.

Definition at line 393 of file Part.php.

394  {
395  if ($this->_headers === null) {
396  $this->getHeaders();
397  }
398 
399  $lowerName = strtolower($name);
400 
401  if ($this->headerExists($name) == false) {
402  $lowerName = strtolower(preg_replace('%([a-z])([A-Z])%', '\1-\2', $name));
403  if($this->headerExists($lowerName) == false) {
407  #require_once 'Zend/Mail/Exception.php';
408  throw new Zend_Mail_Exception("no Header with Name $name or $lowerName found");
409  }
410  }
411  $name = $lowerName;
412 
413  $header = $this->_headers[$name];
414 
415  switch ($format) {
416  case 'string':
417  if (is_array($header)) {
418  $header = implode(Zend_Mime::LINEEND, $header);
419  }
420  break;
421  case 'array':
422  $header = (array)$header;
423  default:
424  // do nothing
425  }
426 
427  return $header;
428  }
headerExists($name)
Definition: Part.php:436
const LINEEND
Definition: Mime.php:42
$format
Definition: list.phtml:12
if(!isset($_GET['name'])) $name
Definition: log.php:14

◆ getHeaderField()

getHeaderField (   $name,
  $wantedPart = 0,
  $firstName = 0 
)

Get a specific field from a header like content type or all fields as array

If the header occurs more than once, only the value from the first header is returned.

Throws a Zend_Mail_Exception if the requested header does not exist. If the specific header field does not exist, returns null.

Parameters
string$namename of header, like in getHeader()
string$wantedPartthe wanted part, default is first, if null an array with all parts is returned
string$firstNamekey name for the first part
Returns
string|array wanted part or all parts as array($firstName => firstPart, partname => value)
Exceptions
Zend_Exception,Zend_Mail_Exception

Implements Zend_Mail_Part_Interface.

Definition at line 461 of file Part.php.

461  {
462  return Zend_Mime_Decode::splitHeaderField(current($this->getHeader($name, 'array')), $wantedPart, $firstName);
463  }
static splitHeaderField( $field, $wantedPart=null, $firstName=0)
Definition: Decode.php:217
getHeader($name, $format=null)
Definition: Part.php:393
if(!isset($_GET['name'])) $name
Definition: log.php:14

◆ getHeaders()

getHeaders ( )

Get all headers

The returned headers are as saved internally. All names are lowercased. The value is a string or an array if a header with the same name occurs more than once.

Returns
array headers as array(name => value)

Implements Zend_Mail_Part_Interface.

Definition at line 368 of file Part.php.

369  {
370  if ($this->_headers === null) {
371  if (!$this->_mail) {
372  $this->_headers = array();
373  } else {
374  $part = $this->_mail->getRawHeader($this->_messageNum);
375  Zend_Mime_Decode::splitMessage($part, $this->_headers, $null);
376  }
377  }
378 
379  return $this->_headers;
380  }
static splitMessage( $message, &$headers, &$body, $EOL=Zend_Mime::LINEEND)
Definition: Decode.php:123

◆ getPart()

getPart (   $num)

Get part of multipart message

Parameters
int$numnumber of part starting with 1 for first part
Returns
Zend_Mail_Part wanted part
Exceptions
Zend_Mail_Exception
See also
Zend_Mail_Exception
Zend_Mail_Exception

Implements Zend_Mail_Part_Interface.

Definition at line 300 of file Part.php.

301  {
302  if (isset($this->_parts[$num])) {
303  return $this->_parts[$num];
304  }
305 
306  if (!$this->_mail && $this->_content === null) {
310  #require_once 'Zend/Mail/Exception.php';
311  throw new Zend_Mail_Exception('part not found');
312  }
313 
314  if ($this->_mail && $this->_mail->hasFetchPart) {
315  // TODO: fetch part
316  // return
317  }
318 
319  $this->_cacheContent();
320 
321  if (!isset($this->_parts[$num])) {
325  #require_once 'Zend/Mail/Exception.php';
326  throw new Zend_Mail_Exception('part not found');
327  }
328 
329  return $this->_parts[$num];
330  }
_cacheContent()
Definition: Part.php:262

◆ getPartClass()

getPartClass ( )

Retrieve the class name used to encapsulate message parts

Returns
string

Definition at line 196 of file Part.php.

197  {
198  if ( !$this->_partClass ) {
199  $this->_partClass = __CLASS__;
200  }
201  return $this->_partClass;
202  }

◆ getSize()

getSize ( )

Return size of part

Quite simple implemented currently (not decoding). Handle with care.

Returns
int size

Implements Zend_Mail_Part_Interface.

Definition at line 251 of file Part.php.

251  {
252  return strlen($this->getContent());
253  }

◆ hasChildren()

hasChildren ( )

implements RecursiveIterator::hasChildren()

Returns
bool current element has children/is multipart

Definition at line 512 of file Part.php.

513  {
514  $current = $this->current();
515  return $current && $current instanceof Zend_Mail_Part && $current->isMultipart();
516  }

◆ headerExists()

headerExists (   $name)

Check wheater the Mail part has a specific header.

Parameters
string$name
Returns
boolean

Definition at line 436 of file Part.php.

437  {
438  $name = strtolower($name);
439  if(isset($this->_headers[$name])) {
440  return true;
441  } else {
442  return false;
443  }
444  }
if(!isset($_GET['name'])) $name
Definition: log.php:14

◆ isMultipart()

isMultipart ( )

Check if part is a multipart message

Returns
bool if part is multipart

Implements Zend_Mail_Part_Interface.

Definition at line 209 of file Part.php.

210  {
211  try {
212  return stripos($this->contentType, 'multipart/') === 0;
213  } catch(Zend_Mail_Exception $e) {
214  return false;
215  }
216  }

◆ key()

key ( )

implements Iterator::key()

Returns
string key/number of current part

Definition at line 556 of file Part.php.

557  {
558  return $this->_iterationPos;
559  }

◆ next()

next ( )

implements Iterator::next()

Returns
null

Definition at line 546 of file Part.php.

547  {
549  }

◆ rewind()

rewind ( )

implements Iterator::rewind()

Returns
null

Definition at line 576 of file Part.php.

577  {
578  $this->countParts();
579  $this->_iterationPos = 1;
580  }

◆ setPartClass()

setPartClass (   $class)

Set name pf class used to encapsulate message parts

Parameters
string$class
Returns
Zend_Mail_Part
See also
Zend_Mail_Exception
Zend_Mail_Exception

Definition at line 171 of file Part.php.

172  {
173  if ( !class_exists($class) ) {
177  #require_once 'Zend/Mail/Exception.php';
178  throw new Zend_Mail_Exception("Class '{$class}' does not exist");
179  }
180  if ( !is_subclass_of($class, 'Zend_Mail_Part_Interface') ) {
184  #require_once 'Zend/Mail/Exception.php';
185  throw new Zend_Mail_Exception("Class '{$class}' must implement Zend_Mail_Part_Interface");
186  }
187 
188  $this->_partClass = $class;
189  return $this;
190  }
is_subclass_of($obj, $className)
$_option $_optionId $class
Definition: date.phtml:13

◆ valid()

valid ( )

implements Iterator::valid()

Returns
bool check if there's a current element

Definition at line 533 of file Part.php.

534  {
535  if ($this->_countParts === null) {
536  $this->countParts();
537  }
538  return $this->_iterationPos && $this->_iterationPos <= $this->_countParts;
539  }

Field Documentation

◆ $_content

$_content
protected

Definition at line 62 of file Part.php.

◆ $_countParts

$_countParts
protected

Definition at line 80 of file Part.php.

◆ $_headers

$_headers
protected

Definition at line 56 of file Part.php.

◆ $_iterationPos

$_iterationPos = 1
protected

Definition at line 86 of file Part.php.

◆ $_mail

$_mail
protected

Definition at line 92 of file Part.php.

◆ $_messageNum

$_messageNum = 0
protected

Definition at line 98 of file Part.php.

◆ $_partClass

$_partClass
protected

Definition at line 104 of file Part.php.

◆ $_parts

$_parts = array()
protected

Definition at line 74 of file Part.php.

◆ $_topLines

$_topLines = ''
protected

Definition at line 68 of file Part.php.


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