summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--_test/cases/inc/mail_send.php49
-rw-r--r--inc/mail.php11
2 files changed, 56 insertions, 4 deletions
diff --git a/_test/cases/inc/mail_send.php b/_test/cases/inc/mail_send.php
new file mode 100644
index 000000000..5c2b0e896
--- /dev/null
+++ b/_test/cases/inc/mail_send.php
@@ -0,0 +1,49 @@
+<?php
+require_once DOKU_INC.'inc/mail.php';
+
+class mail_send extends UnitTestCase {
+
+ /**
+ * These tests will try to send a bunch of mails to dokuwiki1@spam.la and
+ * dokuwiki2@spam.la - check the correctness at http://spam.la
+ */
+ function test1(){
+ $addr = array(
+ 'dokuwiki1@spam.la',
+ 'dokuwiki2@spam.la',
+ 'Test User <dokuwiki1@spam.la>',
+ 'dokuwiki1@spam.la, dokuwiki2@spam.la',
+ 'Test User 1 <dokuwiki1@spam.la>, Test User 2 <dokuwiki2@spam.la>'
+ );
+
+
+ $run = 0;
+ foreach($addr as $ad){
+ $run++;
+ $data = array(
+ 'to' => $ad,
+ 'subject' => 'mailtest 1-'.$run,
+ 'body' => "Mailtest run 1-$run using to: $ad from:",
+ );
+ $this->assertTrue((bool) _mail_send_action($data));
+
+ $data = array(
+ 'to' => $ad,
+ 'from' => 'dokuwiki1@spam.la',
+ 'subject' => 'mailtest 2-'.$run,
+ 'body' => "Mailtest run 2-$run using to: $ad from: dokuwiki1@spam.la",
+ );
+ $this->assertTrue((bool) _mail_send_action($data));
+
+ $data = array(
+ 'to' => $ad,
+ 'from' => '"Foo Bar" <dokuwiki@spam.la>',
+ 'subject' => 'mailtest 3-'.$run,
+ 'body' => "Mailtest run 3-$run using to: $ad from: \"Foo Bar\" <dokuwiki@spam.la>",
+ );
+ $this->assertTrue((bool) _mail_send_action($data));
+ }
+ }
+
+}
+//Setup VIM: ex: et ts=4 enc=utf-8 :
diff --git a/inc/mail.php b/inc/mail.php
index 5cd7db13d..4b27963ee 100644
--- a/inc/mail.php
+++ b/inc/mail.php
@@ -73,8 +73,8 @@ function _mail_send_action($data) {
// On Unix set the envelope headers correctly:
if($usenames){
- if($from) $params = ((string) $params).' -f '.escapeshellarg($from);
- if($to) $params = ((string) $params).' '.escapeshellarg($to);
+ if($from) $params = ((string) $params).' -f '.escapeshellarg(mail_encode_address($from,'',false));
+ if($to) $params = ((string) $params).' '.escapeshellarg(mail_encode_address($to,'',false));
}
$to = mail_encode_address($to,'',$usenames);
@@ -157,8 +157,11 @@ function mail_encode_address($string,$header='',$names=true){
$text = '';
}
- // add to header comma seperated and in new line to avoid too long headers
- if($headers != '') $headers .= ','.MAILHEADER_EOL.' ';
+ // add to header comma seperated
+ if($headers != ''){
+ $headers .= ',';
+ if($header) $headers .= MAILHEADER_EOL.' '; // avoid overlong mail headers
+ }
$headers .= $text.' '.$addr;
}