Make address clearing functions also remove entries from all_recipients array

Add doctype and charset to test output
Fix error test
Make test resuts a bit prettier
Improve addressing tests
Fix Russian and Polish corrupted language files, make sure all use UTF-8
Remove BOM from chinese language file
Make sure file descriptior is closed in EncodeFile
Fix private access problems to SMTP error message by adding getError function (caused by recent addition of SMTP error reporting)
All unit tests now pass
This commit is contained in:
Marcus Bointon 2008-11-21 14:21:06 +00:00
parent 51d601058c
commit 263bf12e2e
7 changed files with 63 additions and 28 deletions

View File

@ -1260,20 +1260,20 @@ class PHPMailer {
public function EncodeFile ($path, $encoding = 'base64') {
if(!@$fd = fopen($path, 'rb')) {
$this->SetError($this->Lang('file_open') . $path);
fclose($fd);
return '';
}
if (function_exists('get_magic_quotes')) {
function get_magic_quotes() {
return false;
}
}
}
if (PHP_VERSION < 6) {
$magic_quotes = get_magic_quotes_runtime();
set_magic_quotes_runtime(0);
}
$file_buffer = file_get_contents($path);
$file_buffer = $this->EncodeString($file_buffer, $encoding);
fclose($fd);
if (PHP_VERSION < 6) { set_magic_quotes_runtime($magic_quotes); }
return $file_buffer;
}
@ -1622,6 +1622,9 @@ class PHPMailer {
* @return void
*/
public function ClearAddresses() {
foreach($this->to as $to) {
unset($this->all_recipients[strtolower($to[0])]);
}
$this->to = array();
}
@ -1630,6 +1633,9 @@ class PHPMailer {
* @return void
*/
public function ClearCCs() {
foreach($this->cc as $cc) {
unset($this->all_recipients[strtolower($cc[0])]);
}
$this->cc = array();
}
@ -1638,6 +1644,9 @@ class PHPMailer {
* @return void
*/
public function ClearBCCs() {
foreach($this->bcc as $bcc) {
unset($this->all_recipients[strtolower($bcc[0])]);
}
$this->bcc = array();
}
@ -1658,6 +1667,7 @@ class PHPMailer {
$this->to = array();
$this->cc = array();
$this->bcc = array();
$this->all_recipients = array();
}
/**
@ -1690,8 +1700,11 @@ class PHPMailer {
*/
private function SetError($msg) {
$this->error_count++;
if ($this->Mailer == 'smtp' and !empty($this->smtp->error['smtp_msg'])) {
$msg .= '<p>' . $this->Lang('smtp_error') . $this->smtp->error['smtp_msg'] . "</p>\n";
if ($this->Mailer == 'smtp' and !is_null($this->smtp)) {
$lasterror = $this->smtp->getError();
if (!empty($lasterror) and array_key_exists('smtp_msg', $lasterror)) {
$msg .= '<p>' . $this->Lang('smtp_error') . $lasterror['smtp_msg'] . "</p>\n";
}
}
$this->ErrorInfo = $msg;
}

View File

@ -1085,6 +1085,15 @@ class SMTP {
return $rply;
}
/**
* Get the current error
* @access public
* @return array
*/
public function getError() {
return $this->error;
}
/*******************************************************************
* INTERNAL FUNCTIONS *
******************************************************************/

Binary file not shown.

View File

@ -1,24 +1,23 @@
<?php
/**
* PHPMailer language file.
* Polish Version, encoding: windows-1250
* translated from english lang file ver. 1.72
* Polish Version
*/
$PHPMAILER_LANG = array();
$PHPMAILER_LANG["provide_address"] = 'Nale¿y podaæ prawid³owy adres email Odbiorcy.';
$PHPMAILER_LANG["mailer_not_supported"] = 'Wybrana metoda wysy³ki wiadomoœci nie jest obs³ugiwana.';
$PHPMAILER_LANG["execute"] = 'Nie mo¿na uruchomiæ: ';
$PHPMAILER_LANG["instantiate"] = 'Nie mo¿na wywo³aæ funkcji mail(). SprawdŸ konfiguracjê serwera.';
$PHPMAILER_LANG["authenticate"] = 'B³¹d SMTP: Nie mo¿na przeprowadziæ autentykacji.';
$PHPMAILER_LANG["from_failed"] = 'Nastêpuj¹cy adres Nadawcy jest jest nieprawid³owy: ';
$PHPMAILER_LANG["recipients_failed"] = 'B³¹d SMTP: Nastêpuj¹cy odbiorcy s¹ nieprawid³owi: ';
$PHPMAILER_LANG["data_not_accepted"] = 'B³¹d SMTP: Dane nie zosta³y przyjête.';
$PHPMAILER_LANG["connect_host"] = 'B³¹d SMTP: Nie mo¿na po³¹czyæ siê z wybranym hostem.';
$PHPMAILER_LANG["file_access"] = 'Brak dostêpu do pliku: ';
$PHPMAILER_LANG["file_open"] = 'Nie mo¿na otworzyæ pliku: ';
$PHPMAILER_LANG["encoding"] = 'Nieznany sposób kodowania znaków: ';
$PHPMAILER_LANG["signing"] = 'Signing Error: ';
$PHPMAILER_LANG['smtp_error'] = 'SMTP server error: ';
$PHPMAILER_LANG["provide_address"] = 'Należy podać prawidłowy adres email Odbiorcy.';
$PHPMAILER_LANG["mailer_not_supported"] = 'Wybrana metoda wysyłki wiadomości nie jest obsługiwana.';
$PHPMAILER_LANG["execute"] = 'Nie można uruchomić: ';
$PHPMAILER_LANG["instantiate"] = 'Nie można wywołać funkcji mail(). Sprawdź konfigurację serwera.';
$PHPMAILER_LANG["authenticate"] = 'Błąd SMTP: Nie można przeprowadzić autentykacji.';
$PHPMAILER_LANG["from_failed"] = 'Następujący adres Nadawcy jest jest nieprawidłowy: ';
$PHPMAILER_LANG["recipients_failed"] = 'Błąd SMTP: Następujący odbiorcy są nieprawidłowi: ';
$PHPMAILER_LANG["data_not_accepted"] = 'Błąd SMTP: Dane nie zostały przyjęte.';
$PHPMAILER_LANG["connect_host"] = 'Błąd SMTP: Nie można połączyć się z wybranym hostem.';
$PHPMAILER_LANG["file_access"] = 'Brak dostępu do pliku: ';
$PHPMAILER_LANG["file_open"] = 'Nie można otworzyć pliku: ';
$PHPMAILER_LANG["encoding"] = 'Nieznany sposób kodowania znaków: ';
$PHPMAILER_LANG['signing'] = 'Signing Error: ';
$PHPMAILER_LANG['smtp_error'] = 'SMTP server error: ';
?>

View File

@ -1,4 +1,4 @@
<?php
<?php
/**
* PHPMailer language file.
* Traditional Chinese Version
@ -6,7 +6,6 @@
*/
$PHPMAILER_LANG = array();
$PHPMAILER_LANG['provide_address'] = '必須提供至少一個收件人地址。';
$PHPMAILER_LANG['mailer_not_supported'] = '發信客戶端不被支持。';
$PHPMAILER_LANG['execute'] = '無法執行:';

View File

@ -515,8 +515,8 @@ class phpmailerTest extends TestCase
$this->assert($this->Mail->IsError() == false, "Error found");
$this->assert($this->Mail->Send() == false, "Send succeeded");
$this->assert($this->Mail->IsError(), "No error found");
$this->assertEquals('You must provide at least one ' .
'recipient email address.', $this->Mail->ErrorInfo);
//Note that this is language dependent
$this->assertEquals('You must provide at least one recipient email address.', $this->Mail->ErrorInfo);
$this->Mail->AddAddress(get("mail_to"));
$this->assert($this->Mail->Send(), "Send failed");
}
@ -530,6 +530,16 @@ class phpmailerTest extends TestCase
$this->assert($this->Mail->AddBCC('c@example.com'), 'BCC addressing failed');
$this->assert(!$this->Mail->AddBCC('c@example.com'), 'BCC duplicate addressing failed');
$this->assert(!$this->Mail->AddBCC('a@example.com'), 'BCC duplicate Addressing failed (2)');
$this->Mail->ClearAddresses();
$this->assert($this->Mail->AddAddress('a@example.com'), 'Addressing after clear failed');
$this->Mail->ClearCCs();
$this->assert($this->Mail->AddAddress('b@example.com'), 'CC addressing after clear failed');
$this->Mail->ClearBCCs();
$this->assert($this->Mail->AddAddress('c@example.com'), 'BCC addressing after clear failed');
$this->Mail->AddAddress('a@example.com');
$this->Mail->AddCC('b@example.com');
$this->Mail->AddBCC('c@example.com');
$this->Mail->ClearAllRecipients(); //Not much of a test, but helps coverage
}
// Check that we are not missing any translations in any langauges
@ -600,8 +610,13 @@ function get($sName) {
}
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8">
<title>PHPMailer Unit Tests</title>
</head>
<body>
<h3>phpmailer Unit Test</h3>
By entering a SMTP hostname it will automatically perform tests with SMTP.

View File

@ -352,14 +352,14 @@ class TextTestResult extends TestResult {
}
function _startTest($test) {
printf("%s ", $test->name());
printf("%s: ", $test->name());
flush();
}
function _endTest($test) {
$outcome = $test->failed()
? "<font color=\"red\">FAIL</font>"
: "<font color=\"green\">ok</font>";
: "<font color=\"green\">Pass</font>";
printf("$outcome<br>\n");
flush();
}