Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Public Member Functions | Static Public Member Functions | Data Fields | Static Public Attributes | Protected Attributes | Static Protected Attributes
Zend_Mime Class Reference

Public Member Functions

 __construct ($boundary=null)
 
 boundary ()
 
 boundaryLine ($EOL=self::LINEEND)
 
 mimeEnd ($EOL=self::LINEEND)
 

Static Public Member Functions

static isPrintable ($str)
 
static encodeQuotedPrintable ( $str, $lineLength=self::LINELENGTH, $lineEnd=self::LINEEND)
 
static encodeQuotedPrintableHeader ( $str, $charset, $lineLength=self::LINELENGTH, $lineEnd=self::LINEEND)
 
static encodeBase64Header ( $str, $charset, $lineLength=self::LINELENGTH, $lineEnd=self::LINEEND)
 
static encodeBase64 ( $str, $lineLength=self::LINELENGTH, $lineEnd=self::LINEEND)
 
static encode ($str, $encoding, $EOL=self::LINEEND)
 

Data Fields

const TYPE_OCTETSTREAM = 'application/octet-stream'
 
const TYPE_TEXT = 'text/plain'
 
const TYPE_HTML = 'text/html'
 
const ENCODING_7BIT = '7bit'
 
const ENCODING_8BIT = '8bit'
 
const ENCODING_QUOTEDPRINTABLE = 'quoted-printable'
 
const ENCODING_BASE64 = 'base64'
 
const DISPOSITION_ATTACHMENT = 'attachment'
 
const DISPOSITION_INLINE = 'inline'
 
const LINELENGTH = 72
 
const LINEEND = "\n"
 
const MULTIPART_ALTERNATIVE = 'multipart/alternative'
 
const MULTIPART_MIXED = 'multipart/mixed'
 
const MULTIPART_RELATED = 'multipart/related'
 

Static Public Attributes

static $qpKeys
 
static $qpReplaceValues
 
static $qpKeysString
 

Protected Attributes

 $_boundary
 

Static Protected Attributes

static $makeUnique = 0
 

Detailed Description

Definition at line 30 of file Mime.php.

Constructor & Destructor Documentation

◆ __construct()

__construct (   $boundary = null)

Constructor

Parameters
null | string$boundary

Definition at line 603 of file Mime.php.

604  {
605  // This string needs to be somewhat unique
606  if ($boundary === null) {
607  $this->_boundary = '=_' . md5(microtime(1) . self::$makeUnique++);
608  } else {
609  $this->_boundary = $boundary;
610  }
611  }

Member Function Documentation

◆ boundary()

boundary ( )

Return a MIME boundary

@access public

Returns
string

Definition at line 644 of file Mime.php.

645  {
646  return $this->_boundary;
647  }
$_boundary
Definition: Mime.php:52

◆ boundaryLine()

boundaryLine (   $EOL = self::LINEEND)

Return a MIME boundary line

Parameters
string$EOLLine end; defaults to LINEEND
Returns
string

Definition at line 655 of file Mime.php.

656  {
657  return $EOL . '--' . $this->_boundary . $EOL;
658  }

◆ encode()

static encode (   $str,
  $encoding,
  $EOL = self::LINEEND 
)
static

Encode the given string with the given encoding.

Parameters
string$str
string$encoding
string$EOLLine end; defaults to Zend_Mime::LINEEND
Returns
string
Todo:
7Bit and 8Bit is currently handled the same way.

Definition at line 621 of file Mime.php.

622  {
623  switch ($encoding) {
625  return self::encodeBase64($str, self::LINELENGTH, $EOL);
626 
628  return self::encodeQuotedPrintable($str, self::LINELENGTH, $EOL);
629 
630  default:
634  return $str;
635  }
636  }
const ENCODING_QUOTEDPRINTABLE
Definition: Mime.php:37
const ENCODING_BASE64
Definition: Mime.php:38
static encodeBase64( $str, $lineLength=self::LINELENGTH, $lineEnd=self::LINEEND)
Definition: Mime.php:591
static encodeQuotedPrintable( $str, $lineLength=self::LINELENGTH, $lineEnd=self::LINEEND)
Definition: Mime.php:423

◆ encodeBase64()

static encodeBase64 (   $str,
  $lineLength = self::LINELENGTH,
  $lineEnd = self::LINEEND 
)
static

Encode a given string in base64 encoding and break lines according to the maximum linelength.

Parameters
string$str
int$lineLengthLine length; defaults to LINELENGTH
string$lineEndLine end; defaults to LINEEND
Returns
string

Definition at line 591 of file Mime.php.

594  {
595  return rtrim(chunk_split(base64_encode($str), $lineLength, $lineEnd));
596  }

◆ encodeBase64Header()

