Skip to content

Commit

Permalink
Make address clearing functions also remove entries from all_recipien…
Browse files Browse the repository at this point in the history
…ts 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
  • Loading branch information
Synchro committed Nov 21, 2008
1 parent 51d6010 commit 263bf12
Show file tree
Hide file tree
Showing 7 changed files with 63 additions and 28 deletions.
21 changes: 17 additions & 4 deletions class.phpmailer.php
Original file line number Diff line number Diff line change
Expand Up @@ -1260,20 +1260,20 @@ public function AttachAll() {
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;
}
Expand Down Expand Up @@ -1622,6 +1622,9 @@ public function InlineImageExists() {
* @return void
*/
public function ClearAddresses() {
foreach($this->to as $to) {
unset($this->all_recipients[strtolower($to[0])]);
}
$this->to = array();
}

Expand All @@ -1630,6 +1633,9 @@ public function ClearAddresses() {
* @return void
*/
public function ClearCCs() {
foreach($this->cc as $cc) {
unset($this->all_recipients[strtolower($cc[0])]);
}
$this->cc = array();
}

Expand All @@ -1638,6 +1644,9 @@ public function ClearCCs() {
* @return void
*/
public function ClearBCCs() {
foreach($this->bcc as $bcc) {
unset($this->all_recipients[strtolower($bcc[0])]);
}
$this->bcc = array();
}

Expand All @@ -1658,6 +1667,7 @@ public function ClearAllRecipients() {
$this->to = array();
$this->cc = array();
$this->bcc = array();
$this->all_recipients = array();
}

/**
Expand Down Expand Up @@ -1690,8 +1700,11 @@ public function ClearCustomHeaders() {
*/
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;
}
Expand Down
9 changes: 9 additions & 0 deletions class.smtp.php
Original file line number Diff line number Diff line change
Expand Up @@ -1085,6 +1085,15 @@ public function Verify($name) {
return $rply;
}

/**
* Get the current error
* @access public
* @return array
*/
public function getError() {
return $this->error;
}

/*******************************************************************
* INTERNAL FUNCTIONS *
******************************************************************/
Expand Down
Binary file modified language/phpmailer.lang-ja.php
Binary file not shown.
33 changes: 16 additions & 17 deletions language/phpmailer.lang-pl.php
Original file line number Diff line number Diff line change
@@ -1,24 +1,23 @@
<?php
/**
* PHPMailer language file.
* Polish Version, encoding: windows-1250
* translated from english lang file ver. 1.72
* PHPMailer language file.
* 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: ';
?>
3 changes: 1 addition & 2 deletions language/phpmailer.lang-zh.php
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
<?php
<?php
/**
* PHPMailer language file.
* Traditional Chinese Version
* @author liqwei <[email protected]>
*/

$PHPMAILER_LANG = array();

$PHPMAILER_LANG['provide_address'] = '必須提供至少一個收件人地址。';
$PHPMAILER_LANG['mailer_not_supported'] = '發信客戶端不被支持。';
$PHPMAILER_LANG['execute'] = '無法執行:';
Expand Down
21 changes: 18 additions & 3 deletions test/phpmailer_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -515,8 +515,8 @@ function test_Error() {
$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");
}
Expand All @@ -530,6 +530,16 @@ function test_Addressing() {
$this->assert($this->Mail->AddBCC('[email protected]'), 'BCC addressing failed');
$this->assert(!$this->Mail->AddBCC('[email protected]'), 'BCC duplicate addressing failed');
$this->assert(!$this->Mail->AddBCC('[email protected]'), 'BCC duplicate Addressing failed (2)');
$this->Mail->ClearAddresses();
$this->assert($this->Mail->AddAddress('[email protected]'), 'Addressing after clear failed');
$this->Mail->ClearCCs();
$this->assert($this->Mail->AddAddress('[email protected]'), 'CC addressing after clear failed');
$this->Mail->ClearBCCs();
$this->assert($this->Mail->AddAddress('[email protected]'), 'BCC addressing after clear failed');
$this->Mail->AddAddress('[email protected]');
$this->Mail->AddCC('[email protected]');
$this->Mail->AddBCC('[email protected]');
$this->Mail->ClearAllRecipients(); //Not much of a test, but helps coverage
}

// Check that we are not missing any translations in any langauges
Expand Down Expand Up @@ -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.
Expand Down
4 changes: 2 additions & 2 deletions test/phpunit.php
Original file line number Diff line number Diff line change
Expand Up @@ -352,14 +352,14 @@ function report() {
}

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();
}
Expand Down

0 comments on commit 263bf12

Please sign in to comment.