function test_simplemail() { global $conf; $conf['htmlmail'] = 0; $mail = new TestMailer(); $mail->to('*****@*****.**'); $mail->setBody('A test mail in ASCII'); $dump = $mail->dump(); $this->assertNotRegexp('/Content-Type: multipart/', $dump); $this->assertRegexp('#Content-Type: text/plain; charset=UTF-8#', $dump); $this->assertRegexp('/' . base64_encode('A test mail in ASCII') . '/', $dump); $conf['htmlmail'] = 1; }
/** * @group internet */ function test_lint() { // prepare a simple multipart message $mail = new TestMailer(); $mail->to(array('Möp <*****@*****.**> ', ' foo <*****@*****.**>')); $mail->from('Me <*****@*****.**>'); $mail->subject('This is a töst'); $mail->setBody('Hello Wörld, please don\'t burn, okay? '); $mail->attachContent('some test data', 'text/plain', 'a text.txt'); $msg = $mail->dump(); $msglines = explode("\n", $msg); //echo $msg; // ask message lint if it is okay $html = new HTTPClient(); $results = $html->post('http://tools.ietf.org/tools/msglint/msglint', array('msg' => $msg)); if ($results === false) { $this->markTestSkipped('no response from validator'); return; } // parse the result lines $lines = explode("\n", $results); $rows = count($lines); $i = 0; while (trim($lines[$i]) != '-----------' && $i < $rows) { $i++; } //skip preamble for ($i = $i + 1; $i < $rows; $i++) { $line = trim($lines[$i]); if ($line == '-----------') { break; } //skip appendix // get possible continuation of the line while ($lines[$i + 1][0] == ' ') { $line .= ' ' . trim($lines[$i + 1]); $i++; } // check the line for errors if (substr($line, 0, 5) == 'ERROR' || substr($line, 0, 7) == 'WARNING') { // ignore some errors if (strpos($line, "missing mandatory header 'return-path'")) { continue; } #set by MDA if (strpos($line, "bare newline in text body decoded")) { continue; } #seems to be false positive // get the context in which the error occured $errorin = ''; if (preg_match('/line (\\d+)$/', $line, $m)) { $errorin .= "\n" . $msglines[$m[1] - 1]; } if (preg_match('/lines (\\d+)-(\\d+)$/', $line, $m)) { for ($x = $m[1] - 1; $x < $m[2]; $x++) { $errorin .= "\n" . $msglines[$x]; } } // raise the error throw new Exception($line . $errorin); } } }