static encodeBase64Header (   $str,
  $charset,
  $lineLength = self::LINELENGTH,
  $lineEnd = self::LINEEND 
)
static

Encode a given string in mail header compatible base64 encoding.

Parameters
string$str
string$charset
int$lineLengthLine length; defaults to LINELENGTH
string$lineEndLine end; defaults to LINEEND
Returns
string

Definition at line 565 of file Mime.php.

568  {
569  $prefix = '=?' . $charset . '?B?';
570  $suffix = '?=';
571  $remainingLength = $lineLength - strlen($prefix) - strlen($suffix);
572 
573  $encodedValue = self::encodeBase64($str, $remainingLength, $lineEnd);
574  $encodedValue = str_replace(
575  $lineEnd, $suffix . $lineEnd . ' ' . $prefix, $encodedValue
576  );
577  $encodedValue = $prefix . $encodedValue . $suffix;
578 
579  return $encodedValue;
580  }
$suffix
Definition: name.phtml:27
$prefix
Definition: name.phtml:25
static encodeBase64( $str, $lineLength=self::LINELENGTH, $lineEnd=self::LINEEND)
Definition: Mime.php:591

◆ encodeQuotedPrintable()

static encodeQuotedPrintable (   $str,
  $lineLength = self::LINELENGTH,
  $lineEnd = self::LINEEND 
)
static

Encode a given string with the QUOTED_PRINTABLE mechanism and wrap the lines.

Parameters
string$str
int$lineLengthLine length; defaults to LINELENGTH
string$lineEndLine end; defaults to LINEEND
Returns
string

Definition at line 423 of file Mime.php.

428  {
429  $out = '';
430  $str = self::_encodeQuotedPrintable($str);
431 
432  // Split encoded text into separate lines
433  while (strlen($str) > 0) {
434  $ptr = strlen($str);
435  if ($ptr > $lineLength) {
436  $ptr = $lineLength;
437  }
438 
439  // Ensure we are not splitting across an encoded character
440  $pos = strrpos(substr($str, 0, $ptr), '=');
441  if ($pos !== false && $pos >= $ptr - 2) {
442  $ptr = $pos;
443  }
444 
445  // Check if there is a space at the end of the line and rewind
446  if ($ptr > 0 && $str[$ptr - 1] == ' ') {
447  --$ptr;
448  }
449 
450  // Add string and continue
451  $out .= substr($str, 0, $ptr) . '=' . $lineEnd;
452  $str = substr($str, $ptr);
453  }
454 
455  $out = rtrim($out, $lineEnd);
456  $out = rtrim($out, '=');
457 
458  return $out;
459  }
$pos
Definition: list.phtml:42

◆ encodeQuotedPrintableHeader()

static encodeQuotedPrintableHeader (   $str,
  $charset,
  $lineLength = self::LINELENGTH,
  $lineEnd = self::LINEEND 
)
static

Encode a given string with the QUOTED_PRINTABLE mechanism for Mail Headers.

Mail headers depend on an extended quoted printable algorithm otherwise a range of bugs can occur.

Parameters
string$str
string$charset
int$lineLengthLine length; defaults to LINELENGTH
string$lineEndLine end; defaults to LINEEND
Returns
string

Definition at line 488 of file Mime.php.

491  {
492  // Reduce line-length by the length of the required delimiter, charsets and encoding
493  $prefix = sprintf('=?%s?Q?', $charset);
494  $lineLength = $lineLength - strlen($prefix) - 3;
495 
496  $str = self::_encodeQuotedPrintable($str);
497 
498  // Mail-Header required chars have to be encoded also:
499  $str = str_replace(
500  array('?', ' ', '_', ','), array('=3F', '=20', '=5F', '=2C'), $str
501  );
502 
503  // initialize first line, we need it anyways
504  $lines = array(0 => "");
505 
506  // Split encoded text into separate lines
507  $tmp = "";
508  while (strlen($str) > 0) {
509  $currentLine = max(count($lines) - 1, 0);
510  $token = self::getNextQuotedPrintableToken($str);
511  $str = substr($str, strlen($token));
512 
513  $tmp .= $token;
514  if ($token == '=20') {
515  // only if we have a single char token or space, we can append the
516  // tempstring it to the current line or start a new line if necessary.
517  if (strlen($lines[$currentLine] . $tmp) > $lineLength) {
518  $lines[$currentLine + 1] = $tmp;
519  } else {
520  $lines[$currentLine] .= $tmp;
521  }
522  $tmp = "";
523  }
524  // don't forget to append the rest to the last line
525  if (strlen($str) == 0) {
526  $lines[$currentLine] .= $tmp;
527  }
528  }
529 
530  // assemble the lines together by pre- and appending delimiters, charset, encoding.
531  for ($i = 0; $i < count($lines); $i++) {
532  $lines[$i] = " " . $prefix . $lines[$i] . "?=";
533  }
534  $str = trim(implode($lineEnd, $lines));
535 
536  return $str;
537  }
$prefix
Definition: name.phtml:25
$i
Definition: gallery.phtml:31

