xref: /dokuwiki/_test/tests/inc/mailer.test.php (revision 98548fef01f6eb5c04e2ab0aae2c46019fc2b448)
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
107*98548fefSAndreas Gohr        $mail->to('andi@splitbrain.org,foo@example.com');
108*98548fefSAndreas Gohr        $mail->cleanHeaders();
109*98548fefSAndreas Gohr        $headers = $mail->prop('headers');
110*98548fefSAndreas Gohr        $this->assertEquals('andi@splitbrain.org, foo@example.com', $headers['To']);
111*98548fefSAndreas Gohr
112b6c97c70SAndreas Gohr        $mail->to('Andreas Gohr <andi@splitbrain.org> , foo <foo@example.com>');
113b6c97c70SAndreas Gohr        $mail->cleanHeaders();
114b6c97c70SAndreas Gohr        $headers = $mail->prop('headers');
115b6c97c70SAndreas Gohr        $this->assertEquals('Andreas Gohr <andi@splitbrain.org>, foo <foo@example.com>', $headers['To']);
116b6c97c70SAndreas Gohr
117102cdbd7SLarsGit223        $mail->to('"Foo, Dr." <foo@example.com> , foo <foo@example.com>');
118102cdbd7SLarsGit223        $mail->cleanHeaders();
119102cdbd7SLarsGit223        $headers = $mail->prop('headers');
120102cdbd7SLarsGit223        $this->assertEquals('=?UTF-8?B?IkZvbywgRHIuIg==?= <foo@example.com>, foo <foo@example.com>', $headers['To']);
121102cdbd7SLarsGit223
122b6c97c70SAndreas Gohr        $mail->to('Möp <moep@example.com> , foo <foo@example.com>');
123b6c97c70SAndreas Gohr        $mail->cleanHeaders();
124b6c97c70SAndreas Gohr        $headers = $mail->prop('headers');
125b6c97c70SAndreas Gohr        $this->assertEquals('=?UTF-8?B?TcO2cA==?= <moep@example.com>, foo <foo@example.com>', $headers['To']);
126b6c97c70SAndreas Gohr
127b6c97c70SAndreas Gohr        $mail->to(array('Möp <moep@example.com> ',' foo <foo@example.com>'));
128b6c97c70SAndreas Gohr        $mail->cleanHeaders();
129b6c97c70SAndreas Gohr        $headers = $mail->prop('headers');
130b6c97c70SAndreas Gohr        $this->assertEquals('=?UTF-8?B?TcO2cA==?= <moep@example.com>, foo <foo@example.com>', $headers['To']);
131b6c97c70SAndreas Gohr
132b6c97c70SAndreas Gohr        $mail->to(array('Beet, L van <lvb@example.com>',' foo <foo@example.com>'));
133b6c97c70SAndreas Gohr        $mail->cleanHeaders();
134b6c97c70SAndreas Gohr        $headers = $mail->prop('headers');
135b6c97c70SAndreas Gohr        $this->assertEquals('=?UTF-8?B?QmVldCwgTCB2YW4=?= <lvb@example.com>, foo <foo@example.com>', $headers['To']);
136b6c97c70SAndreas Gohr
137b6c97c70SAndreas Gohr
138b6c97c70SAndreas Gohr    }
139b6c97c70SAndreas Gohr
140cc92aca7SAndreas Gohr    function test_simplemail(){
141cc92aca7SAndreas Gohr        global $conf;
142cc92aca7SAndreas Gohr        $conf['htmlmail'] = 0;
1439ea45836SChristopher Smith
1449ea45836SChristopher Smith        $mailbody = 'A test mail in ASCII';
145cc92aca7SAndreas Gohr        $mail = new TestMailer();
146cc92aca7SAndreas Gohr        $mail->to('test@example.com');
1479ea45836SChristopher Smith        $mail->setBody($mailbody);
148cc92aca7SAndreas Gohr
149cc92aca7SAndreas Gohr        $dump = $mail->dump();
1509ea45836SChristopher Smith
1519ea45836SChristopher Smith        // construct the expected mail body text - include the expected dokuwiki signature
1529ea45836SChristopher Smith        $replacements = $mail->prop('replacements');
1539ea45836SChristopher Smith        $expected_mail_body = chunk_split(base64_encode($mailbody.$replacements['text']['EMAILSIGNATURE']),72,MAILHEADER_EOL);
1549ea45836SChristopher Smith
155cc92aca7SAndreas Gohr        $this->assertNotRegexp('/Content-Type: multipart/',$dump);
156cc92aca7SAndreas Gohr        $this->assertRegexp('#Content-Type: text/plain; charset=UTF-8#',$dump);
1579ea45836SChristopher Smith        $this->assertRegexp('/'.preg_quote($expected_mail_body,'/').'/',$dump);
158cc92aca7SAndreas Gohr
159cc92aca7SAndreas Gohr        $conf['htmlmail'] = 1;
160cc92aca7SAndreas Gohr    }
161cc92aca7SAndreas Gohr
162cc92aca7SAndreas Gohr    function test_replacements(){
163cc92aca7SAndreas Gohr        $mail = new TestMailer();
164cc92aca7SAndreas Gohr
1659e01e280SChristopher Smith        $replacements = array( '@DATE@','@BROWSER@','@IPADDRESS@','@HOSTNAME@','@EMAILSIGNATURE@',
166cc92aca7SAndreas Gohr                               '@TITLE@','@DOKUWIKIURL@','@USER@','@NAME@','@MAIL@');
167cc92aca7SAndreas Gohr        $mail->setBody('A test mail in with replacements '.join(' ',$replacements));
168cc92aca7SAndreas Gohr
169cc92aca7SAndreas Gohr        $text = $mail->prop('text');
170cc92aca7SAndreas Gohr        $html = $mail->prop('html');
171cc92aca7SAndreas Gohr
172cc92aca7SAndreas Gohr        foreach($replacements as $repl){
173cc92aca7SAndreas Gohr            $this->assertNotRegexp("/$repl/",$text,"$repl replacement still in text");
174cc92aca7SAndreas Gohr            $this->assertNotRegexp("/$repl/",$html,"$repl replacement still in html");
175cc92aca7SAndreas Gohr        }
176cc92aca7SAndreas Gohr    }
177cc92aca7SAndreas Gohr
17891effd8dSDominik Eckelmann    /**
17991effd8dSDominik Eckelmann     * @see https://forum.dokuwiki.org/post/35822
18091effd8dSDominik Eckelmann     */
1811f61f312SDominik Eckelmann    function test_emptyBCCorCC() {
1821f61f312SDominik Eckelmann        $mail = new TestMailer();
1831f61f312SDominik Eckelmann        $headers = &$mail->propRef('headers');
1841f61f312SDominik Eckelmann        $headers['Bcc'] = '';
1851f61f312SDominik Eckelmann        $headers['Cc'] = '';
1861f61f312SDominik Eckelmann        $header = $mail->prepareHeaders();
1871f61f312SDominik Eckelmann        $this->assertEquals(0, preg_match('/(^|\n)Bcc: (\n|$)/', $header), 'Bcc found in headers.');
1886be717dbSMichael Hamann        $this->assertEquals(0, preg_match('/(^|\n)Cc: (\n|$)/', $header), 'Cc found in headers.');
1896be717dbSMichael Hamann    }
1906be717dbSMichael Hamann
1916be717dbSMichael Hamann    function test_nullTOorCCorBCC() {
1926be717dbSMichael Hamann        $mail = new TestMailer();
1936be717dbSMichael Hamann        $headers = &$mail->propRef('headers');
1946be717dbSMichael Hamann        $headers['Bcc'] = NULL;
1956be717dbSMichael Hamann        $headers['Cc'] = NULL;
1966be717dbSMichael Hamann        $headers['To'] = NULL;
1976be717dbSMichael Hamann        $header = $mail->prepareHeaders();
1986be717dbSMichael Hamann        $this->assertEquals(0, preg_match('/(^|\n)Bcc: (\n|$)/', $header), 'Bcc found in headers.');
1996be717dbSMichael Hamann        $this->assertEquals(0, preg_match('/(^|\n)Cc: (\n|$)/', $header), 'Cc found in headers.');
2006be717dbSMichael Hamann        $this->assertEquals(0, preg_match('/(^|\n)To: (\n|$)/', $header), 'To found in headers.');
2011f61f312SDominik Eckelmann    }
2020ee5ed1eSAndreas Gohr
2030ee5ed1eSAndreas Gohr    /**
2040ee5ed1eSAndreas Gohr     * @group internet
2050ee5ed1eSAndreas Gohr     */
2060ee5ed1eSAndreas Gohr    function test_lint(){
2070ee5ed1eSAndreas Gohr        // prepare a simple multipart message
2080ee5ed1eSAndreas Gohr        $mail = new TestMailer();
2090ee5ed1eSAndreas Gohr        $mail->to(array('Möp <moep@example.com> ',' foo <foo@example.com>'));
210d6e04b60SAndreas Gohr        $mail->from('Me <test@example.com>');
2110ee5ed1eSAndreas Gohr        $mail->subject('This is a töst');
2120ee5ed1eSAndreas Gohr        $mail->setBody('Hello Wörld,
2130ee5ed1eSAndreas Gohr
2140ee5ed1eSAndreas Gohr        please don\'t burn, okay?
2150ee5ed1eSAndreas Gohr        ');
216ec82d005SAndreas Gohr        $mail->attachContent('some test data', 'text/plain', 'a text.txt');
2170ee5ed1eSAndreas Gohr        $msg = $mail->dump();
2180ee5ed1eSAndreas Gohr        $msglines = explode("\n", $msg);
2190ee5ed1eSAndreas Gohr
220d6e04b60SAndreas Gohr        //echo $msg;
221d6e04b60SAndreas Gohr
2220ee5ed1eSAndreas Gohr        // ask message lint if it is okay
2230ee5ed1eSAndreas Gohr        $html = new HTTPClient();
2247468fb90SAndreas Gohr        $results = $html->post('https://tools.ietf.org/tools/msglint/msglint', array('msg'=>$msg));
22595e6ded1SAndreas Gohr        if($results === false) {
22695e6ded1SAndreas Gohr            $this->markTestSkipped('no response from validator');
22795e6ded1SAndreas Gohr            return;
22895e6ded1SAndreas Gohr        }
2290ee5ed1eSAndreas Gohr
2300ee5ed1eSAndreas Gohr        // parse the result lines
2310ee5ed1eSAndreas Gohr        $lines = explode("\n", $results);
2320ee5ed1eSAndreas Gohr        $rows  = count($lines);
2330ee5ed1eSAndreas Gohr        $i=0;
2340ee5ed1eSAndreas Gohr        while(trim($lines[$i]) != '-----------' && $i<$rows) $i++; //skip preamble
2350ee5ed1eSAndreas Gohr        for($i=$i+1; $i<$rows; $i++){
2360ee5ed1eSAndreas Gohr            $line = trim($lines[$i]);
2370ee5ed1eSAndreas Gohr            if($line == '-----------') break; //skip appendix
2380ee5ed1eSAndreas Gohr
2390ee5ed1eSAndreas Gohr            // get possible continuation of the line
2400ee5ed1eSAndreas Gohr            while($lines[$i+1][0] == ' '){
2410ee5ed1eSAndreas Gohr                $line .= ' '.trim($lines[$i+1]);
2420ee5ed1eSAndreas Gohr                $i++;
2430ee5ed1eSAndreas Gohr            }
2440ee5ed1eSAndreas Gohr
2450ee5ed1eSAndreas Gohr            // check the line for errors
246ec82d005SAndreas Gohr            if(substr($line,0,5) == 'ERROR' || substr($line,0,7) == 'WARNING'){
247d6e04b60SAndreas Gohr                // ignore some errors
248d6e04b60SAndreas Gohr                if(strpos($line, "missing mandatory header 'return-path'")) continue; #set by MDA
249acb389a8SAndreas Gohr                if(strpos($line, "bare newline in text body decoded")) continue; #we don't send mail bodies as CRLF, yet
250acb389a8SAndreas Gohr                if(strpos($line, "last decoded line too long")) continue; #we don't send mail bodies as CRLF, yet
251d6e04b60SAndreas Gohr
2520ee5ed1eSAndreas Gohr                // get the context in which the error occured
2530ee5ed1eSAndreas Gohr                $errorin = '';
2540ee5ed1eSAndreas Gohr                if(preg_match('/line (\d+)$/', $line, $m)){
2550ee5ed1eSAndreas Gohr                    $errorin .= "\n".$msglines[$m[1] - 1];
2560ee5ed1eSAndreas Gohr                }
2570ee5ed1eSAndreas Gohr                if(preg_match('/lines (\d+)-(\d+)$/', $line, $m)){
2580ee5ed1eSAndreas Gohr                    for($x=$m[1]-1; $x<$m[2]; $x++){
2590ee5ed1eSAndreas Gohr                        $errorin .= "\n".$msglines[$x];
2600ee5ed1eSAndreas Gohr                    }
2610ee5ed1eSAndreas Gohr                }
2620ee5ed1eSAndreas Gohr
2630ee5ed1eSAndreas Gohr                // raise the error
2640ee5ed1eSAndreas Gohr                throw new Exception($line.$errorin);
2650ee5ed1eSAndreas Gohr            }
2660ee5ed1eSAndreas Gohr        }
2670ee5ed1eSAndreas Gohr
2681bff2abaSAndreas Gohr        $this->assertTrue(true); // avoid being marked as risky for having no assertion
2690ee5ed1eSAndreas Gohr    }
270774514c9SGerrit Uitslag
271774514c9SGerrit Uitslag    function test_simplemailsignature() {
272774514c9SGerrit Uitslag        global $conf;
273774514c9SGerrit Uitslag        $conf['htmlmail'] = 0;
274774514c9SGerrit Uitslag
275774514c9SGerrit Uitslag        $mailbody = 'A test mail in ASCII';
276774514c9SGerrit Uitslag        $signature = "\n-- \n" . 'This mail was generated by DokuWiki at' . "\n" . DOKU_URL . "\n";
277774514c9SGerrit Uitslag        $mail = new TestMailer();
278774514c9SGerrit Uitslag        $mail->to('test@example.com');
279774514c9SGerrit Uitslag        $mail->setBody($mailbody);
280774514c9SGerrit Uitslag
281774514c9SGerrit Uitslag        $dump = $mail->dump();
282774514c9SGerrit Uitslag
283774514c9SGerrit Uitslag        // construct the expected mail body text - include the expected dokuwiki signature
284774514c9SGerrit Uitslag        $expected_mail_body = chunk_split(base64_encode($mailbody . $signature), 72, MAILHEADER_EOL);
285774514c9SGerrit Uitslag        $this->assertRegexp('/' . preg_quote($expected_mail_body, '/') . '/', $dump);
286774514c9SGerrit Uitslag
287774514c9SGerrit Uitslag        $conf['htmlmail'] = 1;
288774514c9SGerrit Uitslag    }
289774514c9SGerrit Uitslag
290774514c9SGerrit Uitslag    function test_htmlmailsignature() {
291774514c9SGerrit Uitslag        $mailbody_text = 'A test mail in ASCII :)';
292774514c9SGerrit Uitslag        $mailbody_html = 'A test mail in <strong>html</strong>';
293774514c9SGerrit Uitslag        $htmlmsg_expected = '<html>
294774514c9SGerrit Uitslag<head>
295774514c9SGerrit Uitslag    <title>My Test Wiki</title>
296774514c9SGerrit Uitslag    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
297774514c9SGerrit Uitslag</head>
298774514c9SGerrit Uitslag<body>
299774514c9SGerrit Uitslag
300774514c9SGerrit UitslagA test mail in <strong>html</strong>
301774514c9SGerrit Uitslag
302774514c9SGerrit Uitslag<br /><hr />
303f3cd98a0SGerrit Uitslag<small>This mail was generated by DokuWiki at<br /><a href="' . DOKU_URL . '">' . DOKU_URL . '</a></small>
304774514c9SGerrit Uitslag</body>
305774514c9SGerrit Uitslag</html>
306774514c9SGerrit Uitslag';
307774514c9SGerrit Uitslag
308774514c9SGerrit Uitslag        $mail = new TestMailer();
309774514c9SGerrit Uitslag        $mail->to('test@example.com');
310774514c9SGerrit Uitslag        $mail->setBody($mailbody_text, null, null, $mailbody_html);
311774514c9SGerrit Uitslag
312774514c9SGerrit Uitslag        $dump = $mail->dump();
313774514c9SGerrit Uitslag
314774514c9SGerrit Uitslag        // construct the expected mail body text - include the expected dokuwiki signature
315774514c9SGerrit Uitslag        $expected_mail_body = chunk_split(base64_encode($htmlmsg_expected), 72, MAILHEADER_EOL);
316774514c9SGerrit Uitslag
317774514c9SGerrit Uitslag        $this->assertRegexp('/Content-Type: multipart/', $dump);
318774514c9SGerrit Uitslag        $this->assertRegexp('#Content-Type: text/plain; charset=UTF-8#', $dump);
319774514c9SGerrit Uitslag        $this->assertRegexp('/' . preg_quote($expected_mail_body, '/') . '/', $dump);
320774514c9SGerrit Uitslag
321774514c9SGerrit Uitslag    }
322774514c9SGerrit Uitslag
323774514c9SGerrit Uitslag    function test_htmlmailsignaturecustom() {
324774514c9SGerrit Uitslag        global $lang;
325774514c9SGerrit 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>';
326774514c9SGerrit Uitslag
327774514c9SGerrit Uitslag        $mailbody_text = 'A test mail in ASCII :)';
328774514c9SGerrit Uitslag        $mailbody_html = 'A test mail in <strong>html</strong>';
329774514c9SGerrit Uitslag        $htmlmsg_expected = '<html>
330774514c9SGerrit Uitslag<head>
331774514c9SGerrit Uitslag    <title>My Test Wiki</title>
332774514c9SGerrit Uitslag    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
333774514c9SGerrit Uitslag</head>
334774514c9SGerrit Uitslag<body>
335774514c9SGerrit Uitslag
336774514c9SGerrit UitslagA test mail in <strong>html</strong>
337774514c9SGerrit Uitslag
338774514c9SGerrit Uitslag<br /><hr />
339f3cd98a0SGerrit 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>
340774514c9SGerrit Uitslag</body>
341774514c9SGerrit Uitslag</html>
342774514c9SGerrit Uitslag';
343774514c9SGerrit Uitslag
344774514c9SGerrit Uitslag        $mail = new TestMailer();
345774514c9SGerrit Uitslag        $mail->to('test@example.com');
346774514c9SGerrit Uitslag        $mail->setBody($mailbody_text, null, null, $mailbody_html);
347774514c9SGerrit Uitslag
348774514c9SGerrit Uitslag        $dump = $mail->dump();
349774514c9SGerrit Uitslag
350774514c9SGerrit Uitslag        // construct the expected mail body text - include the expected dokuwiki signature
351774514c9SGerrit Uitslag        $replacements = $mail->prop('replacements');
352774514c9SGerrit Uitslag        $expected_mail_body = chunk_split(base64_encode($htmlmsg_expected), 72, MAILHEADER_EOL);
353774514c9SGerrit Uitslag
354774514c9SGerrit Uitslag        $this->assertRegexp('/' . preg_quote($expected_mail_body, '/') . '/', $dump);
355774514c9SGerrit Uitslag
356774514c9SGerrit Uitslag    }
357102cdbd7SLarsGit223
358102cdbd7SLarsGit223    function test_getCleanName() {
359102cdbd7SLarsGit223        $mail = new TestMailer();
360102cdbd7SLarsGit223        $name = $mail->getCleanName('Foo Bar');
361102cdbd7SLarsGit223        $this->assertEquals('Foo Bar', $name);
362102cdbd7SLarsGit223        $name = $mail->getCleanName('Foo, Bar');
363102cdbd7SLarsGit223        $this->assertEquals('"Foo, Bar"', $name);
364102cdbd7SLarsGit223        $name = $mail->getCleanName('Foo" Bar');
365102cdbd7SLarsGit223        $this->assertEquals('"Foo\" Bar"', $name);
366102cdbd7SLarsGit223    }
367cc92aca7SAndreas Gohr}
368cc92aca7SAndreas Gohr//Setup VIM: ex: et ts=4 :
369