1cc92aca7SAndreas Gohr<?php 2cc92aca7SAndreas Gohr 35a8d6e48SMichael Großeuse dokuwiki\HTTP\HTTPClient; 4198564abSMichael Große 5cc92aca7SAndreas Gohr/** 6cc92aca7SAndreas Gohr * Extends the mailer class to expose internal variables for testing 7cc92aca7SAndreas Gohr */ 8cc92aca7SAndreas Gohrclass TestMailer extends Mailer { 9cc92aca7SAndreas Gohr public function prop($name){ 10cc92aca7SAndreas Gohr return $this->$name; 11cc92aca7SAndreas Gohr } 121f61f312SDominik Eckelmann 131f61f312SDominik Eckelmann public function &propRef($name) { 141f61f312SDominik Eckelmann return $this->$name; 151f61f312SDominik Eckelmann } 161f61f312SDominik Eckelmann 171f61f312SDominik Eckelmann public function prepareHeaders() { 181f61f312SDominik Eckelmann return parent::prepareHeaders(); 191f61f312SDominik Eckelmann } 20b6c97c70SAndreas Gohr 21b6c97c70SAndreas Gohr public function cleanHeaders() { 22b6c97c70SAndreas Gohr parent::cleanHeaders(); 23b6c97c70SAndreas Gohr } 24b6c97c70SAndreas Gohr 25cc92aca7SAndreas Gohr} 26cc92aca7SAndreas Gohr 27102cdbd7SLarsGit223/** 28102cdbd7SLarsGit223 * @group mailer_class 29102cdbd7SLarsGit223 */ 30cc92aca7SAndreas Gohrclass mailer_test extends DokuWikiTest { 31cc92aca7SAndreas Gohr 32cc92aca7SAndreas Gohr 33cc92aca7SAndreas Gohr function test_userheader(){ 34cc92aca7SAndreas Gohr $mail = new TestMailer(); 35cc92aca7SAndreas Gohr $headers = $mail->prop('headers'); 36cc92aca7SAndreas Gohr $this->assertArrayNotHasKey('X-Dokuwiki-User',$headers); 37cc92aca7SAndreas Gohr 38cc92aca7SAndreas Gohr $_SERVER['REMOTE_USER'] = 'andi'; 39cc92aca7SAndreas Gohr $mail = new TestMailer(); 40cc92aca7SAndreas Gohr $headers = $mail->prop('headers'); 41cc92aca7SAndreas Gohr $this->assertArrayHasKey('X-Dokuwiki-User',$headers); 42cc92aca7SAndreas Gohr } 43cc92aca7SAndreas Gohr 44cc92aca7SAndreas Gohr function test_setHeader(){ 45cc92aca7SAndreas Gohr $mail = new TestMailer(); 46cc92aca7SAndreas Gohr 47cc92aca7SAndreas Gohr // check existance of default headers 48cc92aca7SAndreas Gohr $headers = $mail->prop('headers'); 49cc92aca7SAndreas Gohr $this->assertArrayHasKey('X-Mailer',$headers); 50cc92aca7SAndreas Gohr $this->assertArrayHasKey('X-Dokuwiki-Title',$headers); 51cc92aca7SAndreas Gohr $this->assertArrayHasKey('X-Dokuwiki-Server',$headers); 52cc92aca7SAndreas Gohr $this->assertArrayHasKey('X-Auto-Response-Suppress',$headers); 53cc92aca7SAndreas Gohr $this->assertArrayHasKey('List-Id',$headers); 54cc92aca7SAndreas Gohr 55cc92aca7SAndreas Gohr // set a bunch of test headers 56cc92aca7SAndreas Gohr $mail->setHeader('test-header','bla'); 57cc92aca7SAndreas Gohr $mail->setHeader('to','A valid ASCII name <test@example.com>'); 58c8d2e830SChristopher Smith $mail->setHeader('from',"Thös ne\needs\x00serious cleaning\$§%."); 59c8d2e830SChristopher Smith $mail->setHeader('bad',"Thös ne\needs\x00serious cleaning\$§%.",false); 60cc92aca7SAndreas Gohr $mail->setHeader("weird\n*+\x00foo.-_@bar?",'now clean'); 61cc92aca7SAndreas Gohr 62cc92aca7SAndreas Gohr // are they set? 63cc92aca7SAndreas Gohr $headers = $mail->prop('headers'); 64cc92aca7SAndreas Gohr $this->assertArrayHasKey('Test-Header',$headers); 65cc92aca7SAndreas Gohr $this->assertEquals('bla',$headers['Test-Header']); 66cc92aca7SAndreas Gohr $this->assertArrayHasKey('To',$headers); 67cc92aca7SAndreas Gohr $this->assertEquals('A valid ASCII name <test@example.com>',$headers['To']); 68cc92aca7SAndreas Gohr $this->assertArrayHasKey('From',$headers); 69cc92aca7SAndreas Gohr $this->assertEquals('Ths neeedsserious cleaning.',$headers['From']); 70cc92aca7SAndreas Gohr $this->assertArrayHasKey('Bad',$headers); 71d1612d99SAndreas Gohr $this->assertEquals("Thös ne\needs\x00serious cleaning\$§%.",$headers['Bad']); 72cc92aca7SAndreas Gohr $this->assertArrayHasKey('Weird+foo.-_@bar',$headers); 73cc92aca7SAndreas Gohr 74cc92aca7SAndreas Gohr // unset a header again 75cc92aca7SAndreas Gohr $mail->setHeader('test-header',''); 76cc92aca7SAndreas Gohr $headers = $mail->prop('headers'); 77cc92aca7SAndreas Gohr $this->assertArrayNotHasKey('Test-Header',$headers); 78cc92aca7SAndreas Gohr } 79cc92aca7SAndreas Gohr 80b6c97c70SAndreas Gohr function test_addresses(){ 811d7c1f1bSYurii K if (isWindows()) { 821d7c1f1bSYurii K $this->markTestSkipped(); 831d7c1f1bSYurii K } 841d7c1f1bSYurii K 85b6c97c70SAndreas Gohr $mail = new TestMailer(); 86b6c97c70SAndreas Gohr 87b6c97c70SAndreas Gohr $mail->to('andi@splitbrain.org'); 88b6c97c70SAndreas Gohr $mail->cleanHeaders(); 89b6c97c70SAndreas Gohr $headers = $mail->prop('headers'); 90b6c97c70SAndreas Gohr $this->assertEquals('andi@splitbrain.org', $headers['To']); 91b6c97c70SAndreas Gohr 92b6c97c70SAndreas Gohr $mail->to('<andi@splitbrain.org>'); 93b6c97c70SAndreas Gohr $mail->cleanHeaders(); 94b6c97c70SAndreas Gohr $headers = $mail->prop('headers'); 95b6c97c70SAndreas Gohr $this->assertEquals('andi@splitbrain.org', $headers['To']); 96b6c97c70SAndreas Gohr 97b6c97c70SAndreas Gohr $mail->to('Andreas Gohr <andi@splitbrain.org>'); 98b6c97c70SAndreas Gohr $mail->cleanHeaders(); 99b6c97c70SAndreas Gohr $headers = $mail->prop('headers'); 100b6c97c70SAndreas Gohr $this->assertEquals('Andreas Gohr <andi@splitbrain.org>', $headers['To']); 101b6c97c70SAndreas Gohr 102102cdbd7SLarsGit223 $mail->to('"Andreas Gohr" <andi@splitbrain.org>'); 103102cdbd7SLarsGit223 $mail->cleanHeaders(); 104102cdbd7SLarsGit223 $headers = $mail->prop('headers'); 105102cdbd7SLarsGit223 $this->assertEquals('"Andreas Gohr" <andi@splitbrain.org>', $headers['To']); 106102cdbd7SLarsGit223 10798548fefSAndreas Gohr $mail->to('andi@splitbrain.org,foo@example.com'); 10898548fefSAndreas Gohr $mail->cleanHeaders(); 10998548fefSAndreas Gohr $headers = $mail->prop('headers'); 11098548fefSAndreas Gohr $this->assertEquals('andi@splitbrain.org, foo@example.com', $headers['To']); 11110da1f74SAndreas Gohr 11210da1f74SAndreas Gohr $mail->to('andi@splitbrain.org, Text <foo@example.com>'); 11310da1f74SAndreas Gohr $mail->cleanHeaders(); 11410da1f74SAndreas Gohr $headers = $mail->prop('headers'); 11510da1f74SAndreas Gohr $this->assertEquals('andi@splitbrain.org, Text <foo@example.com>', $headers['To']); 11610da1f74SAndreas Gohr 11710da1f74SAndreas Gohr $mail->to('Andreas Gohr <andi@splitbrain.org>,foo@example.com'); 11810da1f74SAndreas Gohr $mail->cleanHeaders(); 11910da1f74SAndreas Gohr $headers = $mail->prop('headers'); 12010da1f74SAndreas Gohr $this->assertEquals('Andreas Gohr <andi@splitbrain.org>, foo@example.com', $headers['To']); 12198548fefSAndreas Gohr 122b6c97c70SAndreas Gohr $mail->to('Andreas Gohr <andi@splitbrain.org> , foo <foo@example.com>'); 123b6c97c70SAndreas Gohr $mail->cleanHeaders(); 124b6c97c70SAndreas Gohr $headers = $mail->prop('headers'); 125b6c97c70SAndreas Gohr $this->assertEquals('Andreas Gohr <andi@splitbrain.org>, foo <foo@example.com>', $headers['To']); 126b6c97c70SAndreas Gohr 127102cdbd7SLarsGit223 $mail->to('"Foo, Dr." <foo@example.com> , foo <foo@example.com>'); 128102cdbd7SLarsGit223 $mail->cleanHeaders(); 129102cdbd7SLarsGit223 $headers = $mail->prop('headers'); 130102cdbd7SLarsGit223 $this->assertEquals('=?UTF-8?B?IkZvbywgRHIuIg==?= <foo@example.com>, foo <foo@example.com>', $headers['To']); 131102cdbd7SLarsGit223 132b6c97c70SAndreas Gohr $mail->to('Möp <moep@example.com> , foo <foo@example.com>'); 133b6c97c70SAndreas Gohr $mail->cleanHeaders(); 134b6c97c70SAndreas Gohr $headers = $mail->prop('headers'); 135b6c97c70SAndreas Gohr $this->assertEquals('=?UTF-8?B?TcO2cA==?= <moep@example.com>, foo <foo@example.com>', $headers['To']); 136b6c97c70SAndreas Gohr 137b6c97c70SAndreas Gohr $mail->to(array('Möp <moep@example.com> ',' foo <foo@example.com>')); 138b6c97c70SAndreas Gohr $mail->cleanHeaders(); 139b6c97c70SAndreas Gohr $headers = $mail->prop('headers'); 140b6c97c70SAndreas Gohr $this->assertEquals('=?UTF-8?B?TcO2cA==?= <moep@example.com>, foo <foo@example.com>', $headers['To']); 141b6c97c70SAndreas Gohr 142b6c97c70SAndreas Gohr $mail->to(array('Beet, L van <lvb@example.com>',' foo <foo@example.com>')); 143b6c97c70SAndreas Gohr $mail->cleanHeaders(); 144b6c97c70SAndreas Gohr $headers = $mail->prop('headers'); 145b6c97c70SAndreas Gohr $this->assertEquals('=?UTF-8?B?QmVldCwgTCB2YW4=?= <lvb@example.com>, foo <foo@example.com>', $headers['To']); 146b6c97c70SAndreas Gohr 147b6c97c70SAndreas Gohr 148b6c97c70SAndreas Gohr } 149b6c97c70SAndreas Gohr 150cc92aca7SAndreas Gohr function test_simplemail(){ 151cc92aca7SAndreas Gohr global $conf; 152cc92aca7SAndreas Gohr $conf['htmlmail'] = 0; 1539ea45836SChristopher Smith 1549ea45836SChristopher Smith $mailbody = 'A test mail in ASCII'; 155cc92aca7SAndreas Gohr $mail = new TestMailer(); 156cc92aca7SAndreas Gohr $mail->to('test@example.com'); 1579ea45836SChristopher Smith $mail->setBody($mailbody); 158cc92aca7SAndreas Gohr 159cc92aca7SAndreas Gohr $dump = $mail->dump(); 1609ea45836SChristopher Smith 1619ea45836SChristopher Smith // construct the expected mail body text - include the expected dokuwiki signature 1629ea45836SChristopher Smith $replacements = $mail->prop('replacements'); 1639ea45836SChristopher Smith $expected_mail_body = chunk_split(base64_encode($mailbody.$replacements['text']['EMAILSIGNATURE']),72,MAILHEADER_EOL); 1649ea45836SChristopher Smith 165*9ad2b913SAndreas Gohr $this->assertDoesNotMatchRegularExpression('/Content-Type: multipart/',$dump); 166*9ad2b913SAndreas Gohr $this->assertMatchesRegularExpression('#Content-Type: text/plain; charset=UTF-8#',$dump); 167*9ad2b913SAndreas Gohr $this->assertMatchesRegularExpression('/'.preg_quote($expected_mail_body,'/').'/',$dump); 168cc92aca7SAndreas Gohr 169cc92aca7SAndreas Gohr $conf['htmlmail'] = 1; 170cc92aca7SAndreas Gohr } 171cc92aca7SAndreas Gohr 172cc92aca7SAndreas Gohr function test_replacements(){ 173cc92aca7SAndreas Gohr $mail = new TestMailer(); 174cc92aca7SAndreas Gohr 1759e01e280SChristopher Smith $replacements = array( '@DATE@','@BROWSER@','@IPADDRESS@','@HOSTNAME@','@EMAILSIGNATURE@', 176cc92aca7SAndreas Gohr '@TITLE@','@DOKUWIKIURL@','@USER@','@NAME@','@MAIL@'); 177cc92aca7SAndreas Gohr $mail->setBody('A test mail in with replacements '.join(' ',$replacements)); 178cc92aca7SAndreas Gohr 179cc92aca7SAndreas Gohr $text = $mail->prop('text'); 180cc92aca7SAndreas Gohr $html = $mail->prop('html'); 181cc92aca7SAndreas Gohr 182cc92aca7SAndreas Gohr foreach($replacements as $repl){ 183*9ad2b913SAndreas Gohr $this->assertDoesNotMatchRegularExpression("/$repl/",$text,"$repl replacement still in text"); 184*9ad2b913SAndreas Gohr $this->assertDoesNotMatchRegularExpression("/$repl/",$html,"$repl replacement still in html"); 185cc92aca7SAndreas Gohr } 186cc92aca7SAndreas Gohr } 187cc92aca7SAndreas Gohr 18891effd8dSDominik Eckelmann /** 18991effd8dSDominik Eckelmann * @see https://forum.dokuwiki.org/post/35822 19091effd8dSDominik Eckelmann */ 1911f61f312SDominik Eckelmann function test_emptyBCCorCC() { 1921f61f312SDominik Eckelmann $mail = new TestMailer(); 1931f61f312SDominik Eckelmann $headers = &$mail->propRef('headers'); 1941f61f312SDominik Eckelmann $headers['Bcc'] = ''; 1951f61f312SDominik Eckelmann $headers['Cc'] = ''; 1961f61f312SDominik Eckelmann $header = $mail->prepareHeaders(); 1971f61f312SDominik Eckelmann $this->assertEquals(0, preg_match('/(^|\n)Bcc: (\n|$)/', $header), 'Bcc found in headers.'); 1986be717dbSMichael Hamann $this->assertEquals(0, preg_match('/(^|\n)Cc: (\n|$)/', $header), 'Cc found in headers.'); 1996be717dbSMichael Hamann } 2006be717dbSMichael Hamann 2016be717dbSMichael Hamann function test_nullTOorCCorBCC() { 2026be717dbSMichael Hamann $mail = new TestMailer(); 2036be717dbSMichael Hamann $headers = &$mail->propRef('headers'); 2046be717dbSMichael Hamann $headers['Bcc'] = NULL; 2056be717dbSMichael Hamann $headers['Cc'] = NULL; 2066be717dbSMichael Hamann $headers['To'] = NULL; 2076be717dbSMichael Hamann $header = $mail->prepareHeaders(); 2086be717dbSMichael Hamann $this->assertEquals(0, preg_match('/(^|\n)Bcc: (\n|$)/', $header), 'Bcc found in headers.'); 2096be717dbSMichael Hamann $this->assertEquals(0, preg_match('/(^|\n)Cc: (\n|$)/', $header), 'Cc found in headers.'); 2106be717dbSMichael Hamann $this->assertEquals(0, preg_match('/(^|\n)To: (\n|$)/', $header), 'To found in headers.'); 2111f61f312SDominik Eckelmann } 2120ee5ed1eSAndreas Gohr 2130ee5ed1eSAndreas Gohr /** 2140ee5ed1eSAndreas Gohr * @group internet 2150ee5ed1eSAndreas Gohr */ 2160ee5ed1eSAndreas Gohr function test_lint(){ 2170ee5ed1eSAndreas Gohr // prepare a simple multipart message 2180ee5ed1eSAndreas Gohr $mail = new TestMailer(); 2190ee5ed1eSAndreas Gohr $mail->to(array('Möp <moep@example.com> ',' foo <foo@example.com>')); 220d6e04b60SAndreas Gohr $mail->from('Me <test@example.com>'); 2210ee5ed1eSAndreas Gohr $mail->subject('This is a töst'); 2220ee5ed1eSAndreas Gohr $mail->setBody('Hello Wörld, 2230ee5ed1eSAndreas Gohr 2240ee5ed1eSAndreas Gohr please don\'t burn, okay? 2250ee5ed1eSAndreas Gohr '); 226ec82d005SAndreas Gohr $mail->attachContent('some test data', 'text/plain', 'a text.txt'); 2270ee5ed1eSAndreas Gohr $msg = $mail->dump(); 2280ee5ed1eSAndreas Gohr $msglines = explode("\n", $msg); 2290ee5ed1eSAndreas Gohr 230d6e04b60SAndreas Gohr //echo $msg; 231d6e04b60SAndreas Gohr 2320ee5ed1eSAndreas Gohr // ask message lint if it is okay 2330ee5ed1eSAndreas Gohr $html = new HTTPClient(); 23445230f13SAndreas Gohr $results = $html->post('https://www.splitbrain.org/_static/msglint/', array('msg'=>$msg)); 23595e6ded1SAndreas Gohr if($results === false) { 23695e6ded1SAndreas Gohr $this->markTestSkipped('no response from validator'); 23795e6ded1SAndreas Gohr return; 23895e6ded1SAndreas Gohr } 2390ee5ed1eSAndreas Gohr 2400ee5ed1eSAndreas Gohr // parse the result lines 2410ee5ed1eSAndreas Gohr $lines = explode("\n", $results); 2420ee5ed1eSAndreas Gohr $rows = count($lines); 2430ee5ed1eSAndreas Gohr $i=0; 2440ee5ed1eSAndreas Gohr while(trim($lines[$i]) != '-----------' && $i<$rows) $i++; //skip preamble 2450ee5ed1eSAndreas Gohr for($i=$i+1; $i<$rows; $i++){ 2460ee5ed1eSAndreas Gohr $line = trim($lines[$i]); 2470ee5ed1eSAndreas Gohr if($line == '-----------') break; //skip appendix 2480ee5ed1eSAndreas Gohr 2490ee5ed1eSAndreas Gohr // get possible continuation of the line 2500ee5ed1eSAndreas Gohr while($lines[$i+1][0] == ' '){ 2510ee5ed1eSAndreas Gohr $line .= ' '.trim($lines[$i+1]); 2520ee5ed1eSAndreas Gohr $i++; 2530ee5ed1eSAndreas Gohr } 2540ee5ed1eSAndreas Gohr 2550ee5ed1eSAndreas Gohr // check the line for errors 256ec82d005SAndreas Gohr if(substr($line,0,5) == 'ERROR' || substr($line,0,7) == 'WARNING'){ 257d6e04b60SAndreas Gohr // ignore some errors 258d6e04b60SAndreas Gohr if(strpos($line, "missing mandatory header 'return-path'")) continue; #set by MDA 259acb389a8SAndreas Gohr if(strpos($line, "bare newline in text body decoded")) continue; #we don't send mail bodies as CRLF, yet 260acb389a8SAndreas Gohr if(strpos($line, "last decoded line too long")) continue; #we don't send mail bodies as CRLF, yet 261d6e04b60SAndreas Gohr 2620ee5ed1eSAndreas Gohr // get the context in which the error occured 2630ee5ed1eSAndreas Gohr $errorin = ''; 2640ee5ed1eSAndreas Gohr if(preg_match('/line (\d+)$/', $line, $m)){ 2650ee5ed1eSAndreas Gohr $errorin .= "\n".$msglines[$m[1] - 1]; 2660ee5ed1eSAndreas Gohr } 2670ee5ed1eSAndreas Gohr if(preg_match('/lines (\d+)-(\d+)$/', $line, $m)){ 2680ee5ed1eSAndreas Gohr for($x=$m[1]-1; $x<$m[2]; $x++){ 2690ee5ed1eSAndreas Gohr $errorin .= "\n".$msglines[$x]; 2700ee5ed1eSAndreas Gohr } 2710ee5ed1eSAndreas Gohr } 2720ee5ed1eSAndreas Gohr 2730ee5ed1eSAndreas Gohr // raise the error 2740ee5ed1eSAndreas Gohr throw new Exception($line.$errorin); 2750ee5ed1eSAndreas Gohr } 2760ee5ed1eSAndreas Gohr } 2770ee5ed1eSAndreas Gohr 2781bff2abaSAndreas Gohr $this->assertTrue(true); // avoid being marked as risky for having no assertion 2790ee5ed1eSAndreas Gohr } 280774514c9SGerrit Uitslag 281774514c9SGerrit Uitslag function test_simplemailsignature() { 282774514c9SGerrit Uitslag global $conf; 283774514c9SGerrit Uitslag $conf['htmlmail'] = 0; 284774514c9SGerrit Uitslag 285774514c9SGerrit Uitslag $mailbody = 'A test mail in ASCII'; 286774514c9SGerrit Uitslag $signature = "\n-- \n" . 'This mail was generated by DokuWiki at' . "\n" . DOKU_URL . "\n"; 287774514c9SGerrit Uitslag $mail = new TestMailer(); 288774514c9SGerrit Uitslag $mail->to('test@example.com'); 289774514c9SGerrit Uitslag $mail->setBody($mailbody); 290774514c9SGerrit Uitslag 291774514c9SGerrit Uitslag $dump = $mail->dump(); 292774514c9SGerrit Uitslag 293774514c9SGerrit Uitslag // construct the expected mail body text - include the expected dokuwiki signature 294774514c9SGerrit Uitslag $expected_mail_body = chunk_split(base64_encode($mailbody . $signature), 72, MAILHEADER_EOL); 295*9ad2b913SAndreas Gohr $this->assertMatchesRegularExpression('/' . preg_quote($expected_mail_body, '/') . '/', $dump); 296774514c9SGerrit Uitslag 297774514c9SGerrit Uitslag $conf['htmlmail'] = 1; 298774514c9SGerrit Uitslag } 299774514c9SGerrit Uitslag 300774514c9SGerrit Uitslag function test_htmlmailsignature() { 301774514c9SGerrit Uitslag $mailbody_text = 'A test mail in ASCII :)'; 302774514c9SGerrit Uitslag $mailbody_html = 'A test mail in <strong>html</strong>'; 303774514c9SGerrit Uitslag $htmlmsg_expected = '<html> 304774514c9SGerrit Uitslag<head> 305774514c9SGerrit Uitslag <title>My Test Wiki</title> 306774514c9SGerrit Uitslag <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> 307774514c9SGerrit Uitslag</head> 308774514c9SGerrit Uitslag<body> 309774514c9SGerrit Uitslag 310774514c9SGerrit UitslagA test mail in <strong>html</strong> 311774514c9SGerrit Uitslag 312774514c9SGerrit Uitslag<br /><hr /> 313f3cd98a0SGerrit Uitslag<small>This mail was generated by DokuWiki at<br /><a href="' . DOKU_URL . '">' . DOKU_URL . '</a></small> 314774514c9SGerrit Uitslag</body> 315774514c9SGerrit Uitslag</html> 316774514c9SGerrit Uitslag'; 317774514c9SGerrit Uitslag 318774514c9SGerrit Uitslag $mail = new TestMailer(); 319774514c9SGerrit Uitslag $mail->to('test@example.com'); 320774514c9SGerrit Uitslag $mail->setBody($mailbody_text, null, null, $mailbody_html); 321774514c9SGerrit Uitslag 322774514c9SGerrit Uitslag $dump = $mail->dump(); 323774514c9SGerrit Uitslag 324774514c9SGerrit Uitslag // construct the expected mail body text - include the expected dokuwiki signature 325774514c9SGerrit Uitslag $expected_mail_body = chunk_split(base64_encode($htmlmsg_expected), 72, MAILHEADER_EOL); 326774514c9SGerrit Uitslag 327*9ad2b913SAndreas Gohr $this->assertMatchesRegularExpression('/Content-Type: multipart/', $dump); 328*9ad2b913SAndreas Gohr $this->assertMatchesRegularExpression('#Content-Type: text/plain; charset=UTF-8#', $dump); 329*9ad2b913SAndreas Gohr $this->assertMatchesRegularExpression('/' . preg_quote($expected_mail_body, '/') . '/', $dump); 330774514c9SGerrit Uitslag 331774514c9SGerrit Uitslag } 332774514c9SGerrit Uitslag 333774514c9SGerrit Uitslag function test_htmlmailsignaturecustom() { 334774514c9SGerrit Uitslag global $lang; 335774514c9SGerrit Uitslag $lang['email_signature_html'] = 'Official message from your DokuWiki @DOKUWIKIURL@<br />Created by wonderful mail class <a href="https://www.dokuwiki.org/devel:mail">https://www.dokuwiki.org/devel:mail</a>'; 336774514c9SGerrit Uitslag 337774514c9SGerrit Uitslag $mailbody_text = 'A test mail in ASCII :)'; 338774514c9SGerrit Uitslag $mailbody_html = 'A test mail in <strong>html</strong>'; 339774514c9SGerrit Uitslag $htmlmsg_expected = '<html> 340774514c9SGerrit Uitslag<head> 341774514c9SGerrit Uitslag <title>My Test Wiki</title> 342774514c9SGerrit Uitslag <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> 343774514c9SGerrit Uitslag</head> 344774514c9SGerrit Uitslag<body> 345774514c9SGerrit Uitslag 346774514c9SGerrit UitslagA test mail in <strong>html</strong> 347774514c9SGerrit Uitslag 348774514c9SGerrit Uitslag<br /><hr /> 349f3cd98a0SGerrit Uitslag<small>Official message from your DokuWiki <a href="' . DOKU_URL . '">' . DOKU_URL . '</a><br />Created by wonderful mail class <a href="https://www.dokuwiki.org/devel:mail">https://www.dokuwiki.org/devel:mail</a></small> 350774514c9SGerrit Uitslag</body> 351774514c9SGerrit Uitslag</html> 352774514c9SGerrit Uitslag'; 353774514c9SGerrit Uitslag 354774514c9SGerrit Uitslag $mail = new TestMailer(); 355774514c9SGerrit Uitslag $mail->to('test@example.com'); 356774514c9SGerrit Uitslag $mail->setBody($mailbody_text, null, null, $mailbody_html); 357774514c9SGerrit Uitslag 358774514c9SGerrit Uitslag $dump = $mail->dump(); 359774514c9SGerrit Uitslag 360774514c9SGerrit Uitslag // construct the expected mail body text - include the expected dokuwiki signature 361774514c9SGerrit Uitslag $replacements = $mail->prop('replacements'); 362774514c9SGerrit Uitslag $expected_mail_body = chunk_split(base64_encode($htmlmsg_expected), 72, MAILHEADER_EOL); 363774514c9SGerrit Uitslag 364*9ad2b913SAndreas Gohr $this->assertMatchesRegularExpression('/' . preg_quote($expected_mail_body, '/') . '/', $dump); 365774514c9SGerrit Uitslag 366774514c9SGerrit Uitslag } 367102cdbd7SLarsGit223 368102cdbd7SLarsGit223 function test_getCleanName() { 369102cdbd7SLarsGit223 $mail = new TestMailer(); 370102cdbd7SLarsGit223 $name = $mail->getCleanName('Foo Bar'); 371102cdbd7SLarsGit223 $this->assertEquals('Foo Bar', $name); 372102cdbd7SLarsGit223 $name = $mail->getCleanName('Foo, Bar'); 373102cdbd7SLarsGit223 $this->assertEquals('"Foo, Bar"', $name); 374102cdbd7SLarsGit223 $name = $mail->getCleanName('Foo" Bar'); 375102cdbd7SLarsGit223 $this->assertEquals('"Foo\" Bar"', $name); 3762b58f049SAndreas Gohr $name = $mail->getCleanName("\tFoo tar "); 3772b58f049SAndreas Gohr $this->assertEquals('Foo tar', $name); 3782b58f049SAndreas Gohr 379102cdbd7SLarsGit223 } 380cc92aca7SAndreas Gohr} 381cc92aca7SAndreas Gohr//Setup VIM: ex: et ts=4 : 382