summaryrefslogtreecommitdiff
path: root/_test/tests/inc/mailer.test.php
diff options
context:
space:
mode:
authorAndreas Gohr <andi@splitbrain.org>2013-10-28 20:22:05 +0100
committerAndreas Gohr <andi@splitbrain.org>2013-10-28 20:22:05 +0100
commit23a363f01514464eb2238ac09ec7723d03d57ecb (patch)
tree42c7dcff8c5b0e506a25d08ee5583ed2a24e8602 /_test/tests/inc/mailer.test.php
parent25e48e54df60b3df6efa365daceb3a8966c8f427 (diff)
parent75cf672f10a71f7dee6d50eb70b742689838bc36 (diff)
downloadrpg-23a363f01514464eb2238ac09ec7723d03d57ecb.tar.gz
rpg-23a363f01514464eb2238ac09ec7723d03d57ecb.tar.bz2
Merge branch 'master' into stable
* master: (413 commits) release preparation fixed strict violation in ACL plugin Fix issues from teams:i18n:translation-check in localizations ensure locale is set back to the original value skip FS#2867 test if \s doesn't match \xA0 after attempting to change the locale unittests for auth_loadACL translation update allow charset for SSO to be configured FS#2148 Mailer: avoid overlong headers in content ids FS#2868 translation update translation update replace \s, \S with [ \t], [^ \t] in regexs used with acls translation update translation update translation update translation update Fix handling of the legacy subscription action name remove obsolete opera handling and session closing remove no longer used ajax.php fix proxy CONNECT where HTTP 1.1 answer is given ...
Diffstat (limited to '_test/tests/inc/mailer.test.php')
-rw-r--r--_test/tests/inc/mailer.test.php115
1 files changed, 112 insertions, 3 deletions
diff --git a/_test/tests/inc/mailer.test.php b/_test/tests/inc/mailer.test.php
index 053e216b8..bac0c39ba 100644
--- a/_test/tests/inc/mailer.test.php
+++ b/_test/tests/inc/mailer.test.php
@@ -15,6 +15,11 @@ class TestMailer extends Mailer {
public function prepareHeaders() {
return parent::prepareHeaders();
}
+
+ public function cleanHeaders() {
+ parent::cleanHeaders();
+ }
+
}
class mailer_test extends DokuWikiTest {
@@ -45,8 +50,8 @@ class mailer_test extends DokuWikiTest {
// set a bunch of test headers
$mail->setHeader('test-header','bla');
$mail->setHeader('to','A valid ASCII name <test@example.com>');
- $mail->setHeader('from',"Thös ne\needs\x00serious cleaning$§%.");
- $mail->setHeader('bad',"Thös ne\needs\x00serious cleaning$§%.",false);
+ $mail->setHeader('from',"Thös ne\needs\x00serious cleaning\$§%.");
+ $mail->setHeader('bad',"Thös ne\needs\x00serious cleaning\$§%.",false);
$mail->setHeader("weird\n*+\x00foo.-_@bar?",'now clean');
// are they set?
@@ -58,7 +63,7 @@ class mailer_test extends DokuWikiTest {
$this->assertArrayHasKey('From',$headers);
$this->assertEquals('Ths neeedsserious cleaning.',$headers['From']);
$this->assertArrayHasKey('Bad',$headers);
- $this->assertEquals("Thös ne\needs\x00serious cleaning$§%.",$headers['Bad']);
+ $this->assertEquals("Thös ne\needs\x00serious cleaning\$§%.",$headers['Bad']);
$this->assertArrayHasKey('Weird+foo.-_@bar',$headers);
// unset a header again
@@ -67,6 +72,47 @@ class mailer_test extends DokuWikiTest {
$this->assertArrayNotHasKey('Test-Header',$headers);
}
+ function test_addresses(){
+ $mail = new TestMailer();
+
+ $mail->to('andi@splitbrain.org');
+ $mail->cleanHeaders();
+ $headers = $mail->prop('headers');
+ $this->assertEquals('andi@splitbrain.org', $headers['To']);
+
+ $mail->to('<andi@splitbrain.org>');
+ $mail->cleanHeaders();
+ $headers = $mail->prop('headers');
+ $this->assertEquals('andi@splitbrain.org', $headers['To']);
+
+ $mail->to('Andreas Gohr <andi@splitbrain.org>');
+ $mail->cleanHeaders();
+ $headers = $mail->prop('headers');
+ $this->assertEquals('Andreas Gohr <andi@splitbrain.org>', $headers['To']);
+
+ $mail->to('Andreas Gohr <andi@splitbrain.org> , foo <foo@example.com>');
+ $mail->cleanHeaders();
+ $headers = $mail->prop('headers');
+ $this->assertEquals('Andreas Gohr <andi@splitbrain.org>, foo <foo@example.com>', $headers['To']);
+
+ $mail->to('Möp <moep@example.com> , foo <foo@example.com>');
+ $mail->cleanHeaders();
+ $headers = $mail->prop('headers');
+ $this->assertEquals('=?UTF-8?B?TcO2cA==?= <moep@example.com>, foo <foo@example.com>', $headers['To']);
+
+ $mail->to(array('Möp <moep@example.com> ',' foo <foo@example.com>'));
+ $mail->cleanHeaders();
+ $headers = $mail->prop('headers');
+ $this->assertEquals('=?UTF-8?B?TcO2cA==?= <moep@example.com>, foo <foo@example.com>', $headers['To']);
+
+ $mail->to(array('Beet, L van <lvb@example.com>',' foo <foo@example.com>'));
+ $mail->cleanHeaders();
+ $headers = $mail->prop('headers');
+ $this->assertEquals('=?UTF-8?B?QmVldCwgTCB2YW4=?= <lvb@example.com>, foo <foo@example.com>', $headers['To']);
+
+
+ }
+
function test_simplemail(){
global $conf;
$conf['htmlmail'] = 0;
@@ -110,5 +156,68 @@ class mailer_test extends DokuWikiTest {
$this->assertEquals(0, preg_match('/(^|\n)Bcc: (\n|$)/', $header), 'Bcc found in headers.');
$this->assertEquals(0, preg_match('/(^|\n)Cc: (\n|$)/', $header), 'Bcc found in headers.');
}
+
+ /**
+ * @group internet
+ */
+ function test_lint(){
+ // prepare a simple multipart message
+ $mail = new TestMailer();
+ $mail->to(array('Möp <moep@example.com> ',' foo <foo@example.com>'));
+ $mail->from('Me <test@example.com>');
+ $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));
+ $this->assertTrue($results !== false);
+
+ // 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);
+ }
+ }
+
+ }
}
//Setup VIM: ex: et ts=4 :