hasLineLongerThanMax() public static method

Detect if a string contains a line longer than the maximum line length allowed.
public static hasLineLongerThanMax ( string $str ) : boolean
$str string
return boolean
Example #1
0
 /**
  * Test line length detection
  */
 public function testLineLength()
 {
     $oklen = str_repeat(str_repeat('0', PHPMailer::MAX_LINE_LENGTH) . "\r\n", 10);
     $badlen = str_repeat(str_repeat('1', PHPMailer::MAX_LINE_LENGTH + 1) . "\r\n", 2);
     $this->assertTrue(PHPMailer::hasLineLongerThanMax($badlen), 'Long line not detected (only)');
     $this->assertTrue(PHPMailer::hasLineLongerThanMax($oklen . $badlen), 'Long line not detected (first)');
     $this->assertTrue(PHPMailer::hasLineLongerThanMax($badlen . $oklen), 'Long line not detected (last)');
     $this->assertTrue(PHPMailer::hasLineLongerThanMax($oklen . $badlen . $oklen), 'Long line not detected (middle)');
     $this->assertFalse(PHPMailer::hasLineLongerThanMax($oklen), 'Long line false positive');
     $this->Mail->isHTML(false);
     $this->Mail->Subject .= ": Line length test";
     $this->Mail->CharSet = 'UTF-8';
     $this->Mail->Encoding = '8bit';
     $this->Mail->Body = $oklen . $badlen . $oklen . $badlen;
     $this->buildBody();
     $this->assertTrue($this->Mail->send(), $this->Mail->ErrorInfo);
     $this->assertEquals('quoted-printable', $this->Mail->Encoding, 'Long line did not override transfer encoding');
 }