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

Public Member Functions

 __construct (array $params)
 
 getContent ($stream=null)
 
 getSize ()
 
 getPart ($num)
 
- Public Member Functions inherited from Zend_Mail_Part
 __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 Attributes

 $_contentPos = array()
 
 $_partPos = array()
 
 $_fh
 
- Protected Attributes inherited from Zend_Mail_Part
 $_headers
 
 $_content
 
 $_topLines = ''
 
 $_parts = array()
 
 $_countParts
 
 $_iterationPos = 1
 
 $_mail
 
 $_messageNum = 0
 
 $_partClass
 

Additional Inherited Members

- Protected Member Functions inherited from Zend_Mail_Part
 _cacheContent ()
 
 _validateHeaders (array $headers, $assertNames=true)
 

Detailed Description

Definition at line 40 of file File.php.

Constructor & Destructor Documentation

◆ __construct()

__construct ( array  $params)

Public constructor

This handler supports the following params:

  • file filename or open file handler with message content (required)
  • startPos start position of message or part in file (default: current position)
  • endPos end position of message or part in file (default: end of file)
Parameters
array$paramsfull message with or without headers
Exceptions
Zend_Mail_Exception
See also
Zend_Mail_Exception
Zend_Mail_Exception
Zend_Mail_Exception
Zend_Mail_Exception

Definition at line 57 of file File.php.

58  {
59  if (empty($params['file'])) {
63  #require_once 'Zend/Mail/Exception.php';
64  throw new Zend_Mail_Exception('no file given in params');
65  }
66 
67  if (!is_resource($params['file'])) {
68  $this->_fh = fopen($params['file'], 'r');
69  } else {
70  $this->_fh = $params['file'];
71  }
72  if (!$this->_fh) {
76  #require_once 'Zend/Mail/Exception.php';
77  throw new Zend_Mail_Exception('could not open file');
78  }
79  if (isset($params['startPos'])) {
80  fseek($this->_fh, $params['startPos']);
81  }
82  $header = '';
83  $endPos = isset($params['endPos']) ? $params['endPos'] : null;
84  while (($endPos === null || ftell($this->_fh) < $endPos) && trim($line = fgets($this->_fh))) {
85  $header .= $line;
86  }
87 
88  Zend_Mime_Decode::splitMessage($header, $this->_headers, $null);
89 
90  $this->_contentPos[0] = ftell($this->_fh);
91  if ($endPos !== null) {
92  $this->_contentPos[1] = $endPos;
93  } else {
94  fseek($this->_fh, 0, SEEK_END);
95  $this->_contentPos[1] = ftell($this->_fh);
96  }
97  if (!$this->isMultipart()) {
98  return;
99  }
100 
101  $boundary = $this->getHeaderField('content-type', 'boundary');
102  if (!$boundary) {
106  #require_once 'Zend/Mail/Exception.php';
107  throw new Zend_Mail_Exception('no boundary found in content type to split message');
108  }
109 
110  $part = array();
111  $pos = $this->_contentPos[0];
112  fseek($this->_fh, $pos);
113  while (!feof($this->_fh) && ($endPos === null || $pos < $endPos)) {
114  $line = fgets($this->_fh);
115  if ($line === false) {
116  if (feof($this->_fh)) {
117  break;
118  }
122  #require_once 'Zend/Mail/Exception.php';
123  throw new Zend_Mail_Exception('error reading file');
124  }
125 
126  $lastPos = $pos;
127  $pos = ftell($this->_fh);
128  $line = trim($line);
129 
130  if ($line == '--' . $boundary) {
131  if ($part) {
132  // not first part
133  $part[1] = $lastPos;
134  $this->_partPos[] = $part;
135  }
136  $part = array($pos);
137  } else if ($line == '--' . $boundary . '--') {
138  $part[1] = $lastPos;
139  $this->_partPos[] = $part;
140  break;
141  }
142  }
143  $this->_countParts = count($this->_partPos);
144 
145  }
getHeaderField($name, $wantedPart=0, $firstName=0)
Definition: Part.php:461
static splitMessage( $message, &$headers, &$body, $EOL=Zend_Mime::LINEEND)
Definition: Decode.php:123
$pos
Definition: list.phtml:42
$params[\Magento\Store\Model\StoreManager::PARAM_RUN_CODE]
Definition: website.php:18

Member Function Documentation

◆ getContent()

getContent (   $stream = null)

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

Definition at line 156 of file File.php.

157  {
158  fseek($this->_fh, $this->_contentPos[0]);
159  if ($stream !== null) {
160  return stream_copy_to_stream($this->_fh, $stream, $this->_contentPos[1] - $this->_contentPos[0]);
161  }
162  $length = $this->_contentPos[1] - $this->_contentPos[0];
163  return $length < 1 ? '' : fread($this->_fh, $length);
164  }

◆ 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

Implements Zend_Mail_Part_Interface.

Definition at line 184 of file File.php.

185  {
186  --$num;
187  if (!isset($this->_partPos[$num])) {
191  #require_once 'Zend/Mail/Exception.php';
192  throw new Zend_Mail_Exception('part not found');
193  }
194 
195  return new self(array('file' => $this->_fh, 'startPos' => $this->_partPos[$num][0],
196  'endPos' => $this->_partPos[$num][1]));
197  }

◆ 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 173 of file File.php.

173  {
174  return $this->_contentPos[1] - $this->_contentPos[0];
175  }

Field Documentation

◆ $_contentPos

$_contentPos = array()
protected

Definition at line 42 of file File.php.

◆ $_fh

$_fh
protected

Definition at line 44 of file File.php.

◆ $_partPos

$_partPos = array()
protected

Definition at line 43 of file File.php.


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