encodeQP() public method

According to RFC2045 section 6.7.
public encodeQP ( string $string, integer $line_max = 76 ) : string
$string string The text to encode
$line_max integer Number of chars allowed on a line before wrapping
return string
Ejemplo n.º 1
0
 /**
  * Plain quoted-printable message.
  */
 public function testQuotedPrintable()
 {
     $this->Mail->Body = 'Here is the main body';
     $this->Mail->Subject .= ': Plain + Quoted-printable';
     $this->Mail->Encoding = 'quoted-printable';
     $this->buildBody();
     $this->assertTrue($this->Mail->send(), $this->Mail->ErrorInfo);
     //Check that a quoted printable encode and decode results in the same as went in
     $t = file_get_contents(__FILE__);
     //Use this file as test content
     $this->assertEquals($t, quoted_printable_decode($this->Mail->encodeQP($t)), 'Quoted-Printable encoding round-trip failed');
     $this->assertEquals($this->Mail->encodeQP($t), $this->Mail->encodeQPphp($t), 'Quoted-Printable BC wrapper failed');
 }
Ejemplo n.º 2
0
 /**
  * Plain quoted-printable message.
  */
 public function testQuotedPrintable()
 {
     $this->Mail->Body = 'Here is the main body';
     $this->Mail->Subject .= ': Plain + Quoted-printable';
     $this->Mail->Encoding = 'quoted-printable';
     $this->buildBody();
     $this->assertTrue($this->Mail->send(), $this->Mail->ErrorInfo);
     //Check that a quoted printable encode and decode results in the same as went in
     $t = file_get_contents(__FILE__);
     //Use this file as test content
     //Force line breaks to UNIX-style
     $t = str_replace(["\r\n", "\r"], "\n", $t);
     $this->assertEquals($t, quoted_printable_decode($this->Mail->encodeQP($t)), 'Quoted-Printable encoding round-trip failed');
     //Force line breaks to Windows-style
     $t = str_replace("\n", "\r\n", $t);
     $this->assertEquals($t, quoted_printable_decode($this->Mail->encodeQP($t)), 'Quoted-Printable encoding round-trip failed (Windows line breaks)');
 }
Ejemplo n.º 3
0
 /**
  * This is a temporary replacement of the parent::EncodeQP() that does not
  * call quoted_printable_encode() even if it is available. See MDL-23240 for details
  *
  * @see parent::EncodeQP() for full documentation
  */
 public function encodeQP($string, $line_max = 76)
 {
     //if (function_exists('quoted_printable_encode')) { //Use native function if it's available (>= PHP5.3)
     //    return quoted_printable_encode($string);
     //}
     $filters = stream_get_filters();
     if (!in_array('convert.*', $filters)) {
         //Got convert stream filter?
         return parent::encodeQP($string, $line_max);
         //Fall back to old implementation
     }
     $fp = fopen('php://temp/', 'r+');
     $string = preg_replace('/\\r\\n?/', $this->LE, $string);
     //Normalise line breaks
     $params = array('line-length' => $line_max, 'line-break-chars' => $this->LE);
     $s = stream_filter_append($fp, 'convert.quoted-printable-encode', STREAM_FILTER_READ, $params);
     fputs($fp, $string);
     rewind($fp);
     $out = stream_get_contents($fp);
     stream_filter_remove($s);
     $out = preg_replace('/^\\./m', '=2E', $out);
     //Encode . if it is first char on a line, workaround for bug in Exchange
     fclose($fp);
     return $out;
 }