Upgraded to phpmailer 1.60

This commit is contained in:
martin 2002-05-18 06:54:12 +00:00
parent d2e378fb0b
commit 0b821adfdc
9 changed files with 3063 additions and 1594 deletions

View File

@ -1,5 +1,21 @@
ChangeLog
Version 1.60 (Sat, Mar 30 2002)
* Sendmail pipe and address patch (Christian Holtje)
* Added embedded image and read confirmation support (A. Ognio)
* Added unit tests
* Added SMTP timeout support (*nix only)
* Added possibly temporary PluginDir variable for SMTP class
* Added LE message line ending variable
* Refactored boundary and attachment code
* Eliminated SMTP class warnings
* Added SendToQueue method for future queuing support
Version 1.54 (Wed, Dec 19 2001)
* Add some queuing support code
* Fixed a pesky multi/alt bug
* Messages are no longer forced to have "To" addresses
Version 1.50 (Thu, Nov 08 2001)
* Fix extra lines when not using SMTP mailer
* Set WordWrap variable to int with a zero default

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -101,9 +101,9 @@
# sometimes the SMTP server takes a little longer to respond
# so we will give it a longer timeout for the first read
// Commented b/c of win32 warning messages
//if(function_exists("socket_set_timeout"))
// socket_set_timeout($this->smtp_conn, 1, 0);
// Windows still does not have support for this timeout function
if(substr(PHP_OS, 0, 3) != "WIN")
socket_set_timeout($this->smtp_conn, 1, 0);
# get any announcement stuff
$announce = $this->get_lines();
@ -329,8 +329,11 @@
# now send the lines to the server
while(list(,$line_out) = @each($lines_out)) {
if($line_out[0] == ".") {
$line_out = "." . $line_out;
if(strlen($line_out) > 0)
{
if(substr($line_out, 0, 1) == ".") {
$line_out = "." . $line_out;
}
}
fputs($this->smtp_conn,$line_out . $this->CRLF);
}

View File

@ -2,7 +2,7 @@
<!--NewPage-->
<HTML>
<HEAD>
<!-- Generated by javadoc on Sun Aug 12 18:19:10 EDT 2001 -->
<!-- Generated by javadoc on Sat Mar 30 14:15:49 EST 2002 -->
<TITLE>
: Index
</TITLE>
@ -42,49 +42,76 @@
</TABLE>
<!-- =========== END OF NAVBAR =========== -->
<A HREF="#_$_">$</A> <A HREF="#_A_">A</A> <A HREF="#_C_">C</A> <A HREF="#_I_">I</A> <A HREF="#_P_">P</A> <A HREF="#_S_">S</A> <HR>
<A HREF="#_$_">$</A> <A HREF="#_A_">A</A> <A HREF="#_B_">B</A> <A HREF="#_C_">C</A> <A HREF="#_G_">G</A> <A HREF="#_I_">I</A> <A HREF="#_P_">P</A> <A HREF="#_S_">S</A> <HR>
<A NAME="_$_"><!-- --></A><H2>
<B>$</B></H2>
<DL>
<DT><A HREF="phpmailer.html#$AltBody"><B>$AltBody</B></A> -
Variable in class <A HREF="phpmailer.html">phpmailer</A>
<DD>Sets a multipart/alternative message.
<DD>Sets the text-only body of the message.
<DT><A HREF="phpmailer.html#$Body"><B>$Body</B></A> -
Variable in class <A HREF="phpmailer.html">phpmailer</A>
<DD>Sets the Body of the message.
<DT><A HREF="phpmailer.html#$CharSet"><B>$CharSet</B></A> -
Variable in class <A HREF="phpmailer.html">phpmailer</A>
<DD>Sets the CharSet of the message.
<DT><A HREF="Boundary.html#$CharSet"><B>$CharSet</B></A> -
Variable in class <A HREF="Boundary.html">Boundary</A>
<DD>Sets the Char set.
<DT><A HREF="phpmailer.html#$ConfirmReadingTo"><B>$ConfirmReadingTo</B></A> -
Variable in class <A HREF="phpmailer.html">phpmailer</A>
<DD>Sets the email address that a reading confirmation will be sent.
<DT><A HREF="phpmailer.html#$ContentType"><B>$ContentType</B></A> -
Variable in class <A HREF="phpmailer.html">phpmailer</A>
<DD>Sets the Content-type of the message.
<DT><A HREF="Boundary.html#$ContentType"><B>$ContentType</B></A> -
Variable in class <A HREF="Boundary.html">Boundary</A>
<DD>Sets the boundary Content Type.
<DT><A HREF="Boundary.html#$Disposition"><B>$Disposition</B></A> -
Variable in class <A HREF="Boundary.html">Boundary</A>
<DD>Sets an attachment disposition.
<DT><A HREF="phpmailer.html#$Encoding"><B>$Encoding</B></A> -
Variable in class <A HREF="phpmailer.html">phpmailer</A>
<DD>Sets the Encoding of the message.
<DT><A HREF="Boundary.html#$Encoding"><B>$Encoding</B></A> -
Variable in class <A HREF="Boundary.html">Boundary</A>
<DD>Sets the Encoding.
<DT><A HREF="phpmailer.html#$ErrorInfo"><B>$ErrorInfo</B></A> -
Variable in class <A HREF="phpmailer.html">phpmailer</A>
<DD>Holds the most recent mailer error message.
<DT><A HREF="Boundary.html#$FileName"><B>$FileName</B></A> -
Variable in class <A HREF="Boundary.html">Boundary</A>
<DD>Sets an attachment file name.
<DT><A HREF="phpmailer.html#$From"><B>$From</B></A> -
Variable in class <A HREF="phpmailer.html">phpmailer</A>
<DD>Sets the From email of the message.
<DD>Sets the From email address for the message.
<DT><A HREF="phpmailer.html#$FromName"><B>$FromName</B></A> -
Variable in class <A HREF="phpmailer.html">phpmailer</A>
<DD>Sets the From name of the message.
<DT><A HREF="phpmailer.html#$Helo"><B>$Helo</B></A> -
Variable in class <A HREF="phpmailer.html">phpmailer</A>
<DD>Sets the CharSet of the message.
<DD>Sets the SMTP HELO of the message.
<DT><A HREF="phpmailer.html#$Host"><B>$Host</B></A> -
Variable in class <A HREF="phpmailer.html">phpmailer</A>
<DD>Sets the SMTP host.
<DD>Sets the SMTP hosts.
<DT><A HREF="phpmailer.html#$LE"><B>$LE</B></A> -
Variable in class <A HREF="phpmailer.html">phpmailer</A>
<DD>Sets the line endings of the message.
<DT><A HREF="Boundary.html#$LE"><B>$LE</B></A> -
Variable in class <A HREF="Boundary.html">Boundary</A>
<DD>Sets the line endings of the message.
<DT><A HREF="phpmailer.html#$Mailer"><B>$Mailer</B></A> -
Variable in class <A HREF="phpmailer.html">phpmailer</A>
<DD>Method to send mail: ("mail", "sendmail", or "smtp").
<DT><A HREF="phpmailer.html#$Password"><B>$Password</B></A> -
Variable in class <A HREF="phpmailer.html">phpmailer</A>
<DD>Sets SMTP password.
<DT><A HREF="phpmailer.html#$PluginDir"><B>$PluginDir</B></A> -
Variable in class <A HREF="phpmailer.html">phpmailer</A>
<DD>Path to phpmailer plugins.
<DT><A HREF="phpmailer.html#$Port"><B>$Port</B></A> -
Variable in class <A HREF="phpmailer.html">phpmailer</A>
<DD>Sets the SMTP server port.
<DD>Sets the default SMTP server port.
<DT><A HREF="phpmailer.html#$Priority"><B>$Priority</B></A> -
Variable in class <A HREF="phpmailer.html">phpmailer</A>
<DD>Email priority (1 = High, 3 = Normal, 5 = low).
@ -97,15 +124,9 @@ Variable in class <A HREF="phpmailer.html">phpmailer</A>
<DT><A HREF="phpmailer.html#$SMTPAuth"><B>$SMTPAuth</B></A> -
Variable in class <A HREF="phpmailer.html">phpmailer</A>
<DD>Sets SMTP authentication.
<DT><A HREF="phpmailer.html#$SMTPDebug"><B>$SMTPDebug</B></A> -
Variable in class <A HREF="phpmailer.html">phpmailer</A>
<DD>Sets SMTP class debugging on or off.
<DT><A HREF="phpmailer.html#$Subject"><B>$Subject</B></A> -
Variable in class <A HREF="phpmailer.html">phpmailer</A>
<DD>Sets the Subject of the message.
<DT><A HREF="phpmailer.html#$Timeout"><B>$Timeout</B></A> -
Variable in class <A HREF="phpmailer.html">phpmailer</A>
<DD>Sets the SMTP server timeout.
<DT><A HREF="phpmailer.html#$UseMSMailHeaders"><B>$UseMSMailHeaders</B></A> -
Variable in class <A HREF="phpmailer.html">phpmailer</A>
<DD>Turns Microsoft mail client headers on and off.
@ -117,7 +138,8 @@ Variable in class <A HREF="phpmailer.html">phpmailer</A>
<DD>Holds phpmailer version.
<DT><A HREF="phpmailer.html#$WordWrap"><B>$WordWrap</B></A> -
Variable in class <A HREF="phpmailer.html">phpmailer</A>
<DD>Sets word wrapping on the message.
<DD>Sets word wrapping on the body of the message to a given number of
characters.
</DL>
<HR>
<A NAME="_A_"><!-- --></A><H2>
@ -125,11 +147,10 @@ Variable in class <A HREF="phpmailer.html">phpmailer</A>
<DL>
<DT><A HREF="phpmailer.html#AddAddress(var, var)"><B>AddAddress(var, var)</B></A> -
Method in class <A HREF="phpmailer.html">phpmailer</A>
<DD>Adds a "to" address.
<DD>Adds a "To" address.
<DT><A HREF="phpmailer.html#AddAttachment(var, var, var, var)"><B>AddAttachment(var, var, var, var)</B></A> -
Method in class <A HREF="phpmailer.html">phpmailer</A>
<DD>Checks if attachment is valid and then adds
the attachment to the list.
<DD>Adds an attachment from a path on the filesystem.
<DT><A HREF="phpmailer.html#AddBCC(var, var)"><B>AddBCC(var, var)</B></A> -
Method in class <A HREF="phpmailer.html">phpmailer</A>
<DD>Adds a "Bcc" address.
@ -139,12 +160,23 @@ Method in class <A HREF="phpmailer.html">phpmailer</A>
<DT><A HREF="phpmailer.html#AddCustomHeader(var)"><B>AddCustomHeader(var)</B></A> -
Method in class <A HREF="phpmailer.html">phpmailer</A>
<DD>Adds a custom header.
<DT><A HREF="phpmailer.html#AddEmbeddedImage(var, var, var, var, var)"><B>AddEmbeddedImage(var, var, var, var, var)</B></A> -
Method in class <A HREF="phpmailer.html">phpmailer</A>
<DD>Adds an embedded attachment.
<DT><A HREF="phpmailer.html#AddReplyTo(var, var)"><B>AddReplyTo(var, var)</B></A> -
Method in class <A HREF="phpmailer.html">phpmailer</A>
<DD>Adds a "Reply-to" address.
<DT><A HREF="phpmailer.html#AddStringAttachment(var, var, var, var)"><B>AddStringAttachment(var, var, var, var)</B></A> -
Method in class <A HREF="phpmailer.html">phpmailer</A>
<DD>Adds the string attachment to the list.
<DD>Adds a string or binary attachment (non-filesystem) to the list.
</DL>
<HR>
<A NAME="_B_"><!-- --></A><H2>
<B>B</B></H2>
<DL>
<DT><A HREF="Boundary.html"><B>Boundary</B></A> - class <A HREF="Boundary.html">Boundary</A>.<DD>Boundary - MIME message boundary class<DT><A HREF="Boundary.html#Boundary(var)"><B>Boundary(var)</B></A> -
Constructor for class <A HREF="Boundary.html">Boundary</A>
<DD>Main constructor.
</DL>
<HR>
<A NAME="_C_"><!-- --></A><H2>
@ -159,7 +191,8 @@ Method in class <A HREF="phpmailer.html">phpmailer</A>
array.
<DT><A HREF="phpmailer.html#ClearAttachments()"><B>ClearAttachments()</B></A> -
Method in class <A HREF="phpmailer.html">phpmailer</A>
<DD>Clears all previously set attachments.
<DD>Clears all previously set filesystem, string, and binary
attachments.
<DT><A HREF="phpmailer.html#ClearBCCs()"><B>ClearBCCs()</B></A> -
Method in class <A HREF="phpmailer.html">phpmailer</A>
<DD>Clears all recipients assigned in the BCC array.
@ -174,6 +207,14 @@ Method in class <A HREF="phpmailer.html">phpmailer</A>
<DD>Clears all recipients assigned in the ReplyTo array.
</DL>
<HR>
<A NAME="_G_"><!-- --></A><H2>
<B>G</B></H2>
<DL>
<DT><A HREF="Boundary.html#GetSource(var)"><B>GetSource(var)</B></A> -
Method in class <A HREF="Boundary.html">Boundary</A>
<DD>Returns the source of the boundary.
</DL>
<HR>
<A NAME="_I_"><!-- --></A><H2>
<B>I</B></H2>
<DL>
@ -182,16 +223,16 @@ Method in class <A HREF="phpmailer.html">phpmailer</A>
<DD>Sets message type to HTML.
<DT><A HREF="phpmailer.html#IsMail()"><B>IsMail()</B></A> -
Method in class <A HREF="phpmailer.html">phpmailer</A>
<DD>Sets Mailer to use PHP mail() function.
<DD>Sets Mailer to send message using PHP mail() function.
<DT><A HREF="phpmailer.html#IsQmail()"><B>IsQmail()</B></A> -
Method in class <A HREF="phpmailer.html">phpmailer</A>
<DD>Sets Mailer to use qmail MTA.
<DD>Sets Mailer to send message using the qmail MTA.
<DT><A HREF="phpmailer.html#IsSendmail()"><B>IsSendmail()</B></A> -
Method in class <A HREF="phpmailer.html">phpmailer</A>
<DD>Sets Mailer to use $Sendmail program.
<DD>Sets Mailer to send message using the $Sendmail program.
<DT><A HREF="phpmailer.html#IsSMTP()"><B>IsSMTP()</B></A> -
Method in class <A HREF="phpmailer.html">phpmailer</A>
<DD>Sets Mailer to use SMTP.
<DD>Sets Mailer to send message using SMTP.
</DL>
<HR>
<A NAME="_P_"><!-- --></A><H2>
@ -208,9 +249,12 @@ Constructor for class <A HREF="phpmailer.html">phpmailer</A>
<DT><A HREF="phpmailer.html#Send()"><B>Send()</B></A> -
Method in class <A HREF="phpmailer.html">phpmailer</A>
<DD>Creates message and assigns Mailer.
<DT><A HREF="phpmailer.html#SendToQueue(var, var)"><B>SendToQueue(var, var)</B></A> -
Method in class <A HREF="phpmailer.html">phpmailer</A>
<DD>Sends mail message to an assigned queue directory.
</DL>
<HR>
<A HREF="#_$_">$</A> <A HREF="#_A_">A</A> <A HREF="#_C_">C</A> <A HREF="#_I_">I</A> <A HREF="#_P_">P</A> <A HREF="#_S_">S</A>
<A HREF="#_$_">$</A> <A HREF="#_A_">A</A> <A HREF="#_B_">B</A> <A HREF="#_C_">C</A> <A HREF="#_G_">G</A> <A HREF="#_I_">I</A> <A HREF="#_P_">P</A> <A HREF="#_S_">S</A>
<!-- ========== START OF NAVBAR ========== -->
<A NAME="navbar_bottom"><!-- --></A>
<TABLE BORDER="0" WIDTH="100%" CELLPADDING="1" CELLSPACING="0">

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,546 @@
<?php
/*******************
Unit Test
Type: phpmailer class
********************/
$INCLUDE_DIR = "";
require("phpunit.php");
require($INCLUDE_DIR . "class.phpmailer.php");
error_reporting(E_ALL);
/**
* Performs authentication tests
*/
class phpmailerTest extends TestCase
{
/**
* Holds the default phpmailer instance.
* @private
* @type object
*/
var $Mail = false;
/**
* Holds the SMTP mail host.
* @public
* @type string
*/
var $Host = "";
/**
* Holds the change log.
* @private
* @type string array
*/
var $ChangeLog = array();
/**
* Holds the note log.
* @private
* @type string array
*/
var $NoteLog = array();
/**
* Class constuctor.
*/
function phpmailerTest($name) {
/* must define this constructor */
$this->TestCase( $name );
}
/**
* Run before each test is started.
*/
function setUp() {
global $global_vars;
global $INCLUDE_DIR;
$this->Mail = new phpmailer();
$this->Mail->Priority = 3;
$this->Mail->Encoding = "8bit";
$this->Mail->CharSet = "iso-8859-1";
$this->Mail->From = "unit_test@phpmailer.sf.net";
$this->Mail->FromName = "Unit Tester";
$this->Mail->Sender = "";
$this->Mail->Subject = "Unit Test";
$this->Mail->Body = "";
$this->Mail->AltBody = "";
$this->Mail->WordWrap = 0;
$this->Mail->Host = $global_vars["mail_host"];
$this->Mail->Port = 25;
$this->Mail->Helo = "localhost.localdomain";
$this->Mail->SMTPAuth = false;
$this->Mail->Username = "";
$this->Mail->Password = "";
$this->Mail->PluginDir = $INCLUDE_DIR;
$this->Mail->AddReplyTo("no_reply@phpmailer.sf.net", "Reply Guy");
if(strlen($this->Mail->Host) > 0)
$this->Mail->Mailer = "smtp";
else
{
$this->Mail->Mailer = "mail";
$this->Sender = "unit_test@phpmailer.sf.net";
}
global $global_vars;
$this->SetAddress($global_vars["mail_to"]);
// This is where you might place additional To, Bcc, etc addresses
}
/**
* Run after each test is completed.
*/
function tearDown() {
// Clean global variables
$this->Mail = false;
$this->ChangeLog = array();
$this->NoteLog = array();
}
/**
* Build the body of the message in the appropriate format.
* @private
* @returns void
*/
function BuildBody() {
$this->CheckChanges();
// Determine line endings for message
if($this->Mail->ContentType == "text/html" || strlen($this->Mail->AltBody) > 0)
{
$eol = "<br/>";
$bullet = "<li>";
$bullet_start = "<ul>";
$bullet_end = "</ul>";
}
else
{
$eol = "\n";
$bullet = " - ";
$bullet_start = "";
$bullet_end = "";
}
$ReportBody = "";
$ReportBody .= "---------------------" . $eol;
$ReportBody .= "Unit Test Information" . $eol;
$ReportBody .= "---------------------" . $eol;
$ReportBody .= "phpmailer version: " . $this->Mail->Version . $eol;
$ReportBody .= "Content Type: " . $this->Mail->ContentType . $eol;
if(strlen($this->Mail->Host) > 0)
$ReportBody .= "Host: " . $this->Mail->Host . $eol;
// If attachments then create an attachment list
if(count($this->Mail->attachment) > 0)
{
$ReportBody .= "Attachments";
$ReportBody .= $bullet_start;
for($i = 0; $i < count($this->Mail->attachment); $i++)
{
$ReportBody .= $bullet . "Name: " . $this->Mail->attachment[$i][1] . ", ";
$ReportBody .= "Encoding: " . $this->Mail->attachment[$i][3] . ", ";
$ReportBody .= "Type: " . $this->Mail->attachment[$i][4] . $eol;
}
$ReportBody .= $bullet_end . $eol;
}
// If there are changes then list them
if(count($this->ChangeLog) > 0)
{
$ReportBody .= "Changes" . $eol;
$ReportBody .= "-------" . $eol;
$ReportBody .= $bullet_start;
for($i = 0; $i < count($this->ChangeLog); $i++)
{
$ReportBody .= $bullet . $this->ChangeLog[$i][0] . " was changed to [" .
$this->ChangeLog[$i][1] . "]" . $eol;
}
$ReportBody .= $bullet_end . $eol . $eol;
}
// If there are notes then list them
if(count($this->NoteLog) > 0)
{
$ReportBody .= "Notes" . $eol;
$ReportBody .= "-----" . $eol;
$ReportBody .= $bullet_start;
for($i = 0; $i < count($this->NoteLog); $i++)
{
$ReportBody .= $bullet . $this->NoteLog[$i] . $eol;
}
$ReportBody .= $bullet_end;
}
// Re-attach the original body
$this->Mail->Body .= $eol . $eol . $ReportBody;
}
/**
* Check which default settings have been changed for the report.
* @private
* @returns void
*/
function CheckChanges() {
if($this->Mail->Priority != 3)
$this->AddChange("Priority", $this->Mail->Priority);
if($this->Mail->Encoding != "8bit")
$this->AddChange("Encoding", $this->Mail->Encoding);
if($this->Mail->CharSet != "iso-8859-1")
$this->AddChange("CharSet", $this->Mail->CharSet);
if($this->Mail->Sender != "")
$this->AddChange("Sender", $this->Mail->Sender);
if($this->Mail->WordWrap != 0)
$this->AddChange("WordWrap", $this->Mail->WordWrap);
if($this->Mail->Mailer != "mail")
$this->AddChange("Mailer", $this->Mail->Mailer);
if($this->Mail->Port != 25)
$this->AddChange("Port", $this->Mail->Port);
if($this->Mail->Helo != "localhost.localdomain")
$this->AddChange("Helo", $this->Mail->Helo);
if($this->Mail->SMTPAuth)
$this->AddChange("SMTPAuth", "true");
}
/**
* Adds a change entry.
* @private
* @returns void
*/
function AddChange($sName, $sNewValue) {
$cur = count($this->ChangeLog);
$this->ChangeLog[$cur][0] = $sName;
$this->ChangeLog[$cur][1] = $sNewValue;
}
/**
* Adds a simple note to the message.
* @public
* @returns void
*/
function AddNote($sValue) {
$this->NoteLog[] = $sValue;
}
/**
* Adds all of the addresses
* @public
* @returns void
*/
function SetAddress($sAddress, $sName = "", $sType = "to") {
switch($sType)
{
case "to":
$this->Mail->AddAddress($sAddress, $sName);
break;
case "cc":
$this->Mail->AddCC($sAddress, $sName);
break;
case "bcc":
$this->Mail->AddBCC($sAddress, $sName);
break;
}
}
/////////////////////////////////////////////////
// UNIT TESTS
/////////////////////////////////////////////////
/**
* Try a plain message.
*/
function test_WordWrap() {
$this->Mail->WordWrap = 40;
$my_body = "Here is the main body of this message. It should " .
"be quite a few lines. It should be wrapped at the " .
"40 characters. Make sure that it is.";
$nBodyLen = strlen($my_body);
$my_body .= "\n\nThis is the above body length: " . $nBodyLen;
$this->Mail->Body = $my_body;
$this->Mail->Subject .= ": Wordwrap";
$this->BuildBody();
if(!$this->Mail->Send())
{
$this->assert(false, $this->Mail->ErrorInfo);
return;
}
$this->assert(true);
}
/**
* Try a plain message.
*/
function test_Low_Priority() {
$this->Mail->Priority = 5;
$this->Mail->Body = "Here is the main body. There should be " .
"a reply to address in this message.";
$this->Mail->Subject .= ": Low Priority";
$this->Mail->AddReplyTo("nobody@nobody.com", "Nobody (Unit Test)");
$this->BuildBody();
if(!$this->Mail->Send())
{
$this->assert(false, $this->Mail->ErrorInfo);
return;
}
$this->assert(true);
}
/**
* Simple plain file attachment test.
*/
function test_Plain_FileAttachment() {
$this->Mail->Body = "Here is the text body";
$this->Mail->Subject .= ": Plain and FileAttachment";
if(!$this->Mail->AddAttachment("phpmailer_test.php", "test_attach.txt"))
{
$this->assert(false, $this->Mail->ErrorInfo);
return;
}
$this->BuildBody();
if(!$this->Mail->Send())
{
$this->assert(false, $this->Mail->ErrorInfo);
return;
}
$this->assert(true);
}
/**
* Simple plain string attachment test.
*/
function test_Plain_StringAttachment() {
$this->Mail->Body = "Here is the text body";
$this->Mail->Subject .= ": Plain and StringAttachment";
$sAttachment = "These characters are the content of the " .
"string attachment.\nThis might be taken from a ".
"database or some other such thing. ";
$this->Mail->AddStringAttachment($sAttachment, "string_attach.txt");
$this->BuildBody();
if(!$this->Mail->Send())
{
$this->assert(false, $this->Mail->ErrorInfo);
return;
}
$this->assert(true);
}
/**
* Plain quoted-printable message.
*/
function test_Quoted_Printable() {
$this->Mail->Body = "Here is the main body";
$this->Mail->Subject .= ": Plain and Quoted-printable";
$this->Mail->Encoding = "quoted-printable";
$this->BuildBody();
if(!$this->Mail->Send())
{
$this->assert(false, $this->Mail->ErrorInfo);
return;
}
$this->assert(true);
}
/**
* Try a plain message.
*/
function test_Html() {
$this->Mail->IsHTML(true);
$this->Mail->Subject .= ": HTML only";
$this->Mail->Body = "This is a <b>test message</b> written in HTML. </br>" .
"Go to <a href=\"http://phpmailer.sourceforge.net/\">" .
"http://phpmailer.sourceforge.net/</a> for new versions of " .
"phpmailer. <p/> Thank you!";
$this->BuildBody();
if(!$this->Mail->Send())
{
$this->assert(false, $this->Mail->ErrorInfo);
return;
}
$this->assert(true);
}
/**
* Simple HTML and attachment test
*/
function test_HTML_Attachment() {
$this->Mail->Body = "This is the <b>HTML</b> part of the email.";
$this->Mail->Subject .= ": HTML and Attachment";
$this->Mail->IsHTML(true);
if(!$this->Mail->AddAttachment("phpmailer_test.php", "test_attach.txt"))
{
$this->assert(false, $this->Mail->ErrorInfo);
return;
}
$this->BuildBody();
if(!$this->Mail->Send())
{
$this->assert(false, $this->Mail->ErrorInfo);
return;
}
$this->assert(true);
}
/**
* An embedded attachment test.
*/
function test_Embedded_Image() {
$this->Mail->Body = "Embedded Image: <img alt=\"phpmailer\" src=\"cid:my-attach\">" .
"Here is an image!</a>";
$this->Mail->Subject .= ": Embedded Image";
$this->Mail->IsHTML(true);
if(!$this->Mail->AddEmbeddedImage("rocks.png", "my-attach", "rocks.png"))
{
$this->assert(false, $this->Mail->ErrorInfo);
return;
}
if($this->Mail->EmbeddedImageCount() < 0)
{
$this->assert(false, "Embedded image count below 1");
return;
}
$this->BuildBody();
if(!$this->Mail->Send())
{
$this->assert(false, $this->Mail->ErrorInfo);
return;
}
$this->assert(true);
}
/**
* Simple multipart/alternative test.
*/
function test_AltBody() {
$this->Mail->Body = "This is the <b>HTML</b> part of the email.";
$this->Mail->AltBody = "This is the text part of the email.";
$this->AddNote("This is a mulipart alternative email");
$this->Mail->Subject .= ": AltBody";
$this->BuildBody();
if(!$this->Mail->Send())
{
$this->assert(false, $this->Mail->ErrorInfo);
return;
}
$this->assert(true);
}
/**
* Simple HTML and attachment test
*/
function test_AltBody_Attachment() {
$this->Mail->Body = "This is the <b>HTML</b> part of the email.";
$this->Mail->AltBody = "This is the text part of the email.";
$this->Mail->Subject .= ": AltBody and Attachment";
$this->Mail->IsHTML(true);
if(!$this->Mail->AddAttachment("phpmailer_test.php", "test_attach.txt"))
{
$this->assert(false, $this->Mail->ErrorInfo);
return;
}
$this->BuildBody();
if(!$this->Mail->Send())
{
$this->assert(false, $this->Mail->ErrorInfo);
return;
}
$this->assert(true);
}
}
/**
* Create and run test instance.
*/
if(isset($HTTP_GET_VARS))
$global_vars = $HTTP_GET_VARS;
else
$global_vars = $_REQUEST;
if(isset($global_vars["submitted"]))
{
echo "Test results:<br>";
$suite = new TestSuite( "phpmailerTest" );
$testRunner = new TestRunner;
$testRunner->run($suite);
echo "<hr noshade/>";
}
function get($sName) {
global $global_vars;
if(isset($global_vars[$sName]))
return $global_vars[$sName];
else
return "";
}
?>
<html>
<body>
<h3>phpmailer Unit Test</h3>
By entering a SMTP hostname it will automatically perform tests with SMTP.
<form name="phpmailer_unit" action="phpmailer_test.php" method="get">
<input type="hidden" name="submitted" value="1"/>
To Address: <input type="text" size="50" name="mail_to" value="<?php echo get("mail_to"); ?>"/>
<br/>
Bcc Address: <input type="text" size="50" name="mail_bcc" value="<?php echo get("mail_bcc"); ?>"/>
<br/>
SMTP Hostname: <input type="text" size="50" name="mail_host" value="<?php echo get("mail_host"); ?>"/>
<p/>
<input type="submit" value="Run Test"/>
</form>
</body>
</html>

View File

@ -0,0 +1,376 @@
<?php
//
// PHP framework for testing, based on the design of "JUnit".
//
// Written by Fred Yankowski <fred@ontosys.com>
// OntoSys, Inc <http://www.OntoSys.com>
//
// $Id$
// Copyright (c) 2000 Fred Yankowski
// Permission is hereby granted, free of charge, to any person
// obtaining a copy of this software and associated documentation
// files (the "Software"), to deal in the Software without
// restriction, including without limitation the rights to use, copy,
// modify, merge, publish, distribute, sublicense, and/or sell copies
// of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
// BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
// ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
// CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.
//
error_reporting(E_ERROR | E_WARNING | E_PARSE | E_NOTICE |
E_CORE_ERROR | E_CORE_WARNING);
/*
interface Test {
function run(&$aTestResult);
function countTestCases();
}
*/
function trace($msg) {
return;
print($msg);
flush();
}
class Exception {
/* Emulate a Java exception, sort of... */
var $message;
function Exception($message) {
$this->message = $message;
}
function getMessage() {
return $this->message;
}
}
class Assert {
function assert($boolean, $message=0) {
if (! $boolean)
$this->fail($message);
}
function assertEquals($expected, $actual, $message=0) {
if ($expected != $actual) {
$this->failNotEquals($expected, $actual, "expected", $message);
}
}
function assertRegexp($regexp, $actual, $message=false) {
if (! preg_match($regexp, $actual)) {
$this->failNotEquals($regexp, $actual, "pattern", $message);
}
}
function failNotEquals($expected, $actual, $expected_label, $message=0) {
// Private function for reporting failure to match.
$str = $message ? ($message . ' ') : '';
$str .= "($expected_label/actual)<br>";
$htmlExpected = htmlspecialchars($expected);
$htmlActual = htmlspecialchars($actual);
$str .= sprintf("<pre>%s\n--------\n%s</pre>",
$htmlExpected, $htmlActual);
$this->fail($str);
}
}
class TestCase extends Assert /* implements Test */ {
/* Defines context for running tests. Specific context -- such as
instance variables, global variables, global state -- is defined
by creating a subclass that specializes the setUp() and
tearDown() methods. A specific test is defined by a subclass
that specializes the runTest() method. */
var $fName;
var $fResult;
var $fExceptions = array();
function TestCase($name) {
$this->fName = $name;
}
function run($testResult=0) {
/* Run this single test, by calling the run() method of the
TestResult object which will in turn call the runBare() method
of this object. That complication allows the TestResult object
to do various kinds of progress reporting as it invokes each
test. Create/obtain a TestResult object if none was passed in.
Note that if a TestResult object was passed in, it must be by
reference. */
if (! $testResult)
$testResult = $this->_createResult();
$this->fResult = $testResult;
$testResult->run(&$this);
$this->fResult = 0;
return $testResult;
}
function countTestCases() {
return 1;
}
function runTest() {
$name = $this->name();
// Since isset($this->$name) is false, no way to run defensive checks
$this->$name();
}
function setUp() /* expect override */ {
//print("TestCase::setUp()<br>\n");
}
function tearDown() /* possible override */ {
//print("TestCase::tearDown()<br>\n");
}
////////////////////////////////////////////////////////////////
function _createResult() /* protected */ {
/* override this to use specialized subclass of TestResult */
return new TestResult;
}
function fail($message=0) {
//printf("TestCase::fail(%s)<br>\n", ($message) ? $message : '');
/* JUnit throws AssertionFailedError here. We just record the
failure and carry on */
$this->fExceptions[] = new Exception(&$message);
}
function error($message) {
/* report error that requires correction in the test script
itself, or (heaven forbid) in this testing infrastructure */
printf('<b>ERROR: ' . $message . '</b><br>');
$this->fResult->stop();
}
function failed() {
return count($this->fExceptions);
}
function getExceptions() {
return $this->fExceptions;
}
function name() {
return $this->fName;
}
function runBare() {
$this->setup();
$this->runTest();
$this->tearDown();
}
}
class TestSuite /* implements Test */ {
/* Compose a set of Tests (instances of TestCase or TestSuite), and
run them all. */
var $fTests = array();
function TestSuite($classname=false) {
if ($classname) {
// Find all methods of the given class whose name starts with
// "test" and add them to the test suite. We are just _barely_
// able to do this with PHP's limited introspection... Note
// that PHP seems to store method names in lower case, and we
// have to avoid the constructor function for the TestCase class
// superclass. This will fail when $classname starts with
// "Test" since that will have a constructor method that will
// get matched below and then treated (incorrectly) as a test
// method. So don't name any TestCase subclasses as "Test..."!
if (floor(phpversion()) >= 4) {
// PHP4 introspection, submitted by Dylan Kuhn
$names = get_class_methods($classname);
while (list($key, $method) = each($names)) {
if (preg_match('/^test/', $method) && $method != "testcase") {
$this->addTest(new $classname($method));
}
}
}
else {
$dummy = new $classname("dummy");
$names = (array) $dummy;
while (list($key, $value) = each($names)) {
$type = gettype($value);
if ($type == "user function" && preg_match('/^test/', $key)
&& $key != "testcase") {
$this->addTest(new $classname($key));
}
}
}
}
}
function addTest($test) {
/* Add TestCase or TestSuite to this TestSuite */
$this->fTests[] = $test;
}
function run(&$testResult) {
/* Run all TestCases and TestSuites comprising this TestSuite,
accumulating results in the given TestResult object. */
reset($this->fTests);
while (list($na, $test) = each($this->fTests)) {
if ($testResult->shouldStop())
break;
$test->run(&$testResult);
}
}
function countTestCases() {
/* Number of TestCases comprising this TestSuite (including those
in any constituent TestSuites) */
$count = 0;
reset($fTests);
while (list($na, $test_case) = each($this->fTests)) {
$count += $test_case->countTestCases();
}
return $count;
}
}
class TestFailure {
/* Record failure of a single TestCase, associating it with the
exception(s) that occurred */
var $fFailedTestName;
var $fExceptions;
function TestFailure(&$test, &$exceptions) {
$this->fFailedTestName = $test->name();
$this->fExceptions = $exceptions;
}
function getExceptions() {
return $this->fExceptions;
}
function getTestName() {
return $this->fFailedTestName;
}
}
class TestResult {
/* Collect the results of running a set of TestCases. */
var $fFailures = array();
var $fRunTests = 0;
var $fStop = false;
function TestResult() { }
function _endTest($test) /* protected */ {
/* specialize this for end-of-test action, such as progress
reports */
}
function getFailures() {
return $this->fFailures;
}
function run($test) {
/* Run a single TestCase in the context of this TestResult */
$this->_startTest($test);
$this->fRunTests++;
$test->runBare();
/* this is where JUnit would catch AssertionFailedError */
$exceptions = $test->getExceptions();
if ($exceptions)
$this->fFailures[] = new TestFailure(&$test, &$exceptions);
$this->_endTest($test);
}
function countTests() {
return $this->fRunTests;
}
function shouldStop() {
return $this->fStop;
}
function _startTest($test) /* protected */ {
/* specialize this for start-of-test actions */
}
function stop() {
/* set indication that the test sequence should halt */
$fStop = true;
}
function countFailures() {
return count($this->fFailures);
}
}
class TextTestResult extends TestResult {
/* Specialize TestResult to produce text/html report */
function TextTestResult() {
$this->TestResult(); // call superclass constructor
}
function report() {
/* report result of test run */
$nRun = $this->countTests();
$nFailures = $this->countFailures();
printf("<p>%s test%s run<br>", $nRun, ($nRun == 1) ? '' : 's');
printf("%s failure%s.<br>\n", $nFailures, ($nFailures == 1) ? '' : 's');
if ($nFailures == 0)
return;
print("<ol>\n");
$failures = $this->getFailures();
while (list($i, $failure) = each($failures)) {
$failedTestName = $failure->getTestName();
printf("<li>%s\n", $failedTestName);
$exceptions = $failure->getExceptions();
print("<ul>");
while (list($na, $exception) = each($exceptions))
printf("<li>%s\n", $exception->getMessage());
print("</ul>");
}
print("</ol>\n");
}
function _startTest($test) {
printf("%s ", $test->name());
flush();
}
function _endTest($test) {
$outcome = $test->failed()
? "<font color=\"red\">FAIL</font>"
: "<font color=\"green\">ok</font>";
printf("$outcome<br>\n");
flush();
}
}
class TestRunner {
/* Run a suite of tests and report results. */
function run($suite) {
$result = new TextTestResult;
$suite->run($result);
$result->report();
}
}
?>

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.3 KiB