Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Static Public Member Functions
Zend_Mime_Decode Class Reference

Static Public Member Functions

static splitMime ($body, $boundary)
 
static splitMessageStruct ( $message, $boundary, $EOL=Zend_Mime::LINEEND)
 
static splitMessage ( $message, &$headers, &$body, $EOL=Zend_Mime::LINEEND)
 
static splitContentType ($type, $wantedPart=null)
 
static splitHeaderField ( $field, $wantedPart=null, $firstName=0)
 
static decodeQuotedPrintable ($string)
 

Detailed Description

Definition at line 33 of file Decode.php.

Member Function Documentation

◆ decodeQuotedPrintable()

static decodeQuotedPrintable (   $string)
static

decode a quoted printable encoded string

The charset of the returned string depends on your iconv settings.

Parameters
string$stringEncoded string
Returns
string Decoded string

Definition at line 272 of file Decode.php.

273  {
274  return quoted_printable_decode($string);
275  }

◆ splitContentType()

static splitContentType (   $type,
  $wantedPart = null 
)
static

split a content type in its different parts

Parameters
string$typecontent-type
string$wantedPartthe wanted part, else an array with all parts is returned
Returns
string|array wanted part or all parts as array('type' => content-type, partname => value)

Definition at line 203 of file Decode.php.

204  {
205  return self::splitHeaderField($type, $wantedPart, 'type');
206  }
$type
Definition: item.phtml:13
static splitHeaderField( $field, $wantedPart=null, $firstName=0)
Definition: Decode.php:217

◆ splitHeaderField()

static splitHeaderField (   $field,
  $wantedPart = null,
  $firstName = 0 
)
static

split a header field like content type in its different parts

Parameters
string$field
string$wantedPartthe wanted part, else an array with all parts is returned
int | string$firstNamekey name for the first part
Exceptions
Zend_Exception
Returns
string|array wanted part or all parts as array($firstName => firstPart, partname => value)

Definition at line 217 of file Decode.php.

220  {
221  $wantedPart = strtolower($wantedPart);
222  $firstName = strtolower($firstName);
223 
224  // special case - a bit optimized
225  if ($firstName === $wantedPart) {
226  $field = strtok($field, ';');
227 
228  return $field[0] == '"' ? substr($field, 1, -1) : $field;
229  }
230 
231  $field = $firstName . '=' . $field;
232  if (!preg_match_all('%([^=\s]+)\s*=\s*("[^"]+"|[^;]+)(;\s*|$)%', $field, $matches)) {
233  throw new Zend_Exception('not a valid header field');
234  }
235 
236  if ($wantedPart) {
237  foreach ($matches[1] as $key => $name) {
238  if (strcasecmp($name, $wantedPart)) {
239  continue;
240  }
241  if ($matches[2][$key][0] != '"') {
242  return $matches[2][$key];
243  }
244 
245  return substr($matches[2][$key], 1, -1);
246  }
247 
248  return null;
249  }
250 
251  $split = array();
252  foreach ($matches[1] as $key => $name) {
253  $name = strtolower($name);
254  if ($matches[2][$key][0] == '"') {
255  $split[$name] = substr($matches[2][$key], 1, -1);
256  } else {
257  $split[$name] = $matches[2][$key];
258  }
259  }
260 
261  return $split;
262  }
if(!isset($_GET['name'])) $name
Definition: log.php:14

◆ splitMessage()

static splitMessage (   $message,
$headers,
$body,
  $EOL = Zend_Mime::LINEEND 
)
static

split a message in header and body part, if no header or an invalid header is found $headers is empty

The charset of the returned headers depend on your iconv settings.

Parameters
string$messageraw message with header and optional content
array$headersoutput param, array with headers as array(name => value)
string$bodyoutput param, content of message
string$EOLEOL string; defaults to Zend_Mime::LINEEND
Returns
null

Definition at line 123 of file Decode.php.

