allow adresses to be passed as array in Mailer class
This adresses the issue in FS#2677, but only partially. Unless the parameters are passed as array, the old mechanism is used. For passing arrays, at least the COMMON_NOTIFY_ADDRESSLIST event has to be adjusted. There might be other places to modify as well.
This commit is contained in:
parent
8a65ef2ef3
commit
a6aa263e18
|
@ -110,5 +110,23 @@ 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.');
|
||||
}
|
||||
|
||||
function test_cleanAddress() {
|
||||
$mail = new TestMailer();
|
||||
|
||||
$input = 'Joe <joe@example.com>, test@example.com, Sülz <suelz@example.com>';
|
||||
$expected = '"Joe" <joe@example.com>, test@example.com, =?UTF-8?B?IlPDvGx6Ig==?= <suelz@example.com>';
|
||||
$this->assertEquals($expected, $mail->cleanAddress($input));
|
||||
|
||||
$input = array(
|
||||
'Joe <joe@example.com>',
|
||||
'test@example.com',
|
||||
'Sülz <suelz@example.com>',
|
||||
'Doe, John <doe@example.com>',
|
||||
'"Doe, Jane" <jane@example.com>',
|
||||
);
|
||||
$expected = '"Joe" <joe@example.com>, test@example.com, =?UTF-8?B?IlPDvGx6Ig==?= <suelz@example.com>, "Doe, John" <doe@example.com>, "\'Doe, Jane\'" <jane@example.com>';
|
||||
$this->assertEquals($expected, $mail->cleanAddress($input));
|
||||
}
|
||||
}
|
||||
//Setup VIM: ex: et ts=4 :
|
||||
|
|
|
@ -270,7 +270,7 @@ class Mailer {
|
|||
* Add the To: recipients
|
||||
*
|
||||
* @see setAddress
|
||||
* @param string $address Multiple adresses separated by commas
|
||||
* @param string|array $address Multiple adresses (array or string separated by commas)
|
||||
*/
|
||||
public function to($address) {
|
||||
$this->setHeader('To', $address, false);
|
||||
|
@ -280,7 +280,7 @@ class Mailer {
|
|||
* Add the Cc: recipients
|
||||
*
|
||||
* @see setAddress
|
||||
* @param string $address Multiple adresses separated by commas
|
||||
* @param string|array $address Multiple adresses (array or string separated by commas)
|
||||
*/
|
||||
public function cc($address) {
|
||||
$this->setHeader('Cc', $address, false);
|
||||
|
@ -290,7 +290,7 @@ class Mailer {
|
|||
* Add the Bcc: recipients
|
||||
*
|
||||
* @see setAddress
|
||||
* @param string $address Multiple adresses separated by commas
|
||||
* @param string|array $address Multiple adresses (array or string separated by commas)
|
||||
*/
|
||||
public function bcc($address) {
|
||||
$this->setHeader('Bcc', $address, false);
|
||||
|
@ -303,7 +303,7 @@ class Mailer {
|
|||
* to call this function
|
||||
*
|
||||
* @see setAddress
|
||||
* @param string $address from address
|
||||
* @param string|array $address from address
|
||||
*/
|
||||
public function from($address) {
|
||||
$this->setHeader('From', $address, false);
|
||||
|
@ -324,21 +324,23 @@ class Mailer {
|
|||
* Unicode characters will be deaccented and encoded base64
|
||||
* for headers. Addresses may not contain Non-ASCII data!
|
||||
*
|
||||
* Example:
|
||||
* setAddress("föö <foo@bar.com>, me@somewhere.com","TBcc");
|
||||
*
|
||||
* @param string $address Multiple adresses separated by commas
|
||||
* @param string|array $address Multiple adresses either as array or string separated by commas
|
||||
* @return bool|string the prepared header (can contain multiple lines)
|
||||
*/
|
||||
public function cleanAddress($address) {
|
||||
// No named recipients for To: in Windows (see FS#652)
|
||||
$names = (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') ? false : true;
|
||||
|
||||
$address = preg_replace('/[\r\n\0]+/', ' ', $address); // remove attack vectors
|
||||
$usenames = (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') ? false : true;
|
||||
|
||||
$headers = '';
|
||||
$parts = explode(',', $address);
|
||||
|
||||
if(is_array($address)){
|
||||
$parts = $address;
|
||||
}else{
|
||||
$parts = explode(',', $address);
|
||||
}
|
||||
|
||||
foreach($parts as $part) {
|
||||
$part = preg_replace('/[\r\n\0]+/', ' ', $part); // remove attack vectors
|
||||
$part = trim($part);
|
||||
|
||||
// parse address
|
||||
|
@ -346,6 +348,7 @@ class Mailer {
|
|||
$text = trim($matches[1]);
|
||||
$addr = $matches[2];
|
||||
} else {
|
||||
$text = '';
|
||||
$addr = $part;
|
||||
}
|
||||
// skip empty ones
|
||||
|
@ -369,7 +372,7 @@ class Mailer {
|
|||
}
|
||||
|
||||
// text was given
|
||||
if(!empty($text) && $names) {
|
||||
if(!empty($text) && $usenames) {
|
||||
// add address quotes
|
||||
$addr = "<$addr>";
|
||||
|
||||
|
@ -378,18 +381,22 @@ class Mailer {
|
|||
$text = utf8_strip($text);
|
||||
}
|
||||
|
||||
// make sure the name contains no own quotes
|
||||
$text = str_replace('"', "'", $text);
|
||||
|
||||
// surround the name with quotes
|
||||
$text = "\"$text\"";
|
||||
|
||||
if(!utf8_isASCII($text)) {
|
||||
$text = '=?UTF-8?B?'.base64_encode($text).'?=';
|
||||
}
|
||||
} else {
|
||||
$text = '';
|
||||
}
|
||||
|
||||
// add to header comma seperated
|
||||
if($headers != '') {
|
||||
$headers .= ', ';
|
||||
}
|
||||
$headers .= $text.' '.$addr;
|
||||
$headers .= trim($text.' '.$addr);
|
||||
}
|
||||
|
||||
if(empty($headers)) return false;
|
||||
|
|
|
@ -350,13 +350,13 @@ class Subscription {
|
|||
if($style === 'digest') {
|
||||
foreach($change_ids as $change_id) {
|
||||
$this->send_digest(
|
||||
$USERINFO['mail'], $change_id,
|
||||
array($USERINFO['mail']), $change_id,
|
||||
$lastupdate
|
||||
);
|
||||
$count++;
|
||||
}
|
||||
} elseif($style === 'list') {
|
||||
$this->send_list($USERINFO['mail'], $change_ids, $target);
|
||||
$this->send_list(array($USERINFO['mail']), $change_ids, $target);
|
||||
$count++;
|
||||
}
|
||||
// TODO: Handle duplicate subscriptions.
|
||||
|
|
Loading…
Reference in New Issue