Version 0.3.5 beta

This commit is contained in:
Stephan Kasdorf
2018-03-14 16:37:09 +01:00
parent f7f7550833
commit c9f29ce086
152 changed files with 14954 additions and 1124 deletions

View File

@@ -0,0 +1,39 @@
<?php
/**
* PHPMailer - language file tests.
*
* PHP version 5.5.
*
* @author Marcus Bointon <phpmailer@synchromedia.co.uk>
* @author Andy Prevost
* @copyright 2010 - 2017 Marcus Bointon
* @copyright 2004 - 2009 Andy Prevost
* @license http://www.gnu.org/copyleft/lesser.html GNU Lesser General Public License
*/
namespace PHPMailer\Test;
class DebugLogTestListener extends \PHPUnit_Framework_BaseTestListener
{
private static $debugLog = '';
public function addError(\PHPUnit_Framework_Test $test, \Exception $e, $time)
{
echo self::$debugLog;
}
public function addFailure(\PHPUnit_Framework_Test $test, \PHPUnit_Framework_AssertionFailedError $e, $time)
{
echo self::$debugLog;
}
public function startTest(\PHPUnit_Framework_Test $test)
{
self::$debugLog = '';
}
public static function debugLog($str)
{
self::$debugLog .= $str . PHP_EOL;
}
}

View File

@@ -0,0 +1,72 @@
<?php
/**
* PHPMailer - language file tests.
*
* PHP version 5.5.
*
* @author Marcus Bointon <phpmailer@synchromedia.co.uk>
* @author Andy Prevost
* @copyright 2010 - 2017 Marcus Bointon
* @copyright 2004 - 2009 Andy Prevost
* @license http://www.gnu.org/copyleft/lesser.html GNU Lesser General Public License
*/
namespace PHPMailer\Test;
use PHPMailer\PHPMailer\PHPMailer;
use PHPUnit\Framework\TestCase;
/**
* Check language files for missing or excess translations.
*/
final class PHPMailerLangTest extends TestCase
{
/**
* Holds a PHPMailer instance.
*
* @var PHPMailer
*/
private $Mail;
/**
* Run before each test is started.
*/
protected function setUp()
{
$this->Mail = new PHPMailer();
}
/**
* Test language files for missing and excess translations.
* All languages are compared with English.
*
* @group languages
*/
public function testTranslations()
{
$this->Mail->setLanguage('en');
$definedStrings = $this->Mail->getTranslations();
$err = '';
foreach (new \DirectoryIterator('../language') as $fileInfo) {
if ($fileInfo->isDot()) {
continue;
}
$matches = [];
//Only look at language files, ignore anything else in there
if (preg_match('/^phpmailer\.lang-([a-z_]{2,})\.php$/', $fileInfo->getFilename(), $matches)) {
$lang = $matches[1]; //Extract language code
$PHPMAILER_LANG = []; //Language strings get put in here
include $fileInfo->getPathname(); //Get language strings
$missing = array_diff(array_keys($definedStrings), array_keys($PHPMAILER_LANG));
$extra = array_diff(array_keys($PHPMAILER_LANG), array_keys($definedStrings));
if (!empty($missing)) {
$err .= "\nMissing translations in $lang: " . implode(', ', $missing);
}
if (!empty($extra)) {
$err .= "\nExtra translations in $lang: " . implode(', ', $extra);
}
}
}
$this->assertEmpty($err, $err);
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,10 @@
<?php
/**
* PHPUnit bootstrap file.
*/
ini_set('sendmail_path', '/usr/sbin/sendmail -t -i ');
if (file_exists('vendor/autoload.php')) {
require_once 'vendor/autoload.php';
} else {
require_once '../vendor/autoload.php';
}

View File

@@ -0,0 +1,126 @@
#!/usr/bin/env bash
# Fake POP3 server
# By Marcus Bointon <phpmailer@synchromedia.co.uk>
# Copyright 2010 - 2016 Marcus Bointon
# Based on code by 'Frater' found at http://www.linuxquestions.org/questions/programming-9/fake-pop3-server-to-capture-pop3-passwords-933733
# Does not actually serve any mail, but supports commands sufficient to test POP-before SMTP
# Can be run directly from a shell like this:
# mkfifo fifo; nc -l 1100 <fifo |./fakepopserver.sh >fifo; rm fifo
# It will accept any user name and will return a positive response for the password 'test'
# Licensed under the GNU Lesser General Public License: http://www.gnu.org/copyleft/lesser.html
# Enable debug output
#set -xv
export PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin
LOGFOLDER=/tmp
LOGFILE=${LOGFOLDER}/fakepop.log
LOGGING=1
DEBUG=1
TIMEOUT=60
POP_USER=
POP_PASSWRD=test
LINES=1
BREAK=0
write_log () {
if [ ${LINES} -eq 1 ] ; then
echo '---' >>${LOGFILE}
fi
let LINES+=1
[ ${LOGGING} = 0 ] || echo -e "`date '+%b %d %H:%M'` pop3 $*" >>${LOGFILE}
}
ANSWER="+OK Fake POP3 Service Ready"
while [ ${BREAK} -eq 0 ] ; do
echo -en "${ANSWER}\r\n"
REPLY=""
#Input appears in $REPLY
read -t ${TIMEOUT}
ANSWER="+OK "
COMMAND=""
ARGS=""
TIMEOUT=30
if [ "$REPLY" ] ; then
write_log "RAW input: '`echo "${REPLY}" | tr -cd '[ -~]'`'"
COMMAND="`echo "${REPLY}" | awk '{print $1}' | tr -cd '\40-\176' | tr 'a-z' 'A-Z'`"
ARGS="`echo "${REPLY}" | tr -cd '\40-\176' | awk '{for(i=2;i<=NF;i++){printf "%s ", $i};printf "\n"}' | sed 's/ $//'`"
write_log "Command: \"${COMMAND}\""
write_log "Arguments: \"${ARGS}\""
case "$COMMAND" in
QUIT)
break
;;
USER)
if [ -n "${ARGS}" ] ; then
POP_USER="${ARGS}"
ANSWER="+OK Please send PASS command"
fi
;;
AUTH)
ANSWER="+OK \r\n."
;;
CAPA)
ANSWER="+OK Capabilities include\r\nUSER\r\nCAPA\r\n."
;;
PASS)
if [ "${POP_PASSWRD}" == "${ARGS}" ] ; then
ANSWER="+OK Logged in."
AUTH=1
else
ANSWER="-ERR Login failed."
fi
;;
LIST)
if [ "${AUTH}" = 0 ] ; then
ANSWER="-ERR Not authenticated"
else
if [ -z "${ARGS}" ] ; then
ANSWER="+OK No messages, really\r\n."
else
ANSWER="-ERR No messages, no list, no status"
fi
fi
;;
RSET)
ANSWER="+OK Resetting or whatever\r\n."
;;
LAST)
if [ "${AUTH}" = 0 ] ; then
ANSWER="-ERR Not authenticated"
else
ANSWER="+OK 0"
fi
;;
STAT)
if [ "${AUTH}" = 0 ] ; then
ANSWER="-ERR Not authenticated"
else
ANSWER="+OK 0 0"
fi
;;
NOOP)
ANSWER="+OK Hang on, doing nothing"
;;
esac
else
echo "+OK Connection timed out"
break
fi
done
echo "+OK Bye!\r\n"