◆ isPrintable()

static isPrintable (   $str)
static

Check if the given string is "printable"

Checks that a string contains no unprintable characters. If this returns false, encode the string for secure delivery.

Parameters
string$str
Returns
boolean

Definition at line 410 of file Mime.php.

411  {
412  return (strcspn($str, self::$qpKeysString) == strlen($str));
413  }

◆ mimeEnd()

mimeEnd (   $EOL = self::LINEEND)

Return MIME ending

Parameters
string$EOLLine end; defaults to LINEEND
Returns
string

Definition at line 666 of file Mime.php.

667  {
668  return $EOL . '--' . $this->_boundary . '--' . $EOL;
669  }

Field Documentation

◆ $_boundary

$_boundary
protected

Definition at line 52 of file Mime.php.

◆ $makeUnique

$makeUnique = 0
staticprotected

Definition at line 57 of file Mime.php.

◆ $qpKeys

$qpKeys
static

Definition at line 64 of file Mime.php.

◆ $qpKeysString

$qpKeysString
static
Initial value:
=
"\x00\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0A\x0B\x0C\x0D\x0E\x0F\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1A\x1B\x1C\x1D\x1E\x1F\x7F\x80\x81\x82\x83\x84\x85\x86\x87\x88\x89\x8A\x8B\x8C\x8D\x8E\x8F\x90\x91\x92\x93\x94\x95\x96\x97\x98\x99\x9A\x9B\x9C\x9D\x9E\x9F\xA0\xA1\xA2\xA3\xA4\xA5\xA6\xA7\xA8\xA9\xAA\xAB\xAC\xAD\xAE\xAF\xB0\xB1\xB2\xB3\xB4\xB5\xB6\xB7\xB8\xB9\xBA\xBB\xBC\xBD\xBE\xBF\xC0\xC1\xC2\xC3\xC4\xC5\xC6\xC7\xC8\xC9\xCA\xCB\xCC\xCD\xCE\xCF\xD0\xD1\xD2\xD3\xD4\xD5\xD6\xD7\xD8\xD9\xDA\xDB\xDC\xDD\xDE\xDF\xE0\xE1\xE2\xE3\xE4\xE5\xE6\xE7\xE8\xE9\xEA\xEB\xEC\xED\xEE\xEF\xF0\xF1\xF2\xF3\xF4\xF5\xF6\xF7\xF8\xF9\xFA\xFB\xFC\xFD\xFE\xFF"

Definition at line 398 of file Mime.php.

◆ $qpReplaceValues

$qpReplaceValues
static

Definition at line 231 of file Mime.php.

◆ DISPOSITION_ATTACHMENT

const DISPOSITION_ATTACHMENT = 'attachment'

Definition at line 39 of file Mime.php.

◆ DISPOSITION_INLINE

const DISPOSITION_INLINE = 'inline'

Definition at line 40 of file Mime.php.

◆ ENCODING_7BIT

const ENCODING_7BIT = '7bit'

Definition at line 35 of file Mime.php.

◆ ENCODING_8BIT

const ENCODING_8BIT = '8bit'

Definition at line 36 of file Mime.php.

◆ ENCODING_BASE64

const ENCODING_BASE64 = 'base64'

Definition at line 38 of file Mime.php.

◆ ENCODING_QUOTEDPRINTABLE

const ENCODING_QUOTEDPRINTABLE = 'quoted-printable'

Definition at line 37 of file Mime.php.

◆ LINEEND

const LINEEND = "\n"

Definition at line 42 of file Mime.php.

◆ LINELENGTH

const LINELENGTH = 72

Definition at line 41 of file Mime.php.

◆ MULTIPART_ALTERNATIVE

const MULTIPART_ALTERNATIVE = 'multipart/alternative'

Definition at line 43 of file Mime.php.

◆ MULTIPART_MIXED

const MULTIPART_MIXED = 'multipart/mixed'

Definition at line 44 of file Mime.php.

◆ MULTIPART_RELATED

const MULTIPART_RELATED = 'multipart/related'

Definition at line 45 of file Mime.php.

◆ TYPE_HTML

const TYPE_HTML = 'text/html'

Definition at line 34 of file Mime.php.

◆ TYPE_OCTETSTREAM

const TYPE_OCTETSTREAM = 'application/octet-stream'

Definition at line 32 of file Mime.php.

◆ TYPE_TEXT

const TYPE_TEXT = 'text/plain'

Definition at line 33 of file Mime.php.


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