126  {
127  // check for valid header at first line
128  $firstline = strtok($message, "\n");
129  if (!preg_match('%^[^\s]+[^:]*:%', $firstline)) {
130  $headers = array();
131  // TODO: we're ignoring \r for now - is this function fast enough and is it safe to asume noone needs \r?
132  $body = str_replace(
133  array(
134  "\r",
135  "\n"
136  ), array(
137  '',
138  $EOL
139  ), $message
140  );
141 
142  return;
143  }
144 
145  // find an empty line between headers and body
146  // default is set new line
147  if (strpos($message, $EOL . $EOL)) {
148  list($headers, $body) = explode($EOL . $EOL, $message, 2);
149  // next is the standard new line
150  } else {
151  if ($EOL != "\r\n" && strpos($message, "\r\n\r\n")) {
152  list($headers, $body) = explode("\r\n\r\n", $message, 2);
153  // next is the other "standard" new line
154  } else {
155  if ($EOL != "\n" && strpos($message, "\n\n")) {
156  list($headers, $body) = explode("\n\n", $message, 2);
157  // at last resort find anything that looks like a new line
158  } else {
159  @list($headers, $body) =
160  @preg_split("%([\r\n]+)\\1%U", $message, 2);
161  }
162  }
163  }
164 
165  $headers = iconv_mime_decode_headers(
166  $headers, ICONV_MIME_DECODE_CONTINUE_ON_ERROR
167  );
168 
169  if ($headers === false) {
170  // an error occurs during the decoding
171  return;
172  }
173 
174  // normalize header names
175  foreach ($headers as $name => $header) {
176  $lower = strtolower($name);
177  if ($lower == $name) {
178  continue;
179  }
180  unset($headers[$name]);
181  if (!isset($headers[$lower])) {
182  $headers[$lower] = $header;
183  continue;
184  }
185  if (is_array($headers[$lower])) {
186  $headers[$lower][] = $header;
187  continue;
188  }
189  $headers[$lower] = array(
190  $headers[$lower],
191  $header
192  );
193  }
194  }
$message
if(!isset($_GET['name'])) $name
Definition: log.php:14

◆ splitMessageStruct()

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

decodes a mime encoded String and returns a struct of parts with header and body

Parameters
string$messageraw message content
string$boundaryboundary as found in content-type
string$EOLEOL string; defaults to Zend_Mime::LINEEND
Returns
array|null parts as array('header' => array(name => value), 'body' => content), null if no parts found
Exceptions
Zend_Exception

Definition at line 91 of file Decode.php.

94  {
95  $parts = self::splitMime($message, $boundary);
96  if (count($parts) <= 0) {
97  return null;
98  }
99  $result = array();
100  foreach ($parts as $part) {
101  self::splitMessage($part, $headers, $body, $EOL);
102  $result[] = array(
103  'header' => $headers,
104  'body' => $body
105  );
106  }
107 
108  return $result;
109  }
static splitMessage( $message, &$headers, &$body, $EOL=Zend_Mime::LINEEND)
Definition: Decode.php:123
$message
static splitMime($body, $boundary)
Definition: Decode.php:45

◆ splitMime()

static splitMime (   $body,
  $boundary 
)
static

Explode MIME multipart string into seperate parts

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

Parameters
string$bodyraw body of message
string$boundaryboundary as found in content-type
Returns
array parts with content of each part, empty if no parts found
Exceptions
Zend_Exception

Definition at line 45 of file Decode.php.

46  {
47  // TODO: we're ignoring \r for now - is this function fast enough and is it safe to asume noone needs \r?
48  $body = str_replace("\r", '', $body);
49 
50  $start = 0;
51  $res = array();
52  // find every mime part limiter and cut out the
53  // string before it.
54  // the part before the first boundary string is discarded:
55  $p = strpos($body, '--' . $boundary . "\n", $start);
56  if ($p === false) {
57  // no parts found!
58  return array();
59  }
60 
61  // position after first boundary line
62  $start = $p + 3 + strlen($boundary);
63 
64  while (($p = strpos($body, '--' . $boundary . "\n", $start)) !== false) {
65  $res[] = substr($body, $start, $p-$start);
66  $start = $p + 3 + strlen($boundary);
67  }
68 
69  // no more parts, find end boundary
70  $p = strpos($body, '--' . $boundary . '--', $start);
71  if ($p === false) {
72  throw new Zend_Exception('Not a valid Mime Message: End Missing');
73  }
74 
75  // the remaining part also needs to be parsed:
76  $res[] = substr($body, $start, $p - $start);
77 
78  return $res;
79  }
$start
Definition: listing.phtml:18

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