View File

@@ -0,0 +1,22 @@
#!/usr/bin/env bash
#Fake sendmail script, adapted from:
#https://github.com/mrded/MNPP/blob/ee64fb2a88efc70ba523b78e9ce61f9f1ed3b4a9/init/fake-sendmail.sh
#Create a temp folder to put messages in
numPath="${TMPDIR-/tmp/}fakemail"
umask 037
mkdir -p ${numPath}
if [ ! -f ${numPath}/num ]; then
echo "0" > ${numPath}/num
fi
num=`cat ${numPath}/num`
num=$((${num} + 1))
echo ${num} > ${numPath}/num
name="${numPath}/message_${num}.eml"
while read line
do
echo ${line} >> ${name}
done
exit 0

View File

@@ -0,0 +1,13 @@
#!/usr/bin/env bash
set -xv
# Run the fake pop server from bash
# Idea from http://blog.ale-re.net/2007/09/ipersimple-remote-shell-with-netcat.html
# Defaults to port 1100 so it can be run by unpriv users and not clash with a real server
# Optionally, pass in a port number as the first arg
rm -f fifo
mkfifo fifo
nc -l ${1:-1100} <fifo |bash ./fakepopserver.sh >fifo
rm fifo

View File

@@ -0,0 +1,8 @@
<?php
$_REQUEST['submitted'] = 1;
$_REQUEST['mail_to'] = 'somebody@example.com';
$_REQUEST['mail_from'] = 'phpunit@example.com';
$_REQUEST['mail_cc'] = 'cc@example.com';
$_REQUEST['mail_host'] = 'localhost';
$_REQUEST['mail_port'] = 2500;