Commit 0ee13881 by Juliper

Bagian II

parent 9593781c
<?php
namespace Illuminate\Support\Facades;
/**
* @see \Illuminate\Contracts\Broadcasting\Factory
*/
class Broadcast extends Facade
{
/**
* Get the registered name of the component.
*
* @return string
*/
protected static function getFacadeAccessor()
{
return 'Illuminate\Contracts\Broadcasting\Factory';
}
}
<?php
/*
* This file is part of SwiftMailer.
* (c) 2004-2009 Chris Corbyn
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
/**
* Sends Messages using the mail() function.
*
* It is advised that users do not use this transport if at all possible
* since a number of plugin features cannot be used in conjunction with this
* transport due to the internal interface in PHP itself.
*
* The level of error reporting with this transport is incredibly weak, again
* due to limitations of PHP's internal mail() function. You'll get an
* all-or-nothing result from sending.
*
* @author Chris Corbyn
*
* @deprecated since 5.4.5 (to be removed in 6.0)
*/
class Swift_Transport_MailTransport implements Swift_Transport
{
/** Additional parameters to pass to mail() */
private $_extraParams = '-f%s';
/** The event dispatcher from the plugin API */
private $_eventDispatcher;
/** An invoker that calls the mail() function */
private $_invoker;
/**
* Create a new MailTransport with the $log.
*
* @param Swift_Transport_MailInvoker $invoker
* @param Swift_Events_EventDispatcher $eventDispatcher
*/
public function __construct(Swift_Transport_MailInvoker $invoker, Swift_Events_EventDispatcher $eventDispatcher)
{
@trigger_error(sprintf('The %s class is deprecated since version 5.4.5 and will be removed in 6.0. Use the Sendmail or SMTP transport instead.', __CLASS__), E_USER_DEPRECATED);
$this->_invoker = $invoker;
$this->_eventDispatcher = $eventDispatcher;
}
/**
* Not used.
*/
public function isStarted()
{
return false;
}
/**
* Not used.
*/
public function start()
{
}
/**
* Not used.
*/
public function stop()
{
}
/**
* Set the additional parameters used on the mail() function.
*
* This string is formatted for sprintf() where %s is the sender address.
*
* @param string $params
*
* @return Swift_Transport_MailTransport
*/
public function setExtraParams($params)
{
$this->_extraParams = $params;
return $this;
}
/**
* Get the additional parameters used on the mail() function.
*
* This string is formatted for sprintf() where %s is the sender address.
*
* @return string
*/
public function getExtraParams()
{
return $this->_extraParams;
}
/**
* Send the given Message.
*
* Recipient/sender data will be retrieved from the Message API.
* The return value is the number of recipients who were accepted for delivery.
*
* @param Swift_Mime_Message $message
* @param string[] $failedRecipients An array of failures by-reference
*
* @return int
*/
public function send(Swift_Mime_Message $message, &$failedRecipients = null)
{
$failedRecipients = (array) $failedRecipients;
if ($evt = $this->_eventDispatcher->createSendEvent($this, $message)) {
$this->_eventDispatcher->dispatchEvent($evt, 'beforeSendPerformed');
if ($evt->bubbleCancelled()) {
return 0;
}
}
$count = (
count((array) $message->getTo())
+ count((array) $message->getCc())
+ count((array) $message->getBcc())
);
$toHeader = $message->getHeaders()->get('To');
$subjectHeader = $message->getHeaders()->get('Subject');
if (0 === $count) {
$this->_throwException(new Swift_TransportException('Cannot send message without a recipient'));
}
$to = $toHeader ? $toHeader->getFieldBody() : '';
$subject = $subjectHeader ? $subjectHeader->getFieldBody() : '';
$reversePath = $this->_getReversePath($message);
// Remove headers that would otherwise be duplicated
$message->getHeaders()->remove('To');
$message->getHeaders()->remove('Subject');
$messageStr = $message->toString();
if ($toHeader) {
$message->getHeaders()->set($toHeader);
}
$message->getHeaders()->set($subjectHeader);
// Separate headers from body
if (false !== $endHeaders = strpos($messageStr, "\r\n\r\n")) {
$headers = substr($messageStr, 0, $endHeaders)."\r\n"; //Keep last EOL
$body = substr($messageStr, $endHeaders + 4);
} else {
$headers = $messageStr."\r\n";
$body = '';
}
unset($messageStr);
if ("\r\n" != PHP_EOL) {
// Non-windows (not using SMTP)
$headers = str_replace("\r\n", PHP_EOL, $headers);
$subject = str_replace("\r\n", PHP_EOL, $subject);
$body = str_replace("\r\n", PHP_EOL, $body);
$to = str_replace("\r\n", PHP_EOL, $to);
} else {
// Windows, using SMTP
$headers = str_replace("\r\n.", "\r\n..", $headers);
$subject = str_replace("\r\n.", "\r\n..", $subject);
$body = str_replace("\r\n.", "\r\n..", $body);
$to = str_replace("\r\n.", "\r\n..", $to);
}
if ($this->_invoker->mail($to, $subject, $body, $headers, $this->_formatExtraParams($this->_extraParams, $reversePath))) {
if ($evt) {
$evt->setResult(Swift_Events_SendEvent::RESULT_SUCCESS);
$evt->setFailedRecipients($failedRecipients);
$this->_eventDispatcher->dispatchEvent($evt, 'sendPerformed');
}
} else {
$failedRecipients = array_merge(
$failedRecipients,
array_keys((array) $message->getTo()),
array_keys((array) $message->getCc()),
array_keys((array) $message->getBcc())
);
if ($evt) {
$evt->setResult(Swift_Events_SendEvent::RESULT_FAILED);
$evt->setFailedRecipients($failedRecipients);
$this->_eventDispatcher->dispatchEvent($evt, 'sendPerformed');
}
$message->generateId();
$count = 0;
}
return $count;
}
/**
* Register a plugin.
*
* @param Swift_Events_EventListener $plugin
*/
public function registerPlugin(Swift_Events_EventListener $plugin)
{
$this->_eventDispatcher->bindEventListener($plugin);
}
/** Throw a TransportException, first sending it to any listeners */
protected function _throwException(Swift_TransportException $e)
{
if ($evt = $this->_eventDispatcher->createTransportExceptionEvent($this, $e)) {
$this->_eventDispatcher->dispatchEvent($evt, 'exceptionThrown');
if (!$evt->bubbleCancelled()) {
throw $e;
}
} else {
throw $e;
}
}
/** Determine the best-use reverse path for this message */
private function _getReversePath(Swift_Mime_Message $message)
{
$return = $message->getReturnPath();
$sender = $message->getSender();
$from = $message->getFrom();
$path = null;
if (!empty($return)) {
$path = $return;
} elseif (!empty($sender)) {
$keys = array_keys($sender);
$path = array_shift($keys);
} elseif (!empty($from)) {
$keys = array_keys($from);
$path = array_shift($keys);
}
return $path;
}
/**
* Fix CVE-2016-10074 by disallowing potentially unsafe shell characters.
*
* Note that escapeshellarg and escapeshellcmd are inadequate for our purposes, especially on Windows.
*
* @param string $string The string to be validated
*
* @return bool
*/
private function _isShellSafe($string)
{
// Future-proof
if (escapeshellcmd($string) !== $string || !in_array(escapeshellarg($string), array("'$string'", "\"$string\""))) {
return false;
}
$length = strlen($string);
for ($i = 0; $i < $length; ++$i) {
$c = $string[$i];
// All other characters have a special meaning in at least one common shell, including = and +.
// Full stop (.) has a special meaning in cmd.exe, but its impact should be negligible here.
// Note that this does permit non-Latin alphanumeric characters based on the current locale.
if (!ctype_alnum($c) && strpos('@_-.', $c) === false) {
return false;
}
}
return true;
}
/**
* Return php mail extra params to use for invoker->mail.
*
* @param $extraParams
* @param $reversePath
*
* @return string|null
*/
private function _formatExtraParams($extraParams, $reversePath)
{
if (false !== strpos($extraParams, '-f%s')) {
if (empty($reversePath) || false === $this->_isShellSafe($reversePath)) {
$extraParams = str_replace('-f%s', '', $extraParams);
} else {
$extraParams = sprintf($extraParams, $reversePath);
}
}
return !empty($extraParams) ? $extraParams : null;
}
}
<?php
/*
* This file is part of SwiftMailer.
* (c) 2009 Fabien Potencier <fabien.potencier@gmail.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
/**
* Pretends messages have been sent, but just ignores them.
*
* @author Fabien Potencier
*/
class Swift_Transport_NullTransport implements Swift_Transport
{
/** The event dispatcher from the plugin API */
private $_eventDispatcher;
/**
* Constructor.
*/
public function __construct(Swift_Events_EventDispatcher $eventDispatcher)
{
$this->_eventDispatcher = $eventDispatcher;
}
/**
* Tests if this Transport mechanism has started.
*
* @return bool
*/
public function isStarted()
{
return true;
}
/**
* Starts this Transport mechanism.
*/
public function start()
{
}
/**
* Stops this Transport mechanism.
*/
public function stop()
{
}
/**
* Sends the given message.
*
* @param Swift_Mime_Message $message
* @param string[] $failedRecipients An array of failures by-reference
*
* @return int The number of sent emails
*/
public function send(Swift_Mime_Message $message, &$failedRecipients = null)
{
if ($evt = $this->_eventDispatcher->createSendEvent($this, $message)) {
$this->_eventDispatcher->dispatchEvent($evt, 'beforeSendPerformed');
if ($evt->bubbleCancelled()) {
return 0;
}
}
if ($evt) {
$evt->setResult(Swift_Events_SendEvent::RESULT_SUCCESS);
$this->_eventDispatcher->dispatchEvent($evt, 'sendPerformed');
}
$count = (
count((array) $message->getTo())
+ count((array) $message->getCc())
+ count((array) $message->getBcc())
);
return $count;
}
/**
* Register a plugin.
*
* @param Swift_Events_EventListener $plugin
*/
public function registerPlugin(Swift_Events_EventListener $plugin)
{
$this->_eventDispatcher->bindEventListener($plugin);
}
}
<?php
/*
* This file is part of SwiftMailer.
* (c) 2004-2009 Chris Corbyn
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
/**
* SendmailTransport for sending mail through a Sendmail/Postfix (etc..) binary.
*
* Supported modes are -bs and -t, with any additional flags desired.
* It is advised to use -bs mode since error reporting with -t mode is not
* possible.
*
* @author Chris Corbyn
*/
class Swift_Transport_SendmailTransport extends Swift_Transport_AbstractSmtpTransport
{
/**
* Connection buffer parameters.
*
* @var array
*/
private $_params = array(
'timeout' => 30,
'blocking' => 1,
'command' => '/usr/sbin/sendmail -bs',
'type' => Swift_Transport_IoBuffer::TYPE_PROCESS,
);
/**
* Create a new SendmailTransport with $buf for I/O.
*
* @param Swift_Transport_IoBuffer $buf
* @param Swift_Events_EventDispatcher $dispatcher
*/
public function __construct(Swift_Transport_IoBuffer $buf, Swift_Events_EventDispatcher $dispatcher)
{
parent::__construct($buf, $dispatcher);
}
/**
* Start the standalone SMTP session if running in -bs mode.
*/
public function start()
{
if (false !== strpos($this->getCommand(), ' -bs')) {
parent::start();
}
}
/**
* Set the command to invoke.
*
* If using -t mode you are strongly advised to include -oi or -i in the flags.
* For example: /usr/sbin/sendmail -oi -t
* Swift will append a -f<sender> flag if one is not present.
*
* The recommended mode is "-bs" since it is interactive and failure notifications
* are hence possible.
*
* @param string $command
*
* @return Swift_Transport_SendmailTransport
*/
public function setCommand($command)
{
$this->_params['command'] = $command;
return $this;
}
/**
* Get the sendmail command which will be invoked.
*
* @return string
*/
public function getCommand()
{
return $this->_params['command'];
}
/**
* Send the given Message.
*
* Recipient/sender data will be retrieved from the Message API.
*
* The return value is the number of recipients who were accepted for delivery.
* NOTE: If using 'sendmail -t' you will not be aware of any failures until
* they bounce (i.e. send() will always return 100% success).
*
* @param Swift_Mime_Message $message
* @param string[] $failedRecipients An array of failures by-reference
*
* @return int
*/
public function send(Swift_Mime_Message $message, &$failedRecipients = null)
{
$failedRecipients = (array) $failedRecipients;
$command = $this->getCommand();
$buffer = $this->getBuffer();
$count = 0;
if (false !== strpos($command, ' -t')) {
if ($evt = $this->_eventDispatcher->createSendEvent($this, $message)) {
$this->_eventDispatcher->dispatchEvent($evt, 'beforeSendPerformed');
if ($evt->bubbleCancelled()) {
return 0;
}
}
if (false === strpos($command, ' -f')) {
$command .= ' -f'.escapeshellarg($this->_getReversePath($message));
}
$buffer->initialize(array_merge($this->_params, array('command' => $command)));
if (false === strpos($command, ' -i') && false === strpos($command, ' -oi')) {
$buffer->setWriteTranslations(array("\r\n" => "\n", "\n." => "\n.."));
} else {
$buffer->setWriteTranslations(array("\r\n" => "\n"));
}
$count = count((array) $message->getTo())
+ count((array) $message->getCc())
+ count((array) $message->getBcc())
;
$message->toByteStream($buffer);
$buffer->flushBuffers();
$buffer->setWriteTranslations(array());
$buffer->terminate();
if ($evt) {
$evt->setResult(Swift_Events_SendEvent::RESULT_SUCCESS);
$evt->setFailedRecipients($failedRecipients);
$this->_eventDispatcher->dispatchEvent($evt, 'sendPerformed');
}
$message->generateId();
} elseif (false !== strpos($command, ' -bs')) {
$count = parent::send($message, $failedRecipients);
} else {
$this->_throwException(new Swift_TransportException(
'Unsupported sendmail command flags ['.$command.']. '.
'Must be one of "-bs" or "-t" but can include additional flags.'
));
}
return $count;
}
/** Get the params to initialize the buffer */
protected function _getBufferParams()
{
return $this->_params;
}
}
<?php
/*
* This file is part of SwiftMailer.
* (c) 2004-2009 Chris Corbyn
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
/**
* This is the implementation class for {@link Swift_Transport_MailInvoker}.
*
* @author Chris Corbyn
*/
class Swift_Transport_SimpleMailInvoker implements Swift_Transport_MailInvoker
{
/**
* Send mail via the mail() function.
*
* This method takes the same arguments as PHP mail().
*
* @param string $to
* @param string $subject
* @param string $body
* @param string $headers
* @param string $extraParams
*
* @return bool
*/
public function mail($to, $subject, $body, $headers = null, $extraParams = null)
{
if (!ini_get('safe_mode')) {
return @mail($to, $subject, $body, $headers, $extraParams);
}
return @mail($to, $subject, $body, $headers);
}
}
<?php
/*
* This file is part of SwiftMailer.
* (c) 2004-2009 Chris Corbyn
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
/**
* Wraps an IoBuffer to send/receive SMTP commands/responses.
*
* @author Chris Corbyn
*/
interface Swift_Transport_SmtpAgent
{
/**
* Get the IoBuffer where read/writes are occurring.
*
* @return Swift_Transport_IoBuffer
*/
public function getBuffer();
/**
* Run a command against the buffer, expecting the given response codes.
*
* If no response codes are given, the response will not be validated.
* If codes are given, an exception will be thrown on an invalid response.
*
* @param string $command
* @param int[] $codes
* @param string[] $failures An array of failures by-reference
*/
public function executeCommand($command, $codes = array(), &$failures = null);
}
<?php
/*
* This file is part of SwiftMailer.
* (c) 2009 Fabien Potencier <fabien.potencier@gmail.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
/**
* Stores Messages in a queue.
*
* @author Fabien Potencier
*/
class Swift_Transport_SpoolTransport implements Swift_Transport
{
/** The spool instance */
private $_spool;
/** The event dispatcher from the plugin API */
private $_eventDispatcher;
/**
* Constructor.
*/
public function __construct(Swift_Events_EventDispatcher $eventDispatcher, Swift_Spool $spool = null)
{
$this->_eventDispatcher = $eventDispatcher;
$this->_spool = $spool;
}
/**
* Sets the spool object.
*
* @param Swift_Spool $spool
*
* @return Swift_Transport_SpoolTransport
*/
public function setSpool(Swift_Spool $spool)
{
$this->_spool = $spool;
return $this;
}
/**
* Get the spool object.
*
* @return Swift_Spool
*/
public function getSpool()
{
return $this->_spool;
}
/**
* Tests if this Transport mechanism has started.
*
* @return bool
*/
public function isStarted()
{
return true;
}
/**
* Starts this Transport mechanism.
*/
public function start()
{
}
/**
* Stops this Transport mechanism.
*/
public function stop()
{
}
/**
* Sends the given message.
*
* @param Swift_Mime_Message $message
* @param string[] $failedRecipients An array of failures by-reference
*
* @return int The number of sent e-mail's
*/
public function send(Swift_Mime_Message $message, &$failedRecipients = null)
{
if ($evt = $this->_eventDispatcher->createSendEvent($this, $message)) {
$this->_eventDispatcher->dispatchEvent($evt, 'beforeSendPerformed');
if ($evt->bubbleCancelled()) {
return 0;
}
}
$success = $this->_spool->queueMessage($message);
if ($evt) {
$evt->setResult($success ? Swift_Events_SendEvent::RESULT_SPOOLED : Swift_Events_SendEvent::RESULT_FAILED);
$this->_eventDispatcher->dispatchEvent($evt, 'sendPerformed');
}
return 1;
}
/**
* Register a plugin.
*
* @param Swift_Events_EventListener $plugin
*/
public function registerPlugin(Swift_Events_EventListener $plugin)
{
$this->_eventDispatcher->bindEventListener($plugin);
}
}
<?php
/*
* This file is part of SwiftMailer.
* (c) 2004-2009 Chris Corbyn
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
/**
* A generic IoBuffer implementation supporting remote sockets and local processes.
*
* @author Chris Corbyn
*/
class Swift_Transport_StreamBuffer extends Swift_ByteStream_AbstractFilterableInputStream implements Swift_Transport_IoBuffer
{
/** A primary socket */
private $_stream;
/** The input stream */
private $_in;
/** The output stream */
private $_out;
/** Buffer initialization parameters */
private $_params = array();
/** The ReplacementFilterFactory */
private $_replacementFactory;
/** Translations performed on data being streamed into the buffer */
private $_translations = array();
/**
* Create a new StreamBuffer using $replacementFactory for transformations.
*
* @param Swift_ReplacementFilterFactory $replacementFactory
*/
public function __construct(Swift_ReplacementFilterFactory $replacementFactory)
{
$this->_replacementFactory = $replacementFactory;
}
/**
* Perform any initialization needed, using the given $params.
*
* Parameters will vary depending upon the type of IoBuffer used.
*
* @param array $params
*/
public function initialize(array $params)
{
$this->_params = $params;
switch ($params['type']) {
case self::TYPE_PROCESS:
$this->_establishProcessConnection();
break;
case self::TYPE_SOCKET:
default:
$this->_establishSocketConnection();
break;
}
}
/**
* Set an individual param on the buffer (e.g. switching to SSL).
*
* @param string $param
* @param mixed $value
*/
public function setParam($param, $value)
{
if (isset($this->_stream)) {
switch ($param) {
case 'timeout':
if ($this->_stream) {
stream_set_timeout($this->_stream, $value);
}
break;
case 'blocking':
if ($this->_stream) {
stream_set_blocking($this->_stream, 1);
}
}
}
$this->_params[$param] = $value;
}
public function startTLS()
{
return stream_socket_enable_crypto($this->_stream, true, STREAM_CRYPTO_METHOD_TLS_CLIENT);
}
/**
* Perform any shutdown logic needed.
*/
public function terminate()
{
if (isset($this->_stream)) {
switch ($this->_params['type']) {
case self::TYPE_PROCESS:
fclose($this->_in);
fclose($this->_out);
proc_close($this->_stream);
break;
case self::TYPE_SOCKET:
default:
fclose($this->_stream);
break;
}
}
$this->_stream = null;
$this->_out = null;
$this->_in = null;
}
/**
* Set an array of string replacements which should be made on data written
* to the buffer.
*
* This could replace LF with CRLF for example.
*
* @param string[] $replacements
*/
public function setWriteTranslations(array $replacements)
{
foreach ($this->_translations as $search => $replace) {
if (!isset($replacements[$search])) {
$this->removeFilter($search);
unset($this->_translations[$search]);
}
}
foreach ($replacements as $search => $replace) {
if (!isset($this->_translations[$search])) {
$this->addFilter(
$this->_replacementFactory->createFilter($search, $replace), $search
);
$this->_translations[$search] = true;
}
}
}
/**
* Get a line of output (including any CRLF).
*
* The $sequence number comes from any writes and may or may not be used
* depending upon the implementation.
*
* @param int $sequence of last write to scan from
*
* @throws Swift_IoException
*
* @return string
*/
public function readLine($sequence)
{
if (isset($this->_out) && !feof($this->_out)) {
$line = fgets($this->_out);
if (strlen($line) == 0) {
$metas = stream_get_meta_data($this->_out);
if ($metas['timed_out']) {
throw new Swift_IoException(
'Connection to '.
$this->_getReadConnectionDescription().
' Timed Out'
);
}
}
return $line;
}
}
/**
* Reads $length bytes from the stream into a string and moves the pointer
* through the stream by $length.
*
* If less bytes exist than are requested the remaining bytes are given instead.
* If no bytes are remaining at all, boolean false is returned.
*
* @param int $length
*
* @throws Swift_IoException
*
* @return string|bool
*/
public function read($length)
{
if (isset($this->_out) && !feof($this->_out)) {
$ret = fread($this->_out, $length);
if (strlen($ret) == 0) {
$metas = stream_get_meta_data($this->_out);
if ($metas['timed_out']) {
throw new Swift_IoException(
'Connection to '.
$this->_getReadConnectionDescription().
' Timed Out'
);
}
}
return $ret;
}
}
/** Not implemented */
public function setReadPointer($byteOffset)
{
}
/** Flush the stream contents */
protected function _flush()
{
if (isset($this->_in)) {
fflush($this->_in);
}
}
/** Write this bytes to the stream */
protected function _commit($bytes)
{
if (isset($this->_in)) {
$bytesToWrite = strlen($bytes);
$totalBytesWritten = 0;
while ($totalBytesWritten < $bytesToWrite) {
$bytesWritten = fwrite($this->_in, substr($bytes, $totalBytesWritten));
if (false === $bytesWritten || 0 === $bytesWritten) {
break;
}
$totalBytesWritten += $bytesWritten;
}
if ($totalBytesWritten > 0) {
return ++$this->_sequence;
}
}
}
/**
* Establishes a connection to a remote server.
*/
private function _establishSocketConnection()
{
$host = $this->_params['host'];
if (!empty($this->_params['protocol'])) {
$host = $this->_params['protocol'].'://'.$host;
}
$timeout = 15;
if (!empty($this->_params['timeout'])) {
$timeout = $this->_params['timeout'];
}
$options = array();
if (!empty($this->_params['sourceIp'])) {
$options['socket']['bindto'] = $this->_params['sourceIp'].':0';
}
if (isset($this->_params['stream_context_options'])) {
$options = array_merge($options, $this->_params['stream_context_options']);
}
$streamContext = stream_context_create($options);
$this->_stream = @stream_socket_client($host.':'.$this->_params['port'], $errno, $errstr, $timeout, STREAM_CLIENT_CONNECT, $streamContext);
if (false === $this->_stream) {
throw new Swift_TransportException(
'Connection could not be established with host '.$this->_params['host'].
' ['.$errstr.' #'.$errno.']'
);
}
if (!empty($this->_params['blocking'])) {
stream_set_blocking($this->_stream, 1);
} else {
stream_set_blocking($this->_stream, 0);
}
stream_set_timeout($this->_stream, $timeout);
$this->_in = &$this->_stream;
$this->_out = &$this->_stream;
}
/**
* Opens a process for input/output.
*/
private function _establishProcessConnection()
{
$command = $this->_params['command'];
$descriptorSpec = array(
0 => array('pipe', 'r'),
1 => array('pipe', 'w'),
2 => array('pipe', 'w'),
);
$pipes = array();
$this->_stream = proc_open($command, $descriptorSpec, $pipes);
stream_set_blocking($pipes[2], 0);
if ($err = stream_get_contents($pipes[2])) {
throw new Swift_TransportException(
'Process could not be started ['.$err.']'
);
}
$this->_in = &$pipes[0];
$this->_out = &$pipes[1];
}
private function _getReadConnectionDescription()
{
switch ($this->_params['type']) {
case self::TYPE_PROCESS:
return 'Process '.$this->_params['command'];
break;
case self::TYPE_SOCKET:
default:
$host = $this->_params['host'];
if (!empty($this->_params['protocol'])) {
$host = $this->_params['protocol'].'://'.$host;
}
$host .= ':'.$this->_params['port'];
return $host;
break;
}
}
}
<?php
/*
* This file is part of SwiftMailer.
* (c) 2004-2009 Chris Corbyn
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
/**
* TransportException thrown when an error occurs in the Transport subsystem.
*
* @author Chris Corbyn
*/
class Swift_TransportException extends Swift_IoException
{
/**
* Create a new TransportException with $message.
*
* @param string $message
* @param int $code
* @param Exception $previous
*/
public function __construct($message, $code = 0, Exception $previous = null)
{
parent::__construct($message, $code, $previous);
}
}
<?php
/*
* This file is part of SwiftMailer.
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
/**
* Utility Class allowing users to simply check expressions again Swift Grammar.
*
* @author Xavier De Cock <xdecock@gmail.com>
*/
class Swift_Validate
{
/**
* Grammar Object.
*
* @var Swift_Mime_Grammar
*/
private static $grammar = null;
/**
* Checks if an e-mail address matches the current grammars.
*
* @param string $email
*
* @return bool
*/
public static function email($email)
{
if (self::$grammar === null) {
self::$grammar = Swift_DependencyContainer::getInstance()
->lookup('mime.grammar');
}
return (bool) preg_match(
'/^'.self::$grammar->getDefinition('addr-spec').'$/D',
$email
);
}
}
<?php
Swift_DependencyContainer::getInstance()
->register('cache')
->asAliasOf('cache.array')
->register('tempdir')
->asValue('/tmp')
->register('cache.null')
->asSharedInstanceOf('Swift_KeyCache_NullKeyCache')
->register('cache.array')
->asSharedInstanceOf('Swift_KeyCache_ArrayKeyCache')
->withDependencies(array('cache.inputstream'))
->register('cache.disk')
->asSharedInstanceOf('Swift_KeyCache_DiskKeyCache')
->withDependencies(array('cache.inputstream', 'tempdir'))
->register('cache.inputstream')
->asNewInstanceOf('Swift_KeyCache_SimpleKeyCacheInputStream')
;
<?php
Swift_DependencyContainer::getInstance()
->register('message.message')
->asNewInstanceOf('Swift_Message')
->register('message.mimepart')
->asNewInstanceOf('Swift_MimePart')
;
<?php
require __DIR__.'/../mime_types.php';
Swift_DependencyContainer::getInstance()
->register('properties.charset')
->asValue('utf-8')
->register('mime.grammar')
->asSharedInstanceOf('Swift_Mime_Grammar')
->register('mime.message')
->asNewInstanceOf('Swift_Mime_SimpleMessage')
->withDependencies(array(
'mime.headerset',
'mime.qpcontentencoder',
'cache',
'mime.grammar',
'properties.charset',
))
->register('mime.part')
->asNewInstanceOf('Swift_Mime_MimePart')
->withDependencies(array(
'mime.headerset',
'mime.qpcontentencoder',
'cache',
'mime.grammar',
'properties.charset',
))
->register('mime.attachment')
->asNewInstanceOf('Swift_Mime_Attachment')
->withDependencies(array(
'mime.headerset',
'mime.base64contentencoder',
'cache',
'mime.grammar',
))
->addConstructorValue($swift_mime_types)
->register('mime.embeddedfile')
->asNewInstanceOf('Swift_Mime_EmbeddedFile')
->withDependencies(array(
'mime.headerset',
'mime.base64contentencoder',
'cache',
'mime.grammar',
))
->addConstructorValue($swift_mime_types)
->register('mime.headerfactory')
->asNewInstanceOf('Swift_Mime_SimpleHeaderFactory')
->withDependencies(array(
'mime.qpheaderencoder',
'mime.rfc2231encoder',
'mime.grammar',
'properties.charset',
))
->register('mime.headerset')
->asNewInstanceOf('Swift_Mime_SimpleHeaderSet')
->withDependencies(array('mime.headerfactory', 'properties.charset'))
->register('mime.qpheaderencoder')
->asNewInstanceOf('Swift_Mime_HeaderEncoder_QpHeaderEncoder')
->withDependencies(array('mime.charstream'))
->register('mime.base64headerencoder')
->asNewInstanceOf('Swift_Mime_HeaderEncoder_Base64HeaderEncoder')
->withDependencies(array('mime.charstream'))
->register('mime.charstream')
->asNewInstanceOf('Swift_CharacterStream_NgCharacterStream')
->withDependencies(array('mime.characterreaderfactory', 'properties.charset'))
->register('mime.bytecanonicalizer')
->asSharedInstanceOf('Swift_StreamFilters_ByteArrayReplacementFilter')
->addConstructorValue(array(array(0x0D, 0x0A), array(0x0D), array(0x0A)))
->addConstructorValue(array(array(0x0A), array(0x0A), array(0x0D, 0x0A)))
->register('mime.characterreaderfactory')
->asSharedInstanceOf('Swift_CharacterReaderFactory_SimpleCharacterReaderFactory')
->register('mime.safeqpcontentencoder')
->asNewInstanceOf('Swift_Mime_ContentEncoder_QpContentEncoder')
->withDependencies(array('mime.charstream', 'mime.bytecanonicalizer'))
->register('mime.rawcontentencoder')
->asNewInstanceOf('Swift_Mime_ContentEncoder_RawContentEncoder')
->register('mime.nativeqpcontentencoder')
->withDependencies(array('properties.charset'))
->asNewInstanceOf('Swift_Mime_ContentEncoder_NativeQpContentEncoder')
->register('mime.qpcontentencoderproxy')
->asNewInstanceOf('Swift_Mime_ContentEncoder_QpContentEncoderProxy')
->withDependencies(array('mime.safeqpcontentencoder', 'mime.nativeqpcontentencoder', 'properties.charset'))
->register('mime.7bitcontentencoder')
->asNewInstanceOf('Swift_Mime_ContentEncoder_PlainContentEncoder')
->addConstructorValue('7bit')
->addConstructorValue(true)
->register('mime.8bitcontentencoder')
->asNewInstanceOf('Swift_Mime_ContentEncoder_PlainContentEncoder')
->addConstructorValue('8bit')
->addConstructorValue(true)
->register('mime.base64contentencoder')
->asSharedInstanceOf('Swift_Mime_ContentEncoder_Base64ContentEncoder')
->register('mime.rfc2231encoder')
->asNewInstanceOf('Swift_Encoder_Rfc2231Encoder')
->withDependencies(array('mime.charstream'))
// As of PHP 5.4.7, the quoted_printable_encode() function behaves correctly.
// see https://github.com/php/php-src/commit/18bb426587d62f93c54c40bf8535eb8416603629
->register('mime.qpcontentencoder')
->asAliasOf(PHP_VERSION_ID >= 50407 ? 'mime.qpcontentencoderproxy' : 'mime.safeqpcontentencoder')
;
unset($swift_mime_types);
<?php
Swift_DependencyContainer::getInstance()
->register('transport.smtp')
->asNewInstanceOf('Swift_Transport_EsmtpTransport')
->withDependencies(array(
'transport.buffer',
array('transport.authhandler'),
'transport.eventdispatcher',
))
->register('transport.sendmail')
->asNewInstanceOf('Swift_Transport_SendmailTransport')
->withDependencies(array(
'transport.buffer',
'transport.eventdispatcher',
))
->register('transport.mail')
->asNewInstanceOf('Swift_Transport_MailTransport')
->withDependencies(array('transport.mailinvoker', 'transport.eventdispatcher'))
->register('transport.loadbalanced')
->asNewInstanceOf('Swift_Transport_LoadBalancedTransport')
->register('transport.failover')
->asNewInstanceOf('Swift_Transport_FailoverTransport')
->register('transport.spool')
->asNewInstanceOf('Swift_Transport_SpoolTransport')
->withDependencies(array('transport.eventdispatcher'))
->register('transport.null')
->asNewInstanceOf('Swift_Transport_NullTransport')
->withDependencies(array('transport.eventdispatcher'))
->register('transport.mailinvoker')
->asSharedInstanceOf('Swift_Transport_SimpleMailInvoker')
->register('transport.buffer')
->asNewInstanceOf('Swift_Transport_StreamBuffer')
->withDependencies(array('transport.replacementfactory'))
->register('transport.authhandler')
->asNewInstanceOf('Swift_Transport_Esmtp_AuthHandler')
->withDependencies(array(
array(
'transport.crammd5auth',
'transport.loginauth',
'transport.plainauth',
'transport.ntlmauth',
'transport.xoauth2auth',
),
))
->register('transport.crammd5auth')
->asNewInstanceOf('Swift_Transport_Esmtp_Auth_CramMd5Authenticator')
->register('transport.loginauth')
->asNewInstanceOf('Swift_Transport_Esmtp_Auth_LoginAuthenticator')
->register('transport.plainauth')
->asNewInstanceOf('Swift_Transport_Esmtp_Auth_PlainAuthenticator')
->register('transport.xoauth2auth')
->asNewInstanceOf('Swift_Transport_Esmtp_Auth_XOAuth2Authenticator')
->register('transport.ntlmauth')
->asNewInstanceOf('Swift_Transport_Esmtp_Auth_NTLMAuthenticator')
->register('transport.eventdispatcher')
->asNewInstanceOf('Swift_Events_SimpleEventDispatcher')
->register('transport.replacementfactory')
->asSharedInstanceOf('Swift_StreamFilters_StringReplacementFilterFactory')
;
<?php
/*
* This file is part of SwiftMailer.
* (c) 2004-2009 Chris Corbyn
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*
* autogenerated using http://svn.apache.org/repos/asf/httpd/httpd/trunk/docs/conf/mime.types
* and https://raw.github.com/minad/mimemagic/master/script/freedesktop.org.xml
*/
/*
* List of MIME type automatically detected in Swift Mailer.
*/
// You may add or take away what you like (lowercase required)
$swift_mime_types = array(
'3dml' => 'text/vnd.in3d.3dml',
'3ds' => 'image/x-3ds',
'3g2' => 'video/3gpp2',
'3gp' => 'video/3gpp',
'7z' => 'application/x-7z-compressed',
'aab' => 'application/x-authorware-bin',
'aac' => 'audio/x-aac',
'aam' => 'application/x-authorware-map',
'aas' => 'application/x-authorware-seg',
'abw' => 'application/x-abiword',
'ac' => 'application/pkix-attr-cert',
'acc' => 'application/vnd.americandynamics.acc',
'ace' => 'application/x-ace-compressed',
'acu' => 'application/vnd.acucobol',
'acutc' => 'application/vnd.acucorp',
'adp' => 'audio/adpcm',
'aep' => 'application/vnd.audiograph',
'afm' => 'application/x-font-type1',
'afp' => 'application/vnd.ibm.modcap',
'ahead' => 'application/vnd.ahead.space',
'ai' => 'application/postscript',
'aif' => 'audio/x-aiff',
'aifc' => 'audio/x-aiff',
'aiff' => 'audio/x-aiff',
'air' => 'application/vnd.adobe.air-application-installer-package+zip',
'ait' => 'application/vnd.dvb.ait',
'ami' => 'application/vnd.amiga.ami',
'apk' => 'application/vnd.android.package-archive',
'appcache' => 'text/cache-manifest',
'apr' => 'application/vnd.lotus-approach',
'aps' => 'application/postscript',
'arc' => 'application/x-freearc',
'asc' => 'application/pgp-signature',
'asf' => 'video/x-ms-asf',
'asm' => 'text/x-asm',
'aso' => 'application/vnd.accpac.simply.aso',
'asx' => 'video/x-ms-asf',
'atc' => 'application/vnd.acucorp',
'atom' => 'application/atom+xml',
'atomcat' => 'application/atomcat+xml',
'atomsvc' => 'application/atomsvc+xml',
'atx' => 'application/vnd.antix.game-component',
'au' => 'audio/basic',
'avi' => 'video/x-msvideo',
'aw' => 'application/applixware',
'azf' => 'application/vnd.airzip.filesecure.azf',
'azs' => 'application/vnd.airzip.filesecure.azs',
'azw' => 'application/vnd.amazon.ebook',
'bat' => 'application/x-msdownload',
'bcpio' => 'application/x-bcpio',
'bdf' => 'application/x-font-bdf',
'bdm' => 'application/vnd.syncml.dm+wbxml',
'bed' => 'application/vnd.realvnc.bed',
'bh2' => 'application/vnd.fujitsu.oasysprs',
'bin' => 'application/octet-stream',
'blb' => 'application/x-blorb',
'blorb' => 'application/x-blorb',
'bmi' => 'application/vnd.bmi',
'bmp' => 'image/bmp',
'book' => 'application/vnd.framemaker',
'box' => 'application/vnd.previewsystems.box',
'boz' => 'application/x-bzip2',
'bpk' => 'application/octet-stream',
'btif' => 'image/prs.btif',
'bz' => 'application/x-bzip',
'bz2' => 'application/x-bzip2',
'c' => 'text/x-c',
'c11amc' => 'application/vnd.cluetrust.cartomobile-config',
'c11amz' => 'application/vnd.cluetrust.cartomobile-config-pkg',
'c4d' => 'application/vnd.clonk.c4group',
'c4f' => 'application/vnd.clonk.c4group',
'c4g' => 'application/vnd.clonk.c4group',
'c4p' => 'application/vnd.clonk.c4group',
'c4u' => 'application/vnd.clonk.c4group',
'cab' => 'application/vnd.ms-cab-compressed',
'caf' => 'audio/x-caf',
'cap' => 'application/vnd.tcpdump.pcap',
'car' => 'application/vnd.curl.car',
'cat' => 'application/vnd.ms-pki.seccat',
'cb7' => 'application/x-cbr',
'cba' => 'application/x-cbr',
'cbr' => 'application/x-cbr',
'cbt' => 'application/x-cbr',
'cbz' => 'application/x-cbr',
'cc' => 'text/x-c',
'cct' => 'application/x-director',
'ccxml' => 'application/ccxml+xml',
'cdbcmsg' => 'application/vnd.contact.cmsg',
'cdf' => 'application/x-netcdf',
'cdkey' => 'application/vnd.mediastation.cdkey',
'cdmia' => 'application/cdmi-capability',
'cdmic' => 'application/cdmi-container',
'cdmid' => 'application/cdmi-domain',
'cdmio' => 'application/cdmi-object',
'cdmiq' => 'application/cdmi-queue',
'cdx' => 'chemical/x-cdx',
'cdxml' => 'application/vnd.chemdraw+xml',
'cdy' => 'application/vnd.cinderella',
'cer' => 'application/pkix-cert',
'cfs' => 'application/x-cfs-compressed',
'cgm' => 'image/cgm',
'chat' => 'application/x-chat',
'chm' => 'application/vnd.ms-htmlhelp',
'chrt' => 'application/vnd.kde.kchart',
'cif' => 'chemical/x-cif',
'cii' => 'application/vnd.anser-web-certificate-issue-initiation',
'cil' => 'application/vnd.ms-artgalry',
'cla' => 'application/vnd.claymore',
'class' => 'application/java-vm',
'clkk' => 'application/vnd.crick.clicker.keyboard',
'clkp' => 'application/vnd.crick.clicker.palette',
'clkt' => 'application/vnd.crick.clicker.template',
'clkw' => 'application/vnd.crick.clicker.wordbank',
'clkx' => 'application/vnd.crick.clicker',
'clp' => 'application/x-msclip',
'cmc' => 'application/vnd.cosmocaller',
'cmdf' => 'chemical/x-cmdf',
'cml' => 'chemical/x-cml',
'cmp' => 'application/vnd.yellowriver-custom-menu',
'cmx' => 'image/x-cmx',
'cod' => 'application/vnd.rim.cod',
'com' => 'application/x-msdownload',
'conf' => 'text/plain',
'cpio' => 'application/x-cpio',
'cpp' => 'text/x-c',
'cpt' => 'application/mac-compactpro',
'crd' => 'application/x-mscardfile',
'crl' => 'application/pkix-crl',
'crt' => 'application/x-x509-ca-cert',
'csh' => 'application/x-csh',
'csml' => 'chemical/x-csml',
'csp' => 'application/vnd.commonspace',
'css' => 'text/css',
'cst' => 'application/x-director',
'csv' => 'text/csv',
'cu' => 'application/cu-seeme',
'curl' => 'text/vnd.curl',
'cww' => 'application/prs.cww',
'cxt' => 'application/x-director',
'cxx' => 'text/x-c',
'dae' => 'model/vnd.collada+xml',
'daf' => 'application/vnd.mobius.daf',
'dart' => 'application/vnd.dart',
'dataless' => 'application/vnd.fdsn.seed',
'davmount' => 'application/davmount+xml',
'dbk' => 'application/docbook+xml',
'dcr' => 'application/x-director',
'dcurl' => 'text/vnd.curl.dcurl',
'dd2' => 'application/vnd.oma.dd2+xml',
'ddd' => 'application/vnd.fujixerox.ddd',
'deb' => 'application/x-debian-package',
'def' => 'text/plain',
'deploy' => 'application/octet-stream',
'der' => 'application/x-x509-ca-cert',
'dfac' => 'application/vnd.dreamfactory',
'dgc' => 'application/x-dgc-compressed',
'dic' => 'text/x-c',
'dir' => 'application/x-director',
'dis' => 'application/vnd.mobius.dis',
'dist' => 'application/octet-stream',
'distz' => 'application/octet-stream',
'djv' => 'image/vnd.djvu',
'djvu' => 'image/vnd.djvu',
'dll' => 'application/x-msdownload',
'dmg' => 'application/x-apple-diskimage',
'dmp' => 'application/vnd.tcpdump.pcap',
'dms' => 'application/octet-stream',
'dna' => 'application/vnd.dna',
'doc' => 'application/msword',
'docm' => 'application/vnd.ms-word.document.macroenabled.12',
'docx' => 'application/vnd.openxmlformats-officedocument.wordprocessingml.document',
'dot' => 'application/msword',
'dotm' => 'application/vnd.ms-word.template.macroenabled.12',
'dotx' => 'application/vnd.openxmlformats-officedocument.wordprocessingml.template',
'dp' => 'application/vnd.osgi.dp',
'dpg' => 'application/vnd.dpgraph',
'dra' => 'audio/vnd.dra',
'dsc' => 'text/prs.lines.tag',
'dssc' => 'application/dssc+der',
'dtb' => 'application/x-dtbook+xml',
'dtd' => 'application/xml-dtd',
'dts' => 'audio/vnd.dts',
'dtshd' => 'audio/vnd.dts.hd',
'dump' => 'application/octet-stream',
'dvb' => 'video/vnd.dvb.file',
'dvi' => 'application/x-dvi',
'dwf' => 'model/vnd.dwf',
'dwg' => 'image/vnd.dwg',
'dxf' => 'image/vnd.dxf',
'dxp' => 'application/vnd.spotfire.dxp',
'dxr' => 'application/x-director',
'ecelp4800' => 'audio/vnd.nuera.ecelp4800',
'ecelp7470' => 'audio/vnd.nuera.ecelp7470',
'ecelp9600' => 'audio/vnd.nuera.ecelp9600',
'ecma' => 'application/ecmascript',
'edm' => 'application/vnd.novadigm.edm',
'edx' => 'application/vnd.novadigm.edx',
'efif' => 'application/vnd.picsel',
'ei6' => 'application/vnd.pg.osasli',
'elc' => 'application/octet-stream',
'emf' => 'application/x-msmetafile',
'eml' => 'message/rfc822',
'emma' => 'application/emma+xml',
'emz' => 'application/x-msmetafile',
'eol' => 'audio/vnd.digital-winds',
'eot' => 'application/vnd.ms-fontobject',
'eps' => 'application/postscript',
'epub' => 'application/epub+zip',
'es3' => 'application/vnd.eszigno3+xml',
'esa' => 'application/vnd.osgi.subsystem',
'esf' => 'application/vnd.epson.esf',
'et3' => 'application/vnd.eszigno3+xml',
'etx' => 'text/x-setext',
'eva' => 'application/x-eva',
'evy' => 'application/x-envoy',
'exe' => 'application/x-msdownload',
'exi' => 'application/exi',
'ext' => 'application/vnd.novadigm.ext',
'ez' => 'application/andrew-inset',
'ez2' => 'application/vnd.ezpix-album',
'ez3' => 'application/vnd.ezpix-package',
'f' => 'text/x-fortran',
'f4v' => 'video/x-f4v',
'f77' => 'text/x-fortran',
'f90' => 'text/x-fortran',
'fbs' => 'image/vnd.fastbidsheet',
'fcdt' => 'application/vnd.adobe.formscentral.fcdt',
'fcs' => 'application/vnd.isac.fcs',
'fdf' => 'application/vnd.fdf',
'fe_launch' => 'application/vnd.denovo.fcselayout-link',
'fg5' => 'application/vnd.fujitsu.oasysgp',
'fgd' => 'application/x-director',
'fh' => 'image/x-freehand',
'fh4' => 'image/x-freehand',
'fh5' => 'image/x-freehand',
'fh7' => 'image/x-freehand',
'fhc' => 'image/x-freehand',
'fig' => 'application/x-xfig',
'flac' => 'audio/x-flac',
'fli' => 'video/x-fli',
'flo' => 'application/vnd.micrografx.flo',
'flv' => 'video/x-flv',
'flw' => 'application/vnd.kde.kivio',
'flx' => 'text/vnd.fmi.flexstor',
'fly' => 'text/vnd.fly',
'fm' => 'application/vnd.framemaker',
'fnc' => 'application/vnd.frogans.fnc',
'for' => 'text/x-fortran',
'fpx' => 'image/vnd.fpx',
'frame' => 'application/vnd.framemaker',
'fsc' => 'application/vnd.fsc.weblaunch',
'fst' => 'image/vnd.fst',
'ftc' => 'application/vnd.fluxtime.clip',
'fti' => 'application/vnd.anser-web-funds-transfer-initiation',
'fvt' => 'video/vnd.fvt',
'fxp' => 'application/vnd.adobe.fxp',
'fxpl' => 'application/vnd.adobe.fxp',
'fzs' => 'application/vnd.fuzzysheet',
'g2w' => 'application/vnd.geoplan',
'g3' => 'image/g3fax',
'g3w' => 'application/vnd.geospace',
'gac' => 'application/vnd.groove-account',
'gam' => 'application/x-tads',
'gbr' => 'application/rpki-ghostbusters',
'gca' => 'application/x-gca-compressed',
'gdl' => 'model/vnd.gdl',
'geo' => 'application/vnd.dynageo',
'gex' => 'application/vnd.geometry-explorer',
'ggb' => 'application/vnd.geogebra.file',
'ggt' => 'application/vnd.geogebra.tool',
'ghf' => 'application/vnd.groove-help',
'gif' => 'image/gif',
'gim' => 'application/vnd.groove-identity-message',
'gml' => 'application/gml+xml',
'gmx' => 'application/vnd.gmx',
'gnumeric' => 'application/x-gnumeric',
'gph' => 'application/vnd.flographit',
'gpx' => 'application/gpx+xml',
'gqf' => 'application/vnd.grafeq',
'gqs' => 'application/vnd.grafeq',
'gram' => 'application/srgs',
'gramps' => 'application/x-gramps-xml',
'gre' => 'application/vnd.geometry-explorer',
'grv' => 'application/vnd.groove-injector',
'grxml' => 'application/srgs+xml',
'gsf' => 'application/x-font-ghostscript',
'gtar' => 'application/x-gtar',
'gtm' => 'application/vnd.groove-tool-message',
'gtw' => 'model/vnd.gtw',
'gv' => 'text/vnd.graphviz',
'gxf' => 'application/gxf',
'gxt' => 'application/vnd.geonext',
'gz' => 'application/x-gzip',
'h' => 'text/x-c',
'h261' => 'video/h261',
'h263' => 'video/h263',
'h264' => 'video/h264',
'hal' => 'application/vnd.hal+xml',
'hbci' => 'application/vnd.hbci',
'hdf' => 'application/x-hdf',
'hh' => 'text/x-c',
'hlp' => 'application/winhlp',
'hpgl' => 'application/vnd.hp-hpgl',
'hpid' => 'application/vnd.hp-hpid',
'hps' => 'application/vnd.hp-hps',
'hqx' => 'application/mac-binhex40',
'htke' => 'application/vnd.kenameaapp',
'htm' => 'text/html',
'html' => 'text/html',
'hvd' => 'application/vnd.yamaha.hv-dic',
'hvp' => 'application/vnd.yamaha.hv-voice',
'hvs' => 'application/vnd.yamaha.hv-script',
'i2g' => 'application/vnd.intergeo',
'icc' => 'application/vnd.iccprofile',
'ice' => 'x-conference/x-cooltalk',
'icm' => 'application/vnd.iccprofile',
'ico' => 'image/x-icon',
'ics' => 'text/calendar',
'ief' => 'image/ief',
'ifb' => 'text/calendar',
'ifm' => 'application/vnd.shana.informed.formdata',
'iges' => 'model/iges',
'igl' => 'application/vnd.igloader',
'igm' => 'application/vnd.insors.igm',
'igs' => 'model/iges',
'igx' => 'application/vnd.micrografx.igx',
'iif' => 'application/vnd.shana.informed.interchange',
'imp' => 'application/vnd.accpac.simply.imp',
'ims' => 'application/vnd.ms-ims',
'in' => 'text/plain',
'ink' => 'application/inkml+xml',
'inkml' => 'application/inkml+xml',
'install' => 'application/x-install-instructions',
'iota' => 'application/vnd.astraea-software.iota',
'ipfix' => 'application/ipfix',
'ipk' => 'application/vnd.shana.informed.package',
'irm' => 'application/vnd.ibm.rights-management',
'irp' => 'application/vnd.irepository.package+xml',
'iso' => 'application/x-iso9660-image',
'itp' => 'application/vnd.shana.informed.formtemplate',
'ivp' => 'application/vnd.immervision-ivp',
'ivu' => 'application/vnd.immervision-ivu',
'jad' => 'text/vnd.sun.j2me.app-descriptor',
'jam' => 'application/vnd.jam',
'jar' => 'application/java-archive',
'java' => 'text/x-java-source',
'jisp' => 'application/vnd.jisp',
'jlt' => 'application/vnd.hp-jlyt',
'jnlp' => 'application/x-java-jnlp-file',
'joda' => 'application/vnd.joost.joda-archive',
'jpe' => 'image/jpeg',
'jpeg' => 'image/jpeg',
'jpg' => 'image/jpeg',
'jpgm' => 'video/jpm',
'jpgv' => 'video/jpeg',
'jpm' => 'video/jpm',
'js' => 'application/javascript',
'json' => 'application/json',
'jsonml' => 'application/jsonml+json',
'kar' => 'audio/midi',
'karbon' => 'application/vnd.kde.karbon',
'kfo' => 'application/vnd.kde.kformula',
'kia' => 'application/vnd.kidspiration',
'kml' => 'application/vnd.google-earth.kml+xml',
'kmz' => 'application/vnd.google-earth.kmz',
'kne' => 'application/vnd.kinar',
'knp' => 'application/vnd.kinar',
'kon' => 'application/vnd.kde.kontour',
'kpr' => 'application/vnd.kde.kpresenter',
'kpt' => 'application/vnd.kde.kpresenter',
'kpxx' => 'application/vnd.ds-keypoint',
'ksp' => 'application/vnd.kde.kspread',
'ktr' => 'application/vnd.kahootz',
'ktx' => 'image/ktx',
'ktz' => 'application/vnd.kahootz',
'kwd' => 'application/vnd.kde.kword',
'kwt' => 'application/vnd.kde.kword',
'lasxml' => 'application/vnd.las.las+xml',
'latex' => 'application/x-latex',
'lbd' => 'application/vnd.llamagraphics.life-balance.desktop',
'lbe' => 'application/vnd.llamagraphics.life-balance.exchange+xml',
'les' => 'application/vnd.hhe.lesson-player',
'lha' => 'application/x-lzh-compressed',
'link66' => 'application/vnd.route66.link66+xml',
'list' => 'text/plain',
'list3820' => 'application/vnd.ibm.modcap',
'listafp' => 'application/vnd.ibm.modcap',
'lnk' => 'application/x-ms-shortcut',
'log' => 'text/plain',
'lostxml' => 'application/lost+xml',
'lrf' => 'application/octet-stream',
'lrm' => 'application/vnd.ms-lrm',
'ltf' => 'application/vnd.frogans.ltf',
'lvp' => 'audio/vnd.lucent.voice',
'lwp' => 'application/vnd.lotus-wordpro',
'lzh' => 'application/x-lzh-compressed',
'm13' => 'application/x-msmediaview',
'm14' => 'application/x-msmediaview',
'm1v' => 'video/mpeg',
'm21' => 'application/mp21',
'm2a' => 'audio/mpeg',
'm2v' => 'video/mpeg',
'm3a' => 'audio/mpeg',
'm3u' => 'audio/x-mpegurl',
'm3u8' => 'application/vnd.apple.mpegurl',
'm4a' => 'audio/mp4',
'm4u' => 'video/vnd.mpegurl',
'm4v' => 'video/x-m4v',
'ma' => 'application/mathematica',
'mads' => 'application/mads+xml',
'mag' => 'application/vnd.ecowin.chart',
'maker' => 'application/vnd.framemaker',
'man' => 'text/troff',
'mar' => 'application/octet-stream',
'mathml' => 'application/mathml+xml',
'mb' => 'application/mathematica',
'mbk' => 'application/vnd.mobius.mbk',
'mbox' => 'application/mbox',
'mc1' => 'application/vnd.medcalcdata',
'mcd' => 'application/vnd.mcd',
'mcurl' => 'text/vnd.curl.mcurl',
'mdb' => 'application/x-msaccess',
'mdi' => 'image/vnd.ms-modi',
'me' => 'text/troff',
'mesh' => 'model/mesh',
'meta4' => 'application/metalink4+xml',
'metalink' => 'application/metalink+xml',
'mets' => 'application/mets+xml',
'mfm' => 'application/vnd.mfmp',
'mft' => 'application/rpki-manifest',
'mgp' => 'application/vnd.osgeo.mapguide.package',
'mgz' => 'application/vnd.proteus.magazine',
'mid' => 'audio/midi',
'midi' => 'audio/midi',
'mie' => 'application/x-mie',
'mif' => 'application/vnd.mif',
'mime' => 'message/rfc822',
'mj2' => 'video/mj2',
'mjp2' => 'video/mj2',
'mk3d' => 'video/x-matroska',
'mka' => 'audio/x-matroska',
'mks' => 'video/x-matroska',
'mkv' => 'video/x-matroska',
'mlp' => 'application/vnd.dolby.mlp',
'mmd' => 'application/vnd.chipnuts.karaoke-mmd',
'mmf' => 'application/vnd.smaf',
'mmr' => 'image/vnd.fujixerox.edmics-mmr',
'mng' => 'video/x-mng',
'mny' => 'application/x-msmoney',
'mobi' => 'application/x-mobipocket-ebook',
'mods' => 'application/mods+xml',
'mov' => 'video/quicktime',
'movie' => 'video/x-sgi-movie',
'mp2' => 'audio/mpeg',
'mp21' => 'application/mp21',
'mp2a' => 'audio/mpeg',
'mp3' => 'audio/mpeg',
'mp4' => 'video/mp4',
'mp4a' => 'audio/mp4',
'mp4s' => 'application/mp4',
'mp4v' => 'video/mp4',
'mpc' => 'application/vnd.mophun.certificate',
'mpe' => 'video/mpeg',
'mpeg' => 'video/mpeg',
'mpg' => 'video/mpeg',
'mpg4' => 'video/mp4',
'mpga' => 'audio/mpeg',
'mpkg' => 'application/vnd.apple.installer+xml',
'mpm' => 'application/vnd.blueice.multipass',
'mpn' => 'application/vnd.mophun.application',
'mpp' => 'application/vnd.ms-project',
'mpt' => 'application/vnd.ms-project',
'mpy' => 'application/vnd.ibm.minipay',
'mqy' => 'application/vnd.mobius.mqy',
'mrc' => 'application/marc',
'mrcx' => 'application/marcxml+xml',
'ms' => 'text/troff',
'mscml' => 'application/mediaservercontrol+xml',
'mseed' => 'application/vnd.fdsn.mseed',
'mseq' => 'application/vnd.mseq',
'msf' => 'application/vnd.epson.msf',
'msh' => 'model/mesh',
'msi' => 'application/x-msdownload',
'msl' => 'application/vnd.mobius.msl',
'msty' => 'application/vnd.muvee.style',
'mts' => 'model/vnd.mts',
'mus' => 'application/vnd.musician',
'musicxml' => 'application/vnd.recordare.musicxml+xml',
'mvb' => 'application/x-msmediaview',
'mwf' => 'application/vnd.mfer',
'mxf' => 'application/mxf',
'mxl' => 'application/vnd.recordare.musicxml',
'mxml' => 'application/xv+xml',
'mxs' => 'application/vnd.triscape.mxs',
'mxu' => 'video/vnd.mpegurl',
'n-gage' => 'application/vnd.nokia.n-gage.symbian.install',
'n3' => 'text/n3',
'nb' => 'application/mathematica',
'nbp' => 'application/vnd.wolfram.player',
'nc' => 'application/x-netcdf',
'ncx' => 'application/x-dtbncx+xml',
'nfo' => 'text/x-nfo',
'ngdat' => 'application/vnd.nokia.n-gage.data',
'nitf' => 'application/vnd.nitf',
'nlu' => 'application/vnd.neurolanguage.nlu',
'nml' => 'application/vnd.enliven',
'nnd' => 'application/vnd.noblenet-directory',
'nns' => 'application/vnd.noblenet-sealer',
'nnw' => 'application/vnd.noblenet-web',
'npx' => 'image/vnd.net-fpx',
'nsc' => 'application/x-conference',
'nsf' => 'application/vnd.lotus-notes',
'ntf' => 'application/vnd.nitf',
'nzb' => 'application/x-nzb',
'oa2' => 'application/vnd.fujitsu.oasys2',
'oa3' => 'application/vnd.fujitsu.oasys3',
'oas' => 'application/vnd.fujitsu.oasys',
'obd' => 'application/x-msbinder',
'obj' => 'application/x-tgif',
'oda' => 'application/oda',
'odb' => 'application/vnd.oasis.opendocument.database',
'odc' => 'application/vnd.oasis.opendocument.chart',
'odf' => 'application/vnd.oasis.opendocument.formula',
'odft' => 'application/vnd.oasis.opendocument.formula-template',
'odg' => 'application/vnd.oasis.opendocument.graphics',
'odi' => 'application/vnd.oasis.opendocument.image',
'odm' => 'application/vnd.oasis.opendocument.text-master',
'odp' => 'application/vnd.oasis.opendocument.presentation',
'ods' => 'application/vnd.oasis.opendocument.spreadsheet',
'odt' => 'application/vnd.oasis.opendocument.text',
'oga' => 'audio/ogg',
'ogg' => 'audio/ogg',
'ogv' => 'video/ogg',
'ogx' => 'application/ogg',
'omdoc' => 'application/omdoc+xml',
'onepkg' => 'application/onenote',
'onetmp' => 'application/onenote',
'onetoc' => 'application/onenote',
'onetoc2' => 'application/onenote',
'opf' => 'application/oebps-package+xml',
'opml' => 'text/x-opml',
'oprc' => 'application/vnd.palm',
'org' => 'application/vnd.lotus-organizer',
'osf' => 'application/vnd.yamaha.openscoreformat',
'osfpvg' => 'application/vnd.yamaha.openscoreformat.osfpvg+xml',
'otc' => 'application/vnd.oasis.opendocument.chart-template',
'otf' => 'application/x-font-otf',
'otg' => 'application/vnd.oasis.opendocument.graphics-template',
'oth' => 'application/vnd.oasis.opendocument.text-web',
'oti' => 'application/vnd.oasis.opendocument.image-template',
'otp' => 'application/vnd.oasis.opendocument.presentation-template',
'ots' => 'application/vnd.oasis.opendocument.spreadsheet-template',
'ott' => 'application/vnd.oasis.opendocument.text-template',
'oxps' => 'application/oxps',
'oxt' => 'application/vnd.openofficeorg.extension',
'p' => 'text/x-pascal',
'p10' => 'application/pkcs10',
'p12' => 'application/x-pkcs12',
'p7b' => 'application/x-pkcs7-certificates',
'p7c' => 'application/pkcs7-mime',
'p7m' => 'application/pkcs7-mime',
'p7r' => 'application/x-pkcs7-certreqresp',
'p7s' => 'application/pkcs7-signature',
'p8' => 'application/pkcs8',
'pas' => 'text/x-pascal',
'paw' => 'application/vnd.pawaafile',
'pbd' => 'application/vnd.powerbuilder6',
'pbm' => 'image/x-portable-bitmap',
'pcap' => 'application/vnd.tcpdump.pcap',
'pcf' => 'application/x-font-pcf',
'pcl' => 'application/vnd.hp-pcl',
'pclxl' => 'application/vnd.hp-pclxl',
'pct' => 'image/x-pict',
'pcurl' => 'application/vnd.curl.pcurl',
'pcx' => 'image/x-pcx',
'pdb' => 'application/vnd.palm',
'pdf' => 'application/pdf',
'pfa' => 'application/x-font-type1',
'pfb' => 'application/x-font-type1',
'pfm' => 'application/x-font-type1',
'pfr' => 'application/font-tdpfr',
'pfx' => 'application/x-pkcs12',
'pgm' => 'image/x-portable-graymap',
'pgn' => 'application/x-chess-pgn',
'pgp' => 'application/pgp-encrypted',
'php' => 'application/x-php',
'php3' => 'application/x-php',
'php4' => 'application/x-php',
'php5' => 'application/x-php',
'pic' => 'image/x-pict',
'pkg' => 'application/octet-stream',
'pki' => 'application/pkixcmp',
'pkipath' => 'application/pkix-pkipath',
'plb' => 'application/vnd.3gpp.pic-bw-large',
'plc' => 'application/vnd.mobius.plc',
'plf' => 'application/vnd.pocketlearn',
'pls' => 'application/pls+xml',
'pml' => 'application/vnd.ctc-posml',
'png' => 'image/png',
'pnm' => 'image/x-portable-anymap',
'portpkg' => 'application/vnd.macports.portpkg',
'pot' => 'application/vnd.ms-powerpoint',
'potm' => 'application/vnd.ms-powerpoint.template.macroenabled.12',
'potx' => 'application/vnd.openxmlformats-officedocument.presentationml.template',
'ppam' => 'application/vnd.ms-powerpoint.addin.macroenabled.12',
'ppd' => 'application/vnd.cups-ppd',
'ppm' => 'image/x-portable-pixmap',
'pps' => 'application/vnd.ms-powerpoint',
'ppsm' => 'application/vnd.ms-powerpoint.slideshow.macroenabled.12',
'ppsx' => 'application/vnd.openxmlformats-officedocument.presentationml.slideshow',
'ppt' => 'application/vnd.ms-powerpoint',
'pptm' => 'application/vnd.ms-powerpoint.presentation.macroenabled.12',
'pptx' => 'application/vnd.openxmlformats-officedocument.presentationml.presentation',
'pqa' => 'application/vnd.palm',
'prc' => 'application/x-mobipocket-ebook',
'pre' => 'application/vnd.lotus-freelance',
'prf' => 'application/pics-rules',
'ps' => 'application/postscript',
'psb' => 'application/vnd.3gpp.pic-bw-small',
'psd' => 'image/vnd.adobe.photoshop',
'psf' => 'application/x-font-linux-psf',
'pskcxml' => 'application/pskc+xml',
'ptid' => 'application/vnd.pvi.ptid1',
'pub' => 'application/x-mspublisher',
'pvb' => 'application/vnd.3gpp.pic-bw-var',
'pwn' => 'application/vnd.3m.post-it-notes',
'pya' => 'audio/vnd.ms-playready.media.pya',
'pyv' => 'video/vnd.ms-playready.media.pyv',
'qam' => 'application/vnd.epson.quickanime',
'qbo' => 'application/vnd.intu.qbo',
'qfx' => 'application/vnd.intu.qfx',
'qps' => 'application/vnd.publishare-delta-tree',
'qt' => 'video/quicktime',
'qwd' => 'application/vnd.quark.quarkxpress',
'qwt' => 'application/vnd.quark.quarkxpress',
'qxb' => 'application/vnd.quark.quarkxpress',
'qxd' => 'application/vnd.quark.quarkxpress',
'qxl' => 'application/vnd.quark.quarkxpress',
'qxt' => 'application/vnd.quark.quarkxpress',
'ra' => 'audio/x-pn-realaudio',
'ram' => 'audio/x-pn-realaudio',
'rar' => 'application/x-rar-compressed',
'ras' => 'image/x-cmu-raster',
'rcprofile' => 'application/vnd.ipunplugged.rcprofile',
'rdf' => 'application/rdf+xml',
'rdz' => 'application/vnd.data-vision.rdz',
'rep' => 'application/vnd.businessobjects',
'res' => 'application/x-dtbresource+xml',
'rgb' => 'image/x-rgb',
'rif' => 'application/reginfo+xml',
'rip' => 'audio/vnd.rip',
'ris' => 'application/x-research-info-systems',
'rl' => 'application/resource-lists+xml',
'rlc' => 'image/vnd.fujixerox.edmics-rlc',
'rld' => 'application/resource-lists-diff+xml',
'rm' => 'application/vnd.rn-realmedia',
'rmi' => 'audio/midi',
'rmp' => 'audio/x-pn-realaudio-plugin',
'rms' => 'application/vnd.jcp.javame.midlet-rms',
'rmvb' => 'application/vnd.rn-realmedia-vbr',
'rnc' => 'application/relax-ng-compact-syntax',
'roa' => 'application/rpki-roa',
'roff' => 'text/troff',
'rp9' => 'application/vnd.cloanto.rp9',
'rpss' => 'application/vnd.nokia.radio-presets',
'rpst' => 'application/vnd.nokia.radio-preset',
'rq' => 'application/sparql-query',
'rs' => 'application/rls-services+xml',
'rsd' => 'application/rsd+xml',
'rss' => 'application/rss+xml',
'rtf' => 'application/rtf',
'rtx' => 'text/richtext',
's' => 'text/x-asm',
's3m' => 'audio/s3m',
'saf' => 'application/vnd.yamaha.smaf-audio',
'sbml' => 'application/sbml+xml',
'sc' => 'application/vnd.ibm.secure-container',
'scd' => 'application/x-msschedule',
'scm' => 'application/vnd.lotus-screencam',
'scq' => 'application/scvp-cv-request',
'scs' => 'application/scvp-cv-response',
'scurl' => 'text/vnd.curl.scurl',
'sda' => 'application/vnd.stardivision.draw',
'sdc' => 'application/vnd.stardivision.calc',
'sdd' => 'application/vnd.stardivision.impress',
'sdkd' => 'application/vnd.solent.sdkm+xml',
'sdkm' => 'application/vnd.solent.sdkm+xml',
'sdp' => 'application/sdp',
'sdw' => 'application/vnd.stardivision.writer',
'see' => 'application/vnd.seemail',
'seed' => 'application/vnd.fdsn.seed',
'sema' => 'application/vnd.sema',
'semd' => 'application/vnd.semd',
'semf' => 'application/vnd.semf',
'ser' => 'application/java-serialized-object',
'setpay' => 'application/set-payment-initiation',
'setreg' => 'application/set-registration-initiation',
'sfd-hdstx' => 'application/vnd.hydrostatix.sof-data',
'sfs' => 'application/vnd.spotfire.sfs',
'sfv' => 'text/x-sfv',
'sgi' => 'image/sgi',
'sgl' => 'application/vnd.stardivision.writer-global',
'sgm' => 'text/sgml',
'sgml' => 'text/sgml',
'sh' => 'application/x-sh',
'shar' => 'application/x-shar',
'shf' => 'application/shf+xml',
'sid' => 'image/x-mrsid-image',
'sig' => 'application/pgp-signature',
'sil' => 'audio/silk',
'silo' => 'model/mesh',
'sis' => 'application/vnd.symbian.install',
'sisx' => 'application/vnd.symbian.install',
'sit' => 'application/x-stuffit',
'sitx' => 'application/x-stuffitx',
'skd' => 'application/vnd.koan',
'skm' => 'application/vnd.koan',
'skp' => 'application/vnd.koan',
'skt' => 'application/vnd.koan',
'sldm' => 'application/vnd.ms-powerpoint.slide.macroenabled.12',
'sldx' => 'application/vnd.openxmlformats-officedocument.presentationml.slide',
'slt' => 'application/vnd.epson.salt',
'sm' => 'application/vnd.stepmania.stepchart',
'smf' => 'application/vnd.stardivision.math',
'smi' => 'application/smil+xml',
'smil' => 'application/smil+xml',
'smv' => 'video/x-smv',
'smzip' => 'application/vnd.stepmania.package',
'snd' => 'audio/basic',
'snf' => 'application/x-font-snf',
'so' => 'application/octet-stream',
'spc' => 'application/x-pkcs7-certificates',
'spf' => 'application/vnd.yamaha.smaf-phrase',
'spl' => 'application/x-futuresplash',
'spot' => 'text/vnd.in3d.spot',
'spp' => 'application/scvp-vp-response',
'spq' => 'application/scvp-vp-request',
'spx' => 'audio/ogg',
'sql' => 'application/x-sql',
'src' => 'application/x-wais-source',
'srt' => 'application/x-subrip',
'sru' => 'application/sru+xml',
'srx' => 'application/sparql-results+xml',
'ssdl' => 'application/ssdl+xml',
'sse' => 'application/vnd.kodak-descriptor',
'ssf' => 'application/vnd.epson.ssf',
'ssml' => 'application/ssml+xml',
'st' => 'application/vnd.sailingtracker.track',
'stc' => 'application/vnd.sun.xml.calc.template',
'std' => 'application/vnd.sun.xml.draw.template',
'stf' => 'application/vnd.wt.stf',
'sti' => 'application/vnd.sun.xml.impress.template',
'stk' => 'application/hyperstudio',
'stl' => 'application/vnd.ms-pki.stl',
'str' => 'application/vnd.pg.format',
'stw' => 'application/vnd.sun.xml.writer.template',
'sub' => 'text/vnd.dvb.subtitle',
'sus' => 'application/vnd.sus-calendar',
'susp' => 'application/vnd.sus-calendar',
'sv4cpio' => 'application/x-sv4cpio',
'sv4crc' => 'application/x-sv4crc',
'svc' => 'application/vnd.dvb.service',
'svd' => 'application/vnd.svd',
'svg' => 'image/svg+xml',
'svgz' => 'image/svg+xml',
'swa' => 'application/x-director',
'swf' => 'application/x-shockwave-flash',
'swi' => 'application/vnd.aristanetworks.swi',
'sxc' => 'application/vnd.sun.xml.calc',
'sxd' => 'application/vnd.sun.xml.draw',
'sxg' => 'application/vnd.sun.xml.writer.global',
'sxi' => 'application/vnd.sun.xml.impress',
'sxm' => 'application/vnd.sun.xml.math',
'sxw' => 'application/vnd.sun.xml.writer',
't' => 'text/troff',
't3' => 'application/x-t3vm-image',
'taglet' => 'application/vnd.mynfc',
'tao' => 'application/vnd.tao.intent-module-archive',
'tar' => 'application/x-tar',
'tcap' => 'application/vnd.3gpp2.tcap',
'tcl' => 'application/x-tcl',
'teacher' => 'application/vnd.smart.teacher',
'tei' => 'application/tei+xml',
'teicorpus' => 'application/tei+xml',
'tex' => 'application/x-tex',
'texi' => 'application/x-texinfo',
'texinfo' => 'application/x-texinfo',
'text' => 'text/plain',
'tfi' => 'application/thraud+xml',
'tfm' => 'application/x-tex-tfm',
'tga' => 'image/x-tga',
'thmx' => 'application/vnd.ms-officetheme',
'tif' => 'image/tiff',
'tiff' => 'image/tiff',
'tmo' => 'application/vnd.tmobile-livetv',
'torrent' => 'application/x-bittorrent',
'tpl' => 'application/vnd.groove-tool-template',
'tpt' => 'application/vnd.trid.tpt',
'tr' => 'text/troff',
'tra' => 'application/vnd.trueapp',
'trm' => 'application/x-msterminal',
'tsd' => 'application/timestamped-data',
'tsv' => 'text/tab-separated-values',
'ttc' => 'application/x-font-ttf',
'ttf' => 'application/x-font-ttf',
'ttl' => 'text/turtle',
'twd' => 'application/vnd.simtech-mindmapper',
'twds' => 'application/vnd.simtech-mindmapper',
'txd' => 'application/vnd.genomatix.tuxedo',
'txf' => 'application/vnd.mobius.txf',
'txt' => 'text/plain',
'u32' => 'application/x-authorware-bin',
'udeb' => 'application/x-debian-package',
'ufd' => 'application/vnd.ufdl',
'ufdl' => 'application/vnd.ufdl',
'ulx' => 'application/x-glulx',
'umj' => 'application/vnd.umajin',
'unityweb' => 'application/vnd.unity',
'uoml' => 'application/vnd.uoml+xml',
'uri' => 'text/uri-list',
'uris' => 'text/uri-list',
'urls' => 'text/uri-list',
'ustar' => 'application/x-ustar',
'utz' => 'application/vnd.uiq.theme',
'uu' => 'text/x-uuencode',
'uva' => 'audio/vnd.dece.audio',
'uvd' => 'application/vnd.dece.data',
'uvf' => 'application/vnd.dece.data',
'uvg' => 'image/vnd.dece.graphic',
'uvh' => 'video/vnd.dece.hd',
'uvi' => 'image/vnd.dece.graphic',
'uvm' => 'video/vnd.dece.mobile',
'uvp' => 'video/vnd.dece.pd',
'uvs' => 'video/vnd.dece.sd',
'uvt' => 'application/vnd.dece.ttml+xml',
'uvu' => 'video/vnd.uvvu.mp4',
'uvv' => 'video/vnd.dece.video',
'uvva' => 'audio/vnd.dece.audio',
'uvvd' => 'application/vnd.dece.data',
'uvvf' => 'application/vnd.dece.data',
'uvvg' => 'image/vnd.dece.graphic',
'uvvh' => 'video/vnd.dece.hd',
'uvvi' => 'image/vnd.dece.graphic',
'uvvm' => 'video/vnd.dece.mobile',
'uvvp' => 'video/vnd.dece.pd',
'uvvs' => 'video/vnd.dece.sd',
'uvvt' => 'application/vnd.dece.ttml+xml',
'uvvu' => 'video/vnd.uvvu.mp4',
'uvvv' => 'video/vnd.dece.video',
'uvvx' => 'application/vnd.dece.unspecified',
'uvvz' => 'application/vnd.dece.zip',
'uvx' => 'application/vnd.dece.unspecified',
'uvz' => 'application/vnd.dece.zip',
'vcard' => 'text/vcard',
'vcd' => 'application/x-cdlink',
'vcf' => 'text/x-vcard',
'vcg' => 'application/vnd.groove-vcard',
'vcs' => 'text/x-vcalendar',
'vcx' => 'application/vnd.vcx',
'vis' => 'application/vnd.visionary',
'viv' => 'video/vnd.vivo',
'vob' => 'video/x-ms-vob',
'vor' => 'application/vnd.stardivision.writer',
'vox' => 'application/x-authorware-bin',
'vrml' => 'model/vrml',
'vsd' => 'application/vnd.visio',
'vsf' => 'application/vnd.vsf',
'vss' => 'application/vnd.visio',
'vst' => 'application/vnd.visio',
'vsw' => 'application/vnd.visio',
'vtu' => 'model/vnd.vtu',
'vxml' => 'application/voicexml+xml',
'w3d' => 'application/x-director',
'wad' => 'application/x-doom',
'wav' => 'audio/x-wav',
'wax' => 'audio/x-ms-wax',
'wbmp' => 'image/vnd.wap.wbmp',
'wbs' => 'application/vnd.criticaltools.wbs+xml',
'wbxml' => 'application/vnd.wap.wbxml',
'wcm' => 'application/vnd.ms-works',
'wdb' => 'application/vnd.ms-works',
'wdp' => 'image/vnd.ms-photo',
'weba' => 'audio/webm',
'webm' => 'video/webm',
'webp' => 'image/webp',
'wg' => 'application/vnd.pmi.widget',
'wgt' => 'application/widget',
'wks' => 'application/vnd.ms-works',
'wm' => 'video/x-ms-wm',
'wma' => 'audio/x-ms-wma',
'wmd' => 'application/x-ms-wmd',
'wmf' => 'application/x-msmetafile',
'wml' => 'text/vnd.wap.wml',
'wmlc' => 'application/vnd.wap.wmlc',
'wmls' => 'text/vnd.wap.wmlscript',
'wmlsc' => 'application/vnd.wap.wmlscriptc',
'wmv' => 'video/x-ms-wmv',
'wmx' => 'video/x-ms-wmx',
'wmz' => 'application/x-msmetafile',
'woff' => 'application/font-woff',
'wpd' => 'application/vnd.wordperfect',
'wpl' => 'application/vnd.ms-wpl',
'wps' => 'application/vnd.ms-works',
'wqd' => 'application/vnd.wqd',
'wri' => 'application/x-mswrite',
'wrl' => 'model/vrml',
'wsdl' => 'application/wsdl+xml',
'wspolicy' => 'application/wspolicy+xml',
'wtb' => 'application/vnd.webturbo',
'wvx' => 'video/x-ms-wvx',
'x32' => 'application/x-authorware-bin',
'x3d' => 'model/x3d+xml',
'x3db' => 'model/x3d+binary',
'x3dbz' => 'model/x3d+binary',
'x3dv' => 'model/x3d+vrml',
'x3dvz' => 'model/x3d+vrml',
'x3dz' => 'model/x3d+xml',
'xaml' => 'application/xaml+xml',
'xap' => 'application/x-silverlight-app',
'xar' => 'application/vnd.xara',
'xbap' => 'application/x-ms-xbap',
'xbd' => 'application/vnd.fujixerox.docuworks.binder',
'xbm' => 'image/x-xbitmap',
'xdf' => 'application/xcap-diff+xml',
'xdm' => 'application/vnd.syncml.dm+xml',
'xdp' => 'application/vnd.adobe.xdp+xml',
'xdssc' => 'application/dssc+xml',
'xdw' => 'application/vnd.fujixerox.docuworks',
'xenc' => 'application/xenc+xml',
'xer' => 'application/patch-ops-error+xml',
'xfdf' => 'application/vnd.adobe.xfdf',
'xfdl' => 'application/vnd.xfdl',
'xht' => 'application/xhtml+xml',
'xhtml' => 'application/xhtml+xml',
'xhvml' => 'application/xv+xml',
'xif' => 'image/vnd.xiff',
'xla' => 'application/vnd.ms-excel',
'xlam' => 'application/vnd.ms-excel.addin.macroenabled.12',
'xlc' => 'application/vnd.ms-excel',
'xlf' => 'application/x-xliff+xml',
'xlm' => 'application/vnd.ms-excel',
'xls' => 'application/vnd.ms-excel',
'xlsb' => 'application/vnd.ms-excel.sheet.binary.macroenabled.12',
'xlsm' => 'application/vnd.ms-excel.sheet.macroenabled.12',
'xlsx' => 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
'xlt' => 'application/vnd.ms-excel',
'xltm' => 'application/vnd.ms-excel.template.macroenabled.12',
'xltx' => 'application/vnd.openxmlformats-officedocument.spreadsheetml.template',
'xlw' => 'application/vnd.ms-excel',
'xm' => 'audio/xm',
'xml' => 'application/xml',
'xo' => 'application/vnd.olpc-sugar',
'xop' => 'application/xop+xml',
'xpi' => 'application/x-xpinstall',
'xpl' => 'application/xproc+xml',
'xpm' => 'image/x-xpixmap',
'xpr' => 'application/vnd.is-xpr',
'xps' => 'application/vnd.ms-xpsdocument',
'xpw' => 'application/vnd.intercon.formnet',
'xpx' => 'application/vnd.intercon.formnet',
'xsl' => 'application/xml',
'xslt' => 'application/xslt+xml',
'xsm' => 'application/vnd.syncml+xml',
'xspf' => 'application/xspf+xml',
'xul' => 'application/vnd.mozilla.xul+xml',
'xvm' => 'application/xv+xml',
'xvml' => 'application/xv+xml',
'xwd' => 'image/x-xwindowdump',
'xyz' => 'chemical/x-xyz',
'xz' => 'application/x-xz',
'yang' => 'application/yang',
'yin' => 'application/yin+xml',
'z1' => 'application/x-zmachine',
'z2' => 'application/x-zmachine',
'z3' => 'application/x-zmachine',
'z4' => 'application/x-zmachine',
'z5' => 'application/x-zmachine',
'z6' => 'application/x-zmachine',
'z7' => 'application/x-zmachine',
'z8' => 'application/x-zmachine',
'zaz' => 'application/vnd.zzazz.deck+xml',
'zip' => 'application/zip',
'zir' => 'application/vnd.zul',
'zirz' => 'application/vnd.zul',
'zmm' => 'application/vnd.handheld-entertainment+xml',
'123' => 'application/vnd.lotus-1-2-3',
);
<?php
/****************************************************************************/
/* */
/* YOU MAY WISH TO MODIFY OR REMOVE THE FOLLOWING LINES WHICH SET DEFAULTS */
/* */
/****************************************************************************/
$preferences = Swift_Preferences::getInstance();
// Sets the default charset so that setCharset() is not needed elsewhere
$preferences->setCharset('utf-8');
// Without these lines the default caching mechanism is "array" but this uses a lot of memory.
// If possible, use a disk cache to enable attaching large attachments etc.
// You can override the default temporary directory by setting the TMPDIR environment variable.
if (@is_writable($tmpDir = sys_get_temp_dir())) {
$preferences->setTempDir($tmpDir)->setCacheType('disk');
}
// this should only be done when Swiftmailer won't use the native QP content encoder
// see mime_deps.php
if (PHP_VERSION_ID < 50407) {
$preferences->setQPDotEscape(false);
}
<?php
/*
* This file is part of SwiftMailer.
* (c) 2004-2009 Chris Corbyn
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
/*
* Dependency injection initialization for Swift Mailer.
*/
if (defined('SWIFT_INIT_LOADED')) {
return;
}
define('SWIFT_INIT_LOADED', true);
// Load in dependency maps
require __DIR__.'/dependency_maps/cache_deps.php';
require __DIR__.'/dependency_maps/mime_deps.php';
require __DIR__.'/dependency_maps/message_deps.php';
require __DIR__.'/dependency_maps/transport_deps.php';
// Load in global library preferences
require __DIR__.'/preferences.php';
<?php
/*
* This file is part of SwiftMailer.
* (c) 2004-2009 Chris Corbyn
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
/*
* Autoloader and dependency injection initialization for Swift Mailer.
*/
if (class_exists('Swift', false)) {
return;
}
// Load Swift utility class
require __DIR__.'/classes/Swift.php';
if (!function_exists('_swiftmailer_init')) {
function _swiftmailer_init()
{
require __DIR__.'/swift_init.php';
}
}
// Start the autoloader and lazy-load the init script to set up dependency injection
Swift::registerAutoload('_swiftmailer_init');
<?php
/*
* This file is part of SwiftMailer.
* (c) 2004-2009 Chris Corbyn
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
/*
* Autoloader and dependency injection initialization for Swift Mailer.
*/
if (class_exists('Swift', false)) {
return;
}
// Load Swift utility class
require __DIR__.'/Swift.php';
if (!function_exists('_swiftmailer_init')) {
function _swiftmailer_init()
{
require __DIR__.'/swift_init.php';
}
}
// Start the autoloader and lazy-load the init script to set up dependency injection
Swift::registerAutoload('_swiftmailer_init');
#!/usr/bin/php
<?php
define('APACHE_MIME_TYPES_URL', 'http://svn.apache.org/repos/asf/httpd/httpd/trunk/docs/conf/mime.types');
define('FREEDESKTOP_XML_URL', 'https://raw2.github.com/minad/mimemagic/master/script/freedesktop.org.xml');
function generateUpToDateMimeArray()
{
$preamble = "<?php\n\n";
$preamble .= "/*\n";
$preamble .= " * This file is part of SwiftMailer.\n";
$preamble .= " * (c) 2004-2009 Chris Corbyn\n *\n";
$preamble .= " * For the full copyright and license information, please view the LICENSE\n";
$preamble .= " * file that was distributed with this source code.\n *\n";
$preamble .= " * autogenerated using http://svn.apache.org/repos/asf/httpd/httpd/trunk/docs/conf/mime.types\n";
$preamble .= " * and https://raw.github.com/minad/mimemagic/master/script/freedesktop.org.xml\n";
$preamble .= " */\n\n";
$preamble .= "/*\n";
$preamble .= " * List of MIME type automatically detected in Swift Mailer.\n";
$preamble .= " */\n\n";
$preamble .= "// You may add or take away what you like (lowercase required)\n\n";
// get current mime types files
$mime_types = @file_get_contents(APACHE_MIME_TYPES_URL);
$mime_xml = @file_get_contents(FREEDESKTOP_XML_URL);
// prepare valid mime types
$valid_mime_types = array();
// split mime type and extensions eg. "video/x-matroska mkv mk3d mks"
if (preg_match_all('/^#?([a-z0-9\-\+\/\.]+)[\t]+(.*)$/miu', $mime_types, $matches) !== false) {
// collection of predefined mimetypes (bugfix for wrong resolved or missing mime types)
$valid_mime_types_preset = array(
'php' => 'application/x-php',
'php3' => 'application/x-php',
'php4' => 'application/x-php',
'php5' => 'application/x-php',
'zip' => 'application/zip',
'gif' => 'image/gif',
'png' => 'image/png',
'css' => 'text/css',
'js' => 'text/javascript',
'txt' => 'text/plain',
'aif' => 'audio/x-aiff',
'aiff' => 'audio/x-aiff',
'avi' => 'video/avi',
'bmp' => 'image/bmp',
'bz2' => 'application/x-bz2',
'csv' => 'text/csv',
'dmg' => 'application/x-apple-diskimage',
'doc' => 'application/msword',
'docx' => 'application/vnd.openxmlformats-officedocument.wordprocessingml.document',
'eml' => 'message/rfc822',
'aps' => 'application/postscript',
'exe' => 'application/x-ms-dos-executable',
'flv' => 'video/x-flv',
'gz' => 'application/x-gzip',
'hqx' => 'application/stuffit',
'htm' => 'text/html',
'html' => 'text/html',
'jar' => 'application/x-java-archive',
'jpeg' => 'image/jpeg',
'jpg' => 'image/jpeg',
'm3u' => 'audio/x-mpegurl',
'm4a' => 'audio/mp4',
'mdb' => 'application/x-msaccess',
'mid' => 'audio/midi',
'midi' => 'audio/midi',
'mov' => 'video/quicktime',
'mp3' => 'audio/mpeg',
'mp4' => 'video/mp4',
'mpeg' => 'video/mpeg',
'mpg' => 'video/mpeg',
'odg' => 'vnd.oasis.opendocument.graphics',
'odp' => 'vnd.oasis.opendocument.presentation',
'odt' => 'vnd.oasis.opendocument.text',
'ods' => 'vnd.oasis.opendocument.spreadsheet',
'ogg' => 'audio/ogg',
'pdf' => 'application/pdf',
'ppt' => 'application/vnd.ms-powerpoint',
'pptx' => 'application/vnd.openxmlformats-officedocument.presentationml.presentation',
'ps' => 'application/postscript',
'rar' => 'application/x-rar-compressed',
'rtf' => 'application/rtf',
'tar' => 'application/x-tar',
'sit' => 'application/x-stuffit',
'svg' => 'image/svg+xml',
'tif' => 'image/tiff',
'tiff' => 'image/tiff',
'ttf' => 'application/x-font-truetype',
'vcf' => 'text/x-vcard',
'wav' => 'audio/wav',
'wma' => 'audio/x-ms-wma',
'wmv' => 'audio/x-ms-wmv',
'xls' => 'application/excel',
'xlsx' => 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
'xml' => 'application/xml',
);
// wrap array for generating file
foreach ($valid_mime_types_preset as $extension => $mime_type) {
// generate array for mimetype to extension resolver (only first match)
$valid_mime_types[$extension] = "'{$extension}' => '{$mime_type}'";
}
// collect extensions
$valid_extensions = array();
// all extensions from second match
foreach ($matches[2] as $i => $extensions) {
// explode multiple extensions from string
$extensions = explode(' ', strtolower($extensions));
// force array for foreach
if (!is_array($extensions)) {
$extensions = array($extensions);
}
foreach ($extensions as $extension) {
// get mime type
$mime_type = $matches[1][$i];
// check if string length lower than 10
if (strlen($extension) < 10) {
// add extension
$valid_extensions[] = $extension;
if (!isset($valid_mime_types[$mime_type])) {
// generate array for mimetype to extension resolver (only first match)
$valid_mime_types[$extension] = "'{$extension}' => '{$mime_type}'";
}
}
}
}
}
$xml = simplexml_load_string($mime_xml);
foreach ($xml as $node) {
// check if there is no pattern
if (!isset($node->glob['pattern'])) {
continue;
}
// get all matching extensions from match
foreach ((array) $node->glob['pattern'] as $extension) {
// skip none glob extensions
if (strpos($extension, '.') === false) {
continue;
}
// remove get only last part
$extension = explode('.', strtolower($extension));
$extension = end($extension);
// maximum length in database column
if (strlen($extension) <= 9) {
$valid_extensions[] = $extension;
}
}
if (isset($node->glob['pattern'][0])) {
// mime type
$mime_type = strtolower((string) $node['type']);
// get first extension
$extension = strtolower(trim($node->glob['ddpattern'][0], '*.'));
// skip none glob extensions and check if string length between 1 and 10
if (strpos($extension, '.') !== false || strlen($extension) < 1 || strlen($extension) > 9) {
continue;
}
// check if string length lower than 10
if (!isset($valid_mime_types[$mime_type])) {
// generate array for mimetype to extension resolver (only first match)
$valid_mime_types[$extension] = "'{$extension}' => '{$mime_type}'";
}
}
}
// full list of valid extensions only
$valid_mime_types = array_unique($valid_mime_types);
ksort($valid_mime_types);
// combine mime types and extensions array
$output = "$preamble\$swift_mime_types = array(\n ".implode($valid_mime_types, ",\n ")."\n);";
// write mime_types.php config file
@file_put_contents('./mime_types.php', $output);
}
generateUpToDateMimeArray();
<?xml version="1.0" encoding="UTF-8"?>
<phpunit backupGlobals="false"
backupStaticAttributes="false"
colors="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
processIsolation="false"
stopOnFailure="false"
syntaxCheck="false"
bootstrap="tests/bootstrap.php"
>
<php>
<ini name="intl.default_locale" value="en"/>
<ini name="intl.error_level" value="0"/>
<ini name="memory_limit" value="-1"/>
<ini name="error_reporting" value="-1" />
</php>
<testsuites>
<testsuite name="SwiftMailer unit tests">
<directory>tests/unit</directory>
</testsuite>
<testsuite name="SwiftMailer acceptance tests">
<directory>tests/acceptance</directory>
</testsuite>
<testsuite name="SwiftMailer bug">
<directory>tests/bug</directory>
</testsuite>
<testsuite name="SwiftMailer smoke tests">
<directory>tests/smoke</directory>
</testsuite>
</testsuites>
<listeners>
<listener class="Symfony\Bridge\PhpUnit\SymfonyTestsListener" />
<listener class="Mockery\Adapter\Phpunit\TestListener" />
</listeners>
</phpunit>
<?php
/**
* A binary safe string comparison.
*
* @author Chris Corbyn
*/
class IdenticalBinaryConstraint extends \PHPUnit_Framework_Constraint
{
protected $value;
public function __construct($value)
{
$this->value = $value;
}
/**
* Evaluates the constraint for parameter $other. Returns TRUE if the
* constraint is met, FALSE otherwise.
*
* @param mixed $other Value or object to evaluate.
*
* @return bool
*/
public function matches($other)
{
$aHex = $this->asHexString($this->value);
$bHex = $this->asHexString($other);
return $aHex === $bHex;
}
/**
* Returns a string representation of the constraint.
*
* @return string
*/
public function toString()
{
return 'indentical binary';
}
/**
* Get the given string of bytes as a stirng of Hexadecimal sequences.
*
* @param string $binary
*
* @return string
*/
private function asHexString($binary)
{
$hex = '';
$bytes = unpack('H*', $binary);
foreach ($bytes as &$byte) {
$byte = strtoupper($byte);
}
return implode('', $bytes);
}
}
<?php
class Swift_StreamCollector
{
public $content = '';
public function __invoke($arg)
{
$this->content .= $arg;
}
}
<?php
/**
* Base test for smoke tests.
*
* @author Rouven Weßling
*/
class SwiftMailerSmokeTestCase extends SwiftMailerTestCase
{
protected function setUp()
{
if (!defined('SWIFT_SMOKE_TRANSPORT_TYPE')) {
$this->markTestSkipped(
'Smoke tests are skipped if tests/smoke.conf.php is not edited'
);
}
}
protected function _getMailer()
{
switch (SWIFT_SMOKE_TRANSPORT_TYPE) {
case 'smtp':
$transport = Swift_DependencyContainer::getInstance()->lookup('transport.smtp')
->setHost(SWIFT_SMOKE_SMTP_HOST)
->setPort(SWIFT_SMOKE_SMTP_PORT)
->setUsername(SWIFT_SMOKE_SMTP_USER)
->setPassword(SWIFT_SMOKE_SMTP_PASS)
->setEncryption(SWIFT_SMOKE_SMTP_ENCRYPTION)
;
break;
case 'sendmail':
$transport = Swift_DependencyContainer::getInstance()->lookup('transport.sendmail')
->setCommand(SWIFT_SMOKE_SENDMAIL_COMMAND)
;
break;
case 'mail':
case 'nativemail':
$transport = Swift_DependencyContainer::getInstance()->lookup('transport.mail');
break;
default:
throw new Exception('Undefined transport ['.SWIFT_SMOKE_TRANSPORT_TYPE.']');
}
return new Swift_Mailer($transport);
}
}
<?php
/**
* A base test case with some custom expectations.
*
* @author Rouven Weßling
*/
class SwiftMailerTestCase extends \PHPUnit_Framework_TestCase
{
public static function regExp($pattern)
{
if (!is_string($pattern)) {
throw PHPUnit_Util_InvalidArgumentHelper::factory(1, 'string');
}
return new PHPUnit_Framework_Constraint_PCREMatch($pattern);
}
public function assertIdenticalBinary($expected, $actual, $message = '')
{
$constraint = new IdenticalBinaryConstraint($expected);
self::assertThat($actual, $constraint, $message);
}
protected function tearDown()
{
\Mockery::close();
}
protected function getMockery($class)
{
return \Mockery::mock($class);
}
}
ISO-2022-JPは、インターネット上(特に電子メール)などで使われる日本の文字用の文字符号化方式。ISO/IEC 2022のエスケープシーケンスを利用して文字集合を切り替える7ビットのコードであることを特徴とする (アナウンス機能のエスケープシーケンスは省略される)。俗に「JISコード」と呼ばれることもある。
概要
日本語表記への利用が想定されている文字コードであり、日本語の利用されるネットワークにおいて、日本の規格を応用したものである。また文字集合としては、日本語で用いられる漢字、ひらがな、カタカナはもちろん、ラテン文字、ギリシア文字、キリル文字なども含んでおり、学術や産業の分野での利用も考慮たものとなっている。規格名に、ISOの日本語の言語コードであるjaではなく、国・地域名コードのJPが示されているゆえんである。
文字集合としてJIS X 0201のC0集合(制御文字)、JIS X 0201のラテン文字集合、ISO 646の国際基準版図形文字、JIS X 0208の1978年版(JIS C 6226-1978)と1983年および1990年版が利用できる。JIS X 0201の片仮名文字集合は利用できない。1986年以降、日本の電子メールで用いられてきたJUNETコードを、村井純・Mark Crispin・Erik van der Poelが1993年にRFC化したもの(RFC 1468)。後にJIS X 0208:1997の附属書2としてJISに規定された。MIMEにおける文字符号化方式の識別用の名前として IANA に登録されている。
なお、符号化の仕様についてはISO/IEC 2022#ISO-2022-JPも参照。
ISO-2022-JPと非標準的拡張使用
「JISコード」(または「ISO-2022-JP」)というコード名の規定下では、その仕様通りの使用が求められる。しかし、Windows OS上では、実際にはCP932コード (MicrosoftによるShift JISを拡張した亜種。ISO-2022-JP規定外文字が追加されている。)による独自拡張(の文字)を断りなく使うアプリケーションが多い。この例としてInternet ExplorerやOutlook Expressがある。また、EmEditor、秀丸エディタやThunderbirdのようなMicrosoft社以外のWindowsアプリケーションでも同様の場合がある。この場合、ISO-2022-JPの範囲外の文字を使ってしまうと、異なる製品間では未定義不明文字として認識されるか、もしくは文字化けを起こす原因となる。そのため、Windows用の電子メールクライアントであっても独自拡張の文字を使用すると警告を出したり、あえて使えないように制限しているものも存在する。さらにはISO-2022-JPの範囲内であってもCP932は非標準文字(FULLWIDTH TILDE等)を持つので文字化けの原因になり得る。
また、符号化方式名をISO-2022-JPとしているのに、文字集合としてはJIS X 0212 (いわゆる補助漢字) やJIS X 0201の片仮名文字集合 (いわゆる半角カナ) をも符号化している例があるが、ISO-2022-JPではこれらの文字を許容していない。これらの符号化は独自拡張の実装であり、中にはISO/IEC 2022の仕様に準拠すらしていないものもある[2]。従って受信側の電子メールクライアントがこれらの独自拡張に対応していない場合、その文字あるいはその文字を含む行、時にはテキスト全体が文字化けすることがある。
Op mat eraus hinnen beschte, rou zënne schaddreg ké. Ké sin Eisen Kaffi prächteg, den haut esou Fielse wa, Well zielen d'Welt am dir. Aus grousse rëschten d'Stroos do, as dat Kléder gewëss d'Kàchen. Schied gehéiert d'Vioule net hu, rou ke zënter Säiten d'Hierz. Ze eise Fletschen mat, gei as gréng d'Lëtzebuerger. Wäit räich no mat.
Säiten d'Liewen aus en. Un gëtt bléit lossen wee, da wéi alle weisen Kolrettchen. Et deser d'Pan d'Kirmes vun, en wuel Benn rëschten méi. En get drem ménger beschte, da wär Stad welle. Nun Dach d'Pied do, mä gét ruffen gehéiert. Ze onser ugedon fir, d'Liewen Plett'len ech no, si Räis wielen bereet wat. Iwer spilt fir jo.
An hin däischter Margréitchen, eng ke Frot brommt, vu den Räis néierens. Da hir Hunn Frot nozegon, rout Fläiß Himmel zum si, net gutt Kaffi Gesträich fu. Vill lait Gaart sou wa, Land Mamm Schuebersonndeg rei do. Gei geet Minutt en, gei d'Leit beschte Kolrettchen et, Mamm fergiess un hun.
Et gutt Heck kommen oft, Lann rëscht rei um, Hunn rëscht schéinste ke der. En lait zielen schnéiwäiss hir, fu rou botze éiweg Minutt, rem fest gudden schaddreg en. Noper bereet Margréitchen mat op, dem denkt d'Leit d'Vioule no, oft ké Himmel Hämmel. En denkt blénken Fréijor net, Gart Schiet d'Natur no wou. No hin Ierd Frot d'Kirmes. Hire aremt un rou, ké den éiweg wielen Milliounen.
Mir si Hunn Blénkeg. Ké get ston derfir d'Kàchen. Haut d'Pan fu ons, dé frou löschteg d'Meereische rei. Sou op wuel Léift. Stret schlon grousse gin hu. Mä denkt d'Leit hinnen net, ké gét haut fort rëscht.
Koum d'Pan hannendrun ass ké, ké den brét Kaffi geplot. Schéi Hären d'Pied fu gét, do d'Mier néierens bei. Rëm päift Hämmel am, wee Engel beschéngt mä. Brommt klinzecht der ke, wa rout jeitzt dén. Get Zalot d'Vioule däischter da, jo fir Bänk päift duerch, bei d'Beem schéinen Plett'len jo. Den haut Faarwen ze, eng en Biereg Kirmesdag, um sin alles Faarwen d'Vioule.
Eng Hunn Schied et, wat wa Frot fest gebotzt. Bei jo bleiwe ruffen Klarinett. Un Feld klinzecht gét, rifft Margréitchen rem ke. Mir dé Noper duurch gewëss, ston sech kille sin en. Gei Stret d'Wise um, Haus Gart wee as. Monn ménger an blo, wat da Gart gefällt Hämmelsbrot.
Brommt geplot och ze, dat wa Räis Well Kaffi. Do get spilt prächteg, as wär kille bleiwe gewalteg. Onser frësch Margréitchen rem ke, blo en huet ugedon. Onser Hemecht wär de, hu eraus d'Sonn dat, eise deser hannendrun da och.
As durch Himmel hun, no fest iw'rem schéinste mir, Hunn séngt Hierz ke zum. Séngt iw'rem d'Natur zum an. Ke wär gutt Grénge. Kënnt gudden prächteg mä rei. Dé dir Blénkeg Klarinett Kolrettchen, da fort muerges d'Kanner wou, main Feld ruffen vu wéi. Da gin esou Zalot gewalteg, gét vill Hemecht blénken dé.
Haut gréng nun et, nei vu Bass gréng d'Gaassen. Fest d'Beem uechter si gin. Oft vu sinn wellen kréien. Et ass lait Zalot schéinen.
\ No newline at end of file
Код одно гринспана руководишь на. Его вы знания движение. Ты две начать
одиночку, сказать основатель удовольствием но миф. Бы какие система тем.
Полностью использует три мы, человек клоунов те нас, бы давать творческую
эзотерическая шеф.
Мог не помнить никакого сэкономленного, две либо какие пишите бы. Должен
компанию кто те, этот заключалась проектировщик не ты. Глупые периоды ты
для. Вам который хороший он. Те любых кремния концентрируются мог,
собирать принадлежите без вы.
Джоэла меньше хорошего вы миф, за тем году разработки. Даже управляющим
руководители был не. Три коде выпускать заботиться ну. То его система
удовольствием безостановочно, или ты главной процессорах. Мы без джоэл
знания получат, статьи остальные мы ещё.
Них русском касается поскольку по, образование должником
систематизированный ну мои. Прийти кандидата университет но нас, для бы
должны никакого, биг многие причин интервьюирования за.
Тем до плиту почему. Вот учёт такие одного бы, об биг разным внешних
промежуток. Вас до какому возможностей безответственный, были погодите бы
его, по них глупые долгий количества.
Αν ήδη διάβασε γλιτώσει μεταγλωτίσει, αυτήν θυμάμαι μου μα. Την κατάσταση χρησιμοποίησέ να! Τα διαφορά φαινόμενο διολισθήσεις πες, υψηλότερη προκαλείς περισσότερες όχι κι. Με ελέγχου γίνεται σας, μικρής δημιουργούν τη του. Τις τα γράψει εικόνες απαράδεκτη?
Να ότι πρώτοι απαραίτητο. Άμεση πετάνε κακόκεφος τον ώς, να χώρου πιθανότητες του. Το μέχρι ορίστε λιγότερους σας. Πω ναί φυσικά εικόνες.
Μου οι κώδικα αποκλειστικούς, λες το μάλλον συνεχώς. Νέου σημεία απίστευτα σας μα. Χρόνου μεταγλωτιστής σε νέα, τη τις πιάνει μπορούσες προγραμματιστές. Των κάνε βγαίνει εντυπωσιακό τα? Κρατάει τεσσαρών δυστυχώς της κι, ήδη υψηλότερη εξακολουθεί τα?
Ώρα πετάνε μπορούσε λιγότερους αν, τα απαράδεκτη συγχωνευτεί ροή. Τη έγραψες συνηθίζουν σαν. Όλα με υλικό στήλες χειρότερα. Ανώδυνη δουλέψει επί ως, αν διαδίκτυο εσωτερικών παράγοντες από. Κεντρικό επιτυχία πες το.
Πω ναι λέει τελειώσει, έξι ως έργων τελειώσει. Με αρχεία βουτήξουν ανταγωνιστής ώρα, πολύ γραφικά σελίδων τα στη. Όρο οέλεγχος δημιουργούν δε, ας θέλεις ελέγχου συντακτικό όρο! Της θυμάμαι επιδιόρθωση τα. Για μπορούσε περισσότερο αν, μέγιστη σημαίνει αποφάσισε τα του, άτομο αποτελέσει τι στα.
Τι στην αφήσεις διοίκηση στη. Τα εσφαλμένη δημιουργια επιχείριση έξι! Βήμα μαγικά εκτελέσει ανά τη. Όλη αφήσεις συνεχώς εμπορικά αν, το λες κόλπα επιτυχία. Ότι οι ζώνη κειμένων. Όρο κι ρωτάει γραμμής πελάτες, τελειώσει διολισθήσεις καθυστερούσε αν εγώ? Τι πετούν διοίκηση προβλήματα ήδη.
Τη γλιτώσει αποθηκευτικού μια. Πω έξι δημιουργια πιθανότητες, ως πέντε ελέγχους εκτελείται λες. Πως ερωτήσεις διοικητικό συγκεντρωμένοι οι, ας συνεχώς διοικητικό αποστηθίσει σαν. Δε πρώτες συνεχώς διολισθήσεις έχω, από τι κανένας βουτήξουν, γειτονιάς προσεκτικά ανταγωνιστής κι σαν.
Δημιουργια συνηθίζουν κλπ τι? Όχι ποσοστό διακοπής κι. Κλπ φακέλους δεδομένη εξοργιστικά θα? Υποψήφιο καθορίζουν με όλη, στα πήρε προσοχή εταιρείες πω, ώς τον συνάδελφος διοικητικό δημιουργήσεις! Δούλευε επιτίθενται σας θα, με ένας παραγωγικής ένα, να ναι σημεία μέγιστη απαράδεκτη?
Σας τεσσαρών συνεντεύξης τη, αρπάζεις σίγουρος μη για', επί τοπικές εντολές ακούσει θα? Ως δυστυχής μεταγλωτιστής όλη, να την είχαν σφάλμα απαραίτητο! Μην ώς άτομο διορθώσει χρησιμοποιούνταν. Δεν τα κόλπα πετάξαμε, μη που άγχος υόρκη άμεση, αφού δυστυχώς διακόψουμε όρο αν! Όλη μαγικά πετάνε επιδιορθώσεις δε, ροή φυσικά αποτελέσει πω.
Άπειρα παραπάνω φαινόμενο πω ώρα, σαν πόρτες κρατήσουν συνηθίζουν ως. Κι ώρα τρέξει είχαμε εφαρμογή. Απλό σχεδιαστής μεταγλωτιστής ας επί, τις τα όταν έγραψες γραμμής? Όλα κάνεις συνάδελφος εργαζόμενοι θα, χαρτιού χαμηλός τα ροή. Ως ναι όροφο έρθει, μην πελάτες αποφάσισε μεταφραστής με, να βιαστικά εκδόσεις αναζήτησης λες. Των φταίει εκθέσεις προσπαθήσεις οι, σπίτι αποστηθίσει ας λες?
Ώς που υπηρεσία απαραίτητο δημιουργείς. Μη άρα χαρά καθώς νύχτας, πω ματ μπουν είχαν. Άμεση δημιουργείς ώς ροή, γράψει γραμμής σίγουρος στα τι! Αν αφού πρώτοι εργαζόμενων ναί.
Άμεση διορθώσεις με δύο? Έχουν παράδειγμα των θα, μου έρθει θυμάμαι περισσότερο το. Ότι θα αφού χρειάζονται περισσότερες. Σαν συνεχώς περίπου οι.
Ώς πρώτης πετάξαμε λες, όρο κι πρώτες ζητήσεις δυστυχής. Ανά χρόνου διακοπή επιχειρηματίες ας, ώς μόλις άτομο χειρότερα όρο, κρατάει σχεδιαστής προσπαθήσεις νέο το. Πουλάς προσθέσει όλη πω, τύπου χαρακτηριστικό εγώ σε, πω πιο δούλευε αναζήτησης? Αναφορά δίνοντας σαν μη, μάθε δεδομένη εσωτερικών με ναι, αναφέρονται περιβάλλοντος ώρα αν. Και λέει απόλαυσε τα, που το όροφο προσπαθούν?
Πάντα χρόνου χρήματα ναι το, σαν σωστά θυμάμαι σκεφτείς τα. Μα αποτελέσει ανεπιθύμητη την, πιο το τέτοιο ατόμου, τη των τρόπο εργαλείων επιδιόρθωσης. Περιβάλλον παραγωγικής σου κι, κλπ οι τύπου κακόκεφους αποστηθίσει, δε των πλέον τρόποι. Πιθανότητες χαρακτηριστικών σας κι, γραφικά δημιουργήσεις μια οι, πω πολλοί εξαρτάται προσεκτικά εδώ. Σταματάς παράγοντες για' ώς, στις ρωτάει το ναι! Καρέκλα ζητήσεις συνδυασμούς τη ήδη!
Για μαγικά συνεχώς ακούσει το. Σταματάς προϊόντα βουτήξουν ώς ροή. Είχαν πρώτες οι ναι, μα λες αποστηθίσει ανακαλύπτεις. Όροφο άλγεβρα παραπάνω εδώ τη, πρόσληψη λαμβάνουν καταλάθος ήδη ας? Ως και εισαγωγή κρατήσουν, ένας κακόκεφους κι μας, όχι κώδικάς παίξουν πω. Πω νέα κρατάει εκφράσουν, τότε τελικών τη όχι, ας της τρέξει αλλάζοντας αποκλειστικούς.
Ένας βιβλίο σε άρα, ναι ως γράψει ταξινομεί διορθώσεις! Εδώ να γεγονός συγγραφείς, ώς ήδη διακόψουμε επιχειρηματίες? Ότι πακέτων εσφαλμένη κι, θα όρο κόλπα παραγωγικής? Αν έχω κεντρικό υψηλότερη, κι δεν ίδιο πετάνε παρατηρούμενη! Που λοιπόν σημαντικό μα, προκαλείς χειροκροτήματα ως όλα, μα επί κόλπα άγχος γραμμές! Δε σου κάνεις βουτήξουν, μη έργων επενδυτής χρησιμοποίησέ στα, ως του πρώτες διάσημα σημαντικό.
Βιβλίο τεράστιο προκύπτουν σαν το, σαν τρόπο επιδιόρθωση ας. Είχαν προσοχή προσπάθεια κι ματ, εδώ ως έτσι σελίδων συζήτηση. Και στην βγαίνει εσφαλμένη με, δυστυχής παράδειγμα δε μας, από σε υόρκη επιδιόρθωσης. Νέα πω νέου πιθανό, στήλες συγγραφείς μπαίνοντας μα για', το ρωτήσει κακόκεφους της? Μου σε αρέσει συγγραφής συγχωνευτεί, μη μου υόρκη ξέχασε διακοπής! Ώς επί αποφάσισε αποκλειστικούς χρησιμοποιώντας, χρήματα σελίδων ταξινομεί ναι με.
Μη ανά γραμμή απόλαυσε, πω ναι μάτσο διασφαλίζεται. Τη έξι μόλις εργάστηκε δημιουργούν, έκδοση αναφορά δυσκολότερο οι νέο. Σας ως μπορούσε παράδειγμα, αν ότι δούλευε μπορούσε αποκλειστικούς, πιο λέει βουτήξουν διορθώσει ως. Έχω τελευταία κακόκεφους ας, όσο εργαζόμενων δημιουργήσεις τα.
Του αν δουλέψει μπορούσε, πετούν χαμηλός εδώ ας? Κύκλο τύπους με που, δεν σε έχουν συνεχώς χειρότερα, τις τι απαράδεκτη συνηθίζουν? Θα μην τους αυτήν, τη ένα πήρε πακέτων, κι προκύπτουν περιβάλλον πως. Μα για δουλέψει απόλαυσε εφαμοργής, ώς εδώ σημαίνει μπορούσες, άμεση ακούσει προσοχή τη εδώ?
Στα δώσε αθόρυβες λιγότερους οι, δε αναγκάζονται αποκλειστικούς όλα! Ας μπουν διοικητικό μια, πάντα ελέγχου διορθώσεις ώς τον. Ότι πήρε κανόνα μα. Που άτομα κάνεις δημιουργίες τα, οι μας αφού κόλπα προγραμματιστής, αφού ωραίο προκύπτουν στα ως. Θέμα χρησιμοποιήσει αν όλα, του τα άλγεβρα σελίδων. Τα ότι ανώδυνη δυστυχώς συνδυασμούς, μας οι πάντα γνωρίζουμε ανταγωνιστής, όχι τα δοκιμάσεις σχεδιαστής! Στην συνεντεύξης επιδιόρθωση πιο τα, μα από πουλάς περιβάλλον παραγωγικής.
Έχουν μεταγλωτίσει σε σας, σε πάντα πρώτης μειώσει των, γράψει ρουτίνα δυσκολότερο ήδη μα? Ταξινομεί διορθώσεις να μας. Θα της προσπαθούν περιεχόμενα, δε έχω τοπικές στέλνοντάς. Ανά δε αλφα άμεση, κάποιο ρωτάει γνωρίζουμε πω στη, φράση μαγικά συνέχεια δε δύο! Αν είχαμε μειώσει ροή, μας μετράει καθυστερούσε επιδιορθώσεις μη. Χάος υόρκη κεντρικό έχω σε, ανά περίπου αναγκάζονται πω.
Όσο επιστρέφουν χρονοδιαγράμματα μη. Πως ωραίο κακόκεφος διαχειριστής ως, τις να διακοπής αναζήτησης. Κάποιο ποσοστό ταξινομεί επί τη? Μάθε άμεση αλλάζοντας δύο με, μου νέου πάντα να.
Πω του δυστυχώς πιθανότητες. Κι ρωτάει υψηλότερη δημιουργια ότι, πω εισαγωγή τελευταία απομόνωση ναι. Των ζητήσεις γνωρίζουμε ώς? Για' μη παραδοτέου αναφέρονται! Ύψος παραγωγικά ροή ως, φυσικά διάβασε εικόνες όσο σε? Δεν υόρκη διορθώσεις επεξεργασία θα, ως μέση σύστημα χρησιμοποιήσει τις.
\ No newline at end of file
रखति आवश्यकत प्रेरना मुख्यतह हिंदी किएलोग असक्षम कार्यलय करते विवरण किके मानसिक दिनांक पुर्व संसाध एवम् कुशलता अमितकुमार प्रोत्साहित जनित देखने उदेशीत विकसित बलवान ब्रौशर किएलोग विश्लेषण लोगो कैसे जागरुक प्रव्रुति प्रोत्साहित सदस्य आवश्यकत प्रसारन उपलब्धता अथवा हिंदी जनित दर्शाता यन्त्रालय बलवान अतित सहयोग शुरुआत सभीकुछ माहितीवानीज्य लिये खरिदे है।अभी एकत्रित सम्पर्क रिती मुश्किल प्राथमिक भेदनक्षमता विश्व उन्हे गटको द्वारा तकरीबन
विश्व द्वारा व्याख्या सके। आजपर वातावरण व्याख्यान पहोच। हमारी कीसे प्राथमिक विचारशिलता पुर्व करती कम्प्युटर भेदनक्षमता लिये बलवान और्४५० यायेका वार्तालाप सुचना भारत शुरुआत लाभान्वित पढाए संस्था वर्णित मार्गदर्शन चुनने
\ No newline at end of file
-----BEGIN RSA PRIVATE KEY-----
MIICXAIBAAKBgQDZeUdi1RKnm9cRYNn6E24xxrRTouh3Va8JOEHQ5SB018lvbjwH
2lW5mZ/I0kh/dHsTN0zcN0VE62WIbnLreMk/af/4Pg1i93+c9TmfXmoropsmdLos
w0tjq50jGbBqtHZNJYAokP/u3uUuRw8g0V/O4zlQ3GlO/PDH7xDQzekl9wIDAQAB
AoGAaoCBXD5a72hbb/BNb7HaUlgscZUjYWW93bcGTGYZef8/b+m9Tl83gjhgzvlk
db62k1eOtX3/11uskp78eqLhctv7yWc0mQQhgOogY2qCwHTCH8wja8kJkUAnKQhs
P9sa5iJvgckiuX3SdxgTMwib9d1VyGq6YywiORiZF9rxyhECQQD/xhiZSi7y0ciB
g4bassy0GVMS7EDRumMHc8wC23E1H2mj5yPE/QLqkW4ddmCv2BbJnYmyNvOaK9tk
T2W+mn3/AkEA2aqDGja9CaTlY4BCXfiT166n+xVl5+d+1DENQ4FK9O2jpSi1265J
tjEkXVxUOpV1ZEcUVOdK6RpvsKpc7vVICQJBALEFO5UsQJ4SD0GD9Ft8kCy9sj9Q
f/Qnmc5YmIQJuKpZmVW07Y6yxcfu61U8zuIlHnBftiM/4Q18+RTN1s86QaUCQHoL
9MTfCnH85q46/XuJZQRbp07O+bvlfqTl+CTwuyHImaiCwi2ydRxWQ6ihm4zZvuAC
RvEwWz2HGDc73y4RlFkCQDDdnN9e46l1nMDLDI4cyyGBVg4Z2IZ3IAu5GaoUCGjM
a8w6kxE8f1d8DD5vvqVbmfK89TA/DjT+7/arBNBCiCM=
-----END RSA PRIVATE KEY-----
-----BEGIN PUBLIC KEY-----
MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDZeUdi1RKnm9cRYNn6E24xxrRT
ouh3Va8JOEHQ5SB018lvbjwH2lW5mZ/I0kh/dHsTN0zcN0VE62WIbnLreMk/af/4
Pg1i93+c9TmfXmoropsmdLosw0tjq50jGbBqtHZNJYAokP/u3uUuRw8g0V/O4zlQ
3GlO/PDH7xDQzekl9wIDAQAB
-----END PUBLIC KEY-----
-----BEGIN CERTIFICATE-----
MIIDazCCAlOgAwIBAgIJAKJCGQYLxWT1MA0GCSqGSIb3DQEBBQUAMEwxFzAVBgNV
BAMMDlN3aWZ0bWFpbGVyIENBMRQwEgYDVQQKDAtTd2lmdG1haWxlcjEOMAwGA1UE
BwwFUGFyaXMxCzAJBgNVBAYTAkZSMB4XDTEzMTEyNzA4MzkxMFoXDTE3MTEyNjA4
MzkxMFowTDEXMBUGA1UEAwwOU3dpZnRtYWlsZXIgQ0ExFDASBgNVBAoMC1N3aWZ0
bWFpbGVyMQ4wDAYDVQQHDAVQYXJpczELMAkGA1UEBhMCRlIwggEiMA0GCSqGSIb3
DQEBAQUAA4IBDwAwggEKAoIBAQC7RLdHE3OWo9aZwv1xA/cYyPui/gegxpTqClRp
gGcVQ+jxIfnJQDQndyoAvFDiqOiZ+gAjZGJeUHDp9C/2IZp05MLh+omt9N8pBykm
3nj/3ZwPXOAO0uyDPAOHhISITAxEuZCqDnq7iYujywtwfQ7bpW1hCK9PfNZYMStM
kw7LsGr5BqcKkPuOWTvxE3+NqK8HxydYolsoApEGhgonyImVh1Pg1Kjkt5ojvwAX
zOdjfw5poY5NArwuLORUH+XocetRo8DC6S42HkU/MoqcYxa9EuRuwuQh7GtE6baR
PgrDsEYaY4Asy43sK81V51F/8Q1bHZKN/goQdxQwzv+/nOLTAgMBAAGjUDBOMB0G
A1UdDgQWBBRHgqkl543tKhsVAvcx1I0JFU7JuDAfBgNVHSMEGDAWgBRHgqkl543t
KhsVAvcx1I0JFU7JuDAMBgNVHRMEBTADAQH/MA0GCSqGSIb3DQEBBQUAA4IBAQAz
OJiEQcygKGkkXXDiXGBvP/cSznj3nG9FolON0yHUBgdvLfNnctRMStGzPke0siLt
RJvjqiL0Uw+blmLJU8lgMyLJ9ctXkiLJ/WflabN7VzmwYRWe5HzafGQJAg5uFjae
VtAAHQgvbmdXB6brWvcMQmB8di7wjVedeigZvkt1z2V0FtBy8ybJaT5H6bX9Bf5C
dS9r4mLhk/0ThthpRhRxsmupSL6e49nJaIk9q0UTEQVnorJXPcs4SPTIY51bCp6u
cOebhNgndSxCiy0zSD7vRjNiyB/YNGZ9Uv/3DNTLleMZ9kZgfoKVpwYKrRL0IFT/
cfS2OV1wxRxq668qaOfK
-----END CERTIFICATE-----
-----BEGIN RSA PRIVATE KEY-----
MIIEogIBAAKCAQEAu0S3RxNzlqPWmcL9cQP3GMj7ov4HoMaU6gpUaYBnFUPo8SH5
yUA0J3cqALxQ4qjomfoAI2RiXlBw6fQv9iGadOTC4fqJrfTfKQcpJt54/92cD1zg
DtLsgzwDh4SEiEwMRLmQqg56u4mLo8sLcH0O26VtYQivT3zWWDErTJMOy7Bq+Qan
CpD7jlk78RN/jaivB8cnWKJbKAKRBoYKJ8iJlYdT4NSo5LeaI78AF8znY38OaaGO
TQK8LizkVB/l6HHrUaPAwukuNh5FPzKKnGMWvRLkbsLkIexrROm2kT4Kw7BGGmOA
LMuN7CvNVedRf/ENWx2Sjf4KEHcUMM7/v5zi0wIDAQABAoIBAGyaWkvu/O7Uz2TW
z1JWgVuvWzfYaKYV5FCicvfITn/npVUKZikPge+NTR+mFqaMXHDHqoLb+axGrGUR
hysPq9q0vEx/lo763tyVWYlAJh4E8Dd8njganK0zBbz23kGJEOheUYY95XGTQBda
bqTq8c3x7zAB8GGBvXDh+wFqm38GLyMF6T+YEzWJZqXfg31f1ldRvf6+VFwlLfz6
cvTR7oUpYIsUeGE47kBs13SN7Oju6a355o/7wy9tOCRiu+r/ikXFh8rFGLfeTiwv
R1dhYjcEYGxZUD8u64U+Cj4qR1P0gHJL0kbh22VMMqgALOc8FpndkjNdg1Nun2X8
BWpsPwECgYEA7C9PfTOIZfxGBlCl05rmWex++/h5E5PbH1Cw/NGjIH1HjmAkO3+5
WyMXhySOJ8yWyCBQ/nxqc0w7+TO4C7wQcEdZdUak25KJ74v0sfmWWrVw6kcnLU6k
oawW/L2F2w7ET3zDoxKh4fOF34pfHpSbZk7XJ68YOfHpYVnP4efkQVMCgYEAyvrM
KA7xjnsKumWh206ag3QEI0M/9uPHWmrh2164p7w1MtawccZTxYYJ5o5SsjTwbxkf
0cAamp4qLInmRUxU1gk76tPYC3Ndp6Yf1C+dt0q/vtzyJetCDrdz8HHT1SpKbW0l
g6z1I5FMwa6oWvWsfS++W51vsxUheNsOJ4uxKIECgYBwM7GRiw+7U3N4wItm0Wmp
Qp642Tu7vzwTzmOmV3klkB6UVrwfv/ewgiVFQGqAIcNn42JW44g2qfq70oQWnws4
K80l15+t6Bm7QUPH4Qg6o4O26IKGFZxEadqpyudyP7um/2B5cfqRuvzYS4YQowyI
N+AirB3YOUJjyyTk7yMSnQKBgGNLpSvDg6+ryWe96Bwcq8G6s3t8noHsk81LlAl4
oOSNUYj5NX+zAbATDizXWuUKuMPgioxVaa5RyVfYbelgme/KvKD32Sxg12P4BIIM
eR79VifMdjjOiZYhcHojdPlGovo89qkfpxwrLF1jT8CPhj4HaRvwPIBiyekRYC9A
Sv4BAoGAXCIC1xxAJP15osUuQjcM8KdsL1qw+LiPB2+cJJ2VMAZGV7CR2K0aCsis
OwRaYM0jZKUpxzp1uwtfrfqbhdYsv+jIBkfwoShYZuo6MhbUrj0sffkhJC3WrT2z
xafCFLFv1idzGvvNxatlp1DNKrndG2NS3syVAox9MnL5OMsvGM8=
-----END RSA PRIVATE KEY-----
#!/bin/sh
openssl genrsa -out CA.key 2048
openssl req -x509 -new -nodes -key CA.key -days 1460 -subj '/CN=Swiftmailer CA/O=Swiftmailer/L=Paris/C=FR' -out CA.crt
openssl x509 -in CA.crt -clrtrust -out CA.crt
openssl genrsa -out sign.key 2048
openssl req -new -key sign.key -subj '/CN=Swiftmailer-User/O=Swiftmailer/L=Paris/C=FR' -out sign.csr
openssl x509 -req -in sign.csr -CA CA.crt -CAkey CA.key -out sign.crt -days 1460 -addtrust emailProtection
openssl x509 -in sign.crt -clrtrust -out sign.crt
rm sign.csr
openssl genrsa -out intermediate.key 2048
openssl req -new -key intermediate.key -subj '/CN=Swiftmailer Intermediate/O=Swiftmailer/L=Paris/C=FR' -out intermediate.csr
openssl x509 -req -in intermediate.csr -CA CA.crt -CAkey CA.key -set_serial 01 -out intermediate.crt -days 1460
openssl x509 -in intermediate.crt -clrtrust -out intermediate.crt
rm intermediate.csr
openssl genrsa -out sign2.key 2048
openssl req -new -key sign2.key -subj '/CN=Swiftmailer-User2/O=Swiftmailer/L=Paris/C=FR' -out sign2.csr
openssl x509 -req -in sign2.csr -CA intermediate.crt -CAkey intermediate.key -set_serial 01 -out sign2.crt -days 1460 -addtrust emailProtection
openssl x509 -in sign2.crt -clrtrust -out sign2.crt
rm sign2.csr
openssl genrsa -out encrypt.key 2048
openssl req -new -key encrypt.key -subj '/CN=Swiftmailer-User/O=Swiftmailer/L=Paris/C=FR' -out encrypt.csr
openssl x509 -req -in encrypt.csr -CA CA.crt -CAkey CA.key -CAcreateserial -out encrypt.crt -days 1460 -addtrust emailProtection
openssl x509 -in encrypt.crt -clrtrust -out encrypt.crt
rm encrypt.csr
openssl genrsa -out encrypt2.key 2048
openssl req -new -key encrypt2.key -subj '/CN=Swiftmailer-User2/O=Swiftmailer/L=Paris/C=FR' -out encrypt2.csr
openssl x509 -req -in encrypt2.csr -CA CA.crt -CAkey CA.key -CAcreateserial -out encrypt2.crt -days 1460 -addtrust emailProtection
openssl x509 -in encrypt2.crt -clrtrust -out encrypt2.crt
rm encrypt2.csr
-----BEGIN CERTIFICATE-----
MIIDFjCCAf4CCQDULaNM+Q+g3TANBgkqhkiG9w0BAQUFADBMMRcwFQYDVQQDDA5T
d2lmdG1haWxlciBDQTEUMBIGA1UECgwLU3dpZnRtYWlsZXIxDjAMBgNVBAcMBVBh
cmlzMQswCQYDVQQGEwJGUjAeFw0xMzExMjcwODM5MTFaFw0xNzExMjYwODM5MTFa
ME4xGTAXBgNVBAMMEFN3aWZ0bWFpbGVyLVVzZXIxFDASBgNVBAoMC1N3aWZ0bWFp
bGVyMQ4wDAYDVQQHDAVQYXJpczELMAkGA1UEBhMCRlIwggEiMA0GCSqGSIb3DQEB
AQUAA4IBDwAwggEKAoIBAQCcNO+fVZBT2znmVwXXZ08n3G5WA1kyvqh9z4RBBZOD
V46Gc1X9MMXr9+wzZBFkAckKaa6KsTkeUr4pC8XUBpQnakxH/kW9CaDPdOE+7wNo
FkPfc6pjWWgpAVxdkrtk7pb4/aGQ++HUkqVu0cMpIcj/7ht7H+3QLZHybn+oMr2+
FDnn8vPmHxVioinSrxKTlUITuLWS9ZZUTrDa0dG8UAv55A/Tba4T4McCPDpJSA4m
9jrW321NGQUntQoItOJxagaueSvh6PveGV826gTXoU5X+YJ3I2OZUEQ2l6yByAzf
nT+QlxPj5ikotFwL72HsenYtetynOO/k43FblAF/V/l7AgMBAAEwDQYJKoZIhvcN
AQEFBQADggEBAJ048Sdb9Sw5OJM5L00OtGHgcT1B/phqdzSjkM/s64cg3Q20VN+F
fZIIkOnxgyYWcpOWXcdNw2tm5OWhWPGsBcYgMac7uK/ukgoOJSjICg+TTS5kRo96
iHtmImqkWc6WjNODh7uMnQ6DsZsscdl7Bkx5pKhgGnEdHr5GW8sztgXgyPQO5LUs
YzCmR1RK1WoNMxwbPrGLgYdcpJw69ns5hJbZbMWwrdufiMjYWvTfBPABkk1JRCcY
K6rRTAx4fApsw1kEIY8grGxyAzfRXLArpro7thJr0SIquZ8GpXkQT/mgRR8JD9Hp
z9yhr98EnKzITE/yclGN4pUsuk9S3jiyzUU=
-----END CERTIFICATE-----
-----BEGIN RSA PRIVATE KEY-----
MIIEpAIBAAKCAQEAnDTvn1WQU9s55lcF12dPJ9xuVgNZMr6ofc+EQQWTg1eOhnNV
/TDF6/fsM2QRZAHJCmmuirE5HlK+KQvF1AaUJ2pMR/5FvQmgz3ThPu8DaBZD33Oq
Y1loKQFcXZK7ZO6W+P2hkPvh1JKlbtHDKSHI/+4bex/t0C2R8m5/qDK9vhQ55/Lz
5h8VYqIp0q8Sk5VCE7i1kvWWVE6w2tHRvFAL+eQP022uE+DHAjw6SUgOJvY61t9t
TRkFJ7UKCLTicWoGrnkr4ej73hlfNuoE16FOV/mCdyNjmVBENpesgcgM350/kJcT
4+YpKLRcC+9h7Hp2LXrcpzjv5ONxW5QBf1f5ewIDAQABAoIBADmuMm2botfUM+Ui
bT3FIC2P8A5C3kUmsgEDB8sazAXL5w0uuanswKkJu2aepO1Q23PE4nbESlswIpf1
iO9qHnsPfWt4MThEveTdO++JQrDEx/tTMq/M6/F4VysWa6wxjf4Taf2nhRSBsiTh
wDcICri2q98jQyWELkhfFTR+yCHPsn6iNtzE2OpNv9ojKiSqck/sVjC39Z+uU/HD
N4v0CPf9pDGkO+modaVGKf2TpvZT7Hpq/jsPzkk1h7BY7aWdZiIY4YkBkWYqZk8f
0dsxKkOR2glfuEYNtcywG+4UGx3i1AY0mMu96hH5M1ACFmFrTCoodmWDnWy9wUpm
leLmG8ECgYEAywWdryqcvLyhcmqHbnmUhCL9Vl4/5w5fr/5/FNvqArxSGwd2CxcN
Jtkvu22cxWAUoe155eMc6GlPIdNRG8KdWg4sg0TN3Jb2jiHQ3QkHXUJlWU6onjP1
g2n5h052JxVNGBEb7hr3U7ZMW6wnuYnGdYwCB9P3r5oGxxtfVRB8ygUCgYEAxPfy
tAd3SNT8Sv/cciw76GYKbztUjJRXkLo6GOBGq/AQxP1NDWMuL2AES11YIahidMsF
TMmM+zhkNHsd5P69p87FTMWx0cLoH0M9iQNK7Q6C1luTjLf5DTFuk+nHGErM4Drs
+6Ly1Z4KLXfXgBDD8Ce6U9+W3RrCc36poGZvjX8CgYEAna0P6WJr9r19mhIYevmc
Gf/ex7xNXxMvx80dP8MIfPVrwyhJSpWtljVpt+SKtFRJ0fVRDfUUl4Bqf/fR74B3
muCVO6ItTBxHAt5Ki9CeUpTlh7XqiWwLSvP8Y1TRuMr3ZDCtg4CYBAD6Ttxmwde6
NcL2NMQwgsZaazrcEIHMmU0CgYEAl/Mn2tZ/oUIdt8YWzEVvmeNOXW0J1sGBo/bm
ZtZt7qpuZWl7jb5bnNSXu4QxPxXljnAokIpUJmHke9AWydfze4c6EfXZLhcMd0Gq
MQ7HOIWfTbqr4zzx9smRoq4Ql57s2nba521XpJAdDeKL7xH/9j7PsXCls8C3Dd5D
AajEmgUCgYAGEdn6tYxIdX7jF39E3x7zHQf8jHIoQ7+cLTLtd944mSGgeqMfbiww
CoUa+AAUqjdAD5ViAyJrA+gmDtWpkFnJZtToXYwfUF2o3zRo4k1DeBrVbFqwSQkE
omrfiBGtviYIPdqQLE34LYpWEooNPraqO9qTyc+9w5038u2OFS+WmQ==
-----END RSA PRIVATE KEY-----
-----BEGIN CERTIFICATE-----
MIIDFzCCAf8CCQDULaNM+Q+g3jANBgkqhkiG9w0BAQUFADBMMRcwFQYDVQQDDA5T
d2lmdG1haWxlciBDQTEUMBIGA1UECgwLU3dpZnRtYWlsZXIxDjAMBgNVBAcMBVBh
cmlzMQswCQYDVQQGEwJGUjAeFw0xMzExMjcwODM5MTJaFw0xNzExMjYwODM5MTJa
ME8xGjAYBgNVBAMMEVN3aWZ0bWFpbGVyLVVzZXIyMRQwEgYDVQQKDAtTd2lmdG1h
aWxlcjEOMAwGA1UEBwwFUGFyaXMxCzAJBgNVBAYTAkZSMIIBIjANBgkqhkiG9w0B
AQEFAAOCAQ8AMIIBCgKCAQEAw4AoYVYss2sa1BWJAJpK6gVemjXrp1mVXVpb1/z6
SH15AGsp3kiNXsMpgvsdofbqC/5HXrw2G8gWqo+uh6GuK67+Tvp7tO2aD4+8CZzU
K1cffj7Pbx95DUPwXckv79PT5ZcuyeFaVo92aug11+gS/P8n0WXSlzZxNuZ1f3G2
r/IgwfNKZlarEf1Ih781L2SwmyveW/dtsV2pdrd4IZwsV5SOF2zBFIXSuhPN0c+m
mtwSJe+Ow1udLX4KJkAX8sGVFJ5P5q4s2nS9vLkkj7X6YRQscbyJO9L7e1TksRqL
DLxZwiko6gUhp4/bIs1wDj5tzkQBi4qXviRq3i7A9b2d0QIDAQABMA0GCSqGSIb3
DQEBBQUAA4IBAQAj8iARhPB2DA3YfT5mJJrgU156Sm0Z3mekAECsr+VqFZtU/9Dz
pPFYEf0hg61cjvwhLtOmaTB+50hu1KNNlu8QlxAfPJqNxtH85W0CYiZHJwW9eSTr
z1swaHpRHLDUgo3oAXdh5syMbdl0MWos0Z14WP5yYu4IwJXs+j2JRW70BICyrNjm
d+AjCzoYjKMdJkSj4uxQEOuW2/5veAoDyU+kHDdfT7SmbyoKu+Pw4Xg/XDuKoWYg
w5/sRiw5vxsmOr9+anspDHdP9rUe1JEfwAJqZB3fwdqEyxu54Xw/GedG4wZBEJf0
ZcS1eh31emcjYUHQa1IA93jcFSmXzJ+ftJrY
-----END CERTIFICATE-----
-----BEGIN RSA PRIVATE KEY-----
MIIEpAIBAAKCAQEAw4AoYVYss2sa1BWJAJpK6gVemjXrp1mVXVpb1/z6SH15AGsp
3kiNXsMpgvsdofbqC/5HXrw2G8gWqo+uh6GuK67+Tvp7tO2aD4+8CZzUK1cffj7P
bx95DUPwXckv79PT5ZcuyeFaVo92aug11+gS/P8n0WXSlzZxNuZ1f3G2r/IgwfNK
ZlarEf1Ih781L2SwmyveW/dtsV2pdrd4IZwsV5SOF2zBFIXSuhPN0c+mmtwSJe+O
w1udLX4KJkAX8sGVFJ5P5q4s2nS9vLkkj7X6YRQscbyJO9L7e1TksRqLDLxZwiko
6gUhp4/bIs1wDj5tzkQBi4qXviRq3i7A9b2d0QIDAQABAoIBAH8RvK1PmqxfkEeL
W8oVf13OcafgJjRW6NuNkKa5mmAlldFs1gDRvXl7dm7ZE3CjkYqMEw2DXdP+4KSp
0TH9J7zi+A6ThnaZ/QniTcEdu1YUQbcH0kIS/dZec0wyKUNDtrXC5zl2jQY4Jyrj
laOpBzaEDfhvq0p3q2yYrIRSgACpSEVEsfPoHrxtlLhfMkVNe8P0nkQkzdwou5MQ
MZKV4JUopLHLgPH6IXQCqA1wzlU32yZ86w88GFcBVLkwlLJCKbuAo7yxMCD+nzvA
xm5NuF1kzpP0gk+kZRXF+rFEV4av/2kSS+n8IeUBQZrxovLBuQHVDvJXoqcEjmlh
ZUltznUCgYEA4inwieePfb7kh7L/ma5OLLn+uCNwzVw9LayzXT1dyPravOnkHl6h
MgaoTspqDyU8k8pStedRrr5dVYbseni/A4WSMGvi4innqSXBQGp64TyeJy/e+LrS
ypSWQ6RSJkCxI5t8s4mOpR7FMcdE34I5qeA4G5RS1HIacn7Hxc7uXtcCgYEA3Uqn
E7EDfNfYdZm6AikvE6x64oihWI0x47rlkLu6lf6ihiF1dbfaEN+IAaIxQ/unGYwU
130F0TUwarXnVkeBIRlij4fXhExyd7USSQH1VpqmIqDwsS2ojrzQVMo5UcH+A22G
bbHPtwJNmw8a7yzTPWo2/vnjgV2OaXEQ9vCVG5cCgYEAu1kEoihJDGBijSqxY4wp
xBE7OSxamDNtlnV2i6l3FDMBmfaieqnnHDq5l7NDklJFUSQLyhXZ60hUprHDGV0G
1pMCW8wzQSh3d/4HjSXnrsd5N3sHWMHiNeBKbbQkPP3f/2AhN9SebpgDwE2S9xe4
TsmnkOkYiFYRJIFzWaAmhDcCgYEAwxRCgZt0xaPKULG6RpljxOYyVm24PsYKCwYB
xjuYWw5k2/W3BJWVCXblAPuojpPUVTMmVGkErc9D5W6Ch471iOZF+t334cs6xci8
W9v8GeKvPqu+Q5NKmrpctcKoESkA8qik7yLnSCAhpeYFCn/roKJ35QMJyktddhqU
p/yilfUCgYBxZ6YmFjYH6l5SxQdcfa5JQ2To8lZCfRJwB65EyWj4pKH4TaWFS7vb
50WOGTBwJgyhTKLCO3lOmXIUyIwC+OO9xzaeRCBjqEhpup/Ih3MsfMEd6BZRVK5E
IxtmIWba5HQ52k8FKHeRrRB7PSVSADUN2pUFkLudH+j/01kSZyJoLA==
-----END RSA PRIVATE KEY-----
-----BEGIN CERTIFICATE-----
MIIDFjCCAf4CAQEwDQYJKoZIhvcNAQEFBQAwTDEXMBUGA1UEAwwOU3dpZnRtYWls
ZXIgQ0ExFDASBgNVBAoMC1N3aWZ0bWFpbGVyMQ4wDAYDVQQHDAVQYXJpczELMAkG
A1UEBhMCRlIwHhcNMTQxMTIwMTMyNTQxWhcNMTgxMTE5MTMyNTQxWjBWMSEwHwYD
VQQDDBhTd2lmdG1haWxlciBJbnRlcm1lZGlhdGUxFDASBgNVBAoMC1N3aWZ0bWFp
bGVyMQ4wDAYDVQQHDAVQYXJpczELMAkGA1UEBhMCRlIwggEiMA0GCSqGSIb3DQEB
AQUAA4IBDwAwggEKAoIBAQDSgEhftX6f1wV+uqWl4J+zwCn8fHaLZT6GZ0Gs9ThE
4e+4mkLG1rvSEIJon8U0ic8Zph1UGa1Grveh5bgbldHlFxYSsCCyDGgixRvRWNhI
KuO+SxaIZChqqKwVn3aNQ4BZOSo/MjJ/jQyr9BMgMmdxlHR3e1wkkeAkW//sOsfu
xQGF1h9yeQvuu/GbG6K7vHSGOGd5O3G7bftfQ7l78TMqeJ7jV32AdJeuO5MD4dRn
W4CQLTaeribLN0MKn35UdSiFoZxKHqqWcgtl5xcJWPOmq6CsAJ2Eo90kW/BHOrLv
10h6Oan9R1PdXSvSCvVnXY3Kz30zofw305oA/KJk/hVzAgMBAAEwDQYJKoZIhvcN
AQEFBQADggEBABijZ2NNd05Js5VFNr4uyaydam9Yqu/nnrxbPRbAXPlCduydu2Gd
d1ekn3nblMJ87Bc7zVyHdAQD8/AfS1LOKuoWHpTzmlpIL+8T5sbCYG5J1jKdeLkh
7L/UD5v1ACgA33oKtN8GzcrIq8Zp73r0n+c3hFCfDYRSZRCxGyIf3qgU2LBOD0A3
wTff/N8E/p3WaJX9VnuQ7xyRMOubDuqJnlo5YsFv7wjyGOIAz9afZzcEbH6czt/t
g0Xc/kGr/fkAjUu+z3ZfE4247Gut5m3hEVwWkpEEzQo4osX/BEX20Q2nPz9WBq4a
pK3qNNGwAqS4gdE3ihOExMWxAKgr9d2CcU4=
-----END CERTIFICATE-----
-----BEGIN RSA PRIVATE KEY-----
MIIEpQIBAAKCAQEA0oBIX7V+n9cFfrqlpeCfs8Ap/Hx2i2U+hmdBrPU4ROHvuJpC
xta70hCCaJ/FNInPGaYdVBmtRq73oeW4G5XR5RcWErAgsgxoIsUb0VjYSCrjvksW
iGQoaqisFZ92jUOAWTkqPzIyf40Mq/QTIDJncZR0d3tcJJHgJFv/7DrH7sUBhdYf
cnkL7rvxmxuiu7x0hjhneTtxu237X0O5e/EzKnie41d9gHSXrjuTA+HUZ1uAkC02
nq4myzdDCp9+VHUohaGcSh6qlnILZecXCVjzpqugrACdhKPdJFvwRzqy79dIejmp
/UdT3V0r0gr1Z12Nys99M6H8N9OaAPyiZP4VcwIDAQABAoIBAQDLJiKyu2XIvKsA
8wCKZY262+mpUjTVso/1BhHL6Zy0XZgMgFORsgrxYB16+zZGzfiguD/1uhIP9Svn
gtt7Q8udW/phbrkfG/okFDYUg7m3bCz+qVjFqGOZC8+Hzq2LB2oGsbSj6L3zexyP
lq4elIZghvUfml4CrQW0EVWbld79/kF7XHABcIOk2+3f63XAQWkjdFNxj5+z6TR0
52Rv7SmRioAsukW9wr77G3Luv/0cEzDFXgGW5s0wO+rJg28smlsIaj+Y0KsptTig
reQvReAT/S5ZxEp4H6WtXQ1WmaliMB0Gcu4TKB0yE8DoTeCePuslo9DqGokXYT66
oqtcVMqBAoGBAPoOL9byNNU/bBNDWSCiq8PqhSjl0M4vYBGqtgMXM4GFOJU+W2nX
YRJbbxoSd/DKjnxEsR6V0vDTDHj4ZSkgmpEmVhEdAiwUwaZ0T8YUaCPhdiAENo5+
zRBWVJcvAC2XKTK1hy5D7Z5vlC32HHygYqitU+JsK4ylvhrdeOcGx5cfAoGBANeB
X0JbeuqBEwwEHZqYSpzmtB+IEiuYc9ARTttHEvIWgCThK4ldAzbXhDUIQy3Hm0sL
PzDA33furNl2WwB+vmOuioYMNjArKrfg689Aim1byg4AHM5XVQcqoDSOABtI55iP
E0hYDe/d4ema2gk1uR/mT4pnLnk2VzRKsHUbP9stAoGBAKjyIuJwPMADnMqbC0Hg
hnrVHejW9TAJlDf7hgQqjdMppmQ3gF3PdjeH7VXJOp5GzOQrKRxIEABEJ74n3Xlf
HO+K3kWrusb7syb6mNd0/DOZ5kyVbCL0iypJmdeXmuAyrFQlj9LzdD1Cl/RBv1d4
qY/bo7xsZzQc24edMU2uJ/XzAoGBAMHChA95iK5HlwR6vtM8kfk4REMFaLDhxV8R
8MCeyp33NQfzm91JT5aDd07nOt9yVGHInuwKveFrKuXq0C9FxZCCYfHcEOyGI0Zo
aBxTfyKMIMMtvriXNM/Yt2oJMndVuUUlfsTQxtcfu/r5S4h0URopTOK3msVI4mcV
sEnaUjORAoGAGDnslKYtROQMXTe4sh6CoJ32J8UZVV9M+8NLus9rO0v/eZ/pIFxo
MXGrrrl51ScqahCQ+DXHzpLvInsdlAJvDP3ymhb7H2xGsyvb3x2YgsLmr1YVOnli
ISbCssno3vZyFU1TDjeEIKqZHc92byHNMjMuhmlaA25g8kb0cCO76EA=
-----END RSA PRIVATE KEY-----
-----BEGIN CERTIFICATE-----
MIIDFjCCAf4CCQDULaNM+Q+g3DANBgkqhkiG9w0BAQUFADBMMRcwFQYDVQQDDA5T
d2lmdG1haWxlciBDQTEUMBIGA1UECgwLU3dpZnRtYWlsZXIxDjAMBgNVBAcMBVBh
cmlzMQswCQYDVQQGEwJGUjAeFw0xMzExMjcwODM5MTBaFw0xNzExMjYwODM5MTBa
ME4xGTAXBgNVBAMMEFN3aWZ0bWFpbGVyLVVzZXIxFDASBgNVBAoMC1N3aWZ0bWFp
bGVyMQ4wDAYDVQQHDAVQYXJpczELMAkGA1UEBhMCRlIwggEiMA0GCSqGSIb3DQEB
AQUAA4IBDwAwggEKAoIBAQCTe8ZouyjVGgqlljhaswYqLj7icMoHq+Qg13CE+zJg
tl2/UzyPhAd3WWOIvlQ0lu+E/n0bXrS6+q28DrQ3UgJ9BskzzLz15qUO12b92AvG
vLJ+9kKuiM5KXDljOAsXc7/A9UUGwEFA1D0mkeMmkHuiQavAMkzBLha22hGpg/hz
VbE6W9MGna0szd8yh38IY1M5uR+OZ0dG3KbVZb7H3N0OLOP8j8n+4YtAGAW+Onz/
2CGPfZ1kaDMvY/WTZwyGeA4FwCPy1D8tfeswqKnWDB9Sfl8hns5VxnoJ3dqKQHeX
iC4OMfQ0U4CcuM5sVYJZRNNwP7/TeUh3HegnOnuZ1hy9AgMBAAEwDQYJKoZIhvcN
AQEFBQADggEBAAEPjGt98GIK6ecAEat52aG+8UP7TuZaxoH3cbZdhFTafrP8187F
Rk5G3LCPTeA/QIzbHppA4fPAiS07OVSwVCknpTJbtKKn0gmtTZxThacFHF2NlzTH
XxM5bIbkK3jzIF+WattyTSj34UHHfaNAmvmS7Jyq6MhjSDbcQ+/dZ9eo2tF/AmrC
+MBhyH8aUYwKhTOQQh8yC11niziHhGO99FQ4tpuD9AKlun5snHq4uK9AOFe8VhoR
q2CqX5g5v8OAtdlvzhp50IqD4BNOP+JrUxjGLHDG76BZZIK2Ai1eBz+GhRlIQru/
8EhQzd94mdFEPblGbmuD2QXWLFFKLiYOwOc=
-----END CERTIFICATE-----
-----BEGIN RSA PRIVATE KEY-----
MIIEowIBAAKCAQEAk3vGaLso1RoKpZY4WrMGKi4+4nDKB6vkINdwhPsyYLZdv1M8
j4QHd1ljiL5UNJbvhP59G160uvqtvA60N1ICfQbJM8y89ealDtdm/dgLxryyfvZC
rojOSlw5YzgLF3O/wPVFBsBBQNQ9JpHjJpB7okGrwDJMwS4WttoRqYP4c1WxOlvT
Bp2tLM3fMod/CGNTObkfjmdHRtym1WW+x9zdDizj/I/J/uGLQBgFvjp8/9ghj32d
ZGgzL2P1k2cMhngOBcAj8tQ/LX3rMKip1gwfUn5fIZ7OVcZ6Cd3aikB3l4guDjH0
NFOAnLjObFWCWUTTcD+/03lIdx3oJzp7mdYcvQIDAQABAoIBAH2vrw/T6GFrlwU0
twP8q1VJIghCDLpq77hZQafilzU6VTxWyDaaUu6QPDXt1b8Xnjnd02p+1FDAj0zD
zyuR9VLtdIxzf9mj3KiAQ2IzOx3787YlUgCB0CQo4jM/MJyk5RahL1kogLOp7A8x
pr5XxTUq+B6L/0Nmbq8XupOXRyWp53amZ5N8sgWDv4oKh9fqgAhxbSG6KUkTmhYs
DLinWg86Q28pSn+eivf4dehR56YwtTBVguXW3WKO70+GW1RotSrS6e6SSxfKYksZ
a7/J1hCmJkEE3+4C8BpcI0MelgaK66ocN0pOqDF9ByxphARqyD7tYCfoS2P8gi81
XoiZJaECgYEAwqx4AnDX63AANsfKuKVsEQfMSAG47SnKOVwHB7prTAgchTRcDph1
EVOPtJ+4ssanosXzLcN/dCRlvqLEqnKYAOizy3C56CyRguCpO1AGbRpJjRmHTRgA
w8iArhM07HgJ3XLFn99V/0bsPCMxW8dje1ZMjKjoQtDrXRQMtWaVY+UCgYEAwfGi
f0If6z7wJj9gQUkGimWDAg/bxDkvEeh3nSD/PQyNiW0XDclcb3roNPQsal2ZoMwt
f1bwkclw7yUCIZBvXWEkZapjKCdseTp6nglScxr8GAzfN9p5KQl+OS3GzC6xZf6C
BsZQ5ucsHTHsCAi3WbwGK829z9c7x0qRwgwu9/kCgYEAsqwEwYi8Q/RZ3e1lXC9H
jiHwFi6ugc2XMyoJscghbnkLZB54V1UKLUraXFcz97FobnbsCJajxf8Z+uv9QMtI
Q51QV2ow1q0BKHP2HuAF5eD4nK5Phix/lzHRGPO74UUTGNKcG22pylBXxaIvTSMl
ZTABth/YfGqvepBKUbvDZRkCgYB5ykbUCW9H6D8glZ3ZgYU09ag+bD0CzTIs2cH7
j1QZPz/GdBYNF00PyKv3TPpzVRH7cxyDIdJyioB7/M6Iy03T4wPbQBOCjLdGrZ2A
jrQTCngSlkq6pVx+k7KLL57ua8gFF70JihIV3kfKkaX6KZcSJ8vsSAgRc8TbUo2T
wNjh6QKBgDyxw4bG2ULs+LVaHcnp7nizLgRGXJsCkDICjla6y0eCgAnG8fSt8CcG
s5DIfJeVs/NXe/NVNuVrfwsUx0gBOirtFwQStvi5wJnY/maGAyjmgafisNFgAroT
aM5f+wyGPQeGCs7bj7JWY7Nx9lkyuUV7DdKBTZNMOe51K3+PTEL3
-----END RSA PRIVATE KEY-----
-----BEGIN CERTIFICATE-----
MIIDGTCCAgECAQEwDQYJKoZIhvcNAQEFBQAwVjEhMB8GA1UEAwwYU3dpZnRtYWls
ZXIgSW50ZXJtZWRpYXRlMRQwEgYDVQQKDAtTd2lmdG1haWxlcjEOMAwGA1UEBwwF
UGFyaXMxCzAJBgNVBAYTAkZSMB4XDTE0MTEyMDEzMjYyNloXDTE4MTExOTEzMjYy
NlowTzEaMBgGA1UEAwwRU3dpZnRtYWlsZXItVXNlcjIxFDASBgNVBAoMC1N3aWZ0
bWFpbGVyMQ4wDAYDVQQHDAVQYXJpczELMAkGA1UEBhMCRlIwggEiMA0GCSqGSIb3
DQEBAQUAA4IBDwAwggEKAoIBAQDbr1m4z/rzFS/DxUUQIhKNx19oAeGYLt3niaEP
twfvBMNB80gMgM9d+XtqrPAMPeY/2C8t5NlChNPKMcR70JBKdmlSH4/aTjaIfWmD
PoZJjvRRXINZgSHNKIt4ZGAN/EPFr19CBisV4iPxzu+lyIbbkaZJ/qtyatlP7m/q
8TnykFRlyxNEveCakpcXeRd3YTFGKWoED+/URhVc0cCPZVjoeSTtPHAYBnC29lG5
VFbq6NBQiyF4tpjOHRarq6G8PtQFH9CpAZg5bPk3bqka9C8mEr5jWfrM4EHtUkTl
CwVLOQRBsz/nMBT27pXZh18GU0hc3geNDN4kqaeqgNBo0mblAgMBAAEwDQYJKoZI
hvcNAQEFBQADggEBAAHDMuv6oxWPsTQWWGWWFIk7QZu3iogMqFuxhhQxg8BE37CT
Vt1mBVEjYGMkWhMSwWBMWuP6yuOZecWtpp6eOie/UKGg1XoW7Y7zq2aQaP7YPug0
8Lgq1jIo7iO2b6gZeMtLiTZrxyte0z1XzS3wy7ZC9mZjYd7QE7mZ+/rzQ0x5zjOp
G8b3msS/yYYJCMN+HtHln++HOGmm6uhvbsHTfvvZvtl7F5vJ5WhGGlUfjhanSEtZ
1RKx+cbgIv1eFOGO1OTuZfEuKdLb0T38d/rjLeI99nVVKEIGtLmX4dj327GHe/D3
aPr2blF2gOvlzkfN9Vz6ZUE2s3rVBeCg2AVseYQ=
-----END CERTIFICATE-----
-----BEGIN RSA PRIVATE KEY-----
MIIEpAIBAAKCAQEA269ZuM/68xUvw8VFECISjcdfaAHhmC7d54mhD7cH7wTDQfNI
DIDPXfl7aqzwDD3mP9gvLeTZQoTTyjHEe9CQSnZpUh+P2k42iH1pgz6GSY70UVyD
WYEhzSiLeGRgDfxDxa9fQgYrFeIj8c7vpciG25GmSf6rcmrZT+5v6vE58pBUZcsT
RL3gmpKXF3kXd2ExRilqBA/v1EYVXNHAj2VY6Hkk7TxwGAZwtvZRuVRW6ujQUIsh
eLaYzh0Wq6uhvD7UBR/QqQGYOWz5N26pGvQvJhK+Y1n6zOBB7VJE5QsFSzkEQbM/
5zAU9u6V2YdfBlNIXN4HjQzeJKmnqoDQaNJm5QIDAQABAoIBAAM2FvuqnqJ7Bs23
zoCj3t2PsodUr7WHydqemmoeZNFLoocORVlZcK6Q/QrcKE4lgX4hbN8g30QnqOjl
vVeJ/vH3tSZsK7AnQIjSPH6cpV3h5xRhY9IlHxdepltGLFlH/L2hCKVwbaTOP3RD
cCFeQwpmoKWoQV1UzoRqmdw3Vn+DMaUULomLVR9aSW9PnKeFL+tPWShf7GmVISfM
2H6xKw/qT0XAX59ZHA1laxSFVvbV5ZcKrBOFMV407Vzw2d3ojmfEzNsHjUVBXX8j
B5nK1VeJiTVmcoVhnRX7tXESDaZy+Kv38pqOmc8Svn70lDJ35SM2EpWnX39w5LsQ
29NsIUECgYEA/vNKiMfVmmZNQrpcuHQe5adlmz9+I4xJ4wbRzrS7czpbKF0/iaPf
dKoVz67yYHOJCBHTVaXWkElQsq1mkyuFt/cc0ReJXO8709+t+6ULsE50cLQm/HN5
npg3gw0Ls/9dy/cHM5SdVIHMBm9oQ65rXup/dqWC8Dz2cAAOQhIPwx0CgYEA3Jbk
DPdUlrj4sXcE3V/CtmBuK9Xq1xolJt026fYCrle0YhdMKmchRBDCc6BzM+F/vDyC
llPfQu8TDXK40Oan7GbxMdoLqKK9gSIq1dvfG1YMMz8OrBcX8xKe61KFRWd7QSBJ
BcY575NzYHapOHVGnUJ68j8zCow0gfb7q6iK4GkCgYEAz2mUuKSCxYL21hORfUqT
HFjMU7oa38axEa6pn9XvLjZKlRMPruWP1HTPG9ADRa6Yy+TcnrA1V9sdeM+TRKXC
usCiRAU27lF+xccS30gNs1iQaGRX10gGqJzDhK1nWP+nClmlFTSRrn+OQan/FBjh
Jy31lsveM54VC1cwQlY5Vo0CgYEArtjfnLNzFiE55xjq/znHUd4vlYlzItrzddHE
lEBOsbiNH29ODRI/2P7b0uDsT8Q/BoqEC/ohLqHn3TIA8nzRv91880HdGecdBL17
bJZiSv2yn/AshhWsAxzQYMDBKFk05lNb7jrIc3DR9DU6PqketsoaP+f+Yi7t89I8
fD0VD3kCgYAaJCoQshng/ijiHF/RJXLrXXHJSUmaOfbweX/mzFup0YR1LxUjcv85
cxvwc41Y2iI5MwUXyX97/GYKeoobzWZy3XflNWtg04rcInVaPsb/OOFDDqI+MkzT
B4PcCurOmjzcxHMVE34CYvl3YVwWrPb5JO1rYG9T2gKUJnLU6qG4Bw==
-----END RSA PRIVATE KEY-----
<?php
/*
Swift Mailer V4 accpetance test configuration.
YOU ONLY NEED TO EDIT THIS FILE IF YOU WISH TO RUN THE ACCEPTANCE TESTS.
The acceptance tests are run by default when "All Tests" are run with the
testing suite, however, without configuration options here only the unit tests
will be run and the acceptance tests will be skipped.
You can fill out only the parts you know and leave the other bits.
*/
/*
Defines: The name and port of a SMTP server you can connect to.
Recommended: smtp.gmail.com:25
*/
define('SWIFT_SMTP_HOST', 'localhost:4456');
/*
Defines: An SMTP server and port which uses TLS encryption.
Recommended: smtp.gmail.com:465
*/
define('SWIFT_TLS_HOST', 'smtp.gmail.com:465');
/*
Defines: An SMTP server and port which uses SSL encryption.
Recommended: smtp.gmail.com:465
*/
define('SWIFT_SSL_HOST', 'smtp.gmail.com:465');
/*
Defines: The path to a sendmail binary (one which can run in -bs mode).
Recommended: /usr/sbin/sendmail
*/
define('SWIFT_SENDMAIL_PATH', '/usr/sbin/sendmail -bs');
<?php
require_once 'swift_required.php';
require_once __DIR__.'/Mime/AttachmentAcceptanceTest.php';
class Swift_AttachmentAcceptanceTest extends Swift_Mime_AttachmentAcceptanceTest
{
protected function _createAttachment()
{
return Swift_Attachment::newInstance();
}
}
<?php
class Swift_ByteStream_FileByteStreamAcceptanceTest extends \PHPUnit_Framework_TestCase
{
private $_testFile;
protected function setUp()
{
$this->_testFile = sys_get_temp_dir().'/swift-test-file'.__CLASS__;
file_put_contents($this->_testFile, 'abcdefghijklm');
}
protected function tearDown()
{
unlink($this->_testFile);
}
public function testFileDataCanBeRead()
{
$file = $this->_createFileStream($this->_testFile);
$str = '';
while (false !== $bytes = $file->read(8192)) {
$str .= $bytes;
}
$this->assertEquals('abcdefghijklm', $str);
}
public function testFileDataCanBeReadSequentially()
{
$file = $this->_createFileStream($this->_testFile);
$this->assertEquals('abcde', $file->read(5));
$this->assertEquals('fghijklm', $file->read(8));
$this->assertFalse($file->read(1));
}
public function testFilenameIsReturned()
{
$file = $this->_createFileStream($this->_testFile);
$this->assertEquals($this->_testFile, $file->getPath());
}
public function testFileCanBeWrittenTo()
{
$file = $this->_createFileStream($this->_testFile, true);
$file->write('foobar');
$this->assertEquals('foobar', $file->read(8192));
}
public function testReadingFromThenWritingToFile()
{
$file = $this->_createFileStream($this->_testFile, true);
$file->write('foobar');
$this->assertEquals('foobar', $file->read(8192));
$file->write('zipbutton');
$this->assertEquals('zipbutton', $file->read(8192));
}
public function testWritingToFileWithCanonicalization()
{
$file = $this->_createFileStream($this->_testFile, true);
$file->addFilter($this->_createFilter(array("\r\n", "\r"), "\n"), 'allToLF');
$file->write("foo\r\nbar\r");
$file->write("\nzip\r\ntest\r");
$file->flushBuffers();
$this->assertEquals("foo\nbar\nzip\ntest\n", file_get_contents($this->_testFile));
}
public function testWritingWithFulleMessageLengthOfAMultipleOf8192()
{
$file = $this->_createFileStream($this->_testFile, true);
$file->addFilter($this->_createFilter(array("\r\n", "\r"), "\n"), 'allToLF');
$file->write('');
$file->flushBuffers();
$this->assertEquals('', file_get_contents($this->_testFile));
}
public function testBindingOtherStreamsMirrorsWriteOperations()
{
$file = $this->_createFileStream($this->_testFile, true);
$is1 = $this->_createMockInputStream();
$is2 = $this->_createMockInputStream();
$is1->expects($this->at(0))
->method('write')
->with('x');
$is1->expects($this->at(1))
->method('write')
->with('y');
$is2->expects($this->at(0))
->method('write')
->with('x');
$is2->expects($this->at(1))
->method('write')
->with('y');
$file->bind($is1);
$file->bind($is2);
$file->write('x');
$file->write('y');
}
public function testBindingOtherStreamsMirrorsFlushOperations()
{
$file = $this->_createFileStream(
$this->_testFile, true
);
$is1 = $this->_createMockInputStream();
$is2 = $this->_createMockInputStream();
$is1->expects($this->once())
->method('flushBuffers');
$is2->expects($this->once())
->method('flushBuffers');
$file->bind($is1);
$file->bind($is2);
$file->flushBuffers();
}
public function testUnbindingStreamPreventsFurtherWrites()
{
$file = $this->_createFileStream($this->_testFile, true);
$is1 = $this->_createMockInputStream();
$is2 = $this->_createMockInputStream();
$is1->expects($this->at(0))
->method('write')
->with('x');
$is1->expects($this->at(1))
->method('write')
->with('y');
$is2->expects($this->once())
->method('write')
->with('x');
$file->bind($is1);
$file->bind($is2);
$file->write('x');
$file->unbind($is2);
$file->write('y');
}
private function _createFilter($search, $replace)
{
return new Swift_StreamFilters_StringReplacementFilter($search, $replace);
}
private function _createMockInputStream()
{
return $this->getMockBuilder('Swift_InputByteStream')->getMock();
}
private function _createFileStream($file, $writable = false)
{
return new Swift_ByteStream_FileByteStream($file, $writable);
}
}
<?php
class Swift_CharacterReaderFactory_SimpleCharacterReaderFactoryAcceptanceTest extends \PHPUnit_Framework_TestCase
{
private $_factory;
private $_prefix = 'Swift_CharacterReader_';
protected function setUp()
{
$this->_factory = new Swift_CharacterReaderFactory_SimpleCharacterReaderFactory();
}
public function testCreatingUtf8Reader()
{
foreach (array('utf8', 'utf-8', 'UTF-8', 'UTF8') as $utf8) {
$reader = $this->_factory->getReaderFor($utf8);
$this->assertInstanceof($this->_prefix.'Utf8Reader', $reader);
}
}
public function testCreatingIso8859XReaders()
{
$charsets = array();
foreach (range(1, 16) as $number) {
foreach (array('iso', 'iec') as $body) {
$charsets[] = $body.'-8859-'.$number;
$charsets[] = $body.'8859-'.$number;
$charsets[] = strtoupper($body).'-8859-'.$number;
$charsets[] = strtoupper($body).'8859-'.$number;
}
}
foreach ($charsets as $charset) {
$reader = $this->_factory->getReaderFor($charset);
$this->assertInstanceof($this->_prefix.'GenericFixedWidthReader', $reader);
$this->assertEquals(1, $reader->getInitialByteSize());
}
}
public function testCreatingWindows125XReaders()
{
$charsets = array();
foreach (range(0, 8) as $number) {
$charsets[] = 'windows-125'.$number;
$charsets[] = 'windows125'.$number;
$charsets[] = 'WINDOWS-125'.$number;
$charsets[] = 'WINDOWS125'.$number;
}
foreach ($charsets as $charset) {
$reader = $this->_factory->getReaderFor($charset);
$this->assertInstanceof($this->_prefix.'GenericFixedWidthReader', $reader);
$this->assertEquals(1, $reader->getInitialByteSize());
}
}
public function testCreatingCodePageReaders()
{
$charsets = array();
foreach (range(0, 8) as $number) {
$charsets[] = 'cp-125'.$number;
$charsets[] = 'cp125'.$number;
$charsets[] = 'CP-125'.$number;
$charsets[] = 'CP125'.$number;
}
foreach (array(437, 737, 850, 855, 857, 858, 860,
861, 863, 865, 866, 869, ) as $number) {
$charsets[] = 'cp-'.$number;
$charsets[] = 'cp'.$number;
$charsets[] = 'CP-'.$number;
$charsets[] = 'CP'.$number;
}
foreach ($charsets as $charset) {
$reader = $this->_factory->getReaderFor($charset);
$this->assertInstanceof($this->_prefix.'GenericFixedWidthReader', $reader);
$this->assertEquals(1, $reader->getInitialByteSize());
}
}
public function testCreatingAnsiReader()
{
foreach (array('ansi', 'ANSI') as $ansi) {
$reader = $this->_factory->getReaderFor($ansi);
$this->assertInstanceof($this->_prefix.'GenericFixedWidthReader', $reader);
$this->assertEquals(1, $reader->getInitialByteSize());
}
}
public function testCreatingMacintoshReader()
{
foreach (array('macintosh', 'MACINTOSH') as $mac) {
$reader = $this->_factory->getReaderFor($mac);
$this->assertInstanceof($this->_prefix.'GenericFixedWidthReader', $reader);
$this->assertEquals(1, $reader->getInitialByteSize());
}
}
public function testCreatingKOIReaders()
{
$charsets = array();
foreach (array('7', '8-r', '8-u', '8u', '8r') as $end) {
$charsets[] = 'koi-'.$end;
$charsets[] = 'koi'.$end;
$charsets[] = 'KOI-'.$end;
$charsets[] = 'KOI'.$end;
}
foreach ($charsets as $charset) {
$reader = $this->_factory->getReaderFor($charset);
$this->assertInstanceof($this->_prefix.'GenericFixedWidthReader', $reader);
$this->assertEquals(1, $reader->getInitialByteSize());
}
}
public function testCreatingIsciiReaders()
{
foreach (array('iscii', 'ISCII', 'viscii', 'VISCII') as $charset) {
$reader = $this->_factory->getReaderFor($charset);
$this->assertInstanceof($this->_prefix.'GenericFixedWidthReader', $reader);
$this->assertEquals(1, $reader->getInitialByteSize());
}
}
public function testCreatingMIKReader()
{
foreach (array('mik', 'MIK') as $charset) {
$reader = $this->_factory->getReaderFor($charset);
$this->assertInstanceof($this->_prefix.'GenericFixedWidthReader', $reader);
$this->assertEquals(1, $reader->getInitialByteSize());
}
}
public function testCreatingCorkReader()
{
foreach (array('cork', 'CORK', 't1', 'T1') as $charset) {
$reader = $this->_factory->getReaderFor($charset);
$this->assertInstanceof($this->_prefix.'GenericFixedWidthReader', $reader);
$this->assertEquals(1, $reader->getInitialByteSize());
}
}
public function testCreatingUcs2Reader()
{
foreach (array('ucs-2', 'UCS-2', 'ucs2', 'UCS2') as $charset) {
$reader = $this->_factory->getReaderFor($charset);
$this->assertInstanceof($this->_prefix.'GenericFixedWidthReader', $reader);
$this->assertEquals(2, $reader->getInitialByteSize());
}
}
public function testCreatingUtf16Reader()
{
foreach (array('utf-16', 'UTF-16', 'utf16', 'UTF16') as $charset) {
$reader = $this->_factory->getReaderFor($charset);
$this->assertInstanceof($this->_prefix.'GenericFixedWidthReader', $reader);
$this->assertEquals(2, $reader->getInitialByteSize());
}
}
public function testCreatingUcs4Reader()
{
foreach (array('ucs-4', 'UCS-4', 'ucs4', 'UCS4') as $charset) {
$reader = $this->_factory->getReaderFor($charset);
$this->assertInstanceof($this->_prefix.'GenericFixedWidthReader', $reader);
$this->assertEquals(4, $reader->getInitialByteSize());
}
}
public function testCreatingUtf32Reader()
{
foreach (array('utf-32', 'UTF-32', 'utf32', 'UTF32') as $charset) {
$reader = $this->_factory->getReaderFor($charset);
$this->assertInstanceof($this->_prefix.'GenericFixedWidthReader', $reader);
$this->assertEquals(4, $reader->getInitialByteSize());
}
}
}
<?php
require_once 'swift_required.php';
//This is more of a "cross your fingers and hope it works" test!
class Swift_DependencyContainerAcceptanceTest extends \PHPUnit_Framework_TestCase
{
public function testNoLookupsFail()
{
$di = Swift_DependencyContainer::getInstance();
foreach ($di->listItems() as $itemName) {
try {
// to be removed in 6.0
if ('transport.mail' === $itemName) {
continue;
}
$di->lookup($itemName);
} catch (Swift_DependencyException $e) {
$this->fail($e->getMessage());
}
}
}
}
<?php
require_once 'swift_required.php';
require_once __DIR__.'/Mime/EmbeddedFileAcceptanceTest.php';
class Swift_EmbeddedFileAcceptanceTest extends Swift_Mime_EmbeddedFileAcceptanceTest
{
protected function _createEmbeddedFile()
{
return Swift_EmbeddedFile::newInstance();
}
}
<?php
class Swift_Encoder_Base64EncoderAcceptanceTest extends \PHPUnit_Framework_TestCase
{
private $_samplesDir;
private $_encoder;
protected function setUp()
{
$this->_samplesDir = realpath(__DIR__.'/../../../_samples/charsets');
$this->_encoder = new Swift_Encoder_Base64Encoder();
}
public function testEncodingAndDecodingSamples()
{
$sampleFp = opendir($this->_samplesDir);
while (false !== $encodingDir = readdir($sampleFp)) {
if (substr($encodingDir, 0, 1) == '.') {
continue;
}
$sampleDir = $this->_samplesDir.'/'.$encodingDir;
if (is_dir($sampleDir)) {
$fileFp = opendir($sampleDir);
while (false !== $sampleFile = readdir($fileFp)) {
if (substr($sampleFile, 0, 1) == '.') {
continue;
}
$text = file_get_contents($sampleDir.'/'.$sampleFile);
$encodedText = $this->_encoder->encodeString($text);
$this->assertEquals(
base64_decode($encodedText), $text,
'%s: Encoded string should decode back to original string for sample '.
$sampleDir.'/'.$sampleFile
);
}
closedir($fileFp);
}
}
closedir($sampleFp);
}
}
<?php
class Swift_Encoder_QpEncoderAcceptanceTest extends \PHPUnit_Framework_TestCase
{
private $_samplesDir;
private $_factory;
protected function setUp()
{
$this->_samplesDir = realpath(__DIR__.'/../../../_samples/charsets');
$this->_factory = new Swift_CharacterReaderFactory_SimpleCharacterReaderFactory();
}
public function testEncodingAndDecodingSamples()
{
$sampleFp = opendir($this->_samplesDir);
while (false !== $encodingDir = readdir($sampleFp)) {
if (substr($encodingDir, 0, 1) == '.') {
continue;
}
$encoding = $encodingDir;
$charStream = new Swift_CharacterStream_ArrayCharacterStream(
$this->_factory, $encoding);
$encoder = new Swift_Encoder_QpEncoder($charStream);
$sampleDir = $this->_samplesDir.'/'.$encodingDir;
if (is_dir($sampleDir)) {
$fileFp = opendir($sampleDir);
while (false !== $sampleFile = readdir($fileFp)) {
if (substr($sampleFile, 0, 1) == '.') {
continue;
}
$text = file_get_contents($sampleDir.'/'.$sampleFile);
$encodedText = $encoder->encodeString($text);
foreach (explode("\r\n", $encodedText) as $line) {
$this->assertLessThanOrEqual(76, strlen($line));
}
$this->assertEquals(
quoted_printable_decode($encodedText), $text,
'%s: Encoded string should decode back to original string for sample '.
$sampleDir.'/'.$sampleFile
);
}
closedir($fileFp);
}
}
closedir($sampleFp);
}
}
<?php
class Swift_Encoder_Rfc2231EncoderAcceptanceTest extends \PHPUnit_Framework_TestCase
{
private $_samplesDir;
private $_factory;
protected function setUp()
{
$this->_samplesDir = realpath(__DIR__.'/../../../_samples/charsets');
$this->_factory = new Swift_CharacterReaderFactory_SimpleCharacterReaderFactory();
}
public function testEncodingAndDecodingSamples()
{
$sampleFp = opendir($this->_samplesDir);
while (false !== $encodingDir = readdir($sampleFp)) {
if (substr($encodingDir, 0, 1) == '.') {
continue;
}
$encoding = $encodingDir;
$charStream = new Swift_CharacterStream_ArrayCharacterStream(
$this->_factory, $encoding);
$encoder = new Swift_Encoder_Rfc2231Encoder($charStream);
$sampleDir = $this->_samplesDir.'/'.$encodingDir;
if (is_dir($sampleDir)) {
$fileFp = opendir($sampleDir);
while (false !== $sampleFile = readdir($fileFp)) {
if (substr($sampleFile, 0, 1) == '.') {
continue;
}
$text = file_get_contents($sampleDir.'/'.$sampleFile);
$encodedText = $encoder->encodeString($text);
$this->assertEquals(
urldecode(implode('', explode("\r\n", $encodedText))), $text,
'%s: Encoded string should decode back to original string for sample '.
$sampleDir.'/'.$sampleFile
);
}
closedir($fileFp);
}
}
closedir($sampleFp);
}
}
<?php
require_once 'swift_required.php';
class Swift_EncodingAcceptanceTest extends \PHPUnit_Framework_TestCase
{
public function testGet7BitEncodingReturns7BitEncoder()
{
$encoder = Swift_Encoding::get7BitEncoding();
$this->assertEquals('7bit', $encoder->getName());
}
public function testGet8BitEncodingReturns8BitEncoder()
{
$encoder = Swift_Encoding::get8BitEncoding();
$this->assertEquals('8bit', $encoder->getName());
}
public function testGetQpEncodingReturnsQpEncoder()
{
$encoder = Swift_Encoding::getQpEncoding();
$this->assertEquals('quoted-printable', $encoder->getName());
}
public function testGetBase64EncodingReturnsBase64Encoder()
{
$encoder = Swift_Encoding::getBase64Encoding();
$this->assertEquals('base64', $encoder->getName());
}
}
<?php
class Swift_KeyCache_ArrayKeyCacheAcceptanceTest extends \PHPUnit_Framework_TestCase
{
private $_cache;
private $_key1 = 'key1';
private $_key2 = 'key2';
protected function setUp()
{
$this->_cache = new Swift_KeyCache_ArrayKeyCache(
new Swift_KeyCache_SimpleKeyCacheInputStream()
);
}
public function testStringDataCanBeSetAndFetched()
{
$this->_cache->setString(
$this->_key1, 'foo', 'test', Swift_KeyCache::MODE_WRITE
);
$this->assertEquals('test', $this->_cache->getString($this->_key1, 'foo'));
}
public function testStringDataCanBeOverwritten()
{
$this->_cache->setString(
$this->_key1, 'foo', 'test', Swift_KeyCache::MODE_WRITE
);
$this->_cache->setString(
$this->_key1, 'foo', 'whatever', Swift_KeyCache::MODE_WRITE
);
$this->assertEquals('whatever', $this->_cache->getString($this->_key1, 'foo'));
}
public function testStringDataCanBeAppended()
{
$this->_cache->setString(
$this->_key1, 'foo', 'test', Swift_KeyCache::MODE_WRITE
);
$this->_cache->setString(
$this->_key1, 'foo', 'ing', Swift_KeyCache::MODE_APPEND
);
$this->assertEquals('testing', $this->_cache->getString($this->_key1, 'foo'));
}
public function testHasKeyReturnValue()
{
$this->assertFalse($this->_cache->hasKey($this->_key1, 'foo'));
$this->_cache->setString(
$this->_key1, 'foo', 'test', Swift_KeyCache::MODE_WRITE
);
$this->assertTrue($this->_cache->hasKey($this->_key1, 'foo'));
}
public function testNsKeyIsWellPartitioned()
{
$this->_cache->setString(
$this->_key1, 'foo', 'test', Swift_KeyCache::MODE_WRITE
);
$this->_cache->setString(
$this->_key2, 'foo', 'ing', Swift_KeyCache::MODE_WRITE
);
$this->assertEquals('test', $this->_cache->getString($this->_key1, 'foo'));
$this->assertEquals('ing', $this->_cache->getString($this->_key2, 'foo'));
}
public function testItemKeyIsWellPartitioned()
{
$this->_cache->setString(
$this->_key1, 'foo', 'test', Swift_KeyCache::MODE_WRITE
);
$this->_cache->setString(
$this->_key1, 'bar', 'ing', Swift_KeyCache::MODE_WRITE
);
$this->assertEquals('test', $this->_cache->getString($this->_key1, 'foo'));
$this->assertEquals('ing', $this->_cache->getString($this->_key1, 'bar'));
}
public function testByteStreamCanBeImported()
{
$os = new Swift_ByteStream_ArrayByteStream();
$os->write('abcdef');
$this->_cache->importFromByteStream(
$this->_key1, 'foo', $os, Swift_KeyCache::MODE_WRITE
);
$this->assertEquals('abcdef', $this->_cache->getString($this->_key1, 'foo'));
}
public function testByteStreamCanBeAppended()
{
$os1 = new Swift_ByteStream_ArrayByteStream();
$os1->write('abcdef');
$os2 = new Swift_ByteStream_ArrayByteStream();
$os2->write('xyzuvw');
$this->_cache->importFromByteStream(
$this->_key1, 'foo', $os1, Swift_KeyCache::MODE_APPEND
);
$this->_cache->importFromByteStream(
$this->_key1, 'foo', $os2, Swift_KeyCache::MODE_APPEND
);
$this->assertEquals('abcdefxyzuvw', $this->_cache->getString($this->_key1, 'foo'));
}
public function testByteStreamAndStringCanBeAppended()
{
$this->_cache->setString(
$this->_key1, 'foo', 'test', Swift_KeyCache::MODE_APPEND
);
$os = new Swift_ByteStream_ArrayByteStream();
$os->write('abcdef');
$this->_cache->importFromByteStream(
$this->_key1, 'foo', $os, Swift_KeyCache::MODE_APPEND
);
$this->assertEquals('testabcdef', $this->_cache->getString($this->_key1, 'foo'));
}
public function testDataCanBeExportedToByteStream()
{
$this->_cache->setString(
$this->_key1, 'foo', 'test', Swift_KeyCache::MODE_WRITE
);
$is = new Swift_ByteStream_ArrayByteStream();
$this->_cache->exportToByteStream($this->_key1, 'foo', $is);
$string = '';
while (false !== $bytes = $is->read(8192)) {
$string .= $bytes;
}
$this->assertEquals('test', $string);
}
public function testKeyCanBeCleared()
{
$this->_cache->setString(
$this->_key1, 'foo', 'test', Swift_KeyCache::MODE_WRITE
);
$this->assertTrue($this->_cache->hasKey($this->_key1, 'foo'));
$this->_cache->clearKey($this->_key1, 'foo');
$this->assertFalse($this->_cache->hasKey($this->_key1, 'foo'));
}
public function testNsKeyCanBeCleared()
{
$this->_cache->setString(
$this->_key1, 'foo', 'test', Swift_KeyCache::MODE_WRITE
);
$this->_cache->setString(
$this->_key1, 'bar', 'xyz', Swift_KeyCache::MODE_WRITE
);
$this->assertTrue($this->_cache->hasKey($this->_key1, 'foo'));
$this->assertTrue($this->_cache->hasKey($this->_key1, 'bar'));
$this->_cache->clearAll($this->_key1);
$this->assertFalse($this->_cache->hasKey($this->_key1, 'foo'));
$this->assertFalse($this->_cache->hasKey($this->_key1, 'bar'));
}
public function testKeyCacheInputStream()
{
$is = $this->_cache->getInputByteStream($this->_key1, 'foo');
$is->write('abc');
$is->write('xyz');
$this->assertEquals('abcxyz', $this->_cache->getString($this->_key1, 'foo'));
}
}
<?php
class Swift_KeyCache_DiskKeyCacheAcceptanceTest extends \PHPUnit_Framework_TestCase
{
private $_cache;
private $_key1;
private $_key2;
protected function setUp()
{
$this->_key1 = uniqid(microtime(true), true);
$this->_key2 = uniqid(microtime(true), true);
$this->_cache = new Swift_KeyCache_DiskKeyCache(new Swift_KeyCache_SimpleKeyCacheInputStream(), sys_get_temp_dir());
}
public function testStringDataCanBeSetAndFetched()
{
$this->_cache->setString(
$this->_key1, 'foo', 'test', Swift_KeyCache::MODE_WRITE
);
$this->assertEquals('test', $this->_cache->getString($this->_key1, 'foo'));
}
public function testStringDataCanBeOverwritten()
{
$this->_cache->setString(
$this->_key1, 'foo', 'test', Swift_KeyCache::MODE_WRITE
);
$this->_cache->setString(
$this->_key1, 'foo', 'whatever', Swift_KeyCache::MODE_WRITE
);
$this->assertEquals('whatever', $this->_cache->getString($this->_key1, 'foo'));
}
public function testStringDataCanBeAppended()
{
$this->_cache->setString(
$this->_key1, 'foo', 'test', Swift_KeyCache::MODE_WRITE
);
$this->_cache->setString(
$this->_key1, 'foo', 'ing', Swift_KeyCache::MODE_APPEND
);
$this->assertEquals('testing', $this->_cache->getString($this->_key1, 'foo'));
}
public function testHasKeyReturnValue()
{
$this->assertFalse($this->_cache->hasKey($this->_key1, 'foo'));
$this->_cache->setString(
$this->_key1, 'foo', 'test', Swift_KeyCache::MODE_WRITE
);
$this->assertTrue($this->_cache->hasKey($this->_key1, 'foo'));
}
public function testNsKeyIsWellPartitioned()
{
$this->_cache->setString(
$this->_key1, 'foo', 'test', Swift_KeyCache::MODE_WRITE
);
$this->_cache->setString(
$this->_key2, 'foo', 'ing', Swift_KeyCache::MODE_WRITE
);
$this->assertEquals('test', $this->_cache->getString($this->_key1, 'foo'));
$this->assertEquals('ing', $this->_cache->getString($this->_key2, 'foo'));
}
public function testItemKeyIsWellPartitioned()
{
$this->_cache->setString(
$this->_key1, 'foo', 'test', Swift_KeyCache::MODE_WRITE
);
$this->_cache->setString(
$this->_key1, 'bar', 'ing', Swift_KeyCache::MODE_WRITE
);
$this->assertEquals('test', $this->_cache->getString($this->_key1, 'foo'));
$this->assertEquals('ing', $this->_cache->getString($this->_key1, 'bar'));
}
public function testByteStreamCanBeImported()
{
$os = new Swift_ByteStream_ArrayByteStream();
$os->write('abcdef');
$this->_cache->importFromByteStream(
$this->_key1, 'foo', $os, Swift_KeyCache::MODE_WRITE
);
$this->assertEquals('abcdef', $this->_cache->getString($this->_key1, 'foo'));
}
public function testByteStreamCanBeAppended()
{
$os1 = new Swift_ByteStream_ArrayByteStream();
$os1->write('abcdef');
$os2 = new Swift_ByteStream_ArrayByteStream();
$os2->write('xyzuvw');
$this->_cache->importFromByteStream(
$this->_key1, 'foo', $os1, Swift_KeyCache::MODE_APPEND
);
$this->_cache->importFromByteStream(
$this->_key1, 'foo', $os2, Swift_KeyCache::MODE_APPEND
);
$this->assertEquals('abcdefxyzuvw', $this->_cache->getString($this->_key1, 'foo'));
}
public function testByteStreamAndStringCanBeAppended()
{
$this->_cache->setString(
$this->_key1, 'foo', 'test', Swift_KeyCache::MODE_APPEND
);
$os = new Swift_ByteStream_ArrayByteStream();
$os->write('abcdef');
$this->_cache->importFromByteStream(
$this->_key1, 'foo', $os, Swift_KeyCache::MODE_APPEND
);
$this->assertEquals('testabcdef', $this->_cache->getString($this->_key1, 'foo'));
}
public function testDataCanBeExportedToByteStream()
{
$this->_cache->setString(
$this->_key1, 'foo', 'test', Swift_KeyCache::MODE_WRITE
);
$is = new Swift_ByteStream_ArrayByteStream();
$this->_cache->exportToByteStream($this->_key1, 'foo', $is);
$string = '';
while (false !== $bytes = $is->read(8192)) {
$string .= $bytes;
}
$this->assertEquals('test', $string);
}
public function testKeyCanBeCleared()
{
$this->_cache->setString(
$this->_key1, 'foo', 'test', Swift_KeyCache::MODE_WRITE
);
$this->assertTrue($this->_cache->hasKey($this->_key1, 'foo'));
$this->_cache->clearKey($this->_key1, 'foo');
$this->assertFalse($this->_cache->hasKey($this->_key1, 'foo'));
}
public function testNsKeyCanBeCleared()
{
$this->_cache->setString(
$this->_key1, 'foo', 'test', Swift_KeyCache::MODE_WRITE
);
$this->_cache->setString(
$this->_key1, 'bar', 'xyz', Swift_KeyCache::MODE_WRITE
);
$this->assertTrue($this->_cache->hasKey($this->_key1, 'foo'));
$this->assertTrue($this->_cache->hasKey($this->_key1, 'bar'));
$this->_cache->clearAll($this->_key1);
$this->assertFalse($this->_cache->hasKey($this->_key1, 'foo'));
$this->assertFalse($this->_cache->hasKey($this->_key1, 'bar'));
}
public function testKeyCacheInputStream()
{
$is = $this->_cache->getInputByteStream($this->_key1, 'foo');
$is->write('abc');
$is->write('xyz');
$this->assertEquals('abcxyz', $this->_cache->getString($this->_key1, 'foo'));
}
}
<?php
require_once 'swift_required.php';
require_once __DIR__.'/Mime/SimpleMessageAcceptanceTest.php';
class Swift_MessageAcceptanceTest extends Swift_Mime_SimpleMessageAcceptanceTest
{
public function testAddPartWrapper()
{
$message = $this->_createMessage();
$message->setSubject('just a test subject');
$message->setFrom(array(
'chris.corbyn@swiftmailer.org' => 'Chris Corbyn', ));
$id = $message->getId();
$date = $message->getDate();
$boundary = $message->getBoundary();
$message->addPart('foo', 'text/plain', 'iso-8859-1');
$message->addPart('test <b>foo</b>', 'text/html', 'iso-8859-1');
$this->assertEquals(
'Message-ID: <'.$id.'>'."\r\n".
'Date: '.date('r', $date)."\r\n".
'Subject: just a test subject'."\r\n".
'From: Chris Corbyn <chris.corbyn@swiftmailer.org>'."\r\n".
'MIME-Version: 1.0'."\r\n".
'Content-Type: multipart/alternative;'."\r\n".
' boundary="'.$boundary.'"'."\r\n".
"\r\n\r\n".
'--'.$boundary."\r\n".
'Content-Type: text/plain; charset=iso-8859-1'."\r\n".
'Content-Transfer-Encoding: quoted-printable'."\r\n".
"\r\n".
'foo'.
"\r\n\r\n".
'--'.$boundary."\r\n".
'Content-Type: text/html; charset=iso-8859-1'."\r\n".
'Content-Transfer-Encoding: quoted-printable'."\r\n".
"\r\n".
'test <b>foo</b>'.
"\r\n\r\n".
'--'.$boundary.'--'."\r\n",
$message->toString()
);
}
protected function _createMessage()
{
Swift_DependencyContainer::getInstance()
->register('properties.charset')->asValue(null);
return Swift_Message::newInstance();
}
}
<?php
class Swift_Mime_AttachmentAcceptanceTest extends \PHPUnit_Framework_TestCase
{
private $_contentEncoder;
private $_cache;
private $_grammar;
private $_headers;
protected function setUp()
{
$this->_cache = new Swift_KeyCache_ArrayKeyCache(
new Swift_KeyCache_SimpleKeyCacheInputStream()
);
$factory = new Swift_CharacterReaderFactory_SimpleCharacterReaderFactory();
$this->_contentEncoder = new Swift_Mime_ContentEncoder_Base64ContentEncoder();
$headerEncoder = new Swift_Mime_HeaderEncoder_QpHeaderEncoder(
new Swift_CharacterStream_ArrayCharacterStream($factory, 'utf-8')
);
$paramEncoder = new Swift_Encoder_Rfc2231Encoder(
new Swift_CharacterStream_ArrayCharacterStream($factory, 'utf-8')
);
$this->_grammar = new Swift_Mime_Grammar();
$this->_headers = new Swift_Mime_SimpleHeaderSet(
new Swift_Mime_SimpleHeaderFactory($headerEncoder, $paramEncoder, $this->_grammar)
);
}
public function testDispositionIsSetInHeader()
{
$attachment = $this->_createAttachment();
$attachment->setContentType('application/pdf');
$attachment->setDisposition('inline');
$this->assertEquals(
'Content-Type: application/pdf'."\r\n".
'Content-Transfer-Encoding: base64'."\r\n".
'Content-Disposition: inline'."\r\n",
$attachment->toString()
);
}
public function testDispositionIsAttachmentByDefault()
{
$attachment = $this->_createAttachment();
$attachment->setContentType('application/pdf');
$this->assertEquals(
'Content-Type: application/pdf'."\r\n".
'Content-Transfer-Encoding: base64'."\r\n".
'Content-Disposition: attachment'."\r\n",
$attachment->toString()
);
}
public function testFilenameIsSetInHeader()
{
$attachment = $this->_createAttachment();
$attachment->setContentType('application/pdf');
$attachment->setFilename('foo.pdf');
$this->assertEquals(
'Content-Type: application/pdf; name=foo.pdf'."\r\n".
'Content-Transfer-Encoding: base64'."\r\n".
'Content-Disposition: attachment; filename=foo.pdf'."\r\n",
$attachment->toString()
);
}
public function testSizeIsSetInHeader()
{
$attachment = $this->_createAttachment();
$attachment->setContentType('application/pdf');
$attachment->setSize(12340);
$this->assertEquals(
'Content-Type: application/pdf'."\r\n".
'Content-Transfer-Encoding: base64'."\r\n".
'Content-Disposition: attachment; size=12340'."\r\n",
$attachment->toString()
);
}
public function testMultipleParametersInHeader()
{
$attachment = $this->_createAttachment();
$attachment->setContentType('application/pdf');
$attachment->setFilename('foo.pdf');
$attachment->setSize(12340);
$this->assertEquals(
'Content-Type: application/pdf; name=foo.pdf'."\r\n".
'Content-Transfer-Encoding: base64'."\r\n".
'Content-Disposition: attachment; filename=foo.pdf; size=12340'."\r\n",
$attachment->toString()
);
}
public function testEndToEnd()
{
$attachment = $this->_createAttachment();
$attachment->setContentType('application/pdf');
$attachment->setFilename('foo.pdf');
$attachment->setSize(12340);
$attachment->setBody('abcd');
$this->assertEquals(
'Content-Type: application/pdf; name=foo.pdf'."\r\n".
'Content-Transfer-Encoding: base64'."\r\n".
'Content-Disposition: attachment; filename=foo.pdf; size=12340'."\r\n".
"\r\n".
base64_encode('abcd'),
$attachment->toString()
);
}
protected function _createAttachment()
{
$entity = new Swift_Mime_Attachment(
$this->_headers,
$this->_contentEncoder,
$this->_cache,
$this->_grammar
);
return $entity;
}
}
<?php
class Swift_Mime_ContentEncoder_Base64ContentEncoderAcceptanceTest extends \PHPUnit_Framework_TestCase
{
private $_samplesDir;
private $_encoder;
protected function setUp()
{
$this->_samplesDir = realpath(__DIR__.'/../../../../_samples/charsets');
$this->_encoder = new Swift_Mime_ContentEncoder_Base64ContentEncoder();
}
public function testEncodingAndDecodingSamples()
{
$sampleFp = opendir($this->_samplesDir);
while (false !== $encodingDir = readdir($sampleFp)) {
if (substr($encodingDir, 0, 1) == '.') {
continue;
}
$sampleDir = $this->_samplesDir.'/'.$encodingDir;
if (is_dir($sampleDir)) {
$fileFp = opendir($sampleDir);
while (false !== $sampleFile = readdir($fileFp)) {
if (substr($sampleFile, 0, 1) == '.') {
continue;
}
$text = file_get_contents($sampleDir.'/'.$sampleFile);
$os = new Swift_ByteStream_ArrayByteStream();
$os->write($text);
$is = new Swift_ByteStream_ArrayByteStream();
$this->_encoder->encodeByteStream($os, $is);
$encoded = '';
while (false !== $bytes = $is->read(8192)) {
$encoded .= $bytes;
}
$this->assertEquals(
base64_decode($encoded), $text,
'%s: Encoded string should decode back to original string for sample '.
$sampleDir.'/'.$sampleFile
);
}
closedir($fileFp);
}
}
closedir($sampleFp);
}
}
<?php
class Swift_Mime_ContentEncoder_NativeQpContentEncoderAcceptanceTest extends \PHPUnit_Framework_TestCase
{
protected $_samplesDir;
/**
* @var Swift_Mime_ContentEncoder_NativeQpContentEncoder
*/
protected $_encoder;
protected function setUp()
{
$this->_samplesDir = realpath(__DIR__.'/../../../../_samples/charsets');
$this->_encoder = new Swift_Mime_ContentEncoder_NativeQpContentEncoder();
}
public function testEncodingAndDecodingSamples()
{
$sampleFp = opendir($this->_samplesDir);
while (false !== $encodingDir = readdir($sampleFp)) {
if (substr($encodingDir, 0, 1) == '.') {
continue;
}
$sampleDir = $this->_samplesDir.'/'.$encodingDir;
if (is_dir($sampleDir)) {
$fileFp = opendir($sampleDir);
while (false !== $sampleFile = readdir($fileFp)) {
if (substr($sampleFile, 0, 1) == '.') {
continue;
}
$text = file_get_contents($sampleDir.'/'.$sampleFile);
$os = new Swift_ByteStream_ArrayByteStream();
$os->write($text);
$is = new Swift_ByteStream_ArrayByteStream();
$this->_encoder->encodeByteStream($os, $is);
$encoded = '';
while (false !== $bytes = $is->read(8192)) {
$encoded .= $bytes;
}
$this->assertEquals(
quoted_printable_decode($encoded),
// CR and LF are converted to CRLF
preg_replace('~\r(?!\n)|(?<!\r)\n~', "\r\n", $text),
'%s: Encoded string should decode back to original string for sample '.$sampleDir.'/'.$sampleFile
);
}
closedir($fileFp);
}
}
closedir($sampleFp);
}
public function testEncodingAndDecodingSamplesFromDiConfiguredInstance()
{
$encoder = $this->_createEncoderFromContainer();
$this->assertSame('=C3=A4=C3=B6=C3=BC=C3=9F', $encoder->encodeString('äöüß'));
}
/**
* @expectedException \RuntimeException
*/
public function testCharsetChangeNotImplemented()
{
$this->_encoder->charsetChanged('utf-8');
$this->_encoder->charsetChanged('charset');
$this->_encoder->encodeString('foo');
}
public function testGetName()
{
$this->assertSame('quoted-printable', $this->_encoder->getName());
}
private function _createEncoderFromContainer()
{
return Swift_DependencyContainer::getInstance()
->lookup('mime.nativeqpcontentencoder')
;
}
}
<?php
class Swift_Mime_ContentEncoder_PlainContentEncoderAcceptanceTest extends \PHPUnit_Framework_TestCase
{
private $_samplesDir;
private $_encoder;
protected function setUp()
{
$this->_samplesDir = realpath(__DIR__.'/../../../../_samples/charsets');
$this->_encoder = new Swift_Mime_ContentEncoder_PlainContentEncoder('8bit');
}
public function testEncodingAndDecodingSamplesString()
{
$sampleFp = opendir($this->_samplesDir);
while (false !== $encodingDir = readdir($sampleFp)) {
if (substr($encodingDir, 0, 1) == '.') {
continue;
}
$sampleDir = $this->_samplesDir.'/'.$encodingDir;
if (is_dir($sampleDir)) {
$fileFp = opendir($sampleDir);
while (false !== $sampleFile = readdir($fileFp)) {
if (substr($sampleFile, 0, 1) == '.') {
continue;
}
$text = file_get_contents($sampleDir.'/'.$sampleFile);
$encodedText = $this->_encoder->encodeString($text);
$this->assertEquals(
$encodedText, $text,
'%s: Encoded string should be identical to original string for sample '.
$sampleDir.'/'.$sampleFile
);
}
closedir($fileFp);
}
}
closedir($sampleFp);
}
public function testEncodingAndDecodingSamplesByteStream()
{
$sampleFp = opendir($this->_samplesDir);
while (false !== $encodingDir = readdir($sampleFp)) {
if (substr($encodingDir, 0, 1) == '.') {
continue;
}
$sampleDir = $this->_samplesDir.'/'.$encodingDir;
if (is_dir($sampleDir)) {
$fileFp = opendir($sampleDir);
while (false !== $sampleFile = readdir($fileFp)) {
if (substr($sampleFile, 0, 1) == '.') {
continue;
}
$text = file_get_contents($sampleDir.'/'.$sampleFile);
$os = new Swift_ByteStream_ArrayByteStream();
$os->write($text);
$is = new Swift_ByteStream_ArrayByteStream();
$this->_encoder->encodeByteStream($os, $is);
$encoded = '';
while (false !== $bytes = $is->read(8192)) {
$encoded .= $bytes;
}
$this->assertEquals(
$encoded, $text,
'%s: Encoded string should be identical to original string for sample '.
$sampleDir.'/'.$sampleFile
);
}
closedir($fileFp);
}
}
closedir($sampleFp);
}
}
<?php
class Swift_Mime_ContentEncoder_QpContentEncoderAcceptanceTest extends \PHPUnit_Framework_TestCase
{
private $_samplesDir;
private $_factory;
protected function setUp()
{
$this->_samplesDir = realpath(__DIR__.'/../../../../_samples/charsets');
$this->_factory = new Swift_CharacterReaderFactory_SimpleCharacterReaderFactory();
}
protected function tearDown()
{
Swift_Preferences::getInstance()->setQPDotEscape(false);
}
public function testEncodingAndDecodingSamples()
{
$sampleFp = opendir($this->_samplesDir);
while (false !== $encodingDir = readdir($sampleFp)) {
if (substr($encodingDir, 0, 1) == '.') {
continue;
}
$encoding = $encodingDir;
$charStream = new Swift_CharacterStream_NgCharacterStream(
$this->_factory, $encoding);
$encoder = new Swift_Mime_ContentEncoder_QpContentEncoder($charStream);
$sampleDir = $this->_samplesDir.'/'.$encodingDir;
if (is_dir($sampleDir)) {
$fileFp = opendir($sampleDir);
while (false !== $sampleFile = readdir($fileFp)) {
if (substr($sampleFile, 0, 1) == '.') {
continue;
}
$text = file_get_contents($sampleDir.'/'.$sampleFile);
$os = new Swift_ByteStream_ArrayByteStream();
$os->write($text);
$is = new Swift_ByteStream_ArrayByteStream();
$encoder->encodeByteStream($os, $is);
$encoded = '';
while (false !== $bytes = $is->read(8192)) {
$encoded .= $bytes;
}
$this->assertEquals(
quoted_printable_decode($encoded), $text,
'%s: Encoded string should decode back to original string for sample '.
$sampleDir.'/'.$sampleFile
);
}
closedir($fileFp);
}
}
closedir($sampleFp);
}
public function testEncodingAndDecodingSamplesFromDiConfiguredInstance()
{
$sampleFp = opendir($this->_samplesDir);
while (false !== $encodingDir = readdir($sampleFp)) {
if (substr($encodingDir, 0, 1) == '.') {
continue;
}
$encoding = $encodingDir;
$encoder = $this->_createEncoderFromContainer();
$sampleDir = $this->_samplesDir.'/'.$encodingDir;
if (is_dir($sampleDir)) {
$fileFp = opendir($sampleDir);
while (false !== $sampleFile = readdir($fileFp)) {
if (substr($sampleFile, 0, 1) == '.') {
continue;
}
$text = file_get_contents($sampleDir.'/'.$sampleFile);
$os = new Swift_ByteStream_ArrayByteStream();
$os->write($text);
$is = new Swift_ByteStream_ArrayByteStream();
$encoder->encodeByteStream($os, $is);
$encoded = '';
while (false !== $bytes = $is->read(8192)) {
$encoded .= $bytes;
}
$this->assertEquals(
str_replace("\r\n", "\n", quoted_printable_decode($encoded)), str_replace("\r\n", "\n", $text),
'%s: Encoded string should decode back to original string for sample '.
$sampleDir.'/'.$sampleFile
);
}
closedir($fileFp);
}
}
closedir($sampleFp);
}
public function testEncodingLFTextWithDiConfiguredInstance()
{
$encoder = $this->_createEncoderFromContainer();
$this->assertEquals("a\r\nb\r\nc", $encoder->encodeString("a\nb\nc"));
}
public function testEncodingCRTextWithDiConfiguredInstance()
{
$encoder = $this->_createEncoderFromContainer();
$this->assertEquals("a\r\nb\r\nc", $encoder->encodeString("a\rb\rc"));
}
public function testEncodingLFCRTextWithDiConfiguredInstance()
{
$encoder = $this->_createEncoderFromContainer();
$this->assertEquals("a\r\n\r\nb\r\n\r\nc", $encoder->encodeString("a\n\rb\n\rc"));
}
public function testEncodingCRLFTextWithDiConfiguredInstance()
{
$encoder = $this->_createEncoderFromContainer();
$this->assertEquals("a\r\nb\r\nc", $encoder->encodeString("a\r\nb\r\nc"));
}
public function testEncodingDotStuffingWithDiConfiguredInstance()
{
// Enable DotEscaping
Swift_Preferences::getInstance()->setQPDotEscape(true);
$encoder = $this->_createEncoderFromContainer();
$this->assertEquals("a=2E\r\n=2E\r\n=2Eb\r\nc", $encoder->encodeString("a.\r\n.\r\n.b\r\nc"));
// Return to default
Swift_Preferences::getInstance()->setQPDotEscape(false);
$encoder = $this->_createEncoderFromContainer();
$this->assertEquals("a.\r\n.\r\n.b\r\nc", $encoder->encodeString("a.\r\n.\r\n.b\r\nc"));
}
public function testDotStuffingEncodingAndDecodingSamplesFromDiConfiguredInstance()
{
// Enable DotEscaping
Swift_Preferences::getInstance()->setQPDotEscape(true);
$this->testEncodingAndDecodingSamplesFromDiConfiguredInstance();
}
private function _createEncoderFromContainer()
{
return Swift_DependencyContainer::getInstance()
->lookup('mime.qpcontentencoder')
;
}
}
<?php
class Swift_Mime_HeaderEncoder_Base64HeaderEncoderAcceptanceTest extends \PHPUnit_Framework_TestCase
{
private $_encoder;
protected function setUp()
{
$this->_encoder = new Swift_Mime_HeaderEncoder_Base64HeaderEncoder();
}
public function testEncodingJIS()
{
if (function_exists('mb_convert_encoding')) {
// base64_encode and split cannot handle long JIS text to fold
$subject = '長い長い長い長い長い長い長い長い長い長い長い長い長い長い長い長い長い長い長い長い件名';
$encodedWrapperLength = strlen('=?iso-2022-jp?'.$this->_encoder->getName().'??=');
$old = mb_internal_encoding();
mb_internal_encoding('utf-8');
$newstring = mb_encode_mimeheader($subject, 'iso-2022-jp', 'B', "\r\n");
mb_internal_encoding($old);
$encoded = $this->_encoder->encodeString($subject, 0, 75 - $encodedWrapperLength, 'iso-2022-jp');
$this->assertEquals(
$encoded, $newstring,
'Encoded string should decode back to original string for sample '
);
}
}
}
<?php
class Swift_Mime_MimePartAcceptanceTest extends \PHPUnit_Framework_TestCase
{
private $_contentEncoder;
private $_cache;
private $_grammar;
private $_headers;
protected function setUp()
{
$this->_cache = new Swift_KeyCache_ArrayKeyCache(
new Swift_KeyCache_SimpleKeyCacheInputStream()
);
$factory = new Swift_CharacterReaderFactory_SimpleCharacterReaderFactory();
$this->_contentEncoder = new Swift_Mime_ContentEncoder_QpContentEncoder(
new Swift_CharacterStream_ArrayCharacterStream($factory, 'utf-8'),
new Swift_StreamFilters_ByteArrayReplacementFilter(
array(array(0x0D, 0x0A), array(0x0D), array(0x0A)),
array(array(0x0A), array(0x0A), array(0x0D, 0x0A))
)
);
$headerEncoder = new Swift_Mime_HeaderEncoder_QpHeaderEncoder(
new Swift_CharacterStream_ArrayCharacterStream($factory, 'utf-8')
);
$paramEncoder = new Swift_Encoder_Rfc2231Encoder(
new Swift_CharacterStream_ArrayCharacterStream($factory, 'utf-8')
);
$this->_grammar = new Swift_Mime_Grammar();
$this->_headers = new Swift_Mime_SimpleHeaderSet(
new Swift_Mime_SimpleHeaderFactory($headerEncoder, $paramEncoder, $this->_grammar)
);
}
public function testCharsetIsSetInHeader()
{
$part = $this->_createMimePart();
$part->setContentType('text/plain');
$part->setCharset('utf-8');
$part->setBody('foobar');
$this->assertEquals(
'Content-Type: text/plain; charset=utf-8'."\r\n".
'Content-Transfer-Encoding: quoted-printable'."\r\n".
"\r\n".
'foobar',
$part->toString()
);
}
public function testFormatIsSetInHeaders()
{
$part = $this->_createMimePart();
$part->setContentType('text/plain');
$part->setFormat('flowed');
$part->setBody('> foobar');
$this->assertEquals(
'Content-Type: text/plain; format=flowed'."\r\n".
'Content-Transfer-Encoding: quoted-printable'."\r\n".
"\r\n".
'> foobar',
$part->toString()
);
}
public function testDelSpIsSetInHeaders()
{
$part = $this->_createMimePart();
$part->setContentType('text/plain');
$part->setDelSp(true);
$part->setBody('foobar');
$this->assertEquals(
'Content-Type: text/plain; delsp=yes'."\r\n".
'Content-Transfer-Encoding: quoted-printable'."\r\n".
"\r\n".
'foobar',
$part->toString()
);
}
public function testAll3ParamsInHeaders()
{
$part = $this->_createMimePart();
$part->setContentType('text/plain');
$part->setCharset('utf-8');
$part->setFormat('fixed');
$part->setDelSp(true);
$part->setBody('foobar');
$this->assertEquals(
'Content-Type: text/plain; charset=utf-8; format=fixed; delsp=yes'."\r\n".
'Content-Transfer-Encoding: quoted-printable'."\r\n".
"\r\n".
'foobar',
$part->toString()
);
}
public function testBodyIsCanonicalized()
{
$part = $this->_createMimePart();
$part->setContentType('text/plain');
$part->setCharset('utf-8');
$part->setBody("foobar\r\rtest\ning\r");
$this->assertEquals(
'Content-Type: text/plain; charset=utf-8'."\r\n".
'Content-Transfer-Encoding: quoted-printable'."\r\n".
"\r\n".
"foobar\r\n".
"\r\n".
"test\r\n".
"ing\r\n",
$part->toString()
);
}
protected function _createMimePart()
{
$entity = new Swift_Mime_MimePart(
$this->_headers,
$this->_contentEncoder,
$this->_cache,
$this->_grammar
);
return $entity;
}
}
<?php
class Swift_Mime_SimpleMessageAcceptanceTest extends \PHPUnit_Framework_TestCase
{
protected function setUp()
{
Swift_Preferences::getInstance()->setCharset(null); //TODO: Test with the charset defined
}
public function testBasicHeaders()
{
/* -- RFC 2822, 3.6.
*/
$message = $this->_createMessage();
$id = $message->getId();
$date = $message->getDate();
$this->assertEquals(
'Message-ID: <'.$id.'>'."\r\n".
'Date: '.date('r', $date)."\r\n".
'From: '."\r\n".
'MIME-Version: 1.0'."\r\n".
'Content-Type: text/plain'."\r\n".
'Content-Transfer-Encoding: quoted-printable'."\r\n",
$message->toString(),
'%s: Only required headers, and non-empty headers should be displayed'
);
}
public function testSubjectIsDisplayedIfSet()
{
$message = $this->_createMessage();
$message->setSubject('just a test subject');
$id = $message->getId();
$date = $message->getDate();
$this->assertEquals(
'Message-ID: <'.$id.'>'."\r\n".
'Date: '.date('r', $date)."\r\n".
'Subject: just a test subject'."\r\n".
'From: '."\r\n".
'MIME-Version: 1.0'."\r\n".
'Content-Type: text/plain'."\r\n".
'Content-Transfer-Encoding: quoted-printable'."\r\n",
$message->toString()
);
}
public function testDateCanBeSet()
{
$message = $this->_createMessage();
$message->setSubject('just a test subject');
$id = $message->getId();
$message->setDate(1234);
$this->assertEquals(
'Message-ID: <'.$id.'>'."\r\n".
'Date: '.date('r', 1234)."\r\n".
'Subject: just a test subject'."\r\n".
'From: '."\r\n".
'MIME-Version: 1.0'."\r\n".
'Content-Type: text/plain'."\r\n".
'Content-Transfer-Encoding: quoted-printable'."\r\n",
$message->toString()
);
}
public function testMessageIdCanBeSet()
{
$message = $this->_createMessage();
$message->setSubject('just a test subject');
$message->setId('foo@bar');
$date = $message->getDate();
$this->assertEquals(
'Message-ID: <foo@bar>'."\r\n".
'Date: '.date('r', $date)."\r\n".
'Subject: just a test subject'."\r\n".
'From: '."\r\n".
'MIME-Version: 1.0'."\r\n".
'Content-Type: text/plain'."\r\n".
'Content-Transfer-Encoding: quoted-printable'."\r\n",
$message->toString()
);
}
public function testContentTypeCanBeChanged()
{
$message = $this->_createMessage();
$message->setSubject('just a test subject');
$message->setContentType('text/html');
$id = $message->getId();
$date = $message->getDate();
$this->assertEquals(
'Message-ID: <'.$id.'>'."\r\n".
'Date: '.date('r', $date)."\r\n".
'Subject: just a test subject'."\r\n".
'From: '."\r\n".
'MIME-Version: 1.0'."\r\n".
'Content-Type: text/html'."\r\n".
'Content-Transfer-Encoding: quoted-printable'."\r\n",
$message->toString()
);
}
public function testCharsetCanBeSet()
{
$message = $this->_createMessage();
$message->setSubject('just a test subject');
$message->setContentType('text/html');
$message->setCharset('iso-8859-1');
$id = $message->getId();
$date = $message->getDate();
$this->assertEquals(
'Message-ID: <'.$id.'>'."\r\n".
'Date: '.date('r', $date)."\r\n".
'Subject: just a test subject'."\r\n".
'From: '."\r\n".
'MIME-Version: 1.0'."\r\n".
'Content-Type: text/html; charset=iso-8859-1'."\r\n".
'Content-Transfer-Encoding: quoted-printable'."\r\n",
$message->toString()
);
}
public function testFormatCanBeSet()
{
$message = $this->_createMessage();
$message->setSubject('just a test subject');
$message->setFormat('flowed');
$id = $message->getId();
$date = $message->getDate();
$this->assertEquals(
'Message-ID: <'.$id.'>'."\r\n".
'Date: '.date('r', $date)."\r\n".
'Subject: just a test subject'."\r\n".
'From: '."\r\n".
'MIME-Version: 1.0'."\r\n".
'Content-Type: text/plain; format=flowed'."\r\n".
'Content-Transfer-Encoding: quoted-printable'."\r\n",
$message->toString()
);
}
public function testEncoderCanBeSet()
{
$message = $this->_createMessage();
$message->setSubject('just a test subject');
$message->setContentType('text/html');
$message->setEncoder(
new Swift_Mime_ContentEncoder_PlainContentEncoder('7bit')
);
$id = $message->getId();
$date = $message->getDate();
$this->assertEquals(
'Message-ID: <'.$id.'>'."\r\n".
'Date: '.date('r', $date)."\r\n".
'Subject: just a test subject'."\r\n".
'From: '."\r\n".
'MIME-Version: 1.0'."\r\n".
'Content-Type: text/html'."\r\n".
'Content-Transfer-Encoding: 7bit'."\r\n",
$message->toString()
);
}
public function testFromAddressCanBeSet()
{
$message = $this->_createMessage();
$message->setSubject('just a test subject');
$message->setFrom('chris.corbyn@swiftmailer.org');
$id = $message->getId();
$date = $message->getDate();
$this->assertEquals(
'Message-ID: <'.$id.'>'."\r\n".
'Date: '.date('r', $date)."\r\n".
'Subject: just a test subject'."\r\n".
'From: chris.corbyn@swiftmailer.org'."\r\n".
'MIME-Version: 1.0'."\r\n".
'Content-Type: text/plain'."\r\n".
'Content-Transfer-Encoding: quoted-printable'."\r\n",
$message->toString()
);
}
public function testFromAddressCanBeSetWithName()
{
$message = $this->_createMessage();
$message->setSubject('just a test subject');
$message->setFrom(array('chris.corbyn@swiftmailer.org' => 'Chris Corbyn'));
$id = $message->getId();
$date = $message->getDate();
$this->assertEquals(
'Message-ID: <'.$id.'>'."\r\n".
'Date: '.date('r', $date)."\r\n".
'Subject: just a test subject'."\r\n".
'From: Chris Corbyn <chris.corbyn@swiftmailer.org>'."\r\n".
'MIME-Version: 1.0'."\r\n".
'Content-Type: text/plain'."\r\n".
'Content-Transfer-Encoding: quoted-printable'."\r\n",
$message->toString()
);
}
public function testMultipleFromAddressesCanBeSet()
{
$message = $this->_createMessage();
$message->setSubject('just a test subject');
$message->setFrom(array(
'chris.corbyn@swiftmailer.org' => 'Chris Corbyn',
'mark@swiftmailer.org',
));
$id = $message->getId();
$date = $message->getDate();
$this->assertEquals(
'Message-ID: <'.$id.'>'."\r\n".
'Date: '.date('r', $date)."\r\n".
'Subject: just a test subject'."\r\n".
'From: Chris Corbyn <chris.corbyn@swiftmailer.org>, mark@swiftmailer.org'."\r\n".
'MIME-Version: 1.0'."\r\n".
'Content-Type: text/plain'."\r\n".
'Content-Transfer-Encoding: quoted-printable'."\r\n",
$message->toString()
);
}
public function testReturnPathAddressCanBeSet()
{
$message = $this->_createMessage();
$message->setReturnPath('chris@w3style.co.uk');
$message->setSubject('just a test subject');
$message->setFrom(array(
'chris.corbyn@swiftmailer.org' => 'Chris Corbyn', ));
$id = $message->getId();
$date = $message->getDate();
$this->assertEquals(
'Return-Path: <chris@w3style.co.uk>'."\r\n".
'Message-ID: <'.$id.'>'."\r\n".
'Date: '.date('r', $date)."\r\n".
'Subject: just a test subject'."\r\n".
'From: Chris Corbyn <chris.corbyn@swiftmailer.org>'."\r\n".
'MIME-Version: 1.0'."\r\n".
'Content-Type: text/plain'."\r\n".
'Content-Transfer-Encoding: quoted-printable'."\r\n",
$message->toString()
);
}
public function testEmptyReturnPathHeaderCanBeUsed()
{
$message = $this->_createMessage();
$message->setReturnPath('');
$message->setSubject('just a test subject');
$message->setFrom(array(
'chris.corbyn@swiftmailer.org' => 'Chris Corbyn', ));
$id = $message->getId();
$date = $message->getDate();
$this->assertEquals(
'Return-Path: <>'."\r\n".
'Message-ID: <'.$id.'>'."\r\n".
'Date: '.date('r', $date)."\r\n".
'Subject: just a test subject'."\r\n".
'From: Chris Corbyn <chris.corbyn@swiftmailer.org>'."\r\n".
'MIME-Version: 1.0'."\r\n".
'Content-Type: text/plain'."\r\n".
'Content-Transfer-Encoding: quoted-printable'."\r\n",
$message->toString()
);
}
public function testSenderCanBeSet()
{
$message = $this->_createMessage();
$message->setSubject('just a test subject');
$message->setSender('chris.corbyn@swiftmailer.org');
$id = $message->getId();
$date = $message->getDate();
$this->assertEquals(
'Sender: chris.corbyn@swiftmailer.org'."\r\n".
'Message-ID: <'.$id.'>'."\r\n".
'Date: '.date('r', $date)."\r\n".
'Subject: just a test subject'."\r\n".
'From: '."\r\n".
'MIME-Version: 1.0'."\r\n".
'Content-Type: text/plain'."\r\n".
'Content-Transfer-Encoding: quoted-printable'."\r\n",
$message->toString()
);
}
public function testSenderCanBeSetWithName()
{
$message = $this->_createMessage();
$message->setSubject('just a test subject');
$message->setSender(array('chris.corbyn@swiftmailer.org' => 'Chris'));
$id = $message->getId();
$date = $message->getDate();
$this->assertEquals(
'Sender: Chris <chris.corbyn@swiftmailer.org>'."\r\n".
'Message-ID: <'.$id.'>'."\r\n".
'Date: '.date('r', $date)."\r\n".
'Subject: just a test subject'."\r\n".
'From: '."\r\n".
'MIME-Version: 1.0'."\r\n".
'Content-Type: text/plain'."\r\n".
'Content-Transfer-Encoding: quoted-printable'."\r\n",
$message->toString()
);
}
public function testReplyToCanBeSet()
{
$message = $this->_createMessage();
$message->setSubject('just a test subject');
$message->setFrom(array('chris.corbyn@swiftmailer.org' => 'Chris'));
$message->setReplyTo(array('chris@w3style.co.uk' => 'Myself'));
$id = $message->getId();
$date = $message->getDate();
$this->assertEquals(
'Message-ID: <'.$id.'>'."\r\n".
'Date: '.date('r', $date)."\r\n".
'Subject: just a test subject'."\r\n".
'From: Chris <chris.corbyn@swiftmailer.org>'."\r\n".
'Reply-To: Myself <chris@w3style.co.uk>'."\r\n".
'MIME-Version: 1.0'."\r\n".
'Content-Type: text/plain'."\r\n".
'Content-Transfer-Encoding: quoted-printable'."\r\n",
$message->toString()
);
}
public function testMultipleReplyAddressCanBeUsed()
{
$message = $this->_createMessage();
$message->setSubject('just a test subject');
$message->setFrom(array('chris.corbyn@swiftmailer.org' => 'Chris'));
$message->setReplyTo(array(
'chris@w3style.co.uk' => 'Myself',
'my.other@address.com' => 'Me',
));
$id = $message->getId();
$date = $message->getDate();
$this->assertEquals(
'Message-ID: <'.$id.'>'."\r\n".
'Date: '.date('r', $date)."\r\n".
'Subject: just a test subject'."\r\n".
'From: Chris <chris.corbyn@swiftmailer.org>'."\r\n".
'Reply-To: Myself <chris@w3style.co.uk>, Me <my.other@address.com>'."\r\n".
'MIME-Version: 1.0'."\r\n".
'Content-Type: text/plain'."\r\n".
'Content-Transfer-Encoding: quoted-printable'."\r\n",
$message->toString()
);
}
public function testToAddressCanBeSet()
{
$message = $this->_createMessage();
$message->setSubject('just a test subject');
$message->setFrom(array('chris.corbyn@swiftmailer.org' => 'Chris'));
$message->setReplyTo(array(
'chris@w3style.co.uk' => 'Myself',
'my.other@address.com' => 'Me',
));
$message->setTo('mark@swiftmailer.org');
$id = $message->getId();
$date = $message->getDate();
$this->assertEquals(
'Message-ID: <'.$id.'>'."\r\n".
'Date: '.date('r', $date)."\r\n".
'Subject: just a test subject'."\r\n".
'From: Chris <chris.corbyn@swiftmailer.org>'."\r\n".
'Reply-To: Myself <chris@w3style.co.uk>, Me <my.other@address.com>'."\r\n".
'To: mark@swiftmailer.org'."\r\n".
'MIME-Version: 1.0'."\r\n".
'Content-Type: text/plain'."\r\n".
'Content-Transfer-Encoding: quoted-printable'."\r\n",
$message->toString()
);
}
public function testMultipleToAddressesCanBeSet()
{
$message = $this->_createMessage();
$message->setSubject('just a test subject');
$message->setFrom(array('chris.corbyn@swiftmailer.org' => 'Chris'));
$message->setReplyTo(array(
'chris@w3style.co.uk' => 'Myself',
'my.other@address.com' => 'Me',
));
$message->setTo(array(
'mark@swiftmailer.org', 'chris@swiftmailer.org' => 'Chris Corbyn',
));
$id = $message->getId();
$date = $message->getDate();
$this->assertEquals(
'Message-ID: <'.$id.'>'."\r\n".
'Date: '.date('r', $date)."\r\n".
'Subject: just a test subject'."\r\n".
'From: Chris <chris.corbyn@swiftmailer.org>'."\r\n".
'Reply-To: Myself <chris@w3style.co.uk>, Me <my.other@address.com>'."\r\n".
'To: mark@swiftmailer.org, Chris Corbyn <chris@swiftmailer.org>'."\r\n".
'MIME-Version: 1.0'."\r\n".
'Content-Type: text/plain'."\r\n".
'Content-Transfer-Encoding: quoted-printable'."\r\n",
$message->toString()
);
}
public function testCcAddressCanBeSet()
{
$message = $this->_createMessage();
$message->setSubject('just a test subject');
$message->setFrom(array('chris.corbyn@swiftmailer.org' => 'Chris'));
$message->setReplyTo(array(
'chris@w3style.co.uk' => 'Myself',
'my.other@address.com' => 'Me',
));
$message->setTo(array(
'mark@swiftmailer.org', 'chris@swiftmailer.org' => 'Chris Corbyn',
));
$message->setCc('john@some-site.com');
$id = $message->getId();
$date = $message->getDate();
$this->assertEquals(
'Message-ID: <'.$id.'>'."\r\n".
'Date: '.date('r', $date)."\r\n".
'Subject: just a test subject'."\r\n".
'From: Chris <chris.corbyn@swiftmailer.org>'."\r\n".
'Reply-To: Myself <chris@w3style.co.uk>, Me <my.other@address.com>'."\r\n".
'To: mark@swiftmailer.org, Chris Corbyn <chris@swiftmailer.org>'."\r\n".
'Cc: john@some-site.com'."\r\n".
'MIME-Version: 1.0'."\r\n".
'Content-Type: text/plain'."\r\n".
'Content-Transfer-Encoding: quoted-printable'."\r\n",
$message->toString()
);
}
public function testMultipleCcAddressesCanBeSet()
{
$message = $this->_createMessage();
$message->setSubject('just a test subject');
$message->setFrom(array('chris.corbyn@swiftmailer.org' => 'Chris'));
$message->setReplyTo(array(
'chris@w3style.co.uk' => 'Myself',
'my.other@address.com' => 'Me',
));
$message->setTo(array(
'mark@swiftmailer.org', 'chris@swiftmailer.org' => 'Chris Corbyn',
));
$message->setCc(array(
'john@some-site.com' => 'John West',
'fred@another-site.co.uk' => 'Big Fred',
));
$id = $message->getId();
$date = $message->getDate();
$this->assertEquals(
'Message-ID: <'.$id.'>'."\r\n".
'Date: '.date('r', $date)."\r\n".
'Subject: just a test subject'."\r\n".
'From: Chris <chris.corbyn@swiftmailer.org>'."\r\n".
'Reply-To: Myself <chris@w3style.co.uk>, Me <my.other@address.com>'."\r\n".
'To: mark@swiftmailer.org, Chris Corbyn <chris@swiftmailer.org>'."\r\n".
'Cc: John West <john@some-site.com>, Big Fred <fred@another-site.co.uk>'."\r\n".
'MIME-Version: 1.0'."\r\n".
'Content-Type: text/plain'."\r\n".
'Content-Transfer-Encoding: quoted-printable'."\r\n",
$message->toString()
);
}
public function testBccAddressCanBeSet()
{
//Obviously Transports need to setBcc(array()) and send to each Bcc recipient
// separately in accordance with RFC 2822/2821
$message = $this->_createMessage();
$message->setSubject('just a test subject');
$message->setFrom(array('chris.corbyn@swiftmailer.org' => 'Chris'));
$message->setReplyTo(array(
'chris@w3style.co.uk' => 'Myself',
'my.other@address.com' => 'Me',
));
$message->setTo(array(
'mark@swiftmailer.org', 'chris@swiftmailer.org' => 'Chris Corbyn',
));
$message->setCc(array(
'john@some-site.com' => 'John West',
'fred@another-site.co.uk' => 'Big Fred',
));
$message->setBcc('x@alphabet.tld');
$id = $message->getId();
$date = $message->getDate();
$this->assertEquals(
'Message-ID: <'.$id.'>'."\r\n".
'Date: '.date('r', $date)."\r\n".
'Subject: just a test subject'."\r\n".
'From: Chris <chris.corbyn@swiftmailer.org>'."\r\n".
'Reply-To: Myself <chris@w3style.co.uk>, Me <my.other@address.com>'."\r\n".
'To: mark@swiftmailer.org, Chris Corbyn <chris@swiftmailer.org>'."\r\n".
'Cc: John West <john@some-site.com>, Big Fred <fred@another-site.co.uk>'."\r\n".
'Bcc: x@alphabet.tld'."\r\n".
'MIME-Version: 1.0'."\r\n".
'Content-Type: text/plain'."\r\n".
'Content-Transfer-Encoding: quoted-printable'."\r\n",
$message->toString()
);
}
public function testMultipleBccAddressesCanBeSet()
{
//Obviously Transports need to setBcc(array()) and send to each Bcc recipient
// separately in accordance with RFC 2822/2821
$message = $this->_createMessage();
$message->setSubject('just a test subject');
$message->setFrom(array('chris.corbyn@swiftmailer.org' => 'Chris'));
$message->setReplyTo(array(
'chris@w3style.co.uk' => 'Myself',
'my.other@address.com' => 'Me',
));
$message->setTo(array(
'mark@swiftmailer.org', 'chris@swiftmailer.org' => 'Chris Corbyn',
));
$message->setCc(array(
'john@some-site.com' => 'John West',
'fred@another-site.co.uk' => 'Big Fred',
));
$message->setBcc(array('x@alphabet.tld', 'a@alphabet.tld' => 'A'));
$id = $message->getId();
$date = $message->getDate();
$this->assertEquals(
'Message-ID: <'.$id.'>'."\r\n".
'Date: '.date('r', $date)."\r\n".
'Subject: just a test subject'."\r\n".
'From: Chris <chris.corbyn@swiftmailer.org>'."\r\n".
'Reply-To: Myself <chris@w3style.co.uk>, Me <my.other@address.com>'."\r\n".
'To: mark@swiftmailer.org, Chris Corbyn <chris@swiftmailer.org>'."\r\n".
'Cc: John West <john@some-site.com>, Big Fred <fred@another-site.co.uk>'."\r\n".
'Bcc: x@alphabet.tld, A <a@alphabet.tld>'."\r\n".
'MIME-Version: 1.0'."\r\n".
'Content-Type: text/plain'."\r\n".
'Content-Transfer-Encoding: quoted-printable'."\r\n",
$message->toString()
);
}
public function testStringBodyIsAppended()
{
$message = $this->_createMessage();
$message->setReturnPath('chris@w3style.co.uk');
$message->setSubject('just a test subject');
$message->setFrom(array(
'chris.corbyn@swiftmailer.org' => 'Chris Corbyn', ));
$message->setBody(
'just a test body'."\r\n".
'with a new line'
);
$id = $message->getId();
$date = $message->getDate();
$this->assertEquals(
'Return-Path: <chris@w3style.co.uk>'."\r\n".
'Message-ID: <'.$id.'>'."\r\n".
'Date: '.date('r', $date)."\r\n".
'Subject: just a test subject'."\r\n".
'From: Chris Corbyn <chris.corbyn@swiftmailer.org>'."\r\n".
'MIME-Version: 1.0'."\r\n".
'Content-Type: text/plain'."\r\n".
'Content-Transfer-Encoding: quoted-printable'."\r\n".
"\r\n".
'just a test body'."\r\n".
'with a new line',
$message->toString()
);
}
public function testStringBodyIsEncoded()
{
$message = $this->_createMessage();
$message->setReturnPath('chris@w3style.co.uk');
$message->setSubject('just a test subject');
$message->setFrom(array(
'chris.corbyn@swiftmailer.org' => 'Chris Corbyn', ));
$message->setBody(
'Just s'.pack('C*', 0xC2, 0x01, 0x01).'me multi-'."\r\n".
'line message!'
);
$id = $message->getId();
$date = $message->getDate();
$this->assertEquals(
'Return-Path: <chris@w3style.co.uk>'."\r\n".
'Message-ID: <'.$id.'>'."\r\n".
'Date: '.date('r', $date)."\r\n".
'Subject: just a test subject'."\r\n".
'From: Chris Corbyn <chris.corbyn@swiftmailer.org>'."\r\n".
'MIME-Version: 1.0'."\r\n".
'Content-Type: text/plain'."\r\n".
'Content-Transfer-Encoding: quoted-printable'."\r\n".
"\r\n".
'Just s=C2=01=01me multi-'."\r\n".
'line message!',
$message->toString()
);
}
public function testChildrenCanBeAttached()
{
$message = $this->_createMessage();
$message->setReturnPath('chris@w3style.co.uk');
$message->setSubject('just a test subject');
$message->setFrom(array(
'chris.corbyn@swiftmailer.org' => 'Chris Corbyn', ));
$id = $message->getId();
$date = $message->getDate();
$boundary = $message->getBoundary();
$part1 = $this->_createMimePart();
$part1->setContentType('text/plain');
$part1->setCharset('iso-8859-1');
$part1->setBody('foo');
$message->attach($part1);
$part2 = $this->_createMimePart();
$part2->setContentType('text/html');
$part2->setCharset('iso-8859-1');
$part2->setBody('test <b>foo</b>');
$message->attach($part2);
$this->assertEquals(
'Return-Path: <chris@w3style.co.uk>'."\r\n".
'Message-ID: <'.$id.'>'."\r\n".
'Date: '.date('r', $date)."\r\n".
'Subject: just a test subject'."\r\n".
'From: Chris Corbyn <chris.corbyn@swiftmailer.org>'."\r\n".
'MIME-Version: 1.0'."\r\n".
'Content-Type: multipart/alternative;'."\r\n".
' boundary="'.$boundary.'"'."\r\n".
"\r\n\r\n".
'--'.$boundary."\r\n".
'Content-Type: text/plain; charset=iso-8859-1'."\r\n".
'Content-Transfer-Encoding: quoted-printable'."\r\n".
"\r\n".
'foo'.
"\r\n\r\n".
'--'.$boundary."\r\n".
'Content-Type: text/html; charset=iso-8859-1'."\r\n".
'Content-Transfer-Encoding: quoted-printable'."\r\n".
"\r\n".
'test <b>foo</b>'.
"\r\n\r\n".
'--'.$boundary.'--'."\r\n",
$message->toString()
);
}
public function testAttachmentsBeingAttached()
{
$message = $this->_createMessage();
$message->setReturnPath('chris@w3style.co.uk');
$message->setSubject('just a test subject');
$message->setFrom(array(
'chris.corbyn@swiftmailer.org' => 'Chris Corbyn', ));
$id = $message->getId();
$date = preg_quote(date('r', $message->getDate()), '~');
$boundary = $message->getBoundary();
$part = $this->_createMimePart();
$part->setContentType('text/plain');
$part->setCharset('iso-8859-1');
$part->setBody('foo');
$message->attach($part);
$attachment = $this->_createAttachment();
$attachment->setContentType('application/pdf');
$attachment->setFilename('foo.pdf');
$attachment->setBody('<pdf data>');
$message->attach($attachment);
$this->assertRegExp(
'~^'.
'Return-Path: <chris@w3style.co.uk>'."\r\n".
'Message-ID: <'.$id.'>'."\r\n".
'Date: '.$date."\r\n".
'Subject: just a test subject'."\r\n".
'From: Chris Corbyn <chris.corbyn@swiftmailer.org>'."\r\n".
'MIME-Version: 1.0'."\r\n".
'Content-Type: multipart/mixed;'."\r\n".
' boundary="'.$boundary.'"'."\r\n".
"\r\n\r\n".
'--'.$boundary."\r\n".
'Content-Type: multipart/alternative;'."\r\n".
' boundary="(.*?)"'."\r\n".
"\r\n\r\n".
'--\\1'."\r\n".
'Content-Type: text/plain; charset=iso-8859-1'."\r\n".
'Content-Transfer-Encoding: quoted-printable'."\r\n".
"\r\n".
'foo'.
"\r\n\r\n".
'--\\1--'."\r\n".
"\r\n\r\n".
'--'.$boundary."\r\n".
'Content-Type: application/pdf; name=foo.pdf'."\r\n".
'Content-Transfer-Encoding: base64'."\r\n".
'Content-Disposition: attachment; filename=foo.pdf'."\r\n".
"\r\n".
preg_quote(base64_encode('<pdf data>'), '~').
"\r\n\r\n".
'--'.$boundary.'--'."\r\n".
'$~D',
$message->toString()
);
}
public function testAttachmentsAndEmbeddedFilesBeingAttached()
{
$message = $this->_createMessage();
$message->setReturnPath('chris@w3style.co.uk');
$message->setSubject('just a test subject');
$message->setFrom(array(
'chris.corbyn@swiftmailer.org' => 'Chris Corbyn', ));
$id = $message->getId();
$date = preg_quote(date('r', $message->getDate()), '~');
$boundary = $message->getBoundary();
$part = $this->_createMimePart();
$part->setContentType('text/plain');
$part->setCharset('iso-8859-1');
$part->setBody('foo');
$message->attach($part);
$attachment = $this->_createAttachment();
$attachment->setContentType('application/pdf');
$attachment->setFilename('foo.pdf');
$attachment->setBody('<pdf data>');
$message->attach($attachment);
$file = $this->_createEmbeddedFile();
$file->setContentType('image/jpeg');
$file->setFilename('myimage.jpg');
$file->setBody('<image data>');
$message->attach($file);
$cid = $file->getId();
$this->assertRegExp(
'~^'.
'Return-Path: <chris@w3style.co.uk>'."\r\n".
'Message-ID: <'.$id.'>'."\r\n".
'Date: '.$date."\r\n".
'Subject: just a test subject'."\r\n".
'From: Chris Corbyn <chris.corbyn@swiftmailer.org>'."\r\n".
'MIME-Version: 1.0'."\r\n".
'Content-Type: multipart/mixed;'."\r\n".
' boundary="'.$boundary.'"'."\r\n".
"\r\n\r\n".
'--'.$boundary."\r\n".
'Content-Type: multipart/alternative;'."\r\n".
' boundary="(.*?)"'."\r\n".
"\r\n\r\n".
'--\\1'."\r\n".
'Content-Type: text/plain; charset=iso-8859-1'."\r\n".
'Content-Transfer-Encoding: quoted-printable'."\r\n".
"\r\n".
'foo'.
"\r\n\r\n".
'--\\1'."\r\n".
'Content-Type: multipart/related;'."\r\n".
' boundary="(.*?)"'."\r\n".
"\r\n\r\n".
'--\\2'."\r\n".
'Content-Type: image/jpeg; name=myimage.jpg'."\r\n".
'Content-Transfer-Encoding: base64'."\r\n".
'Content-ID: <'.$cid.'>'."\r\n".
'Content-Disposition: inline; filename=myimage.jpg'."\r\n".
"\r\n".
preg_quote(base64_encode('<image data>'), '~').
"\r\n\r\n".
'--\\2--'."\r\n".
"\r\n\r\n".
'--\\1--'."\r\n".
"\r\n\r\n".
'--'.$boundary."\r\n".
'Content-Type: application/pdf; name=foo.pdf'."\r\n".
'Content-Transfer-Encoding: base64'."\r\n".
'Content-Disposition: attachment; filename=foo.pdf'."\r\n".
"\r\n".
preg_quote(base64_encode('<pdf data>'), '~').
"\r\n\r\n".
'--'.$boundary.'--'."\r\n".
'$~D',
$message->toString()
);
}
public function testComplexEmbeddingOfContent()
{
$message = $this->_createMessage();
$message->setReturnPath('chris@w3style.co.uk');
$message->setSubject('just a test subject');
$message->setFrom(array(
'chris.corbyn@swiftmailer.org' => 'Chris Corbyn', ));
$id = $message->getId();
$date = preg_quote(date('r', $message->getDate()), '~');
$boundary = $message->getBoundary();
$attachment = $this->_createAttachment();
$attachment->setContentType('application/pdf');
$attachment->setFilename('foo.pdf');
$attachment->setBody('<pdf data>');
$message->attach($attachment);
$file = $this->_createEmbeddedFile();
$file->setContentType('image/jpeg');
$file->setFilename('myimage.jpg');
$file->setBody('<image data>');
$part = $this->_createMimePart();
$part->setContentType('text/html');
$part->setCharset('iso-8859-1');
$part->setBody('foo <img src="'.$message->embed($file).'" />');
$message->attach($part);
$cid = $file->getId();
$this->assertRegExp(
'~^'.
'Return-Path: <chris@w3style.co.uk>'."\r\n".
'Message-ID: <'.$id.'>'."\r\n".
'Date: '.$date."\r\n".
'Subject: just a test subject'."\r\n".
'From: Chris Corbyn <chris.corbyn@swiftmailer.org>'."\r\n".
'MIME-Version: 1.0'."\r\n".
'Content-Type: multipart/mixed;'."\r\n".
' boundary="'.$boundary.'"'."\r\n".
"\r\n\r\n".
'--'.$boundary."\r\n".
'Content-Type: multipart/related;'."\r\n".
' boundary="(.*?)"'."\r\n".
"\r\n\r\n".
'--\\1'."\r\n".
'Content-Type: text/html; charset=iso-8859-1'."\r\n".
'Content-Transfer-Encoding: quoted-printable'."\r\n".
"\r\n".
'foo <img src=3D"cid:'.$cid.'" />'.//=3D is just = in QP
"\r\n\r\n".
'--\\1'."\r\n".
'Content-Type: image/jpeg; name=myimage.jpg'."\r\n".
'Content-Transfer-Encoding: base64'."\r\n".
'Content-ID: <'.$cid.'>'."\r\n".
'Content-Disposition: inline; filename=myimage.jpg'."\r\n".
"\r\n".
preg_quote(base64_encode('<image data>'), '~').
"\r\n\r\n".
'--\\1--'."\r\n".
"\r\n\r\n".
'--'.$boundary."\r\n".
'Content-Type: application/pdf; name=foo.pdf'."\r\n".
'Content-Transfer-Encoding: base64'."\r\n".
'Content-Disposition: attachment; filename=foo.pdf'."\r\n".
"\r\n".
preg_quote(base64_encode('<pdf data>'), '~').
"\r\n\r\n".
'--'.$boundary.'--'."\r\n".
'$~D',
$message->toString()
);
}
public function testAttachingAndDetachingContent()
{
$message = $this->_createMessage();
$message->setReturnPath('chris@w3style.co.uk');
$message->setSubject('just a test subject');
$message->setFrom(array(
'chris.corbyn@swiftmailer.org' => 'Chris Corbyn', ));
$id = $message->getId();
$date = preg_quote(date('r', $message->getDate()), '~');
$boundary = $message->getBoundary();
$part = $this->_createMimePart();
$part->setContentType('text/plain');
$part->setCharset('iso-8859-1');
$part->setBody('foo');
$message->attach($part);
$attachment = $this->_createAttachment();
$attachment->setContentType('application/pdf');
$attachment->setFilename('foo.pdf');
$attachment->setBody('<pdf data>');
$message->attach($attachment);
$file = $this->_createEmbeddedFile();
$file->setContentType('image/jpeg');
$file->setFilename('myimage.jpg');
$file->setBody('<image data>');
$message->attach($file);
$cid = $file->getId();
$message->detach($attachment);
$this->assertRegExp(
'~^'.
'Return-Path: <chris@w3style.co.uk>'."\r\n".
'Message-ID: <'.$id.'>'."\r\n".
'Date: '.$date."\r\n".
'Subject: just a test subject'."\r\n".
'From: Chris Corbyn <chris.corbyn@swiftmailer.org>'."\r\n".
'MIME-Version: 1.0'."\r\n".
'Content-Type: multipart/alternative;'."\r\n".
' boundary="'.$boundary.'"'."\r\n".
"\r\n\r\n".
'--'.$boundary."\r\n".
'Content-Type: text/plain; charset=iso-8859-1'."\r\n".
'Content-Transfer-Encoding: quoted-printable'."\r\n".
"\r\n".
'foo'.
"\r\n\r\n".
'--'.$boundary."\r\n".
'Content-Type: multipart/related;'."\r\n".
' boundary="(.*?)"'."\r\n".
"\r\n\r\n".
'--\\1'."\r\n".
'Content-Type: image/jpeg; name=myimage.jpg'."\r\n".
'Content-Transfer-Encoding: base64'."\r\n".
'Content-ID: <'.$cid.'>'."\r\n".
'Content-Disposition: inline; filename=myimage.jpg'."\r\n".
"\r\n".
preg_quote(base64_encode('<image data>'), '~').
"\r\n\r\n".
'--\\1--'."\r\n".
"\r\n\r\n".
'--'.$boundary.'--'."\r\n".
'$~D',
$message->toString(),
'%s: Attachment should have been detached'
);
}
public function testBoundaryDoesNotAppearAfterAllPartsAreDetached()
{
$message = $this->_createMessage();
$message->setReturnPath('chris@w3style.co.uk');
$message->setSubject('just a test subject');
$message->setFrom(array(
'chris.corbyn@swiftmailer.org' => 'Chris Corbyn', ));
$id = $message->getId();
$date = $message->getDate();
$boundary = $message->getBoundary();
$part1 = $this->_createMimePart();
$part1->setContentType('text/plain');
$part1->setCharset('iso-8859-1');
$part1->setBody('foo');
$message->attach($part1);
$part2 = $this->_createMimePart();
$part2->setContentType('text/html');
$part2->setCharset('iso-8859-1');
$part2->setBody('test <b>foo</b>');
$message->attach($part2);
$message->detach($part1);
$message->detach($part2);
$this->assertEquals(
'Return-Path: <chris@w3style.co.uk>'."\r\n".
'Message-ID: <'.$id.'>'."\r\n".
'Date: '.date('r', $date)."\r\n".
'Subject: just a test subject'."\r\n".
'From: Chris Corbyn <chris.corbyn@swiftmailer.org>'."\r\n".
'MIME-Version: 1.0'."\r\n".
'Content-Type: text/plain'."\r\n".
'Content-Transfer-Encoding: quoted-printable'."\r\n",
$message->toString(),
'%s: Message should be restored to orignal state after parts are detached'
);
}
public function testCharsetFormatOrDelSpAreNotShownWhenBoundaryIsSet()
{
$message = $this->_createMessage();
$message->setReturnPath('chris@w3style.co.uk');
$message->setSubject('just a test subject');
$message->setFrom(array(
'chris.corbyn@swiftmailer.org' => 'Chris Corbyn', ));
$message->setCharset('utf-8');
$message->setFormat('flowed');
$message->setDelSp(true);
$id = $message->getId();
$date = $message->getDate();
$boundary = $message->getBoundary();
$part1 = $this->_createMimePart();
$part1->setContentType('text/plain');
$part1->setCharset('iso-8859-1');
$part1->setBody('foo');
$message->attach($part1);
$part2 = $this->_createMimePart();
$part2->setContentType('text/html');
$part2->setCharset('iso-8859-1');
$part2->setBody('test <b>foo</b>');
$message->attach($part2);
$this->assertEquals(
'Return-Path: <chris@w3style.co.uk>'."\r\n".
'Message-ID: <'.$id.'>'."\r\n".
'Date: '.date('r', $date)."\r\n".
'Subject: just a test subject'."\r\n".
'From: Chris Corbyn <chris.corbyn@swiftmailer.org>'."\r\n".
'MIME-Version: 1.0'."\r\n".
'Content-Type: multipart/alternative;'."\r\n".
' boundary="'.$boundary.'"'."\r\n".
"\r\n\r\n".
'--'.$boundary."\r\n".
'Content-Type: text/plain; charset=iso-8859-1'."\r\n".
'Content-Transfer-Encoding: quoted-printable'."\r\n".
"\r\n".
'foo'.
"\r\n\r\n".
'--'.$boundary."\r\n".
'Content-Type: text/html; charset=iso-8859-1'."\r\n".
'Content-Transfer-Encoding: quoted-printable'."\r\n".
"\r\n".
'test <b>foo</b>'.
"\r\n\r\n".
'--'.$boundary.'--'."\r\n",
$message->toString()
);
}
public function testBodyCanBeSetWithAttachments()
{
$message = $this->_createMessage();
$message->setReturnPath('chris@w3style.co.uk');
$message->setSubject('just a test subject');
$message->setFrom(array(
'chris.corbyn@swiftmailer.org' => 'Chris Corbyn', ));
$message->setContentType('text/html');
$message->setCharset('iso-8859-1');
$message->setBody('foo');
$id = $message->getId();
$date = date('r', $message->getDate());
$boundary = $message->getBoundary();
$attachment = $this->_createAttachment();
$attachment->setContentType('application/pdf');
$attachment->setFilename('foo.pdf');
$attachment->setBody('<pdf data>');
$message->attach($attachment);
$this->assertEquals(
'Return-Path: <chris@w3style.co.uk>'."\r\n".
'Message-ID: <'.$id.'>'."\r\n".
'Date: '.$date."\r\n".
'Subject: just a test subject'."\r\n".
'From: Chris Corbyn <chris.corbyn@swiftmailer.org>'."\r\n".
'MIME-Version: 1.0'."\r\n".
'Content-Type: multipart/mixed;'."\r\n".
' boundary="'.$boundary.'"'."\r\n".
"\r\n\r\n".
'--'.$boundary."\r\n".
'Content-Type: text/html; charset=iso-8859-1'."\r\n".
'Content-Transfer-Encoding: quoted-printable'."\r\n".
"\r\n".
'foo'.
"\r\n\r\n".
'--'.$boundary."\r\n".
'Content-Type: application/pdf; name=foo.pdf'."\r\n".
'Content-Transfer-Encoding: base64'."\r\n".
'Content-Disposition: attachment; filename=foo.pdf'."\r\n".
"\r\n".
base64_encode('<pdf data>').
"\r\n\r\n".
'--'.$boundary.'--'."\r\n",
$message->toString()
);
}
public function testHtmlPartAlwaysAppearsLast()
{
$message = $this->_createMessage();
$message->setReturnPath('chris@w3style.co.uk');
$message->setSubject('just a test subject');
$message->setFrom(array(
'chris.corbyn@swiftmailer.org' => 'Chris Corbyn', ));
$id = $message->getId();
$date = date('r', $message->getDate());
$boundary = $message->getBoundary();
$part1 = $this->_createMimePart();
$part1->setContentType('text/html');
$part1->setBody('foo');
$part2 = $this->_createMimePart();
$part2->setContentType('text/plain');
$part2->setBody('bar');
$message->attach($part1);
$message->attach($part2);
$this->assertEquals(
'Return-Path: <chris@w3style.co.uk>'."\r\n".
'Message-ID: <'.$id.'>'."\r\n".
'Date: '.$date."\r\n".
'Subject: just a test subject'."\r\n".
'From: Chris Corbyn <chris.corbyn@swiftmailer.org>'."\r\n".
'MIME-Version: 1.0'."\r\n".
'Content-Type: multipart/alternative;'."\r\n".
' boundary="'.$boundary.'"'."\r\n".
"\r\n\r\n".
'--'.$boundary."\r\n".
'Content-Type: text/plain'."\r\n".
'Content-Transfer-Encoding: quoted-printable'."\r\n".
"\r\n".
'bar'.
"\r\n\r\n".
'--'.$boundary."\r\n".
'Content-Type: text/html'."\r\n".
'Content-Transfer-Encoding: quoted-printable'."\r\n".
"\r\n".
'foo'.
"\r\n\r\n".
'--'.$boundary.'--'."\r\n",
$message->toString()
);
}
public function testBodyBecomesPartIfOtherPartsAttached()
{
$message = $this->_createMessage();
$message->setReturnPath('chris@w3style.co.uk');
$message->setSubject('just a test subject');
$message->setFrom(array(
'chris.corbyn@swiftmailer.org' => 'Chris Corbyn', ));
$message->setContentType('text/html');
$message->setBody('foo');
$id = $message->getId();
$date = date('r', $message->getDate());
$boundary = $message->getBoundary();
$part2 = $this->_createMimePart();
$part2->setContentType('text/plain');
$part2->setBody('bar');
$message->attach($part2);
$this->assertEquals(
'Return-Path: <chris@w3style.co.uk>'."\r\n".
'Message-ID: <'.$id.'>'."\r\n".
'Date: '.$date."\r\n".
'Subject: just a test subject'."\r\n".
'From: Chris Corbyn <chris.corbyn@swiftmailer.org>'."\r\n".
'MIME-Version: 1.0'."\r\n".
'Content-Type: multipart/alternative;'."\r\n".
' boundary="'.$boundary.'"'."\r\n".
"\r\n\r\n".
'--'.$boundary."\r\n".
'Content-Type: text/plain'."\r\n".
'Content-Transfer-Encoding: quoted-printable'."\r\n".
"\r\n".
'bar'.
"\r\n\r\n".
'--'.$boundary."\r\n".
'Content-Type: text/html'."\r\n".
'Content-Transfer-Encoding: quoted-printable'."\r\n".
"\r\n".
'foo'.
"\r\n\r\n".
'--'.$boundary.'--'."\r\n",
$message->toString()
);
}
public function testBodyIsCanonicalized()
{
$message = $this->_createMessage();
$message->setReturnPath('chris@w3style.co.uk');
$message->setSubject('just a test subject');
$message->setFrom(array(
'chris.corbyn@swiftmailer.org' => 'Chris Corbyn', ));
$message->setBody(
'just a test body'."\n".
'with a new line'
);
$id = $message->getId();
$date = $message->getDate();
$this->assertEquals(
'Return-Path: <chris@w3style.co.uk>'."\r\n".
'Message-ID: <'.$id.'>'."\r\n".
'Date: '.date('r', $date)."\r\n".
'Subject: just a test subject'."\r\n".
'From: Chris Corbyn <chris.corbyn@swiftmailer.org>'."\r\n".
'MIME-Version: 1.0'."\r\n".
'Content-Type: text/plain'."\r\n".
'Content-Transfer-Encoding: quoted-printable'."\r\n".
"\r\n".
'just a test body'."\r\n".
'with a new line',
$message->toString()
);
}
protected function _createMessage()
{
return new Swift_Message();
}
protected function _createMimePart()
{
return new Swift_MimePart();
}
protected function _createAttachment()
{
return new Swift_Attachment();
}
protected function _createEmbeddedFile()
{
return new Swift_EmbeddedFile();
}
}
<?php
require_once 'swift_required.php';
require_once __DIR__.'/Mime/MimePartAcceptanceTest.php';
class Swift_MimePartAcceptanceTest extends Swift_Mime_MimePartAcceptanceTest
{
protected function _createMimePart()
{
Swift_DependencyContainer::getInstance()
->register('properties.charset')->asValue(null);
return Swift_MimePart::newInstance();
}
}
<?php
abstract class Swift_Transport_StreamBuffer_AbstractStreamBufferAcceptanceTest extends \PHPUnit_Framework_TestCase
{
protected $_buffer;
abstract protected function _initializeBuffer();
protected function setUp()
{
if (true == getenv('TRAVIS')) {
$this->markTestSkipped(
'Will fail on travis-ci if not skipped due to travis blocking '.
'socket mailing tcp connections.'
);
}
$this->_buffer = new Swift_Transport_StreamBuffer(
$this->getMockBuilder('Swift_ReplacementFilterFactory')->getMock()
);
}
public function testReadLine()
{
$this->_initializeBuffer();
$line = $this->_buffer->readLine(0);
$this->assertRegExp('/^[0-9]{3}.*?\r\n$/D', $line);
$seq = $this->_buffer->write("QUIT\r\n");
$this->assertTrue((bool) $seq);
$line = $this->_buffer->readLine($seq);
$this->assertRegExp('/^[0-9]{3}.*?\r\n$/D', $line);
$this->_buffer->terminate();
}
public function testWrite()
{
$this->_initializeBuffer();
$line = $this->_buffer->readLine(0);
$this->assertRegExp('/^[0-9]{3}.*?\r\n$/D', $line);
$seq = $this->_buffer->write("HELO foo\r\n");
$this->assertTrue((bool) $seq);
$line = $this->_buffer->readLine($seq);
$this->assertRegExp('/^[0-9]{3}.*?\r\n$/D', $line);
$seq = $this->_buffer->write("QUIT\r\n");
$this->assertTrue((bool) $seq);
$line = $this->_buffer->readLine($seq);
$this->assertRegExp('/^[0-9]{3}.*?\r\n$/D', $line);
$this->_buffer->terminate();
}
public function testBindingOtherStreamsMirrorsWriteOperations()
{
$this->_initializeBuffer();
$is1 = $this->_createMockInputStream();
$is2 = $this->_createMockInputStream();
$is1->expects($this->at(0))
->method('write')
->with('x');
$is1->expects($this->at(1))
->method('write')
->with('y');
$is2->expects($this->at(0))
->method('write')
->with('x');
$is2->expects($this->at(1))
->method('write')
->with('y');
$this->_buffer->bind($is1);
$this->_buffer->bind($is2);
$this->_buffer->write('x');
$this->_buffer->write('y');
}
public function testBindingOtherStreamsMirrorsFlushOperations()
{
$this->_initializeBuffer();
$is1 = $this->_createMockInputStream();
$is2 = $this->_createMockInputStream();
$is1->expects($this->once())
->method('flushBuffers');
$is2->expects($this->once())
->method('flushBuffers');
$this->_buffer->bind($is1);
$this->_buffer->bind($is2);
$this->_buffer->flushBuffers();
}
public function testUnbindingStreamPreventsFurtherWrites()
{
$this->_initializeBuffer();
$is1 = $this->_createMockInputStream();
$is2 = $this->_createMockInputStream();
$is1->expects($this->at(0))
->method('write')
->with('x');
$is1->expects($this->at(1))
->method('write')
->with('y');
$is2->expects($this->once())
->method('write')
->with('x');
$this->_buffer->bind($is1);
$this->_buffer->bind($is2);
$this->_buffer->write('x');
$this->_buffer->unbind($is2);
$this->_buffer->write('y');
}
private function _createMockInputStream()
{
return $this->getMockBuilder('Swift_InputByteStream')->getMock();
}
}
<?php
require_once __DIR__.'/AbstractStreamBufferAcceptanceTest.php';
class Swift_Transport_StreamBuffer_BasicSocketAcceptanceTest extends Swift_Transport_StreamBuffer_AbstractStreamBufferAcceptanceTest
{
protected function setUp()
{
if (!defined('SWIFT_SMTP_HOST')) {
$this->markTestSkipped(
'Cannot run test without an SMTP host to connect to (define '.
'SWIFT_SMTP_HOST in tests/acceptance.conf.php if you wish to run this test)'
);
}
parent::setUp();
}
protected function _initializeBuffer()
{
$parts = explode(':', SWIFT_SMTP_HOST);
$host = $parts[0];
$port = isset($parts[1]) ? $parts[1] : 25;
$this->_buffer->initialize(array(
'type' => Swift_Transport_IoBuffer::TYPE_SOCKET,
'host' => $host,
'port' => $port,
'protocol' => 'tcp',
'blocking' => 1,
'timeout' => 15,
));
}
}
<?php
require_once __DIR__.'/AbstractStreamBufferAcceptanceTest.php';
class Swift_Transport_StreamBuffer_ProcessAcceptanceTest extends Swift_Transport_StreamBuffer_AbstractStreamBufferAcceptanceTest
{
protected function setUp()
{
if (!defined('SWIFT_SENDMAIL_PATH')) {
$this->markTestSkipped(
'Cannot run test without a path to sendmail (define '.
'SWIFT_SENDMAIL_PATH in tests/acceptance.conf.php if you wish to run this test)'
);
}
parent::setUp();
}
protected function _initializeBuffer()
{
$this->_buffer->initialize(array(
'type' => Swift_Transport_IoBuffer::TYPE_PROCESS,
'command' => SWIFT_SENDMAIL_PATH.' -bs',
));
}
}
<?php
class Swift_Transport_StreamBuffer_SocketTimeoutTest extends \PHPUnit_Framework_TestCase
{
protected $_buffer;
protected $_randomHighPort;
protected $_server;
protected function setUp()
{
if (!defined('SWIFT_SMTP_HOST')) {
$this->markTestSkipped(
'Cannot run test without an SMTP host to connect to (define '.
'SWIFT_SMTP_HOST in tests/acceptance.conf.php if you wish to run this test)'
);
}
$serverStarted = false;
for ($i = 0; $i < 5; ++$i) {
$this->_randomHighPort = rand(50000, 65000);
$this->_server = stream_socket_server('tcp://127.0.0.1:'.$this->_randomHighPort);
if ($this->_server) {
$serverStarted = true;
}
}
$this->_buffer = new Swift_Transport_StreamBuffer(
$this->getMockBuilder('Swift_ReplacementFilterFactory')->getMock()
);
}
protected function _initializeBuffer()
{
$host = '127.0.0.1';
$port = $this->_randomHighPort;
$this->_buffer->initialize(array(
'type' => Swift_Transport_IoBuffer::TYPE_SOCKET,
'host' => $host,
'port' => $port,
'protocol' => 'tcp',
'blocking' => 1,
'timeout' => 1,
));
}
public function testTimeoutException()
{
$this->_initializeBuffer();
$e = null;
try {
$line = $this->_buffer->readLine(0);
} catch (Exception $e) {
}
$this->assertInstanceof('Swift_IoException', $e, 'IO Exception Not Thrown On Connection Timeout');
$this->assertRegExp('/Connection to .* Timed Out/', $e->getMessage());
}
protected function tearDown()
{
if ($this->_server) {
stream_socket_shutdown($this->_server, STREAM_SHUT_RDWR);
}
}
}
<?php
require_once __DIR__.'/AbstractStreamBufferAcceptanceTest.php';
class Swift_Transport_StreamBuffer_SslSocketAcceptanceTest extends Swift_Transport_StreamBuffer_AbstractStreamBufferAcceptanceTest
{
protected function setUp()
{
$streams = stream_get_transports();
if (!in_array('ssl', $streams)) {
$this->markTestSkipped(
'SSL is not configured for your system. It is not possible to run this test'
);
}
if (!defined('SWIFT_SSL_HOST')) {
$this->markTestSkipped(
'Cannot run test without an SSL enabled SMTP host to connect to (define '.
'SWIFT_SSL_HOST in tests/acceptance.conf.php if you wish to run this test)'
);
}
parent::setUp();
}
protected function _initializeBuffer()
{
$parts = explode(':', SWIFT_SSL_HOST);
$host = $parts[0];
$port = isset($parts[1]) ? $parts[1] : 25;
$this->_buffer->initialize(array(
'type' => Swift_Transport_IoBuffer::TYPE_SOCKET,
'host' => $host,
'port' => $port,
'protocol' => 'ssl',
'blocking' => 1,
'timeout' => 15,
));
}
}
<?php
require_once __DIR__.'/AbstractStreamBufferAcceptanceTest.php';
class Swift_Transport_StreamBuffer_TlsSocketAcceptanceTest extends Swift_Transport_StreamBuffer_AbstractStreamBufferAcceptanceTest
{
protected function setUp()
{
$streams = stream_get_transports();
if (!in_array('tls', $streams)) {
$this->markTestSkipped(
'TLS is not configured for your system. It is not possible to run this test'
);
}
if (!defined('SWIFT_TLS_HOST')) {
$this->markTestSkipped(
'Cannot run test without a TLS enabled SMTP host to connect to (define '.
'SWIFT_TLS_HOST in tests/acceptance.conf.php if you wish to run this test)'
);
}
parent::setUp();
}
protected function _initializeBuffer()
{
$parts = explode(':', SWIFT_TLS_HOST);
$host = $parts[0];
$port = isset($parts[1]) ? $parts[1] : 25;
$this->_buffer->initialize(array(
'type' => Swift_Transport_IoBuffer::TYPE_SOCKET,
'host' => $host,
'port' => $port,
'protocol' => 'tls',
'blocking' => 1,
'timeout' => 15,
));
}
}
<?php
require_once dirname(__DIR__).'/vendor/autoload.php';
// Disable garbage collector to prevent segfaults
gc_disable();
set_include_path(get_include_path().PATH_SEPARATOR.dirname(__DIR__).'/lib');
Mockery::getConfiguration()->allowMockingNonExistentMethods(true);
if (is_file(__DIR__.'/acceptance.conf.php')) {
require_once __DIR__.'/acceptance.conf.php';
}
if (is_file(__DIR__.'/smoke.conf.php')) {
require_once __DIR__.'/smoke.conf.php';
}
require_once __DIR__.'/StreamCollector.php';
require_once __DIR__.'/IdenticalBinaryConstraint.php';
require_once __DIR__.'/SwiftMailerTestCase.php';
require_once __DIR__.'/SwiftMailerSmokeTestCase.php';
<?php
class Swift_Bug111Test extends \PHPUnit_Framework_TestCase
{
public function testUnstructuredHeaderSlashesShouldNotBeEscaped()
{
$complicated_header = array(
'to' => array(
'email1@example.com',
'email2@example.com',
'email3@example.com',
'email4@example.com',
'email5@example.com',
),
'sub' => array(
'-name-' => array(
'email1',
'"email2"',
'email3\\',
'email4',
'email5',
),
'-url-' => array(
'http://google.com',
'http://yahoo.com',
'http://hotmail.com',
'http://aol.com',
'http://facebook.com',
),
),
);
$json = json_encode($complicated_header);
$message = new Swift_Message();
$headers = $message->getHeaders();
$headers->addTextHeader('X-SMTPAPI', $json);
$header = $headers->get('X-SMTPAPI');
$this->assertEquals('Swift_Mime_Headers_UnstructuredHeader', get_class($header));
$this->assertEquals($json, $header->getFieldBody());
}
}
<?php
class Swift_ByteStream_ArrayByteStreamTest extends \PHPUnit_Framework_TestCase
{
public function testReadingSingleBytesFromBaseInput()
{
$input = array('a', 'b', 'c');
$bs = $this->_createArrayStream($input);
$output = array();
while (false !== $bytes = $bs->read(1)) {
$output[] = $bytes;
}
$this->assertEquals($input, $output,
'%s: Bytes read from stream should be the same as bytes in constructor'
);
}
public function testReadingMultipleBytesFromBaseInput()
{
$input = array('a', 'b', 'c', 'd');
$bs = $this->_createArrayStream($input);
$output = array();
while (false !== $bytes = $bs->read(2)) {
$output[] = $bytes;
}
$this->assertEquals(array('ab', 'cd'), $output,
'%s: Bytes read from stream should be in pairs'
);
}
public function testReadingOddOffsetOnLastByte()
{
$input = array('a', 'b', 'c', 'd', 'e');
$bs = $this->_createArrayStream($input);
$output = array();
while (false !== $bytes = $bs->read(2)) {
$output[] = $bytes;
}
$this->assertEquals(array('ab', 'cd', 'e'), $output,
'%s: Bytes read from stream should be in pairs except final read'
);
}
public function testSettingPointerPartway()
{
$input = array('a', 'b', 'c');
$bs = $this->_createArrayStream($input);
$bs->setReadPointer(1);
$this->assertEquals('b', $bs->read(1),
'%s: Byte should be second byte since pointer as at offset 1'
);
}
public function testResettingPointerAfterExhaustion()
{
$input = array('a', 'b', 'c');
$bs = $this->_createArrayStream($input);
while (false !== $bs->read(1));
$bs->setReadPointer(0);
$this->assertEquals('a', $bs->read(1),
'%s: Byte should be first byte since pointer as at offset 0'
);
}
public function testPointerNeverSetsBelowZero()
{
$input = array('a', 'b', 'c');
$bs = $this->_createArrayStream($input);
$bs->setReadPointer(-1);
$this->assertEquals('a', $bs->read(1),
'%s: Byte should be first byte since pointer should be at offset 0'
);
}
public function testPointerNeverSetsAboveStackSize()
{
$input = array('a', 'b', 'c');
$bs = $this->_createArrayStream($input);
$bs->setReadPointer(3);
$this->assertFalse($bs->read(1),
'%s: Stream should be at end and thus return false'
);
}
public function testBytesCanBeWrittenToStream()
{
$input = array('a', 'b', 'c');
$bs = $this->_createArrayStream($input);
$bs->write('de');
$output = array();
while (false !== $bytes = $bs->read(1)) {
$output[] = $bytes;
}
$this->assertEquals(array('a', 'b', 'c', 'd', 'e'), $output,
'%s: Bytes read from stream should be from initial stack + written'
);
}
public function testContentsCanBeFlushed()
{
$input = array('a', 'b', 'c');
$bs = $this->_createArrayStream($input);
$bs->flushBuffers();
$this->assertFalse($bs->read(1),
'%s: Contents have been flushed so read() should return false'
);
}
public function testConstructorCanTakeStringArgument()
{
$bs = $this->_createArrayStream('abc');
$output = array();
while (false !== $bytes = $bs->read(1)) {
$output[] = $bytes;
}
$this->assertEquals(array('a', 'b', 'c'), $output,
'%s: Bytes read from stream should be the same as bytes in constructor'
);
}
public function testBindingOtherStreamsMirrorsWriteOperations()
{
$bs = $this->_createArrayStream('');
$is1 = $this->getMockBuilder('Swift_InputByteStream')->getMock();
$is2 = $this->getMockBuilder('Swift_InputByteStream')->getMock();
$is1->expects($this->at(0))
->method('write')
->with('x');
$is1->expects($this->at(1))
->method('write')
->with('y');
$is2->expects($this->at(0))
->method('write')
->with('x');
$is2->expects($this->at(1))
->method('write')
->with('y');
$bs->bind($is1);
$bs->bind($is2);
$bs->write('x');
$bs->write('y');
}
public function testBindingOtherStreamsMirrorsFlushOperations()
{
$bs = $this->_createArrayStream('');
$is1 = $this->getMockBuilder('Swift_InputByteStream')->getMock();
$is2 = $this->getMockBuilder('Swift_InputByteStream')->getMock();
$is1->expects($this->once())
->method('flushBuffers');
$is2->expects($this->once())
->method('flushBuffers');
$bs->bind($is1);
$bs->bind($is2);
$bs->flushBuffers();
}
public function testUnbindingStreamPreventsFurtherWrites()
{
$bs = $this->_createArrayStream('');
$is1 = $this->getMockBuilder('Swift_InputByteStream')->getMock();
$is2 = $this->getMockBuilder('Swift_InputByteStream')->getMock();
$is1->expects($this->at(0))
->method('write')
->with('x');
$is1->expects($this->at(1))
->method('write')
->with('y');
$is2->expects($this->once())
->method('write')
->with('x');
$bs->bind($is1);
$bs->bind($is2);
$bs->write('x');
$bs->unbind($is2);
$bs->write('y');
}
private function _createArrayStream($input)
{
return new Swift_ByteStream_ArrayByteStream($input);
}
}
<?php
class Swift_CharacterReader_GenericFixedWidthReaderTest extends \PHPUnit_Framework_TestCase
{
public function testInitialByteSizeMatchesWidth()
{
$reader = new Swift_CharacterReader_GenericFixedWidthReader(1);
$this->assertSame(1, $reader->getInitialByteSize());
$reader = new Swift_CharacterReader_GenericFixedWidthReader(4);
$this->assertSame(4, $reader->getInitialByteSize());
}
public function testValidationValueIsBasedOnOctetCount()
{
$reader = new Swift_CharacterReader_GenericFixedWidthReader(4);
$this->assertSame(
1, $reader->validateByteSequence(array(0x01, 0x02, 0x03), 3)
); //3 octets
$this->assertSame(
2, $reader->validateByteSequence(array(0x01, 0x0A), 2)
); //2 octets
$this->assertSame(
3, $reader->validateByteSequence(array(0xFE), 1)
); //1 octet
$this->assertSame(
0, $reader->validateByteSequence(array(0xFE, 0x03, 0x67, 0x9A), 4)
); //All 4 octets
}
public function testValidationFailsIfTooManyOctets()
{
$reader = new Swift_CharacterReader_GenericFixedWidthReader(6);
$this->assertSame(-1, $reader->validateByteSequence(
array(0xFE, 0x03, 0x67, 0x9A, 0x10, 0x09, 0x85), 7
)); //7 octets
}
}
<?php
class Swift_CharacterReader_UsAsciiReaderTest extends \PHPUnit_Framework_TestCase
{
/*
for ($c = '', $size = 1; false !== $bytes = $os->read($size); ) {
$c .= $bytes;
$size = $v->validateCharacter($c);
if (-1 == $size) {
throw new Exception( ... invalid char .. );
} elseif (0 == $size) {
return $c; //next character in $os
}
}
*/
private $_reader;
protected function setUp()
{
$this->_reader = new Swift_CharacterReader_UsAsciiReader();
}
public function testAllValidAsciiCharactersReturnZero()
{
for ($ordinal = 0x00; $ordinal <= 0x7F; ++$ordinal) {
$this->assertSame(
0, $this->_reader->validateByteSequence(array($ordinal), 1)
);
}
}
public function testMultipleBytesAreInvalid()
{
for ($ordinal = 0x00; $ordinal <= 0x7F; $ordinal += 2) {
$this->assertSame(
-1, $this->_reader->validateByteSequence(array($ordinal, $ordinal + 1), 2)
);
}
}
public function testBytesAboveAsciiRangeAreInvalid()
{
for ($ordinal = 0x80; $ordinal <= 0xFF; ++$ordinal) {
$this->assertSame(
-1, $this->_reader->validateByteSequence(array($ordinal), 1)
);
}
}
}
<?php
class Swift_CharacterReader_Utf8ReaderTest extends \PHPUnit_Framework_TestCase
{
private $_reader;
protected function setUp()
{
$this->_reader = new Swift_CharacterReader_Utf8Reader();
}
public function testLeading7BitOctetCausesReturnZero()
{
for ($ordinal = 0x00; $ordinal <= 0x7F; ++$ordinal) {
$this->assertSame(
0, $this->_reader->validateByteSequence(array($ordinal), 1)
);
}
}
public function testLeadingByteOf2OctetCharCausesReturn1()
{
for ($octet = 0xC0; $octet <= 0xDF; ++$octet) {
$this->assertSame(
1, $this->_reader->validateByteSequence(array($octet), 1)
);
}
}
public function testLeadingByteOf3OctetCharCausesReturn2()
{
for ($octet = 0xE0; $octet <= 0xEF; ++$octet) {
$this->assertSame(
2, $this->_reader->validateByteSequence(array($octet), 1)
);
}
}
public function testLeadingByteOf4OctetCharCausesReturn3()
{
for ($octet = 0xF0; $octet <= 0xF7; ++$octet) {
$this->assertSame(
3, $this->_reader->validateByteSequence(array($octet), 1)
);
}
}
public function testLeadingByteOf5OctetCharCausesReturn4()
{
for ($octet = 0xF8; $octet <= 0xFB; ++$octet) {
$this->assertSame(
4, $this->_reader->validateByteSequence(array($octet), 1)
);
}
}
public function testLeadingByteOf6OctetCharCausesReturn5()
{
for ($octet = 0xFC; $octet <= 0xFD; ++$octet) {
$this->assertSame(
5, $this->_reader->validateByteSequence(array($octet), 1)
);
}
}
}
<?php
class Swift_CharacterStream_ArrayCharacterStreamTest extends \SwiftMailerTestCase
{
public function testValidatorAlgorithmOnImportString()
{
$reader = $this->_getReader();
$factory = $this->_getFactory($reader);
$stream = new Swift_CharacterStream_ArrayCharacterStream($factory, 'utf-8');
$reader->shouldReceive('getInitialByteSize')
->zeroOrMoreTimes()
->andReturn(1);
$reader->shouldReceive('validateByteSequence')->once()->with(array(0xD0), 1)->andReturn(1);
$reader->shouldReceive('validateByteSequence')->once()->with(array(0xD0), 1)->andReturn(1);
$reader->shouldReceive('validateByteSequence')->once()->with(array(0xD0), 1)->andReturn(1);
$reader->shouldReceive('validateByteSequence')->once()->with(array(0xD1), 1)->andReturn(1);
$reader->shouldReceive('validateByteSequence')->once()->with(array(0xD0), 1)->andReturn(1);
$reader->shouldReceive('validateByteSequence')->once()->with(array(0xD0), 1)->andReturn(1);
$stream->importString(pack('C*',
0xD0, 0x94,
0xD0, 0xB6,
0xD0, 0xBE,
0xD1, 0x8D,
0xD0, 0xBB,
0xD0, 0xB0
)
);
}
public function testCharactersWrittenUseValidator()
{
$reader = $this->_getReader();
$factory = $this->_getFactory($reader);
$stream = new Swift_CharacterStream_ArrayCharacterStream($factory, 'utf-8');
$reader->shouldReceive('getInitialByteSize')
->zeroOrMoreTimes()
->andReturn(1);
$reader->shouldReceive('validateByteSequence')->once()->with(array(0xD0), 1)->andReturn(1);
$reader->shouldReceive('validateByteSequence')->once()->with(array(0xD0), 1)->andReturn(1);
$reader->shouldReceive('validateByteSequence')->once()->with(array(0xD0), 1)->andReturn(1);
$reader->shouldReceive('validateByteSequence')->once()->with(array(0xD0), 1)->andReturn(1);
$reader->shouldReceive('validateByteSequence')->once()->with(array(0xD1), 1)->andReturn(1);
$reader->shouldReceive('validateByteSequence')->once()->with(array(0xD0), 1)->andReturn(1);
$reader->shouldReceive('validateByteSequence')->once()->with(array(0xD1), 1)->andReturn(1);
$reader->shouldReceive('validateByteSequence')->once()->with(array(0xD1), 1)->andReturn(1);
$stream->importString(pack('C*', 0xD0, 0x94, 0xD0, 0xB6, 0xD0, 0xBE));
$stream->write(pack('C*',
0xD0, 0xBB,
0xD1, 0x8E,
0xD0, 0xB1,
0xD1, 0x8B,
0xD1, 0x85
)
);
}
public function testReadCharactersAreInTact()
{
$reader = $this->_getReader();
$factory = $this->_getFactory($reader);
$stream = new Swift_CharacterStream_ArrayCharacterStream($factory, 'utf-8');
$reader->shouldReceive('getInitialByteSize')
->zeroOrMoreTimes()
->andReturn(1);
//String
$reader->shouldReceive('validateByteSequence')->once()->with(array(0xD0), 1)->andReturn(1);
$reader->shouldReceive('validateByteSequence')->once()->with(array(0xD0), 1)->andReturn(1);
$reader->shouldReceive('validateByteSequence')->once()->with(array(0xD0), 1)->andReturn(1);
//Stream
$reader->shouldReceive('validateByteSequence')->once()->with(array(0xD0), 1)->andReturn(1);
$reader->shouldReceive('validateByteSequence')->once()->with(array(0xD1), 1)->andReturn(1);
$reader->shouldReceive('validateByteSequence')->once()->with(array(0xD0), 1)->andReturn(1);
$reader->shouldReceive('validateByteSequence')->once()->with(array(0xD1), 1)->andReturn(1);
$reader->shouldReceive('validateByteSequence')->once()->with(array(0xD1), 1)->andReturn(1);
$stream->importString(pack('C*', 0xD0, 0x94, 0xD0, 0xB6, 0xD0, 0xBE));
$stream->write(pack('C*',
0xD0, 0xBB,
0xD1, 0x8E,
0xD0, 0xB1,
0xD1, 0x8B,
0xD1, 0x85
)
);
$this->assertIdenticalBinary(pack('C*', 0xD0, 0x94), $stream->read(1));
$this->assertIdenticalBinary(
pack('C*', 0xD0, 0xB6, 0xD0, 0xBE), $stream->read(2)
);
$this->assertIdenticalBinary(pack('C*', 0xD0, 0xBB), $stream->read(1));
$this->assertIdenticalBinary(
pack('C*', 0xD1, 0x8E, 0xD0, 0xB1, 0xD1, 0x8B), $stream->read(3)
);
$this->assertIdenticalBinary(pack('C*', 0xD1, 0x85), $stream->read(1));
$this->assertFalse($stream->read(1));
}
public function testCharactersCanBeReadAsByteArrays()
{
$reader = $this->_getReader();
$factory = $this->_getFactory($reader);
$stream = new Swift_CharacterStream_ArrayCharacterStream($factory, 'utf-8');
$reader->shouldReceive('getInitialByteSize')
->zeroOrMoreTimes()
->andReturn(1);
//String
$reader->shouldReceive('validateByteSequence')->once()->with(array(0xD0), 1)->andReturn(1);
$reader->shouldReceive('validateByteSequence')->once()->with(array(0xD0), 1)->andReturn(1);
$reader->shouldReceive('validateByteSequence')->once()->with(array(0xD0), 1)->andReturn(1);
//Stream
$reader->shouldReceive('validateByteSequence')->once()->with(array(0xD0), 1)->andReturn(1);
$reader->shouldReceive('validateByteSequence')->once()->with(array(0xD1), 1)->andReturn(1);
$reader->shouldReceive('validateByteSequence')->once()->with(array(0xD0), 1)->andReturn(1);
$reader->shouldReceive('validateByteSequence')->once()->with(array(0xD1), 1)->andReturn(1);
$reader->shouldReceive('validateByteSequence')->once()->with(array(0xD1), 1)->andReturn(1);
$stream->importString(pack('C*', 0xD0, 0x94, 0xD0, 0xB6, 0xD0, 0xBE));
$stream->write(pack('C*',
0xD0, 0xBB,
0xD1, 0x8E,
0xD0, 0xB1,
0xD1, 0x8B,
0xD1, 0x85
)
);
$this->assertEquals(array(0xD0, 0x94), $stream->readBytes(1));
$this->assertEquals(array(0xD0, 0xB6, 0xD0, 0xBE), $stream->readBytes(2));
$this->assertEquals(array(0xD0, 0xBB), $stream->readBytes(1));
$this->assertEquals(
array(0xD1, 0x8E, 0xD0, 0xB1, 0xD1, 0x8B), $stream->readBytes(3)
);
$this->assertEquals(array(0xD1, 0x85), $stream->readBytes(1));
$this->assertFalse($stream->readBytes(1));
}
public function testRequestingLargeCharCountPastEndOfStream()
{
$reader = $this->_getReader();
$factory = $this->_getFactory($reader);
$stream = new Swift_CharacterStream_ArrayCharacterStream($factory, 'utf-8');
$reader->shouldReceive('getInitialByteSize')
->zeroOrMoreTimes()
->andReturn(1);
$reader->shouldReceive('validateByteSequence')->once()->with(array(0xD0), 1)->andReturn(1);
$reader->shouldReceive('validateByteSequence')->once()->with(array(0xD0), 1)->andReturn(1);
$reader->shouldReceive('validateByteSequence')->once()->with(array(0xD0), 1)->andReturn(1);
$stream->importString(pack('C*', 0xD0, 0x94, 0xD0, 0xB6, 0xD0, 0xBE));
$this->assertIdenticalBinary(pack('C*', 0xD0, 0x94, 0xD0, 0xB6, 0xD0, 0xBE),
$stream->read(100)
);
$this->assertFalse($stream->read(1));
}
public function testRequestingByteArrayCountPastEndOfStream()
{
$reader = $this->_getReader();
$factory = $this->_getFactory($reader);
$stream = new Swift_CharacterStream_ArrayCharacterStream($factory, 'utf-8');
$reader->shouldReceive('getInitialByteSize')
->zeroOrMoreTimes()
->andReturn(1);
$reader->shouldReceive('validateByteSequence')->once()->with(array(0xD0), 1)->andReturn(1);
$reader->shouldReceive('validateByteSequence')->once()->with(array(0xD0), 1)->andReturn(1);
$reader->shouldReceive('validateByteSequence')->once()->with(array(0xD0), 1)->andReturn(1);
$stream->importString(pack('C*', 0xD0, 0x94, 0xD0, 0xB6, 0xD0, 0xBE));
$this->assertEquals(array(0xD0, 0x94, 0xD0, 0xB6, 0xD0, 0xBE),
$stream->readBytes(100)
);
$this->assertFalse($stream->readBytes(1));
}
public function testPointerOffsetCanBeSet()
{
$reader = $this->_getReader();
$factory = $this->_getFactory($reader);
$stream = new Swift_CharacterStream_ArrayCharacterStream($factory, 'utf-8');
$reader->shouldReceive('getInitialByteSize')
->zeroOrMoreTimes()
->andReturn(1);
$reader->shouldReceive('validateByteSequence')->once()->with(array(0xD0), 1)->andReturn(1);
$reader->shouldReceive('validateByteSequence')->once()->with(array(0xD0), 1)->andReturn(1);
$reader->shouldReceive('validateByteSequence')->once()->with(array(0xD0), 1)->andReturn(1);
$stream->importString(pack('C*', 0xD0, 0x94, 0xD0, 0xB6, 0xD0, 0xBE));
$this->assertIdenticalBinary(pack('C*', 0xD0, 0x94), $stream->read(1));
$stream->setPointer(0);
$this->assertIdenticalBinary(pack('C*', 0xD0, 0x94), $stream->read(1));
$stream->setPointer(2);
$this->assertIdenticalBinary(pack('C*', 0xD0, 0xBE), $stream->read(1));
}
public function testContentsCanBeFlushed()
{
$reader = $this->_getReader();
$factory = $this->_getFactory($reader);
$stream = new Swift_CharacterStream_ArrayCharacterStream($factory, 'utf-8');
$reader->shouldReceive('getInitialByteSize')
->zeroOrMoreTimes()
->andReturn(1);
$reader->shouldReceive('validateByteSequence')->once()->with(array(0xD0), 1)->andReturn(1);
$reader->shouldReceive('validateByteSequence')->once()->with(array(0xD0), 1)->andReturn(1);
$reader->shouldReceive('validateByteSequence')->once()->with(array(0xD0), 1)->andReturn(1);
$stream->importString(pack('C*', 0xD0, 0x94, 0xD0, 0xB6, 0xD0, 0xBE));
$stream->flushContents();
$this->assertFalse($stream->read(1));
}
public function testByteStreamCanBeImportingUsesValidator()
{
$reader = $this->_getReader();
$factory = $this->_getFactory($reader);
$os = $this->_getByteStream();
$stream = new Swift_CharacterStream_ArrayCharacterStream($factory, 'utf-8');
$os->shouldReceive('setReadPointer')
->between(0, 1)
->with(0);
$os->shouldReceive('read')->once()->andReturn(pack('C*', 0xD0));
$os->shouldReceive('read')->once()->andReturn(pack('C*', 0x94));
$os->shouldReceive('read')->once()->andReturn(pack('C*', 0xD0));
$os->shouldReceive('read')->once()->andReturn(pack('C*', 0xB6));
$os->shouldReceive('read')->once()->andReturn(pack('C*', 0xD0));
$os->shouldReceive('read')->once()->andReturn(pack('C*', 0xBE));
$os->shouldReceive('read')
->zeroOrMoreTimes()
->andReturn(false);
$reader->shouldReceive('getInitialByteSize')
->zeroOrMoreTimes()
->andReturn(1);
$reader->shouldReceive('validateByteSequence')->once()->with(array(0xD0), 1)->andReturn(1);
$reader->shouldReceive('validateByteSequence')->once()->with(array(0xD0), 1)->andReturn(1);
$reader->shouldReceive('validateByteSequence')->once()->with(array(0xD0), 1)->andReturn(1);
$stream->importByteStream($os);
}
public function testImportingStreamProducesCorrectCharArray()
{
$reader = $this->_getReader();
$factory = $this->_getFactory($reader);
$os = $this->_getByteStream();
$stream = new Swift_CharacterStream_ArrayCharacterStream($factory, 'utf-8');
$os->shouldReceive('setReadPointer')
->between(0, 1)
->with(0);
$os->shouldReceive('read')->once()->andReturn(pack('C*', 0xD0));
$os->shouldReceive('read')->once()->andReturn(pack('C*', 0x94));
$os->shouldReceive('read')->once()->andReturn(pack('C*', 0xD0));
$os->shouldReceive('read')->once()->andReturn(pack('C*', 0xB6));
$os->shouldReceive('read')->once()->andReturn(pack('C*', 0xD0));
$os->shouldReceive('read')->once()->andReturn(pack('C*', 0xBE));
$os->shouldReceive('read')
->zeroOrMoreTimes()
->andReturn(false);
$reader->shouldReceive('getInitialByteSize')
->zeroOrMoreTimes()
->andReturn(1);
$reader->shouldReceive('validateByteSequence')->once()->with(array(0xD0), 1)->andReturn(1);
$reader->shouldReceive('validateByteSequence')->once()->with(array(0xD0), 1)->andReturn(1);
$reader->shouldReceive('validateByteSequence')->once()->with(array(0xD0), 1)->andReturn(1);
$stream->importByteStream($os);
$this->assertIdenticalBinary(pack('C*', 0xD0, 0x94), $stream->read(1));
$this->assertIdenticalBinary(pack('C*', 0xD0, 0xB6), $stream->read(1));
$this->assertIdenticalBinary(pack('C*', 0xD0, 0xBE), $stream->read(1));
$this->assertFalse($stream->read(1));
}
public function testAlgorithmWithFixedWidthCharsets()
{
$reader = $this->_getReader();
$factory = $this->_getFactory($reader);
$reader->shouldReceive('getInitialByteSize')
->zeroOrMoreTimes()
->andReturn(2);
$reader->shouldReceive('validateByteSequence')->once()->with(array(0xD1, 0x8D), 2);
$reader->shouldReceive('validateByteSequence')->once()->with(array(0xD0, 0xBB), 2);
$reader->shouldReceive('validateByteSequence')->once()->with(array(0xD0, 0xB0), 2);
$stream = new Swift_CharacterStream_ArrayCharacterStream(
$factory, 'utf-8'
);
$stream->importString(pack('C*', 0xD1, 0x8D, 0xD0, 0xBB, 0xD0, 0xB0));
$this->assertIdenticalBinary(pack('C*', 0xD1, 0x8D), $stream->read(1));
$this->assertIdenticalBinary(pack('C*', 0xD0, 0xBB), $stream->read(1));
$this->assertIdenticalBinary(pack('C*', 0xD0, 0xB0), $stream->read(1));
$this->assertFalse($stream->read(1));
}
private function _getReader()
{
return $this->getMockery('Swift_CharacterReader');
}
private function _getFactory($reader)
{
$factory = $this->getMockery('Swift_CharacterReaderFactory');
$factory->shouldReceive('getReaderFor')
->zeroOrMoreTimes()
->with('utf-8')
->andReturn($reader);
return $factory;
}
private function _getByteStream()
{
return $this->getMockery('Swift_OutputByteStream');
}
}
<?php
class One
{
public $arg1;
public $arg2;
public function __construct($arg1 = null, $arg2 = null)
{
$this->arg1 = $arg1;
$this->arg2 = $arg2;
}
}
class Swift_DependencyContainerTest extends \PHPUnit_Framework_TestCase
{
private $_container;
protected function setUp()
{
$this->_container = new Swift_DependencyContainer();
}
public function testRegisterAndLookupValue()
{
$this->_container->register('foo')->asValue('bar');
$this->assertEquals('bar', $this->_container->lookup('foo'));
}
public function testHasReturnsTrueForRegisteredValue()
{
$this->_container->register('foo')->asValue('bar');
$this->assertTrue($this->_container->has('foo'));
}
public function testHasReturnsFalseForUnregisteredValue()
{
$this->assertFalse($this->_container->has('foo'));
}
public function testRegisterAndLookupNewInstance()
{
$this->_container->register('one')->asNewInstanceOf('One');
$this->assertInstanceof('One', $this->_container->lookup('one'));
}
public function testHasReturnsTrueForRegisteredInstance()
{
$this->_container->register('one')->asNewInstanceOf('One');
$this->assertTrue($this->_container->has('one'));
}
public function testNewInstanceIsAlwaysNew()
{
$this->_container->register('one')->asNewInstanceOf('One');
$a = $this->_container->lookup('one');
$b = $this->_container->lookup('one');
$this->assertEquals($a, $b);
}
public function testRegisterAndLookupSharedInstance()
{
$this->_container->register('one')->asSharedInstanceOf('One');
$this->assertInstanceof('One', $this->_container->lookup('one'));
}
public function testHasReturnsTrueForSharedInstance()
{
$this->_container->register('one')->asSharedInstanceOf('One');
$this->assertTrue($this->_container->has('one'));
}
public function testMultipleSharedInstancesAreSameInstance()
{
$this->_container->register('one')->asSharedInstanceOf('One');
$a = $this->_container->lookup('one');
$b = $this->_container->lookup('one');
$this->assertEquals($a, $b);
}
public function testNewInstanceWithDependencies()
{
$this->_container->register('foo')->asValue('FOO');
$this->_container->register('one')->asNewInstanceOf('One')
->withDependencies(array('foo'));
$obj = $this->_container->lookup('one');
$this->assertSame('FOO', $obj->arg1);
}
public function testNewInstanceWithMultipleDependencies()
{
$this->_container->register('foo')->asValue('FOO');
$this->_container->register('bar')->asValue(42);
$this->_container->register('one')->asNewInstanceOf('One')
->withDependencies(array('foo', 'bar'));
$obj = $this->_container->lookup('one');
$this->assertSame('FOO', $obj->arg1);
$this->assertSame(42, $obj->arg2);
}
public function testNewInstanceWithInjectedObjects()
{
$this->_container->register('foo')->asValue('FOO');
$this->_container->register('one')->asNewInstanceOf('One');
$this->_container->register('two')->asNewInstanceOf('One')
->withDependencies(array('one', 'foo'));
$obj = $this->_container->lookup('two');
$this->assertEquals($this->_container->lookup('one'), $obj->arg1);
$this->assertSame('FOO', $obj->arg2);
}
public function testNewInstanceWithAddConstructorValue()
{
$this->_container->register('one')->asNewInstanceOf('One')
->addConstructorValue('x')
->addConstructorValue(99);
$obj = $this->_container->lookup('one');
$this->assertSame('x', $obj->arg1);
$this->assertSame(99, $obj->arg2);
}
public function testNewInstanceWithAddConstructorLookup()
{
$this->_container->register('foo')->asValue('FOO');
$this->_container->register('bar')->asValue(42);
$this->_container->register('one')->asNewInstanceOf('One')
->addConstructorLookup('foo')
->addConstructorLookup('bar');
$obj = $this->_container->lookup('one');
$this->assertSame('FOO', $obj->arg1);
$this->assertSame(42, $obj->arg2);
}
public function testResolvedDependenciesCanBeLookedUp()
{
$this->_container->register('foo')->asValue('FOO');
$this->_container->register('one')->asNewInstanceOf('One');
$this->_container->register('two')->asNewInstanceOf('One')
->withDependencies(array('one', 'foo'));
$deps = $this->_container->createDependenciesFor('two');
$this->assertEquals(
array($this->_container->lookup('one'), 'FOO'), $deps
);
}
public function testArrayOfDependenciesCanBeSpecified()
{
$this->_container->register('foo')->asValue('FOO');
$this->_container->register('one')->asNewInstanceOf('One');
$this->_container->register('two')->asNewInstanceOf('One')
->withDependencies(array(array('one', 'foo'), 'foo'));
$obj = $this->_container->lookup('two');
$this->assertEquals(array($this->_container->lookup('one'), 'FOO'), $obj->arg1);
$this->assertSame('FOO', $obj->arg2);
}
public function testAliasCanBeSet()
{
$this->_container->register('foo')->asValue('FOO');
$this->_container->register('bar')->asAliasOf('foo');
$this->assertSame('FOO', $this->_container->lookup('bar'));
}
public function testAliasOfAliasCanBeSet()
{
$this->_container->register('foo')->asValue('FOO');
$this->_container->register('bar')->asAliasOf('foo');
$this->_container->register('zip')->asAliasOf('bar');
$this->_container->register('button')->asAliasOf('zip');
$this->assertSame('FOO', $this->_container->lookup('button'));
}
}
<?php
class Swift_Encoder_Base64EncoderTest extends \PHPUnit_Framework_TestCase
{
private $_encoder;
protected function setUp()
{
$this->_encoder = new Swift_Encoder_Base64Encoder();
}
/*
There's really no point in testing the entire base64 encoding to the
level QP encoding has been tested. base64_encode() has been in PHP for
years.
*/
public function testInputOutputRatioIs3to4Bytes()
{
/*
RFC 2045, 6.8
The encoding process represents 24-bit groups of input bits as output
strings of 4 encoded characters. Proceeding from left to right, a
24-bit input group is formed by concatenating 3 8bit input groups.
These 24 bits are then treated as 4 concatenated 6-bit groups, each
of which is translated into a single digit in the base64 alphabet.
*/
$this->assertEquals(
'MTIz', $this->_encoder->encodeString('123'),
'%s: 3 bytes of input should yield 4 bytes of output'
);
$this->assertEquals(
'MTIzNDU2', $this->_encoder->encodeString('123456'),
'%s: 6 bytes in input should yield 8 bytes of output'
);
$this->assertEquals(
'MTIzNDU2Nzg5', $this->_encoder->encodeString('123456789'),
'%s: 9 bytes in input should yield 12 bytes of output'
);
}
public function testPadLength()
{
/*
RFC 2045, 6.8
Special processing is performed if fewer than 24 bits are available
at the end of the data being encoded. A full encoding quantum is
always completed at the end of a body. When fewer than 24 input bits
are available in an input group, zero bits are added (on the right)
to form an integral number of 6-bit groups. Padding at the end of
the data is performed using the "=" character. Since all base64
input is an integral number of octets, only the following cases can
arise: (1) the final quantum of encoding input is an integral
multiple of 24 bits; here, the final unit of encoded output will be
an integral multiple of 4 characters with no "=" padding, (2) the
final quantum of encoding input is exactly 8 bits; here, the final
unit of encoded output will be two characters followed by two "="
padding characters, or (3) the final quantum of encoding input is
exactly 16 bits; here, the final unit of encoded output will be three
characters followed by one "=" padding character.
*/
for ($i = 0; $i < 30; ++$i) {
$input = pack('C', rand(0, 255));
$this->assertRegExp(
'~^[a-zA-Z0-9/\+]{2}==$~', $this->_encoder->encodeString($input),
'%s: A single byte should have 2 bytes of padding'
);
}
for ($i = 0; $i < 30; ++$i) {
$input = pack('C*', rand(0, 255), rand(0, 255));
$this->assertRegExp(
'~^[a-zA-Z0-9/\+]{3}=$~', $this->_encoder->encodeString($input),
'%s: Two bytes should have 1 byte of padding'
);
}
for ($i = 0; $i < 30; ++$i) {
$input = pack('C*', rand(0, 255), rand(0, 255), rand(0, 255));
$this->assertRegExp(
'~^[a-zA-Z0-9/\+]{4}$~', $this->_encoder->encodeString($input),
'%s: Three bytes should have no padding'
);
}
}
public function testMaximumLineLengthIs76Characters()
{
/*
The encoded output stream must be represented in lines of no more
than 76 characters each. All line breaks or other characters not
found in Table 1 must be ignored by decoding software.
*/
$input =
'abcdefghijklmnopqrstuvwxyz'.
'ABCDEFGHIJKLMNOPQRSTUVWXYZ'.
'1234567890'.
'abcdefghijklmnopqrstuvwxyz'.
'ABCDEFGHIJKLMNOPQRSTUVWXYZ'.
'1234567890'.
'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
$output =
'YWJjZGVmZ2hpamtsbW5vcHFyc3R1dnd4eXpBQk'.//38
'NERUZHSElKS0xNTk9QUVJTVFVWV1hZWjEyMzQ1'."\r\n".//76 *
'Njc4OTBhYmNkZWZnaGlqa2xtbm9wcXJzdHV2d3'.//38
'h5ekFCQ0RFRkdISUpLTE1OT1BRUlNUVVZXWFla'."\r\n".//76 *
'MTIzNDU2Nzg5MEFCQ0RFRkdISUpLTE1OT1BRUl'.//38
'NUVVZXWFla'; //48
$this->assertEquals(
$output, $this->_encoder->encodeString($input),
'%s: Lines should be no more than 76 characters'
);
}
public function testMaximumLineLengthCanBeSpecified()
{
$input =
'abcdefghijklmnopqrstuvwxyz'.
'ABCDEFGHIJKLMNOPQRSTUVWXYZ'.
'1234567890'.
'abcdefghijklmnopqrstuvwxyz'.
'ABCDEFGHIJKLMNOPQRSTUVWXYZ'.
'1234567890'.
'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
$output =
'YWJjZGVmZ2hpamtsbW5vcHFyc3R1dnd4eXpBQk'.//38
'NERUZHSElKS0'."\r\n".//50 *
'xNTk9QUVJTVFVWV1hZWjEyMzQ1Njc4OTBhYmNk'.//38
'ZWZnaGlqa2xt'."\r\n".//50 *
'bm9wcXJzdHV2d3h5ekFCQ0RFRkdISUpLTE1OT1'.//38
'BRUlNUVVZXWF'."\r\n".//50 *
'laMTIzNDU2Nzg5MEFCQ0RFRkdISUpLTE1OT1BR'.//38
'UlNUVVZXWFla'; //50 *
$this->assertEquals(
$output, $this->_encoder->encodeString($input, 0, 50),
'%s: Lines should be no more than 100 characters'
);
}
public function testFirstLineLengthCanBeDifferent()
{
$input =
'abcdefghijklmnopqrstuvwxyz'.
'ABCDEFGHIJKLMNOPQRSTUVWXYZ'.
'1234567890'.
'abcdefghijklmnopqrstuvwxyz'.
'ABCDEFGHIJKLMNOPQRSTUVWXYZ'.
'1234567890'.
'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
$output =
'YWJjZGVmZ2hpamtsbW5vcHFyc3R1dnd4eXpBQk'.//38
'NERUZHSElKS0xNTk9QU'."\r\n".//57 *
'VJTVFVWV1hZWjEyMzQ1Njc4OTBhYmNkZWZnaGl'.//38
'qa2xtbm9wcXJzdHV2d3h5ekFCQ0RFRkdISUpLT'."\r\n".//76 *
'E1OT1BRUlNUVVZXWFlaMTIzNDU2Nzg5MEFCQ0R'.//38
'FRkdISUpLTE1OT1BRUlNUVVZXWFla'; //67
$this->assertEquals(
$output, $this->_encoder->encodeString($input, 19),
'%s: First line offset is 19 so first line should be 57 chars long'
);
}
}
<?php
class Swift_Encoder_QpEncoderTest extends \SwiftMailerTestCase
{
/* -- RFC 2045, 6.7 --
(1) (General 8bit representation) Any octet, except a CR or
LF that is part of a CRLF line break of the canonical
(standard) form of the data being encoded, may be
represented by an "=" followed by a two digit
hexadecimal representation of the octet's value. The
digits of the hexadecimal alphabet, for this purpose,
are "0123456789ABCDEF". Uppercase letters must be
used; lowercase letters are not allowed. Thus, for
example, the decimal value 12 (US-ASCII form feed) can
be represented by "=0C", and the decimal value 61 (US-
ASCII EQUAL SIGN) can be represented by "=3D". This
rule must be followed except when the following rules
allow an alternative encoding.
*/
public function testPermittedCharactersAreNotEncoded()
{
/* -- RFC 2045, 6.7 --
(2) (Literal representation) Octets with decimal values of
33 through 60 inclusive, and 62 through 126, inclusive,
MAY be represented as the US-ASCII characters which
correspond to those octets (EXCLAMATION POINT through
LESS THAN, and GREATER THAN through TILDE,
respectively).
*/
foreach (array_merge(range(33, 60), range(62, 126)) as $ordinal) {
$char = chr($ordinal);
$charStream = $this->_createCharStream();
$charStream->shouldReceive('flushContents')
->once();
$charStream->shouldReceive('importString')
->once()
->with($char);
$charStream->shouldReceive('readBytes')
->once()
->andReturn(array($ordinal));
$charStream->shouldReceive('readBytes')
->atLeast()->times(1)
->andReturn(false);
$encoder = new Swift_Encoder_QpEncoder($charStream);
$this->assertIdenticalBinary($char, $encoder->encodeString($char));
}
}
public function testWhiteSpaceAtLineEndingIsEncoded()
{
/* -- RFC 2045, 6.7 --
(3) (White Space) Octets with values of 9 and 32 MAY be
represented as US-ASCII TAB (HT) and SPACE characters,
respectively, but MUST NOT be so represented at the end
of an encoded line. Any TAB (HT) or SPACE characters
on an encoded line MUST thus be followed on that line
by a printable character. In particular, an "=" at the
end of an encoded line, indicating a soft line break
(see rule #5) may follow one or more TAB (HT) or SPACE
characters. It follows that an octet with decimal
value 9 or 32 appearing at the end of an encoded line
must be represented according to Rule #1. This rule is
necessary because some MTAs (Message Transport Agents,
programs which transport messages from one user to
another, or perform a portion of such transfers) are
known to pad lines of text with SPACEs, and others are
known to remove "white space" characters from the end
of a line. Therefore, when decoding a Quoted-Printable
body, any trailing white space on a line must be
deleted, as it will necessarily have been added by
intermediate transport agents.
*/
$HT = chr(0x09); //9
$SPACE = chr(0x20); //32
//HT
$string = 'a'.$HT.$HT."\r\n".'b';
$charStream = $this->_createCharStream();
$charStream->shouldReceive('flushContents')
->once();
$charStream->shouldReceive('importString')
->once()
->with($string);
$charStream->shouldReceive('readBytes')->once()->andReturn(array(ord('a')));
$charStream->shouldReceive('readBytes')->once()->andReturn(array(0x09));
$charStream->shouldReceive('readBytes')->once()->andReturn(array(0x09));
$charStream->shouldReceive('readBytes')->once()->andReturn(array(0x0D));
$charStream->shouldReceive('readBytes')->once()->andReturn(array(0x0A));
$charStream->shouldReceive('readBytes')->once()->andReturn(array(ord('b')));
$charStream->shouldReceive('readBytes')->once()->andReturn(false);
$encoder = new Swift_Encoder_QpEncoder($charStream);
$this->assertEquals(
'a'.$HT.'=09'."\r\n".'b',
$encoder->encodeString($string)
);
//SPACE
$string = 'a'.$SPACE.$SPACE."\r\n".'b';
$charStream = $this->_createCharStream();
$charStream->shouldReceive('flushContents')
->once();
$charStream->shouldReceive('importString')
->once()
->with($string);
$charStream->shouldReceive('readBytes')->once()->andReturn(array(ord('a')));
$charStream->shouldReceive('readBytes')->once()->andReturn(array(0x20));
$charStream->shouldReceive('readBytes')->once()->andReturn(array(0x20));
$charStream->shouldReceive('readBytes')->once()->andReturn(array(0x0D));
$charStream->shouldReceive('readBytes')->once()->andReturn(array(0x0A));
$charStream->shouldReceive('readBytes')->once()->andReturn(array(ord('b')));
$charStream->shouldReceive('readBytes')->once()->andReturn(false);
$encoder = new Swift_Encoder_QpEncoder($charStream);
$this->assertEquals(
'a'.$SPACE.'=20'."\r\n".'b',
$encoder->encodeString($string)
);
}
public function testCRLFIsLeftAlone()
{
/*
(4) (Line Breaks) A line break in a text body, represented
as a CRLF sequence in the text canonical form, must be
represented by a (RFC 822) line break, which is also a
CRLF sequence, in the Quoted-Printable encoding. Since
the canonical representation of media types other than
text do not generally include the representation of
line breaks as CRLF sequences, no hard line breaks
(i.e. line breaks that are intended to be meaningful
and to be displayed to the user) can occur in the
quoted-printable encoding of such types. Sequences
like "=0D", "=0A", "=0A=0D" and "=0D=0A" will routinely
appear in non-text data represented in quoted-
printable, of course.
Note that many implementations may elect to encode the
local representation of various content types directly
rather than converting to canonical form first,
encoding, and then converting back to local
representation. In particular, this may apply to plain
text material on systems that use newline conventions
other than a CRLF terminator sequence. Such an
implementation optimization is permissible, but only
when the combined canonicalization-encoding step is
equivalent to performing the three steps separately.
*/
$string = 'a'."\r\n".'b'."\r\n".'c'."\r\n";
$charStream = $this->_createCharStream();
$charStream->shouldReceive('flushContents')
->once();
$charStream->shouldReceive('importString')
->once()
->with($string);
$charStream->shouldReceive('readBytes')->once()->andReturn(array(ord('a')));
$charStream->shouldReceive('readBytes')->once()->andReturn(array(0x0D));
$charStream->shouldReceive('readBytes')->once()->andReturn(array(0x0A));
$charStream->shouldReceive('readBytes')->once()->andReturn(array(ord('b')));
$charStream->shouldReceive('readBytes')->once()->andReturn(array(0x0D));
$charStream->shouldReceive('readBytes')->once()->andReturn(array(0x0A));
$charStream->shouldReceive('readBytes')->once()->andReturn(array(ord('c')));
$charStream->shouldReceive('readBytes')->once()->andReturn(array(0x0D));
$charStream->shouldReceive('readBytes')->once()->andReturn(array(0x0A));
$charStream->shouldReceive('readBytes')->once()->andReturn(false);
$encoder = new Swift_Encoder_QpEncoder($charStream);
$this->assertEquals($string, $encoder->encodeString($string));
}
public function testLinesLongerThan76CharactersAreSoftBroken()
{
/*
(5) (Soft Line Breaks) The Quoted-Printable encoding
REQUIRES that encoded lines be no more than 76
characters long. If longer lines are to be encoded
with the Quoted-Printable encoding, "soft" line breaks
must be used. An equal sign as the last character on a
encoded line indicates such a non-significant ("soft")
line break in the encoded text.
*/
$input = str_repeat('a', 140);
$charStream = $this->_createCharStream();
$charStream->shouldReceive('flushContents')
->once();
$charStream->shouldReceive('importString')
->once()
->with($input);
$output = '';
for ($i = 0; $i < 140; ++$i) {
$charStream->shouldReceive('readBytes')
->once()
->andReturn(array(ord('a')));
if (75 == $i) {
$output .= "=\r\n";
}
$output .= 'a';
}
$charStream->shouldReceive('readBytes')
->once()
->andReturn(false);
$encoder = new Swift_Encoder_QpEncoder($charStream);
$this->assertEquals($output, $encoder->encodeString($input));
}
public function testMaxLineLengthCanBeSpecified()
{
$input = str_repeat('a', 100);
$charStream = $this->_createCharStream();
$charStream->shouldReceive('flushContents')
->once();
$charStream->shouldReceive('importString')
->once()
->with($input);
$output = '';
for ($i = 0; $i < 100; ++$i) {
$charStream->shouldReceive('readBytes')
->once()
->andReturn(array(ord('a')));
if (53 == $i) {
$output .= "=\r\n";
}
$output .= 'a';
}
$charStream->shouldReceive('readBytes')
->once()
->andReturn(false);
$encoder = new Swift_Encoder_QpEncoder($charStream);
$this->assertEquals($output, $encoder->encodeString($input, 0, 54));
}
public function testBytesBelowPermittedRangeAreEncoded()
{
/*
According to Rule (1 & 2)
*/
foreach (range(0, 32) as $ordinal) {
$char = chr($ordinal);
$charStream = $this->_createCharStream();
$charStream->shouldReceive('flushContents')
->once();
$charStream->shouldReceive('importString')
->once()
->with($char);
$charStream->shouldReceive('readBytes')
->once()
->andReturn(array($ordinal));
$charStream->shouldReceive('readBytes')
->atLeast()->times(1)
->andReturn(false);
$encoder = new Swift_Encoder_QpEncoder($charStream);
$this->assertEquals(
sprintf('=%02X', $ordinal), $encoder->encodeString($char)
);
}
}
public function testDecimalByte61IsEncoded()
{
/*
According to Rule (1 & 2)
*/
$char = '=';
$charStream = $this->_createCharStream();
$charStream->shouldReceive('flushContents')
->once();
$charStream->shouldReceive('importString')
->once()
->with($char);
$charStream->shouldReceive('readBytes')
->once()
->andReturn(array(61));
$charStream->shouldReceive('readBytes')
->atLeast()->times(1)
->andReturn(false);
$encoder = new Swift_Encoder_QpEncoder($charStream);
$this->assertEquals('=3D', $encoder->encodeString('='));
}
public function testBytesAbovePermittedRangeAreEncoded()
{
/*
According to Rule (1 & 2)
*/
foreach (range(127, 255) as $ordinal) {
$char = chr($ordinal);
$charStream = $this->_createCharStream();
$charStream->shouldReceive('flushContents')
->once();
$charStream->shouldReceive('importString')
->once()
->with($char);
$charStream->shouldReceive('readBytes')
->once()
->andReturn(array($ordinal));
$charStream->shouldReceive('readBytes')
->atLeast()->times(1)
->andReturn(false);
$encoder = new Swift_Encoder_QpEncoder($charStream);
$this->assertEquals(
sprintf('=%02X', $ordinal), $encoder->encodeString($char)
);
}
}
public function testFirstLineLengthCanBeDifferent()
{
$input = str_repeat('a', 140);
$charStream = $this->_createCharStream();
$charStream->shouldReceive('flushContents')
->once();
$charStream->shouldReceive('importString')
->once()
->with($input);
$output = '';
for ($i = 0; $i < 140; ++$i) {
$charStream->shouldReceive('readBytes')
->once()
->andReturn(array(ord('a')));
if (53 == $i || 53 + 75 == $i) {
$output .= "=\r\n";
}
$output .= 'a';
}
$charStream->shouldReceive('readBytes')
->once()
->andReturn(false);
$encoder = new Swift_Encoder_QpEncoder($charStream);
$this->assertEquals(
$output, $encoder->encodeString($input, 22),
'%s: First line should start at offset 22 so can only have max length 54'
);
}
public function testTextIsPreWrapped()
{
$encoder = $this->createEncoder();
$input = str_repeat('a', 70)."\r\n".
str_repeat('a', 70)."\r\n".
str_repeat('a', 70);
$this->assertEquals(
$input, $encoder->encodeString($input)
);
}
private function _createCharStream()
{
return $this->getMockery('Swift_CharacterStream')->shouldIgnoreMissing();
}
private function createEncoder()
{
$factory = new Swift_CharacterReaderFactory_SimpleCharacterReaderFactory();
$charStream = new Swift_CharacterStream_NgCharacterStream($factory, 'utf-8');
return new Swift_Encoder_QpEncoder($charStream);
}
}
<?php
class Swift_Encoder_Rfc2231EncoderTest extends \SwiftMailerTestCase
{
private $_rfc2045Token = '/^[\x21\x23-\x27\x2A\x2B\x2D\x2E\x30-\x39\x41-\x5A\x5E-\x7E]+$/D';
/* --
This algorithm is described in RFC 2231, but is barely touched upon except
for mentioning bytes can be represented as their octet values (e.g. %20 for
the SPACE character).
The tests here focus on how to use that representation to always generate text
which matches RFC 2045's definition of "token".
*/
public function testEncodingAsciiCharactersProducesValidToken()
{
$charStream = $this->getMockery('Swift_CharacterStream');
$string = '';
foreach (range(0x00, 0x7F) as $octet) {
$char = pack('C', $octet);
$string .= $char;
$charStream->shouldReceive('read')
->once()
->andReturn($char);
}
$charStream->shouldReceive('flushContents')
->once();
$charStream->shouldReceive('importString')
->once()
->with($string);
$charStream->shouldReceive('read')
->atLeast()->times(1)
->andReturn(false);
$encoder = new Swift_Encoder_Rfc2231Encoder($charStream);
$encoded = $encoder->encodeString($string);
foreach (explode("\r\n", $encoded) as $line) {
$this->assertRegExp($this->_rfc2045Token, $line,
'%s: Encoder should always return a valid RFC 2045 token.');
}
}
public function testEncodingNonAsciiCharactersProducesValidToken()
{
$charStream = $this->getMockery('Swift_CharacterStream');
$string = '';
foreach (range(0x80, 0xFF) as $octet) {
$char = pack('C', $octet);
$string .= $char;
$charStream->shouldReceive('read')
->once()
->andReturn($char);
}
$charStream->shouldReceive('flushContents')
->once();
$charStream->shouldReceive('importString')
->once()
->with($string);
$charStream->shouldReceive('read')
->atLeast()->times(1)
->andReturn(false);
$encoder = new Swift_Encoder_Rfc2231Encoder($charStream);
$encoded = $encoder->encodeString($string);
foreach (explode("\r\n", $encoded) as $line) {
$this->assertRegExp($this->_rfc2045Token, $line,
'%s: Encoder should always return a valid RFC 2045 token.');
}
}
public function testMaximumLineLengthCanBeSet()
{
$charStream = $this->getMockery('Swift_CharacterStream');
$string = '';
for ($x = 0; $x < 200; ++$x) {
$char = 'a';
$string .= $char;
$charStream->shouldReceive('read')
->once()
->andReturn($char);
}
$charStream->shouldReceive('flushContents')
->once();
$charStream->shouldReceive('importString')
->once()
->with($string);
$charStream->shouldReceive('read')
->atLeast()->times(1)
->andReturn(false);
$encoder = new Swift_Encoder_Rfc2231Encoder($charStream);
$encoded = $encoder->encodeString($string, 0, 75);
$this->assertEquals(
str_repeat('a', 75)."\r\n".
str_repeat('a', 75)."\r\n".
str_repeat('a', 50),
$encoded,
'%s: Lines should be wrapped at each 75 characters'
);
}
public function testFirstLineCanHaveShorterLength()
{
$charStream = $this->getMockery('Swift_CharacterStream');
$string = '';
for ($x = 0; $x < 200; ++$x) {
$char = 'a';
$string .= $char;
$charStream->shouldReceive('read')
->once()
->andReturn($char);
}
$charStream->shouldReceive('flushContents')
->once();
$charStream->shouldReceive('importString')
->once()
->with($string);
$charStream->shouldReceive('read')
->atLeast()->times(1)
->andReturn(false);
$encoder = new Swift_Encoder_Rfc2231Encoder($charStream);
$encoded = $encoder->encodeString($string, 25, 75);
$this->assertEquals(
str_repeat('a', 50)."\r\n".
str_repeat('a', 75)."\r\n".
str_repeat('a', 75),
$encoded,
'%s: First line should be 25 bytes shorter than the others.'
);
}
}
<?php
class Swift_Events_CommandEventTest extends \PHPUnit_Framework_TestCase
{
public function testCommandCanBeFetchedByGetter()
{
$evt = $this->_createEvent($this->_createTransport(), "FOO\r\n");
$this->assertEquals("FOO\r\n", $evt->getCommand());
}
public function testSuccessCodesCanBeFetchedViaGetter()
{
$evt = $this->_createEvent($this->_createTransport(), "FOO\r\n", array(250));
$this->assertEquals(array(250), $evt->getSuccessCodes());
}
public function testSourceIsBuffer()
{
$transport = $this->_createTransport();
$evt = $this->_createEvent($transport, "FOO\r\n");
$ref = $evt->getSource();
$this->assertEquals($transport, $ref);
}
private function _createEvent(Swift_Transport $source, $command, $successCodes = array())
{
return new Swift_Events_CommandEvent($source, $command, $successCodes);
}
private function _createTransport()
{
return $this->getMockBuilder('Swift_Transport')->getMock();
}
}
<?php
class Swift_Events_EventObjectTest extends \PHPUnit_Framework_TestCase
{
public function testEventSourceCanBeReturnedViaGetter()
{
$source = new stdClass();
$evt = $this->_createEvent($source);
$ref = $evt->getSource();
$this->assertEquals($source, $ref);
}
public function testEventDoesNotHaveCancelledBubbleWhenNew()
{
$source = new stdClass();
$evt = $this->_createEvent($source);
$this->assertFalse($evt->bubbleCancelled());
}
public function testBubbleCanBeCancelledInEvent()
{
$source = new stdClass();
$evt = $this->_createEvent($source);
$evt->cancelBubble();
$this->assertTrue($evt->bubbleCancelled());
}
private function _createEvent($source)
{
return new Swift_Events_EventObject($source);
}
}
<?php
class Swift_Events_ResponseEventTest extends \PHPUnit_Framework_TestCase
{
public function testResponseCanBeFetchViaGetter()
{
$evt = $this->_createEvent($this->_createTransport(), "250 Ok\r\n", true);
$this->assertEquals("250 Ok\r\n", $evt->getResponse(),
'%s: Response should be available via getResponse()'
);
}
public function testResultCanBeFetchedViaGetter()
{
$evt = $this->_createEvent($this->_createTransport(), "250 Ok\r\n", false);
$this->assertFalse($evt->isValid(),
'%s: Result should be checkable via isValid()'
);
}
public function testSourceIsBuffer()
{
$transport = $this->_createTransport();
$evt = $this->_createEvent($transport, "250 Ok\r\n", true);
$ref = $evt->getSource();
$this->assertEquals($transport, $ref);
}
private function _createEvent(Swift_Transport $source, $response, $result)
{
return new Swift_Events_ResponseEvent($source, $response, $result);
}
private function _createTransport()
{
return $this->getMockBuilder('Swift_Transport')->getMock();
}
}
<?php
class Swift_Events_SendEventTest extends \PHPUnit_Framework_TestCase
{
public function testMessageCanBeFetchedViaGetter()
{
$message = $this->_createMessage();
$transport = $this->_createTransport();
$evt = $this->_createEvent($transport, $message);
$ref = $evt->getMessage();
$this->assertEquals($message, $ref,
'%s: Message should be returned from getMessage()'
);
}
public function testTransportCanBeFetchViaGetter()
{
$message = $this->_createMessage();
$transport = $this->_createTransport();
$evt = $this->_createEvent($transport, $message);
$ref = $evt->getTransport();
$this->assertEquals($transport, $ref,
'%s: Transport should be returned from getTransport()'
);
}
public function testTransportCanBeFetchViaGetSource()
{
$message = $this->_createMessage();
$transport = $this->_createTransport();
$evt = $this->_createEvent($transport, $message);
$ref = $evt->getSource();
$this->assertEquals($transport, $ref,
'%s: Transport should be returned from getSource()'
);
}
public function testResultCanBeSetAndGet()
{
$message = $this->_createMessage();
$transport = $this->_createTransport();
$evt = $this->_createEvent($transport, $message);
$evt->setResult(
Swift_Events_SendEvent::RESULT_SUCCESS | Swift_Events_SendEvent::RESULT_TENTATIVE
);
$this->assertTrue((bool) ($evt->getResult() & Swift_Events_SendEvent::RESULT_SUCCESS));
$this->assertTrue((bool) ($evt->getResult() & Swift_Events_SendEvent::RESULT_TENTATIVE));
}
public function testFailedRecipientsCanBeSetAndGet()
{
$message = $this->_createMessage();
$transport = $this->_createTransport();
$evt = $this->_createEvent($transport, $message);
$evt->setFailedRecipients(array('foo@bar', 'zip@button'));
$this->assertEquals(array('foo@bar', 'zip@button'), $evt->getFailedRecipients(),
'%s: FailedRecipients should be returned from getter'
);
}
public function testFailedRecipientsGetsPickedUpCorrectly()
{
$message = $this->_createMessage();
$transport = $this->_createTransport();
$evt = $this->_createEvent($transport, $message);
$this->assertEquals(array(), $evt->getFailedRecipients());
}
private function _createEvent(Swift_Transport $source,
Swift_Mime_Message $message)
{
return new Swift_Events_SendEvent($source, $message);
}
private function _createTransport()
{
return $this->getMockBuilder('Swift_Transport')->getMock();
}
private function _createMessage()
{
return $this->getMockBuilder('Swift_Mime_Message')->getMock();
}
}
<?php
class Swift_Events_SimpleEventDispatcherTest extends \PHPUnit_Framework_TestCase
{
private $_dispatcher;
protected function setUp()
{
$this->_dispatcher = new Swift_Events_SimpleEventDispatcher();
}
public function testSendEventCanBeCreated()
{
$transport = $this->getMockBuilder('Swift_Transport')->getMock();
$message = $this->getMockBuilder('Swift_Mime_Message')->getMock();
$evt = $this->_dispatcher->createSendEvent($transport, $message);
$this->assertInstanceof('Swift_Events_SendEvent', $evt);
$this->assertSame($message, $evt->getMessage());
$this->assertSame($transport, $evt->getTransport());
}
public function testCommandEventCanBeCreated()
{
$buf = $this->getMockBuilder('Swift_Transport')->getMock();
$evt = $this->_dispatcher->createCommandEvent($buf, "FOO\r\n", array(250));
$this->assertInstanceof('Swift_Events_CommandEvent', $evt);
$this->assertSame($buf, $evt->getSource());
$this->assertEquals("FOO\r\n", $evt->getCommand());
$this->assertEquals(array(250), $evt->getSuccessCodes());
}
public function testResponseEventCanBeCreated()
{
$buf = $this->getMockBuilder('Swift_Transport')->getMock();
$evt = $this->_dispatcher->createResponseEvent($buf, "250 Ok\r\n", true);
$this->assertInstanceof('Swift_Events_ResponseEvent', $evt);
$this->assertSame($buf, $evt->getSource());
$this->assertEquals("250 Ok\r\n", $evt->getResponse());
$this->assertTrue($evt->isValid());
}
public function testTransportChangeEventCanBeCreated()
{
$transport = $this->getMockBuilder('Swift_Transport')->getMock();
$evt = $this->_dispatcher->createTransportChangeEvent($transport);
$this->assertInstanceof('Swift_Events_TransportChangeEvent', $evt);
$this->assertSame($transport, $evt->getSource());
}
public function testTransportExceptionEventCanBeCreated()
{
$transport = $this->getMockBuilder('Swift_Transport')->getMock();
$ex = new Swift_TransportException('');
$evt = $this->_dispatcher->createTransportExceptionEvent($transport, $ex);
$this->assertInstanceof('Swift_Events_TransportExceptionEvent', $evt);
$this->assertSame($transport, $evt->getSource());
$this->assertSame($ex, $evt->getException());
}
public function testListenersAreNotifiedOfDispatchedEvent()
{
$transport = $this->getMockBuilder('Swift_Transport')->getMock();
$evt = $this->_dispatcher->createTransportChangeEvent($transport);
$listenerA = $this->getMockBuilder('Swift_Events_TransportChangeListener')->getMock();
$listenerB = $this->getMockBuilder('Swift_Events_TransportChangeListener')->getMock();
$this->_dispatcher->bindEventListener($listenerA);
$this->_dispatcher->bindEventListener($listenerB);
$listenerA->expects($this->once())
->method('transportStarted')
->with($evt);
$listenerB->expects($this->once())
->method('transportStarted')
->with($evt);
$this->_dispatcher->dispatchEvent($evt, 'transportStarted');
}
public function testListenersAreOnlyCalledIfImplementingCorrectInterface()
{
$transport = $this->getMockBuilder('Swift_Transport')->getMock();
$message = $this->getMockBuilder('Swift_Mime_Message')->getMock();
$evt = $this->_dispatcher->createSendEvent($transport, $message);
$targetListener = $this->getMockBuilder('Swift_Events_SendListener')->getMock();
$otherListener = $this->getMockBuilder('DummyListener')->getMock();
$this->_dispatcher->bindEventListener($targetListener);
$this->_dispatcher->bindEventListener($otherListener);
$targetListener->expects($this->once())
->method('sendPerformed')
->with($evt);
$otherListener->expects($this->never())
->method('sendPerformed');
$this->_dispatcher->dispatchEvent($evt, 'sendPerformed');
}
public function testListenersCanCancelBubblingOfEvent()
{
$transport = $this->getMockBuilder('Swift_Transport')->getMock();
$message = $this->getMockBuilder('Swift_Mime_Message')->getMock();
$evt = $this->_dispatcher->createSendEvent($transport, $message);
$listenerA = $this->getMockBuilder('Swift_Events_SendListener')->getMock();
$listenerB = $this->getMockBuilder('Swift_Events_SendListener')->getMock();
$this->_dispatcher->bindEventListener($listenerA);
$this->_dispatcher->bindEventListener($listenerB);
$listenerA->expects($this->once())
->method('sendPerformed')
->with($evt)
->will($this->returnCallback(function ($object) {
$object->cancelBubble(true);
}));
$listenerB->expects($this->never())
->method('sendPerformed');
$this->_dispatcher->dispatchEvent($evt, 'sendPerformed');
$this->assertTrue($evt->bubbleCancelled());
}
private function _createDispatcher(array $map)
{
return new Swift_Events_SimpleEventDispatcher($map);
}
}
class DummyListener implements Swift_Events_EventListener
{
public function sendPerformed(Swift_Events_SendEvent $evt)
{
}
}
<?php
class Swift_Events_TransportChangeEventTest extends \PHPUnit_Framework_TestCase
{
public function testGetTransportReturnsTransport()
{
$transport = $this->_createTransport();
$evt = $this->_createEvent($transport);
$ref = $evt->getTransport();
$this->assertEquals($transport, $ref);
}
public function testSourceIsTransport()
{
$transport = $this->_createTransport();
$evt = $this->_createEvent($transport);
$ref = $evt->getSource();
$this->assertEquals($transport, $ref);
}
private function _createEvent(Swift_Transport $source)
{
return new Swift_Events_TransportChangeEvent($source);
}
private function _createTransport()
{
return $this->getMockBuilder('Swift_Transport')->getMock();
}
}
<?php
class Swift_Events_TransportExceptionEventTest extends \PHPUnit_Framework_TestCase
{
public function testExceptionCanBeFetchViaGetter()
{
$ex = $this->_createException();
$transport = $this->_createTransport();
$evt = $this->_createEvent($transport, $ex);
$ref = $evt->getException();
$this->assertEquals($ex, $ref,
'%s: Exception should be available via getException()'
);
}
public function testSourceIsTransport()
{
$ex = $this->_createException();
$transport = $this->_createTransport();
$evt = $this->_createEvent($transport, $ex);
$ref = $evt->getSource();
$this->assertEquals($transport, $ref,
'%s: Transport should be available via getSource()'
);
}
private function _createEvent(Swift_Transport $transport, Swift_TransportException $ex)
{
return new Swift_Events_TransportExceptionEvent($transport, $ex);
}
private function _createTransport()
{
return $this->getMockBuilder('Swift_Transport')->getMock();
}
private function _createException()
{
return new Swift_TransportException('');
}
}
<?php
class Swift_KeyCache_ArrayKeyCacheTest extends \PHPUnit_Framework_TestCase
{
private $_key1 = 'key1';
private $_key2 = 'key2';
public function testStringDataCanBeSetAndFetched()
{
$is = $this->_createKeyCacheInputStream();
$cache = $this->_createCache($is);
$cache->setString(
$this->_key1, 'foo', 'test', Swift_KeyCache::MODE_WRITE
);
$this->assertEquals('test', $cache->getString($this->_key1, 'foo'));
}
public function testStringDataCanBeOverwritten()
{
$is = $this->_createKeyCacheInputStream();
$cache = $this->_createCache($is);
$cache->setString(
$this->_key1, 'foo', 'test', Swift_KeyCache::MODE_WRITE
);
$cache->setString(
$this->_key1, 'foo', 'whatever', Swift_KeyCache::MODE_WRITE
);
$this->assertEquals('whatever', $cache->getString($this->_key1, 'foo'));
}
public function testStringDataCanBeAppended()
{
$is = $this->_createKeyCacheInputStream();
$cache = $this->_createCache($is);
$cache->setString(
$this->_key1, 'foo', 'test', Swift_KeyCache::MODE_WRITE
);
$cache->setString(
$this->_key1, 'foo', 'ing', Swift_KeyCache::MODE_APPEND
);
$this->assertEquals('testing', $cache->getString($this->_key1, 'foo'));
}
public function testHasKeyReturnValue()
{
$is = $this->_createKeyCacheInputStream();
$cache = $this->_createCache($is);
$cache->setString(
$this->_key1, 'foo', 'test', Swift_KeyCache::MODE_WRITE
);
$this->assertTrue($cache->hasKey($this->_key1, 'foo'));
}
public function testNsKeyIsWellPartitioned()
{
$is = $this->_createKeyCacheInputStream();
$cache = $this->_createCache($is);
$cache->setString(
$this->_key1, 'foo', 'test', Swift_KeyCache::MODE_WRITE
);
$cache->setString(
$this->_key2, 'foo', 'ing', Swift_KeyCache::MODE_WRITE
);
$this->assertEquals('test', $cache->getString($this->_key1, 'foo'));
$this->assertEquals('ing', $cache->getString($this->_key2, 'foo'));
}
public function testItemKeyIsWellPartitioned()
{
$is = $this->_createKeyCacheInputStream();
$cache = $this->_createCache($is);
$cache->setString(
$this->_key1, 'foo', 'test', Swift_KeyCache::MODE_WRITE
);
$cache->setString(
$this->_key1, 'bar', 'ing', Swift_KeyCache::MODE_WRITE
);
$this->assertEquals('test', $cache->getString($this->_key1, 'foo'));
$this->assertEquals('ing', $cache->getString($this->_key1, 'bar'));
}
public function testByteStreamCanBeImported()
{
$os = $this->_createOutputStream();
$os->expects($this->at(0))
->method('read')
->will($this->returnValue('abc'));
$os->expects($this->at(1))
->method('read')
->will($this->returnValue('def'));
$os->expects($this->at(2))
->method('read')
->will($this->returnValue(false));
$is = $this->_createKeyCacheInputStream();
$cache = $this->_createCache($is);
$cache->importFromByteStream(
$this->_key1, 'foo', $os, Swift_KeyCache::MODE_WRITE
);
$this->assertEquals('abcdef', $cache->getString($this->_key1, 'foo'));
}
public function testByteStreamCanBeAppended()
{
$os1 = $this->_createOutputStream();
$os1->expects($this->at(0))
->method('read')
->will($this->returnValue('abc'));
$os1->expects($this->at(1))
->method('read')
->will($this->returnValue('def'));
$os1->expects($this->at(2))
->method('read')
->will($this->returnValue(false));
$os2 = $this->_createOutputStream();
$os2->expects($this->at(0))
->method('read')
->will($this->returnValue('xyz'));
$os2->expects($this->at(1))
->method('read')
->will($this->returnValue('uvw'));
$os2->expects($this->at(2))
->method('read')
->will($this->returnValue(false));
$is = $this->_createKeyCacheInputStream(true);
$cache = $this->_createCache($is);
$cache->importFromByteStream(
$this->_key1, 'foo', $os1, Swift_KeyCache::MODE_APPEND
);
$cache->importFromByteStream(
$this->_key1, 'foo', $os2, Swift_KeyCache::MODE_APPEND
);
$this->assertEquals('abcdefxyzuvw', $cache->getString($this->_key1, 'foo'));
}
public function testByteStreamAndStringCanBeAppended()
{
$os = $this->_createOutputStream();
$os->expects($this->at(0))
->method('read')
->will($this->returnValue('abc'));
$os->expects($this->at(1))
->method('read')
->will($this->returnValue('def'));
$os->expects($this->at(2))
->method('read')
->will($this->returnValue(false));
$is = $this->_createKeyCacheInputStream(true);
$cache = $this->_createCache($is);
$cache->setString(
$this->_key1, 'foo', 'test', Swift_KeyCache::MODE_APPEND
);
$cache->importFromByteStream(
$this->_key1, 'foo', $os, Swift_KeyCache::MODE_APPEND
);
$this->assertEquals('testabcdef', $cache->getString($this->_key1, 'foo'));
}
public function testDataCanBeExportedToByteStream()
{
//See acceptance test for more detail
$is = $this->_createInputStream();
$is->expects($this->atLeastOnce())
->method('write');
$kcis = $this->_createKeyCacheInputStream(true);
$cache = $this->_createCache($kcis);
$cache->setString(
$this->_key1, 'foo', 'test', Swift_KeyCache::MODE_WRITE
);
$cache->exportToByteStream($this->_key1, 'foo', $is);
}
public function testKeyCanBeCleared()
{
$is = $this->_createKeyCacheInputStream();
$cache = $this->_createCache($is);
$cache->setString(
$this->_key1, 'foo', 'test', Swift_KeyCache::MODE_WRITE
);
$this->assertTrue($cache->hasKey($this->_key1, 'foo'));
$cache->clearKey($this->_key1, 'foo');
$this->assertFalse($cache->hasKey($this->_key1, 'foo'));
}
public function testNsKeyCanBeCleared()
{
$is = $this->_createKeyCacheInputStream();
$cache = $this->_createCache($is);
$cache->setString(
$this->_key1, 'foo', 'test', Swift_KeyCache::MODE_WRITE
);
$cache->setString(
$this->_key1, 'bar', 'xyz', Swift_KeyCache::MODE_WRITE
);
$this->assertTrue($cache->hasKey($this->_key1, 'foo'));
$this->assertTrue($cache->hasKey($this->_key1, 'bar'));
$cache->clearAll($this->_key1);
$this->assertFalse($cache->hasKey($this->_key1, 'foo'));
$this->assertFalse($cache->hasKey($this->_key1, 'bar'));
}
private function _createCache($is)
{
return new Swift_KeyCache_ArrayKeyCache($is);
}
private function _createKeyCacheInputStream()
{
return $this->getMockBuilder('Swift_KeyCache_KeyCacheInputStream')->getMock();
}
private function _createOutputStream()
{
return $this->getMockBuilder('Swift_OutputByteStream')->getMock();
}
private function _createInputStream()
{
return $this->getMockBuilder('Swift_InputByteStream')->getMock();
}
}
<?php
class Swift_KeyCache_SimpleKeyCacheInputStreamTest extends \PHPUnit_Framework_TestCase
{
private $_nsKey = 'ns1';
public function testStreamWritesToCacheInAppendMode()
{
$cache = $this->getMockBuilder('Swift_KeyCache')->getMock();
$cache->expects($this->at(0))
->method('setString')
->with($this->_nsKey, 'foo', 'a', Swift_KeyCache::MODE_APPEND);
$cache->expects($this->at(1))
->method('setString')
->with($this->_nsKey, 'foo', 'b', Swift_KeyCache::MODE_APPEND);
$cache->expects($this->at(2))
->method('setString')
->with($this->_nsKey, 'foo', 'c', Swift_KeyCache::MODE_APPEND);
$stream = new Swift_KeyCache_SimpleKeyCacheInputStream();
$stream->setKeyCache($cache);
$stream->setNsKey($this->_nsKey);
$stream->setItemKey('foo');
$stream->write('a');
$stream->write('b');
$stream->write('c');
}
public function testFlushContentClearsKey()
{
$cache = $this->getMockBuilder('Swift_KeyCache')->getMock();
$cache->expects($this->once())
->method('clearKey')
->with($this->_nsKey, 'foo');
$stream = new Swift_KeyCache_SimpleKeyCacheInputStream();
$stream->setKeyCache($cache);
$stream->setNsKey($this->_nsKey);
$stream->setItemKey('foo');
$stream->flushBuffers();
}
public function testClonedStreamStillReferencesSameCache()
{
$cache = $this->getMockBuilder('Swift_KeyCache')->getMock();
$cache->expects($this->at(0))
->method('setString')
->with($this->_nsKey, 'foo', 'a', Swift_KeyCache::MODE_APPEND);
$cache->expects($this->at(1))
->method('setString')
->with($this->_nsKey, 'foo', 'b', Swift_KeyCache::MODE_APPEND);
$cache->expects($this->at(2))
->method('setString')
->with('test', 'bar', 'x', Swift_KeyCache::MODE_APPEND);
$stream = new Swift_KeyCache_SimpleKeyCacheInputStream();
$stream->setKeyCache($cache);
$stream->setNsKey($this->_nsKey);
$stream->setItemKey('foo');
$stream->write('a');
$stream->write('b');
$newStream = clone $stream;
$newStream->setKeyCache($cache);
$newStream->setNsKey('test');
$newStream->setItemKey('bar');
$newStream->write('x');
}
}
<?php
class Swift_Mailer_ArrayRecipientIteratorTest extends \PHPUnit_Framework_TestCase
{
public function testHasNextReturnsFalseForEmptyArray()
{
$it = new Swift_Mailer_ArrayRecipientIterator(array());
$this->assertFalse($it->hasNext());
}
public function testHasNextReturnsTrueIfItemsLeft()
{
$it = new Swift_Mailer_ArrayRecipientIterator(array('foo@bar' => 'Foo'));
$this->assertTrue($it->hasNext());
}
public function testReadingToEndOfListCausesHasNextToReturnFalse()
{
$it = new Swift_Mailer_ArrayRecipientIterator(array('foo@bar' => 'Foo'));
$this->assertTrue($it->hasNext());
$it->nextRecipient();
$this->assertFalse($it->hasNext());
}
public function testReturnedValueHasPreservedKeyValuePair()
{
$it = new Swift_Mailer_ArrayRecipientIterator(array('foo@bar' => 'Foo'));
$this->assertEquals(array('foo@bar' => 'Foo'), $it->nextRecipient());
}
public function testIteratorMovesNextAfterEachIteration()
{
$it = new Swift_Mailer_ArrayRecipientIterator(array(
'foo@bar' => 'Foo',
'zip@button' => 'Zip thing',
'test@test' => null,
));
$this->assertEquals(array('foo@bar' => 'Foo'), $it->nextRecipient());
$this->assertEquals(array('zip@button' => 'Zip thing'), $it->nextRecipient());
$this->assertEquals(array('test@test' => null), $it->nextRecipient());
}
}
<?php
class Swift_MailerTest extends \SwiftMailerTestCase
{
public function testTransportIsStartedWhenSending()
{
$transport = $this->_createTransport();
$message = $this->_createMessage();
$started = false;
$transport->shouldReceive('isStarted')
->zeroOrMoreTimes()
->andReturnUsing(function () use (&$started) {
return $started;
});
$transport->shouldReceive('start')
->once()
->andReturnUsing(function () use (&$started) {
$started = true;
return;
});
$mailer = $this->_createMailer($transport);
$mailer->send($message);
}
public function testTransportIsOnlyStartedOnce()
{
$transport = $this->_createTransport();
$message = $this->_createMessage();
$started = false;
$transport->shouldReceive('isStarted')
->zeroOrMoreTimes()
->andReturnUsing(function () use (&$started) {
return $started;
});
$transport->shouldReceive('start')
->once()
->andReturnUsing(function () use (&$started) {
$started = true;
return;
});
$mailer = $this->_createMailer($transport);
for ($i = 0; $i < 10; ++$i) {
$mailer->send($message);
}
}
public function testMessageIsPassedToTransport()
{
$transport = $this->_createTransport();
$message = $this->_createMessage();
$transport->shouldReceive('send')
->once()
->with($message, \Mockery::any());
$mailer = $this->_createMailer($transport);
$mailer->send($message);
}
public function testSendReturnsCountFromTransport()
{
$transport = $this->_createTransport();
$message = $this->_createMessage();
$transport->shouldReceive('send')
->once()
->with($message, \Mockery::any())
->andReturn(57);
$mailer = $this->_createMailer($transport);
$this->assertEquals(57, $mailer->send($message));
}
public function testFailedRecipientReferenceIsPassedToTransport()
{
$failures = array();
$transport = $this->_createTransport();
$message = $this->_createMessage();
$transport->shouldReceive('send')
->once()
->with($message, $failures)
->andReturn(57);
$mailer = $this->_createMailer($transport);
$mailer->send($message, $failures);
}
public function testSendRecordsRfcComplianceExceptionAsEntireSendFailure()
{
$failures = array();
$rfcException = new Swift_RfcComplianceException('test');
$transport = $this->_createTransport();
$message = $this->_createMessage();
$message->shouldReceive('getTo')
->once()
->andReturn(array('foo&invalid' => 'Foo', 'bar@valid.tld' => 'Bar'));
$transport->shouldReceive('send')
->once()
->with($message, $failures)
->andThrow($rfcException);
$mailer = $this->_createMailer($transport);
$this->assertEquals(0, $mailer->send($message, $failures), '%s: Should return 0');
$this->assertEquals(array('foo&invalid', 'bar@valid.tld'), $failures, '%s: Failures should contain all addresses since the entire message failed to compile');
}
public function testRegisterPluginDelegatesToTransport()
{
$plugin = $this->_createPlugin();
$transport = $this->_createTransport();
$mailer = $this->_createMailer($transport);
$transport->shouldReceive('registerPlugin')
->once()
->with($plugin);
$mailer->registerPlugin($plugin);
}
private function _createPlugin()
{
return $this->getMockery('Swift_Events_EventListener')->shouldIgnoreMissing();
}
private function _createTransport()
{
return $this->getMockery('Swift_Transport')->shouldIgnoreMissing();
}
private function _createMessage()
{
return $this->getMockery('Swift_Mime_Message')->shouldIgnoreMissing();
}
private function _createMailer(Swift_Transport $transport)
{
return new Swift_Mailer($transport);
}
}
<?php
class Swift_MessageTest extends \PHPUnit_Framework_TestCase
{
public function testCloning()
{
$message1 = new Swift_Message('subj', 'body', 'ctype');
$message2 = new Swift_Message('subj', 'body', 'ctype');
$message1_clone = clone $message1;
$this->_recursiveObjectCloningCheck($message1, $message2, $message1_clone);
}
public function testCloningWithSigners()
{
$message1 = new Swift_Message('subj', 'body', 'ctype');
$signer = new Swift_Signers_DKIMSigner(dirname(dirname(__DIR__)).'/_samples/dkim/dkim.test.priv', 'test.example', 'example');
$message1->attachSigner($signer);
$message2 = new Swift_Message('subj', 'body', 'ctype');
$signer = new Swift_Signers_DKIMSigner(dirname(dirname(__DIR__)).'/_samples/dkim/dkim.test.priv', 'test.example', 'example');
$message2->attachSigner($signer);
$message1_clone = clone $message1;
$this->_recursiveObjectCloningCheck($message1, $message2, $message1_clone);
}
public function testBodySwap()
{
$message1 = new Swift_Message('Test');
$html = Swift_MimePart::newInstance('<html></html>', 'text/html');
$html->getHeaders()->addTextHeader('X-Test-Remove', 'Test-Value');
$html->getHeaders()->addTextHeader('X-Test-Alter', 'Test-Value');
$message1->attach($html);
$source = $message1->toString();
$message2 = clone $message1;
$message2->setSubject('Message2');
foreach ($message2->getChildren() as $child) {
$child->setBody('Test');
$child->getHeaders()->removeAll('X-Test-Remove');
$child->getHeaders()->get('X-Test-Alter')->setValue('Altered');
}
$final = $message1->toString();
if ($source != $final) {
$this->fail("Difference although object cloned \n [".$source."]\n[".$final."]\n");
}
$final = $message2->toString();
if ($final == $source) {
$this->fail('Two body matches although they should differ'."\n [".$source."]\n[".$final."]\n");
}
$id_1 = $message1->getId();
$id_2 = $message2->getId();
$this->assertEquals($id_1, $id_2, 'Message Ids differ');
$id_2 = $message2->generateId();
$this->assertNotEquals($id_1, $id_2, 'Message Ids are the same');
}
protected function _recursiveObjectCloningCheck($obj1, $obj2, $obj1_clone)
{
$obj1_properties = (array) $obj1;
$obj2_properties = (array) $obj2;
$obj1_clone_properties = (array) $obj1_clone;
foreach ($obj1_properties as $property => $value) {
if (is_object($value)) {
$obj1_value = $obj1_properties[$property];
$obj2_value = $obj2_properties[$property];
$obj1_clone_value = $obj1_clone_properties[$property];
if ($obj1_value !== $obj2_value) {
// two separetely instanciated objects property not referencing same object
$this->assertFalse(
// but object's clone does - not everything copied
$obj1_value === $obj1_clone_value,
"Property `$property` cloning error: source and cloned objects property is referencing same object"
);
} else {
// two separetely instanciated objects have same reference
$this->assertFalse(
// but object's clone doesn't - overdone making copies
$obj1_value !== $obj1_clone_value,
"Property `$property` not properly cloned: it should reference same object as cloning source (overdone copping)"
);
}
// recurse
$this->_recursiveObjectCloningCheck($obj1_value, $obj2_value, $obj1_clone_value);
} elseif (is_array($value)) {
$obj1_value = $obj1_properties[$property];
$obj2_value = $obj2_properties[$property];
$obj1_clone_value = $obj1_clone_properties[$property];
return $this->_recursiveArrayCloningCheck($obj1_value, $obj2_value, $obj1_clone_value);
}
}
}
protected function _recursiveArrayCloningCheck($array1, $array2, $array1_clone)
{
foreach ($array1 as $key => $value) {
if (is_object($value)) {
$arr1_value = $array1[$key];
$arr2_value = $array2[$key];
$arr1_clone_value = $array1_clone[$key];
if ($arr1_value !== $arr2_value) {
// two separetely instanciated objects property not referencing same object
$this->assertFalse(
// but object's clone does - not everything copied
$arr1_value === $arr1_clone_value,
"Key `$key` cloning error: source and cloned objects property is referencing same object"
);
} else {
// two separetely instanciated objects have same reference
$this->assertFalse(
// but object's clone doesn't - overdone making copies
$arr1_value !== $arr1_clone_value,
"Key `$key` not properly cloned: it should reference same object as cloning source (overdone copping)"
);
}
// recurse
$this->_recursiveObjectCloningCheck($arr1_value, $arr2_value, $arr1_clone_value);
} elseif (is_array($value)) {
$arr1_value = $array1[$key];
$arr2_value = $array2[$key];
$arr1_clone_value = $array1_clone[$key];
return $this->_recursiveArrayCloningCheck($arr1_value, $arr2_value, $arr1_clone_value);
}
}
}
}
<?php
require_once dirname(dirname(dirname(__DIR__))).'/fixtures/MimeEntityFixture.php';
abstract class Swift_Mime_AbstractMimeEntityTest extends \SwiftMailerTestCase
{
public function testGetHeadersReturnsHeaderSet()
{
$headers = $this->_createHeaderSet();
$entity = $this->_createEntity($headers, $this->_createEncoder(),
$this->_createCache()
);
$this->assertSame($headers, $entity->getHeaders());
}
public function testContentTypeIsReturnedFromHeader()
{
$ctype = $this->_createHeader('Content-Type', 'image/jpeg-test');
$headers = $this->_createHeaderSet(array('Content-Type' => $ctype));
$entity = $this->_createEntity($headers, $this->_createEncoder(),
$this->_createCache()
);
$this->assertEquals('image/jpeg-test', $entity->getContentType());
}
public function testContentTypeIsSetInHeader()
{
$ctype = $this->_createHeader('Content-Type', 'text/plain', array(), false);
$headers = $this->_createHeaderSet(array('Content-Type' => $ctype));
$ctype->shouldReceive('setFieldBodyModel')
->once()
->with('image/jpeg');
$ctype->shouldReceive('setFieldBodyModel')
->zeroOrMoreTimes()
->with(\Mockery::not('image/jpeg'));
$entity = $this->_createEntity($headers, $this->_createEncoder(),
$this->_createCache()
);
$entity->setContentType('image/jpeg');
}
public function testContentTypeHeaderIsAddedIfNoneSet()
{
$headers = $this->_createHeaderSet(array(), false);
$headers->shouldReceive('addParameterizedHeader')
->once()
->with('Content-Type', 'image/jpeg');
$headers->shouldReceive('addParameterizedHeader')
->zeroOrMoreTimes();
$entity = $this->_createEntity($headers, $this->_createEncoder(),
$this->_createCache()
);
$entity->setContentType('image/jpeg');
}
public function testContentTypeCanBeSetViaSetBody()
{
$headers = $this->_createHeaderSet(array(), false);
$headers->shouldReceive('addParameterizedHeader')
->once()
->with('Content-Type', 'text/html');
$headers->shouldReceive('addParameterizedHeader')
->zeroOrMoreTimes();
$entity = $this->_createEntity($headers, $this->_createEncoder(),
$this->_createCache()
);
$entity->setBody('<b>foo</b>', 'text/html');
}
public function testGetEncoderFromConstructor()
{
$encoder = $this->_createEncoder('base64');
$entity = $this->_createEntity($this->_createHeaderSet(), $encoder,
$this->_createCache()
);
$this->assertSame($encoder, $entity->getEncoder());
}
public function testSetAndGetEncoder()
{
$encoder = $this->_createEncoder('base64');
$headers = $this->_createHeaderSet();
$entity = $this->_createEntity($headers, $this->_createEncoder(),
$this->_createCache()
);
$entity->setEncoder($encoder);
$this->assertSame($encoder, $entity->getEncoder());
}
public function testSettingEncoderUpdatesTransferEncoding()
{
$encoder = $this->_createEncoder('base64');
$encoding = $this->_createHeader(
'Content-Transfer-Encoding', '8bit', array(), false
);
$headers = $this->_createHeaderSet(array(
'Content-Transfer-Encoding' => $encoding,
));
$encoding->shouldReceive('setFieldBodyModel')
->once()
->with('base64');
$encoding->shouldReceive('setFieldBodyModel')
->zeroOrMoreTimes();
$entity = $this->_createEntity($headers, $this->_createEncoder(),
$this->_createCache()
);
$entity->setEncoder($encoder);
}
public function testSettingEncoderAddsEncodingHeaderIfNonePresent()
{
$headers = $this->_createHeaderSet(array(), false);
$headers->shouldReceive('addTextHeader')
->once()
->with('Content-Transfer-Encoding', 'something');
$headers->shouldReceive('addTextHeader')
->zeroOrMoreTimes();
$entity = $this->_createEntity($headers, $this->_createEncoder(),
$this->_createCache()
);
$entity->setEncoder($this->_createEncoder('something'));
}
public function testIdIsReturnedFromHeader()
{
/* -- RFC 2045, 7.
In constructing a high-level user agent, it may be desirable to allow
one body to make reference to another. Accordingly, bodies may be
labelled using the "Content-ID" header field, which is syntactically
identical to the "Message-ID" header field
*/
$cid = $this->_createHeader('Content-ID', 'zip@button');
$headers = $this->_createHeaderSet(array('Content-ID' => $cid));
$entity = $this->_createEntity($headers, $this->_createEncoder(),
$this->_createCache()
);
$this->assertEquals('zip@button', $entity->getId());
}
public function testIdIsSetInHeader()
{
$cid = $this->_createHeader('Content-ID', 'zip@button', array(), false);
$headers = $this->_createHeaderSet(array('Content-ID' => $cid));
$cid->shouldReceive('setFieldBodyModel')
->once()
->with('foo@bar');
$cid->shouldReceive('setFieldBodyModel')
->zeroOrMoreTimes();
$entity = $this->_createEntity($headers, $this->_createEncoder(),
$this->_createCache()
);
$entity->setId('foo@bar');
}
public function testIdIsAutoGenerated()
{
$entity = $this->_createEntity($this->_createHeaderSet(),
$this->_createEncoder(), $this->_createCache()
);
$this->assertRegExp('/^.*?@.*?$/D', $entity->getId());
}
public function testGenerateIdCreatesNewId()
{
$headers = $this->_createHeaderSet();
$entity = $this->_createEntity($headers, $this->_createEncoder(),
$this->_createCache()
);
$id1 = $entity->generateId();
$id2 = $entity->generateId();
$this->assertNotEquals($id1, $id2);
}
public function testGenerateIdSetsNewId()
{
$headers = $this->_createHeaderSet();
$entity = $this->_createEntity($headers, $this->_createEncoder(),
$this->_createCache()
);
$id = $entity->generateId();
$this->assertEquals($id, $entity->getId());
}
public function testDescriptionIsReadFromHeader()
{
/* -- RFC 2045, 8.
The ability to associate some descriptive information with a given
body is often desirable. For example, it may be useful to mark an
"image" body as "a picture of the Space Shuttle Endeavor." Such text
may be placed in the Content-Description header field. This header
field is always optional.
*/
$desc = $this->_createHeader('Content-Description', 'something');
$headers = $this->_createHeaderSet(array('Content-Description' => $desc));
$entity = $this->_createEntity($headers, $this->_createEncoder(),
$this->_createCache()
);
$this->assertEquals('something', $entity->getDescription());
}
public function testDescriptionIsSetInHeader()
{
$desc = $this->_createHeader('Content-Description', '', array(), false);
$desc->shouldReceive('setFieldBodyModel')->once()->with('whatever');
$headers = $this->_createHeaderSet(array('Content-Description' => $desc));
$entity = $this->_createEntity($headers, $this->_createEncoder(),
$this->_createCache()
);
$entity->setDescription('whatever');
}
public function testDescriptionHeaderIsAddedIfNotPresent()
{
$headers = $this->_createHeaderSet(array(), false);
$headers->shouldReceive('addTextHeader')
->once()
->with('Content-Description', 'whatever');
$headers->shouldReceive('addTextHeader')
->zeroOrMoreTimes();
$entity = $this->_createEntity($headers, $this->_createEncoder(),
$this->_createCache()
);
$entity->setDescription('whatever');
}
public function testSetAndGetMaxLineLength()
{
$entity = $this->_createEntity($this->_createHeaderSet(),
$this->_createEncoder(), $this->_createCache()
);
$entity->setMaxLineLength(60);
$this->assertEquals(60, $entity->getMaxLineLength());
}
public function testEncoderIsUsedForStringGeneration()
{
$encoder = $this->_createEncoder('base64', false);
$encoder->expects($this->once())
->method('encodeString')
->with('blah');
$entity = $this->_createEntity($this->_createHeaderSet(),
$encoder, $this->_createCache()
);
$entity->setBody('blah');
$entity->toString();
}
public function testMaxLineLengthIsProvidedWhenEncoding()
{
$encoder = $this->_createEncoder('base64', false);
$encoder->expects($this->once())
->method('encodeString')
->with('blah', 0, 65);
$entity = $this->_createEntity($this->_createHeaderSet(),
$encoder, $this->_createCache()
);
$entity->setBody('blah');
$entity->setMaxLineLength(65);
$entity->toString();
}
public function testHeadersAppearInString()
{
$headers = $this->_createHeaderSet(array(), false);
$headers->shouldReceive('toString')
->once()
->andReturn(
"Content-Type: text/plain; charset=utf-8\r\n".
"X-MyHeader: foobar\r\n"
);
$entity = $this->_createEntity($headers, $this->_createEncoder(),
$this->_createCache()
);
$this->assertEquals(
"Content-Type: text/plain; charset=utf-8\r\n".
"X-MyHeader: foobar\r\n",
$entity->toString()
);
}
public function testSetAndGetBody()
{
$entity = $this->_createEntity($this->_createHeaderSet(),
$this->_createEncoder(), $this->_createCache()
);
$entity->setBody("blah\r\nblah!");
$this->assertEquals("blah\r\nblah!", $entity->getBody());
}
public function testBodyIsAppended()
{
$headers = $this->_createHeaderSet(array(), false);
$headers->shouldReceive('toString')
->once()
->andReturn("Content-Type: text/plain; charset=utf-8\r\n");
$entity = $this->_createEntity($headers, $this->_createEncoder(),
$this->_createCache()
);
$entity->setBody("blah\r\nblah!");
$this->assertEquals(
"Content-Type: text/plain; charset=utf-8\r\n".
"\r\n".
"blah\r\nblah!",
$entity->toString()
);
}
public function testGetBodyReturnsStringFromByteStream()
{
$os = $this->_createOutputStream('byte stream string');
$entity = $this->_createEntity($this->_createHeaderSet(),
$this->_createEncoder(), $this->_createCache()
);
$entity->setBody($os);
$this->assertEquals('byte stream string', $entity->getBody());
}
public function testByteStreamBodyIsAppended()
{
$headers = $this->_createHeaderSet(array(), false);
$os = $this->_createOutputStream('streamed');
$headers->shouldReceive('toString')
->once()
->andReturn("Content-Type: text/plain; charset=utf-8\r\n");
$entity = $this->_createEntity($headers, $this->_createEncoder(),
$this->_createCache()
);
$entity->setBody($os);
$this->assertEquals(
"Content-Type: text/plain; charset=utf-8\r\n".
"\r\n".
'streamed',
$entity->toString()
);
}
public function testBoundaryCanBeRetrieved()
{
/* -- RFC 2046, 5.1.1.
boundary := 0*69<bchars> bcharsnospace
bchars := bcharsnospace / " "
bcharsnospace := DIGIT / ALPHA / "'" / "(" / ")" /
"+" / "_" / "," / "-" / "." /
"/" / ":" / "=" / "?"
*/
$entity = $this->_createEntity($this->_createHeaderSet(),
$this->_createEncoder(), $this->_createCache()
);
$this->assertRegExp(
'/^[a-zA-Z0-9\'\(\)\+_\-,\.\/:=\?\ ]{0,69}[a-zA-Z0-9\'\(\)\+_\-,\.\/:=\?]$/D',
$entity->getBoundary()
);
}
public function testBoundaryNeverChanges()
{
$entity = $this->_createEntity($this->_createHeaderSet(),
$this->_createEncoder(), $this->_createCache()
);
$firstBoundary = $entity->getBoundary();
for ($i = 0; $i < 10; ++$i) {
$this->assertEquals($firstBoundary, $entity->getBoundary());
}
}
public function testBoundaryCanBeSet()
{
$entity = $this->_createEntity($this->_createHeaderSet(),
$this->_createEncoder(), $this->_createCache()
);
$entity->setBoundary('foobar');
$this->assertEquals('foobar', $entity->getBoundary());
}
public function testAddingChildrenGeneratesBoundaryInHeaders()
{
$child = $this->_createChild();
$cType = $this->_createHeader('Content-Type', 'text/plain', array(), false);
$cType->shouldReceive('setParameter')
->once()
->with('boundary', \Mockery::any());
$cType->shouldReceive('setParameter')
->zeroOrMoreTimes();
$entity = $this->_createEntity($this->_createHeaderSet(array(
'Content-Type' => $cType,
)),
$this->_createEncoder(), $this->_createCache()
);
$entity->setChildren(array($child));
}
public function testChildrenOfLevelAttachmentAndLessCauseMultipartMixed()
{
for ($level = Swift_Mime_MimeEntity::LEVEL_MIXED;
$level > Swift_Mime_MimeEntity::LEVEL_TOP; $level /= 2) {
$child = $this->_createChild($level);
$cType = $this->_createHeader(
'Content-Type', 'text/plain', array(), false
);
$cType->shouldReceive('setFieldBodyModel')
->once()
->with('multipart/mixed');
$cType->shouldReceive('setFieldBodyModel')
->zeroOrMoreTimes();
$entity = $this->_createEntity($this->_createHeaderSet(array(
'Content-Type' => $cType, )),
$this->_createEncoder(), $this->_createCache()
);
$entity->setChildren(array($child));
}
}
public function testChildrenOfLevelAlternativeAndLessCauseMultipartAlternative()
{
for ($level = Swift_Mime_MimeEntity::LEVEL_ALTERNATIVE;
$level > Swift_Mime_MimeEntity::LEVEL_MIXED; $level /= 2) {
$child = $this->_createChild($level);
$cType = $this->_createHeader(
'Content-Type', 'text/plain', array(), false
);
$cType->shouldReceive('setFieldBodyModel')
->once()
->with('multipart/alternative');
$cType->shouldReceive('setFieldBodyModel')
->zeroOrMoreTimes();
$entity = $this->_createEntity($this->_createHeaderSet(array(
'Content-Type' => $cType, )),
$this->_createEncoder(), $this->_createCache()
);
$entity->setChildren(array($child));
}
}
public function testChildrenOfLevelRelatedAndLessCauseMultipartRelated()
{
for ($level = Swift_Mime_MimeEntity::LEVEL_RELATED;
$level > Swift_Mime_MimeEntity::LEVEL_ALTERNATIVE; $level /= 2) {
$child = $this->_createChild($level);
$cType = $this->_createHeader(
'Content-Type', 'text/plain', array(), false
);
$cType->shouldReceive('setFieldBodyModel')
->once()
->with('multipart/related');
$cType->shouldReceive('setFieldBodyModel')
->zeroOrMoreTimes();
$entity = $this->_createEntity($this->_createHeaderSet(array(
'Content-Type' => $cType, )),
$this->_createEncoder(), $this->_createCache()
);
$entity->setChildren(array($child));
}
}
public function testHighestLevelChildDeterminesContentType()
{
$combinations = array(
array('levels' => array(Swift_Mime_MimeEntity::LEVEL_MIXED,
Swift_Mime_MimeEntity::LEVEL_ALTERNATIVE,
Swift_Mime_MimeEntity::LEVEL_RELATED,
),
'type' => 'multipart/mixed',
),
array('levels' => array(Swift_Mime_MimeEntity::LEVEL_MIXED,
Swift_Mime_MimeEntity::LEVEL_RELATED,
),
'type' => 'multipart/mixed',
),
array('levels' => array(Swift_Mime_MimeEntity::LEVEL_MIXED,
Swift_Mime_MimeEntity::LEVEL_ALTERNATIVE,
),
'type' => 'multipart/mixed',
),
array('levels' => array(Swift_Mime_MimeEntity::LEVEL_ALTERNATIVE,
Swift_Mime_MimeEntity::LEVEL_RELATED,
),
'type' => 'multipart/alternative',
),
);
foreach ($combinations as $combination) {
$children = array();
foreach ($combination['levels'] as $level) {
$children[] = $this->_createChild($level);
}
$cType = $this->_createHeader(
'Content-Type', 'text/plain', array(), false
);
$cType->shouldReceive('setFieldBodyModel')
->once()
->with($combination['type']);
$headerSet = $this->_createHeaderSet(array('Content-Type' => $cType));
$headerSet->shouldReceive('newInstance')
->zeroOrMoreTimes()
->andReturnUsing(function () use ($headerSet) {
return $headerSet;
});
$entity = $this->_createEntity($headerSet,
$this->_createEncoder(), $this->_createCache()
);
$entity->setChildren($children);
}
}
public function testChildrenAppearNestedInString()
{
/* -- RFC 2046, 5.1.1.
(excerpt too verbose to paste here)
*/
$headers = $this->_createHeaderSet(array(), false);
$child1 = new MimeEntityFixture(Swift_Mime_MimeEntity::LEVEL_ALTERNATIVE,
"Content-Type: text/plain\r\n".
"\r\n".
'foobar', 'text/plain'
);
$child2 = new MimeEntityFixture(Swift_Mime_MimeEntity::LEVEL_ALTERNATIVE,
"Content-Type: text/html\r\n".
"\r\n".
'<b>foobar</b>', 'text/html'
);
$headers->shouldReceive('toString')
->zeroOrMoreTimes()
->andReturn("Content-Type: multipart/alternative; boundary=\"xxx\"\r\n");
$entity = $this->_createEntity($headers, $this->_createEncoder(),
$this->_createCache()
);
$entity->setBoundary('xxx');
$entity->setChildren(array($child1, $child2));
$this->assertEquals(
"Content-Type: multipart/alternative; boundary=\"xxx\"\r\n".
"\r\n".
"\r\n--xxx\r\n".
"Content-Type: text/plain\r\n".
"\r\n".
"foobar\r\n".
"\r\n--xxx\r\n".
"Content-Type: text/html\r\n".
"\r\n".
"<b>foobar</b>\r\n".
"\r\n--xxx--\r\n",
$entity->toString()
);
}
public function testMixingLevelsIsHierarchical()
{
$headers = $this->_createHeaderSet(array(), false);
$newHeaders = $this->_createHeaderSet(array(), false);
$part = $this->_createChild(Swift_Mime_MimeEntity::LEVEL_ALTERNATIVE,
"Content-Type: text/plain\r\n".
"\r\n".
'foobar'
);
$attachment = $this->_createChild(Swift_Mime_MimeEntity::LEVEL_MIXED,
"Content-Type: application/octet-stream\r\n".
"\r\n".
'data'
);
$headers->shouldReceive('toString')
->zeroOrMoreTimes()
->andReturn("Content-Type: multipart/mixed; boundary=\"xxx\"\r\n");
$headers->shouldReceive('newInstance')
->zeroOrMoreTimes()
->andReturn($newHeaders);
$newHeaders->shouldReceive('toString')
->zeroOrMoreTimes()
->andReturn("Content-Type: multipart/alternative; boundary=\"yyy\"\r\n");
$entity = $this->_createEntity($headers, $this->_createEncoder(),
$this->_createCache()
);
$entity->setBoundary('xxx');
$entity->setChildren(array($part, $attachment));
$this->assertRegExp(
'~^'.
"Content-Type: multipart/mixed; boundary=\"xxx\"\r\n".
"\r\n\r\n--xxx\r\n".
"Content-Type: multipart/alternative; boundary=\"yyy\"\r\n".
"\r\n\r\n--(.*?)\r\n".
"Content-Type: text/plain\r\n".
"\r\n".
'foobar'.
"\r\n\r\n--\\1--\r\n".
"\r\n\r\n--xxx\r\n".
"Content-Type: application/octet-stream\r\n".
"\r\n".
'data'.
"\r\n\r\n--xxx--\r\n".
'$~',
$entity->toString()
);
}
public function testSettingEncoderNotifiesChildren()
{
$child = $this->_createChild(0, '', false);
$encoder = $this->_createEncoder('base64');
$child->shouldReceive('encoderChanged')
->once()
->with($encoder);
$entity = $this->_createEntity($this->_createHeaderSet(),
$this->_createEncoder(), $this->_createCache()
);
$entity->setChildren(array($child));
$entity->setEncoder($encoder);
}
public function testReceiptOfEncoderChangeNotifiesChildren()
{
$child = $this->_createChild(0, '', false);
$encoder = $this->_createEncoder('base64');
$child->shouldReceive('encoderChanged')
->once()
->with($encoder);
$entity = $this->_createEntity($this->_createHeaderSet(),
$this->_createEncoder(), $this->_createCache()
);
$entity->setChildren(array($child));
$entity->encoderChanged($encoder);
}
public function testReceiptOfCharsetChangeNotifiesChildren()
{
$child = $this->_createChild(0, '', false);
$child->shouldReceive('charsetChanged')
->once()
->with('windows-874');
$entity = $this->_createEntity($this->_createHeaderSet(),
$this->_createEncoder(), $this->_createCache()
);
$entity->setChildren(array($child));
$entity->charsetChanged('windows-874');
}
public function testEntityIsWrittenToByteStream()
{
$entity = $this->_createEntity($this->_createHeaderSet(),
$this->_createEncoder(), $this->_createCache()
);
$is = $this->_createInputStream(false);
$is->expects($this->atLeastOnce())
->method('write');
$entity->toByteStream($is);
}
public function testEntityHeadersAreComittedToByteStream()
{
$entity = $this->_createEntity($this->_createHeaderSet(),
$this->_createEncoder(), $this->_createCache()
);
$is = $this->_createInputStream(false);
$is->expects($this->atLeastOnce())
->method('write');
$is->expects($this->atLeastOnce())
->method('commit');
$entity->toByteStream($is);
}
public function testOrderingTextBeforeHtml()
{
$htmlChild = new MimeEntityFixture(Swift_Mime_MimeEntity::LEVEL_ALTERNATIVE,
"Content-Type: text/html\r\n".
"\r\n".
'HTML PART',
'text/html'
);
$textChild = new MimeEntityFixture(Swift_Mime_MimeEntity::LEVEL_ALTERNATIVE,
"Content-Type: text/plain\r\n".
"\r\n".
'TEXT PART',
'text/plain'
);
$headers = $this->_createHeaderSet(array(), false);
$headers->shouldReceive('toString')
->zeroOrMoreTimes()
->andReturn("Content-Type: multipart/alternative; boundary=\"xxx\"\r\n");
$entity = $this->_createEntity($headers, $this->_createEncoder(),
$this->_createCache()
);
$entity->setBoundary('xxx');
$entity->setChildren(array($htmlChild, $textChild));
$this->assertEquals(
"Content-Type: multipart/alternative; boundary=\"xxx\"\r\n".
"\r\n\r\n--xxx\r\n".
"Content-Type: text/plain\r\n".
"\r\n".
'TEXT PART'.
"\r\n\r\n--xxx\r\n".
"Content-Type: text/html\r\n".
"\r\n".
'HTML PART'.
"\r\n\r\n--xxx--\r\n",
$entity->toString()
);
}
public function testUnsettingChildrenRestoresContentType()
{
$cType = $this->_createHeader('Content-Type', 'text/plain', array(), false);
$child = $this->_createChild(Swift_Mime_MimeEntity::LEVEL_ALTERNATIVE);
$cType->shouldReceive('setFieldBodyModel')
->twice()
->with('image/jpeg');
$cType->shouldReceive('setFieldBodyModel')
->once()
->with('multipart/alternative');
$cType->shouldReceive('setFieldBodyModel')
->zeroOrMoreTimes()
->with(\Mockery::not('multipart/alternative', 'image/jpeg'));
$entity = $this->_createEntity($this->_createHeaderSet(array(
'Content-Type' => $cType,
)),
$this->_createEncoder(), $this->_createCache()
);
$entity->setContentType('image/jpeg');
$entity->setChildren(array($child));
$entity->setChildren(array());
}
public function testBodyIsReadFromCacheWhenUsingToStringIfPresent()
{
$headers = $this->_createHeaderSet(array(), false);
$headers->shouldReceive('toString')
->zeroOrMoreTimes()
->andReturn("Content-Type: text/plain; charset=utf-8\r\n");
$cache = $this->_createCache(false);
$cache->shouldReceive('hasKey')
->once()
->with(\Mockery::any(), 'body')
->andReturn(true);
$cache->shouldReceive('getString')
->once()
->with(\Mockery::any(), 'body')
->andReturn("\r\ncache\r\ncache!");
$entity = $this->_createEntity($headers, $this->_createEncoder(),
$cache
);
$entity->setBody("blah\r\nblah!");
$this->assertEquals(
"Content-Type: text/plain; charset=utf-8\r\n".
"\r\n".
"cache\r\ncache!",
$entity->toString()
);
}
public function testBodyIsAddedToCacheWhenUsingToString()
{
$headers = $this->_createHeaderSet(array(), false);
$headers->shouldReceive('toString')
->zeroOrMoreTimes()
->andReturn("Content-Type: text/plain; charset=utf-8\r\n");
$cache = $this->_createCache(false);
$cache->shouldReceive('hasKey')
->once()
->with(\Mockery::any(), 'body')
->andReturn(false);
$cache->shouldReceive('setString')
->once()
->with(\Mockery::any(), 'body', "\r\nblah\r\nblah!", Swift_KeyCache::MODE_WRITE);
$entity = $this->_createEntity($headers, $this->_createEncoder(),
$cache
);
$entity->setBody("blah\r\nblah!");
$entity->toString();
}
public function testBodyIsClearedFromCacheIfNewBodySet()
{
$headers = $this->_createHeaderSet(array(), false);
$headers->shouldReceive('toString')
->zeroOrMoreTimes()
->andReturn("Content-Type: text/plain; charset=utf-8\r\n");
$cache = $this->_createCache(false);
$entity = $this->_createEntity($headers, $this->_createEncoder(),
$cache
);
$entity->setBody("blah\r\nblah!");
$entity->toString();
// We set the expectation at this point because we only care what happens when calling setBody()
$cache->shouldReceive('clearKey')
->once()
->with(\Mockery::any(), 'body');
$entity->setBody("new\r\nnew!");
}
public function testBodyIsNotClearedFromCacheIfSameBodySet()
{
$headers = $this->_createHeaderSet(array(), false);
$headers->shouldReceive('toString')
->zeroOrMoreTimes()
->andReturn("Content-Type: text/plain; charset=utf-8\r\n");
$cache = $this->_createCache(false);
$entity = $this->_createEntity($headers, $this->_createEncoder(),
$cache
);
$entity->setBody("blah\r\nblah!");
$entity->toString();
// We set the expectation at this point because we only care what happens when calling setBody()
$cache->shouldReceive('clearKey')
->never();
$entity->setBody("blah\r\nblah!");
}
public function testBodyIsClearedFromCacheIfNewEncoderSet()
{
$headers = $this->_createHeaderSet(array(), false);
$headers->shouldReceive('toString')
->zeroOrMoreTimes()
->andReturn("Content-Type: text/plain; charset=utf-8\r\n");
$cache = $this->_createCache(false);
$otherEncoder = $this->_createEncoder();
$entity = $this->_createEntity($headers, $this->_createEncoder(),
$cache
);
$entity->setBody("blah\r\nblah!");
$entity->toString();
// We set the expectation at this point because we only care what happens when calling setEncoder()
$cache->shouldReceive('clearKey')
->once()
->with(\Mockery::any(), 'body');
$entity->setEncoder($otherEncoder);
}
public function testBodyIsReadFromCacheWhenUsingToByteStreamIfPresent()
{
$is = $this->_createInputStream();
$cache = $this->_createCache(false);
$cache->shouldReceive('hasKey')
->once()
->with(\Mockery::any(), 'body')
->andReturn(true);
$cache->shouldReceive('exportToByteStream')
->once()
->with(\Mockery::any(), 'body', $is);
$entity = $this->_createEntity($this->_createHeaderSet(),
$this->_createEncoder(), $cache
);
$entity->setBody('foo');
$entity->toByteStream($is);
}
public function testBodyIsAddedToCacheWhenUsingToByteStream()
{
$is = $this->_createInputStream();
$cache = $this->_createCache(false);
$cache->shouldReceive('hasKey')
->once()
->with(\Mockery::any(), 'body')
->andReturn(false);
$cache->shouldReceive('getInputByteStream')
->once()
->with(\Mockery::any(), 'body');
$entity = $this->_createEntity($this->_createHeaderSet(),
$this->_createEncoder(), $cache
);
$entity->setBody('foo');
$entity->toByteStream($is);
}
public function testFluidInterface()
{
$entity = $this->_createEntity($this->_createHeaderSet(),
$this->_createEncoder(), $this->_createCache()
);
$this->assertSame($entity,
$entity
->setContentType('text/plain')
->setEncoder($this->_createEncoder())
->setId('foo@bar')
->setDescription('my description')
->setMaxLineLength(998)
->setBody('xx')
->setBoundary('xyz')
->setChildren(array())
);
}
abstract protected function _createEntity($headers, $encoder, $cache);
protected function _createChild($level = null, $string = '', $stub = true)
{
$child = $this->getMockery('Swift_Mime_MimeEntity')->shouldIgnoreMissing();
if (isset($level)) {
$child->shouldReceive('getNestingLevel')
->zeroOrMoreTimes()
->andReturn($level);
}
$child->shouldReceive('toString')
->zeroOrMoreTimes()
->andReturn($string);
return $child;
}
protected function _createEncoder($name = 'quoted-printable', $stub = true)
{
$encoder = $this->getMockBuilder('Swift_Mime_ContentEncoder')->getMock();
$encoder->expects($this->any())
->method('getName')
->will($this->returnValue($name));
$encoder->expects($this->any())
->method('encodeString')
->will($this->returnCallback(function () {
$args = func_get_args();
return array_shift($args);
}));
return $encoder;
}
protected function _createCache($stub = true)
{
return $this->getMockery('Swift_KeyCache')->shouldIgnoreMissing();
}
protected function _createHeaderSet($headers = array(), $stub = true)
{
$set = $this->getMockery('Swift_Mime_HeaderSet')->shouldIgnoreMissing();
$set->shouldReceive('get')
->zeroOrMoreTimes()
->andReturnUsing(function ($key) use ($headers) {
return $headers[$key];
});
$set->shouldReceive('has')
->zeroOrMoreTimes()
->andReturnUsing(function ($key) use ($headers) {
return array_key_exists($key, $headers);
});
return $set;
}
protected function _createHeader($name, $model = null, $params = array(), $stub = true)
{
$header = $this->getMockery('Swift_Mime_ParameterizedHeader')->shouldIgnoreMissing();
$header->shouldReceive('getFieldName')
->zeroOrMoreTimes()
->andReturn($name);
$header->shouldReceive('getFieldBodyModel')
->zeroOrMoreTimes()
->andReturn($model);
$header->shouldReceive('getParameter')
->zeroOrMoreTimes()
->andReturnUsing(function ($key) use ($params) {
return $params[$key];
});
return $header;
}
protected function _createOutputStream($data = null, $stub = true)
{
$os = $this->getMockery('Swift_OutputByteStream');
if (isset($data)) {
$os->shouldReceive('read')
->zeroOrMoreTimes()
->andReturnUsing(function () use ($data) {
static $first = true;
if (!$first) {
return false;
}
$first = false;
return $data;
});
$os->shouldReceive('setReadPointer')
->zeroOrMoreTimes();
}
return $os;
}
protected function _createInputStream($stub = true)
{
return $this->getMockBuilder('Swift_InputByteStream')->getMock();
}
}
<?php
class Swift_Mime_AttachmentTest extends Swift_Mime_AbstractMimeEntityTest
{
public function testNestingLevelIsAttachment()
{
$attachment = $this->_createAttachment($this->_createHeaderSet(),
$this->_createEncoder(), $this->_createCache()
);
$this->assertEquals(
Swift_Mime_MimeEntity::LEVEL_MIXED, $attachment->getNestingLevel()
);
}
public function testDispositionIsReturnedFromHeader()
{
/* -- RFC 2183, 2.1, 2.2.
*/
$disposition = $this->_createHeader('Content-Disposition', 'attachment');
$attachment = $this->_createAttachment($this->_createHeaderSet(array(
'Content-Disposition' => $disposition, )),
$this->_createEncoder(), $this->_createCache()
);
$this->assertEquals('attachment', $attachment->getDisposition());
}
public function testDispositionIsSetInHeader()
{
$disposition = $this->_createHeader('Content-Disposition', 'attachment',
array(), false
);
$disposition->shouldReceive('setFieldBodyModel')
->once()
->with('inline');
$disposition->shouldReceive('setFieldBodyModel')
->zeroOrMoreTimes();
$attachment = $this->_createAttachment($this->_createHeaderSet(array(
'Content-Disposition' => $disposition, )),
$this->_createEncoder(), $this->_createCache()
);
$attachment->setDisposition('inline');
}
public function testDispositionIsAddedIfNonePresent()
{
$headers = $this->_createHeaderSet(array(), false);
$headers->shouldReceive('addParameterizedHeader')
->once()
->with('Content-Disposition', 'inline');
$headers->shouldReceive('addParameterizedHeader')
->zeroOrMoreTimes();
$attachment = $this->_createAttachment($headers, $this->_createEncoder(),
$this->_createCache()
);
$attachment->setDisposition('inline');
}
public function testDispositionIsAutoDefaultedToAttachment()
{
$headers = $this->_createHeaderSet(array(), false);
$headers->shouldReceive('addParameterizedHeader')
->once()
->with('Content-Disposition', 'attachment');
$headers->shouldReceive('addParameterizedHeader')
->zeroOrMoreTimes();
$attachment = $this->_createAttachment($headers, $this->_createEncoder(),
$this->_createCache()
);
}
public function testDefaultContentTypeInitializedToOctetStream()
{
$cType = $this->_createHeader('Content-Type', '',
array(), false
);
$cType->shouldReceive('setFieldBodyModel')
->once()
->with('application/octet-stream');
$cType->shouldReceive('setFieldBodyModel')
->zeroOrMoreTimes();
$attachment = $this->_createAttachment($this->_createHeaderSet(array(
'Content-Type' => $cType, )),
$this->_createEncoder(), $this->_createCache()
);
}
public function testFilenameIsReturnedFromHeader()
{
/* -- RFC 2183, 2.3.
*/
$disposition = $this->_createHeader('Content-Disposition', 'attachment',
array('filename' => 'foo.txt')
);
$attachment = $this->_createAttachment($this->_createHeaderSet(array(
'Content-Disposition' => $disposition, )),
$this->_createEncoder(), $this->_createCache()
);
$this->assertEquals('foo.txt', $attachment->getFilename());
}
public function testFilenameIsSetInHeader()
{
$disposition = $this->_createHeader('Content-Disposition', 'attachment',
array('filename' => 'foo.txt'), false
);
$disposition->shouldReceive('setParameter')
->once()
->with('filename', 'bar.txt');
$disposition->shouldReceive('setParameter')
->zeroOrMoreTimes();
$attachment = $this->_createAttachment($this->_createHeaderSet(array(
'Content-Disposition' => $disposition, )),
$this->_createEncoder(), $this->_createCache()
);
$attachment->setFilename('bar.txt');
}
public function testSettingFilenameSetsNameInContentType()
{
/*
This is a legacy requirement which isn't covered by up-to-date RFCs.
*/
$cType = $this->_createHeader('Content-Type', 'text/plain',
array(), false
);
$cType->shouldReceive('setParameter')
->once()
->with('name', 'bar.txt');
$cType->shouldReceive('setParameter')
->zeroOrMoreTimes();
$attachment = $this->_createAttachment($this->_createHeaderSet(array(
'Content-Type' => $cType, )),
$this->_createEncoder(), $this->_createCache()
);
$attachment->setFilename('bar.txt');
}
public function testSizeIsReturnedFromHeader()
{
/* -- RFC 2183, 2.7.
*/
$disposition = $this->_createHeader('Content-Disposition', 'attachment',
array('size' => 1234)
);
$attachment = $this->_createAttachment($this->_createHeaderSet(array(
'Content-Disposition' => $disposition, )),
$this->_createEncoder(), $this->_createCache()
);
$this->assertEquals(1234, $attachment->getSize());
}
public function testSizeIsSetInHeader()
{
$disposition = $this->_createHeader('Content-Disposition', 'attachment',
array(), false
);
$disposition->shouldReceive('setParameter')
->once()
->with('size', 12345);
$disposition->shouldReceive('setParameter')
->zeroOrMoreTimes();
$attachment = $this->_createAttachment($this->_createHeaderSet(array(
'Content-Disposition' => $disposition, )),
$this->_createEncoder(), $this->_createCache()
);
$attachment->setSize(12345);
}
public function testFilnameCanBeReadFromFileStream()
{
$file = $this->_createFileStream('/bar/file.ext', '');
$disposition = $this->_createHeader('Content-Disposition', 'attachment',
array('filename' => 'foo.txt'), false
);
$disposition->shouldReceive('setParameter')
->once()
->with('filename', 'file.ext');
$attachment = $this->_createAttachment($this->_createHeaderSet(array(
'Content-Disposition' => $disposition, )),
$this->_createEncoder(), $this->_createCache()
);
$attachment->setFile($file);
}
public function testContentTypeCanBeSetViaSetFile()
{
$file = $this->_createFileStream('/bar/file.ext', '');
$disposition = $this->_createHeader('Content-Disposition', 'attachment',
array('filename' => 'foo.txt'), false
);
$disposition->shouldReceive('setParameter')
->once()
->with('filename', 'file.ext');
$ctype = $this->_createHeader('Content-Type', 'text/plain', array(), false);
$ctype->shouldReceive('setFieldBodyModel')
->once()
->with('text/html');
$ctype->shouldReceive('setFieldBodyModel')
->zeroOrMoreTimes();
$headers = $this->_createHeaderSet(array(
'Content-Disposition' => $disposition,
'Content-Type' => $ctype,
));
$attachment = $this->_createAttachment($headers, $this->_createEncoder(),
$this->_createCache()
);
$attachment->setFile($file, 'text/html');
}
public function XtestContentTypeCanBeLookedUpFromCommonListIfNotProvided()
{
$file = $this->_createFileStream('/bar/file.zip', '');
$disposition = $this->_createHeader('Content-Disposition', 'attachment',
array('filename' => 'foo.zip'), false
);
$disposition->shouldReceive('setParameter')
->once()
->with('filename', 'file.zip');
$ctype = $this->_createHeader('Content-Type', 'text/plain', array(), false);
$ctype->shouldReceive('setFieldBodyModel')
->once()
->with('application/zip');
$ctype->shouldReceive('setFieldBodyModel')
->zeroOrMoreTimes();
$headers = $this->_createHeaderSet(array(
'Content-Disposition' => $disposition,
'Content-Type' => $ctype,
));
$attachment = $this->_createAttachment($headers, $this->_createEncoder(),
$this->_createCache(), array('zip' => 'application/zip', 'txt' => 'text/plain')
);
$attachment->setFile($file);
}
public function testDataCanBeReadFromFile()
{
$file = $this->_createFileStream('/foo/file.ext', '<some data>');
$attachment = $this->_createAttachment($this->_createHeaderSet(),
$this->_createEncoder(), $this->_createCache()
);
$attachment->setFile($file);
$this->assertEquals('<some data>', $attachment->getBody());
}
public function testFluidInterface()
{
$attachment = $this->_createAttachment($this->_createHeaderSet(),
$this->_createEncoder(), $this->_createCache()
);
$this->assertSame($attachment,
$attachment
->setContentType('application/pdf')
->setEncoder($this->_createEncoder())
->setId('foo@bar')
->setDescription('my pdf')
->setMaxLineLength(998)
->setBody('xx')
->setBoundary('xyz')
->setChildren(array())
->setDisposition('inline')
->setFilename('afile.txt')
->setSize(123)
->setFile($this->_createFileStream('foo.txt', ''))
);
}
protected function _createEntity($headers, $encoder, $cache)
{
return $this->_createAttachment($headers, $encoder, $cache);
}
protected function _createAttachment($headers, $encoder, $cache, $mimeTypes = array())
{
return new Swift_Mime_Attachment($headers, $encoder, $cache, new Swift_Mime_Grammar(), $mimeTypes);
}
protected function _createFileStream($path, $data, $stub = true)
{
$file = $this->getMockery('Swift_FileStream');
$file->shouldReceive('getPath')
->zeroOrMoreTimes()
->andReturn($path);
$file->shouldReceive('read')
->zeroOrMoreTimes()
->andReturnUsing(function () use ($data) {
static $first = true;
if (!$first) {
return false;
}
$first = false;
return $data;
});
$file->shouldReceive('setReadPointer')
->zeroOrMoreTimes();
return $file;
}
}
<?php
class Swift_Mime_ContentEncoder_Base64ContentEncoderTest extends \SwiftMailerTestCase
{
private $_encoder;
protected function setUp()
{
$this->_encoder = new Swift_Mime_ContentEncoder_Base64ContentEncoder();
}
public function testNameIsBase64()
{
$this->assertEquals('base64', $this->_encoder->getName());
}
/*
There's really no point in testing the entire base64 encoding to the
level QP encoding has been tested. base64_encode() has been in PHP for
years.
*/
public function testInputOutputRatioIs3to4Bytes()
{
/*
RFC 2045, 6.8
The encoding process represents 24-bit groups of input bits as output
strings of 4 encoded characters. Proceeding from left to right, a
24-bit input group is formed by concatenating 3 8bit input groups.
These 24 bits are then treated as 4 concatenated 6-bit groups, each
of which is translated into a single digit in the base64 alphabet.
*/
$os = $this->_createOutputByteStream();
$is = $this->_createInputByteStream();
$collection = new Swift_StreamCollector();
$is->shouldReceive('write')
->zeroOrMoreTimes()
->andReturnUsing($collection);
$os->shouldReceive('read')
->once()
->andReturn('123');
$os->shouldReceive('read')
->zeroOrMoreTimes()
->andReturn(false);
$this->_encoder->encodeByteStream($os, $is);
$this->assertEquals('MTIz', $collection->content);
}
public function testPadLength()
{
/*
RFC 2045, 6.8
Special processing is performed if fewer than 24 bits are available
at the end of the data being encoded. A full encoding quantum is
always completed at the end of a body. When fewer than 24 input bits
are available in an input group, zero bits are added (on the right)
to form an integral number of 6-bit groups. Padding at the end of
the data is performed using the "=" character. Since all base64
input is an integral number of octets, only the following cases can
arise: (1) the final quantum of encoding input is an integral
multiple of 24 bits; here, the final unit of encoded output will be
an integral multiple of 4 characters with no "=" padding, (2) the
final quantum of encoding input is exactly 8 bits; here, the final
unit of encoded output will be two characters followed by two "="
padding characters, or (3) the final quantum of encoding input is
exactly 16 bits; here, the final unit of encoded output will be three
characters followed by one "=" padding character.
*/
for ($i = 0; $i < 30; ++$i) {
$os = $this->_createOutputByteStream();
$is = $this->_createInputByteStream();
$collection = new Swift_StreamCollector();
$is->shouldReceive('write')
->zeroOrMoreTimes()
->andReturnUsing($collection);
$os->shouldReceive('read')
->once()
->andReturn(pack('C', rand(0, 255)));
$os->shouldReceive('read')
->zeroOrMoreTimes()
->andReturn(false);
$this->_encoder->encodeByteStream($os, $is);
$this->assertRegExp('~^[a-zA-Z0-9/\+]{2}==$~', $collection->content,
'%s: A single byte should have 2 bytes of padding'
);
}
for ($i = 0; $i < 30; ++$i) {
$os = $this->_createOutputByteStream();
$is = $this->_createInputByteStream();
$collection = new Swift_StreamCollector();
$is->shouldReceive('write')
->zeroOrMoreTimes()
->andReturnUsing($collection);
$os->shouldReceive('read')
->once()
->andReturn(pack('C*', rand(0, 255), rand(0, 255)));
$os->shouldReceive('read')
->zeroOrMoreTimes()
->andReturn(false);
$this->_encoder->encodeByteStream($os, $is);
$this->assertRegExp('~^[a-zA-Z0-9/\+]{3}=$~', $collection->content,
'%s: Two bytes should have 1 byte of padding'
);
}
for ($i = 0; $i < 30; ++$i) {
$os = $this->_createOutputByteStream();
$is = $this->_createInputByteStream();
$collection = new Swift_StreamCollector();
$is->shouldReceive('write')
->zeroOrMoreTimes()
->andReturnUsing($collection);
$os->shouldReceive('read')
->once()
->andReturn(pack('C*', rand(0, 255), rand(0, 255), rand(0, 255)));
$os->shouldReceive('read')
->zeroOrMoreTimes()
->andReturn(false);
$this->_encoder->encodeByteStream($os, $is);
$this->assertRegExp('~^[a-zA-Z0-9/\+]{4}$~', $collection->content,
'%s: Three bytes should have no padding'
);
}
}
public function testMaximumLineLengthIs76Characters()
{
/*
The encoded output stream must be represented in lines of no more
than 76 characters each. All line breaks or other characters not
found in Table 1 must be ignored by decoding software.
*/
$os = $this->_createOutputByteStream();
$is = $this->_createInputByteStream();
$collection = new Swift_StreamCollector();
$is->shouldReceive('write')
->zeroOrMoreTimes()
->andReturnUsing($collection);
$os->shouldReceive('read')
->once()
->andReturn('abcdefghijkl'); //12
$os->shouldReceive('read')
->once()
->andReturn('mnopqrstuvwx'); //24
$os->shouldReceive('read')
->once()
->andReturn('yzabc1234567'); //36
$os->shouldReceive('read')
->once()
->andReturn('890ABCDEFGHI'); //48
$os->shouldReceive('read')
->once()
->andReturn('JKLMNOPQRSTU'); //60
$os->shouldReceive('read')
->once()
->andReturn('VWXYZ1234567'); //72
$os->shouldReceive('read')
->once()
->andReturn('abcdefghijkl'); //84
$os->shouldReceive('read')
->zeroOrMoreTimes()
->andReturn(false);
$this->_encoder->encodeByteStream($os, $is);
$this->assertEquals(
"YWJjZGVmZ2hpamtsbW5vcHFyc3R1dnd4eXphYmMxMjM0NTY3ODkwQUJDREVGR0hJSktMTU5PUFFS\r\n".
'U1RVVldYWVoxMjM0NTY3YWJjZGVmZ2hpamts',
$collection->content
);
}
public function testMaximumLineLengthCanBeDifferent()
{
$os = $this->_createOutputByteStream();
$is = $this->_createInputByteStream();
$collection = new Swift_StreamCollector();
$is->shouldReceive('write')
->zeroOrMoreTimes()
->andReturnUsing($collection);
$os->shouldReceive('read')
->once()
->andReturn('abcdefghijkl'); //12
$os->shouldReceive('read')
->once()
->andReturn('mnopqrstuvwx'); //24
$os->shouldReceive('read')
->once()
->andReturn('yzabc1234567'); //36
$os->shouldReceive('read')
->once()
->andReturn('890ABCDEFGHI'); //48
$os->shouldReceive('read')
->once()
->andReturn('JKLMNOPQRSTU'); //60
$os->shouldReceive('read')
->once()
->andReturn('VWXYZ1234567'); //72
$os->shouldReceive('read')
->once()
->andReturn('abcdefghijkl'); //84
$os->shouldReceive('read')
->zeroOrMoreTimes()
->andReturn(false);
$this->_encoder->encodeByteStream($os, $is, 0, 50);
$this->assertEquals(
"YWJjZGVmZ2hpamtsbW5vcHFyc3R1dnd4eXphYmMxMjM0NTY3OD\r\n".
"kwQUJDREVGR0hJSktMTU5PUFFSU1RVVldYWVoxMjM0NTY3YWJj\r\n".
'ZGVmZ2hpamts',
$collection->content
);
}
public function testMaximumLineLengthIsNeverMoreThan76Chars()
{
$os = $this->_createOutputByteStream();
$is = $this->_createInputByteStream();
$collection = new Swift_StreamCollector();
$is->shouldReceive('write')
->zeroOrMoreTimes()
->andReturnUsing($collection);
$os->shouldReceive('read')
->once()
->andReturn('abcdefghijkl'); //12
$os->shouldReceive('read')
->once()
->andReturn('mnopqrstuvwx'); //24
$os->shouldReceive('read')
->once()
->andReturn('yzabc1234567'); //36
$os->shouldReceive('read')
->once()
->andReturn('890ABCDEFGHI'); //48
$os->shouldReceive('read')
->once()
->andReturn('JKLMNOPQRSTU'); //60
$os->shouldReceive('read')
->once()
->andReturn('VWXYZ1234567'); //72
$os->shouldReceive('read')
->once()
->andReturn('abcdefghijkl'); //84
$os->shouldReceive('read')
->zeroOrMoreTimes()
->andReturn(false);
$this->_encoder->encodeByteStream($os, $is, 0, 100);
$this->assertEquals(
"YWJjZGVmZ2hpamtsbW5vcHFyc3R1dnd4eXphYmMxMjM0NTY3ODkwQUJDREVGR0hJSktMTU5PUFFS\r\n".
'U1RVVldYWVoxMjM0NTY3YWJjZGVmZ2hpamts',
$collection->content
);
}
public function testFirstLineLengthCanBeDifferent()
{
$os = $this->_createOutputByteStream();
$is = $this->_createInputByteStream();
$collection = new Swift_StreamCollector();
$is->shouldReceive('write')
->zeroOrMoreTimes()
->andReturnUsing($collection);
$os->shouldReceive('read')
->once()
->andReturn('abcdefghijkl'); //12
$os->shouldReceive('read')
->once()
->andReturn('mnopqrstuvwx'); //24
$os->shouldReceive('read')
->once()
->andReturn('yzabc1234567'); //36
$os->shouldReceive('read')
->once()
->andReturn('890ABCDEFGHI'); //48
$os->shouldReceive('read')
->once()
->andReturn('JKLMNOPQRSTU'); //60
$os->shouldReceive('read')
->once()
->andReturn('VWXYZ1234567'); //72
$os->shouldReceive('read')
->once()
->andReturn('abcdefghijkl'); //84
$os->shouldReceive('read')
->zeroOrMoreTimes()
->andReturn(false);
$this->_encoder->encodeByteStream($os, $is, 19);
$this->assertEquals(
"YWJjZGVmZ2hpamtsbW5vcHFyc3R1dnd4eXphYmMxMjM0NTY3ODkwQUJDR\r\n".
'EVGR0hJSktMTU5PUFFSU1RVVldYWVoxMjM0NTY3YWJjZGVmZ2hpamts',
$collection->content
);
}
private function _createOutputByteStream($stub = false)
{
return $this->getMockery('Swift_OutputByteStream')->shouldIgnoreMissing();
}
private function _createInputByteStream($stub = false)
{
return $this->getMockery('Swift_InputByteStream')->shouldIgnoreMissing();
}
}
<?php
class Swift_Mime_ContentEncoder_PlainContentEncoderTest extends \SwiftMailerTestCase
{
public function testNameCanBeSpecifiedInConstructor()
{
$encoder = $this->_getEncoder('7bit');
$this->assertEquals('7bit', $encoder->getName());
$encoder = $this->_getEncoder('8bit');
$this->assertEquals('8bit', $encoder->getName());
}
public function testNoOctetsAreModifiedInString()
{
$encoder = $this->_getEncoder('7bit');
foreach (range(0x00, 0xFF) as $octet) {
$byte = pack('C', $octet);
$this->assertIdenticalBinary($byte, $encoder->encodeString($byte));
}
}
public function testNoOctetsAreModifiedInByteStream()
{
$encoder = $this->_getEncoder('7bit');
foreach (range(0x00, 0xFF) as $octet) {
$byte = pack('C', $octet);
$os = $this->_createOutputByteStream();
$is = $this->_createInputByteStream();
$collection = new Swift_StreamCollector();
$is->shouldReceive('write')
->zeroOrMoreTimes()
->andReturnUsing($collection);
$os->shouldReceive('read')
->once()
->andReturn($byte);
$os->shouldReceive('read')
->zeroOrMoreTimes()
->andReturn(false);
$encoder->encodeByteStream($os, $is);
$this->assertIdenticalBinary($byte, $collection->content);
}
}
public function testLineLengthCanBeSpecified()
{
$encoder = $this->_getEncoder('7bit');
$chars = array();
for ($i = 0; $i < 50; ++$i) {
$chars[] = 'a';
}
$input = implode(' ', $chars); //99 chars long
$this->assertEquals(
'a a a a a a a a a a a a a a a a a a a a a a a a a '."\r\n".//50 *
'a a a a a a a a a a a a a a a a a a a a a a a a a', //99
$encoder->encodeString($input, 0, 50),
'%s: Lines should be wrapped at 50 chars'
);
}
public function testLineLengthCanBeSpecifiedInByteStream()
{
$encoder = $this->_getEncoder('7bit');
$os = $this->_createOutputByteStream();
$is = $this->_createInputByteStream();
$collection = new Swift_StreamCollector();
$is->shouldReceive('write')
->zeroOrMoreTimes()
->andReturnUsing($collection);
for ($i = 0; $i < 50; ++$i) {
$os->shouldReceive('read')
->once()
->andReturn('a ');
}
$os->shouldReceive('read')
->zeroOrMoreTimes()
->andReturn(false);
$encoder->encodeByteStream($os, $is, 0, 50);
$this->assertEquals(
str_repeat('a ', 25)."\r\n".str_repeat('a ', 25),
$collection->content
);
}
public function testencodeStringGeneratesCorrectCrlf()
{
$encoder = $this->_getEncoder('7bit', true);
$this->assertEquals("a\r\nb", $encoder->encodeString("a\rb"),
'%s: Line endings should be standardized'
);
$this->assertEquals("a\r\nb", $encoder->encodeString("a\nb"),
'%s: Line endings should be standardized'
);
$this->assertEquals("a\r\n\r\nb", $encoder->encodeString("a\n\rb"),
'%s: Line endings should be standardized'
);
$this->assertEquals("a\r\n\r\nb", $encoder->encodeString("a\r\rb"),
'%s: Line endings should be standardized'
);
$this->assertEquals("a\r\n\r\nb", $encoder->encodeString("a\n\nb"),
'%s: Line endings should be standardized'
);
}
public function crlfProvider()
{
return array(
array("\r", "a\r\nb"),
array("\n", "a\r\nb"),
array("\n\r", "a\r\n\r\nb"),
array("\n\n", "a\r\n\r\nb"),
array("\r\r", "a\r\n\r\nb"),
);
}
/**
* @dataProvider crlfProvider
*/
public function testCanonicEncodeByteStreamGeneratesCorrectCrlf($test, $expected)
{
$encoder = $this->_getEncoder('7bit', true);
$os = $this->_createOutputByteStream();
$is = $this->_createInputByteStream();
$collection = new Swift_StreamCollector();
$is->shouldReceive('write')
->zeroOrMoreTimes()
->andReturnUsing($collection);
$os->shouldReceive('read')
->once()
->andReturn('a');
$os->shouldReceive('read')
->once()
->andReturn($test);
$os->shouldReceive('read')
->once()
->andReturn('b');
$os->shouldReceive('read')
->zeroOrMoreTimes()
->andReturn(false);
$encoder->encodeByteStream($os, $is);
$this->assertEquals($expected, $collection->content);
}
private function _getEncoder($name, $canonical = false)
{
return new Swift_Mime_ContentEncoder_PlainContentEncoder($name, $canonical);
}
private function _createOutputByteStream($stub = false)
{
return $this->getMockery('Swift_OutputByteStream')->shouldIgnoreMissing();
}
private function _createInputByteStream($stub = false)
{
return $this->getMockery('Swift_InputByteStream')->shouldIgnoreMissing();
}
}
<?php
class Swift_Mime_ContentEncoder_QpContentEncoderTest extends \SwiftMailerTestCase
{
public function testNameIsQuotedPrintable()
{
$encoder = new Swift_Mime_ContentEncoder_QpContentEncoder(
$this->_createCharacterStream(true)
);
$this->assertEquals('quoted-printable', $encoder->getName());
}
/* -- RFC 2045, 6.7 --
(1) (General 8bit representation) Any octet, except a CR or
LF that is part of a CRLF line break of the canonical
(standard) form of the data being encoded, may be
represented by an "=" followed by a two digit
hexadecimal representation of the octet's value. The
digits of the hexadecimal alphabet, for this purpose,
are "0123456789ABCDEF". Uppercase letters must be
used; lowercase letters are not allowed. Thus, for
example, the decimal value 12 (US-ASCII form feed) can
be represented by "=0C", and the decimal value 61 (US-
ASCII EQUAL SIGN) can be represented by "=3D". This
rule must be followed except when the following rules
allow an alternative encoding.
*/
public function testPermittedCharactersAreNotEncoded()
{
/* -- RFC 2045, 6.7 --
(2) (Literal representation) Octets with decimal values of
33 through 60 inclusive, and 62 through 126, inclusive,
MAY be represented as the US-ASCII characters which
correspond to those octets (EXCLAMATION POINT through
LESS THAN, and GREATER THAN through TILDE,
respectively).
*/
foreach (array_merge(range(33, 60), range(62, 126)) as $ordinal) {
$char = chr($ordinal);
$os = $this->_createOutputByteStream(true);
$charStream = $this->_createCharacterStream();
$is = $this->_createInputByteStream();
$collection = new Swift_StreamCollector();
$is->shouldReceive('write')
->zeroOrMoreTimes()
->andReturnUsing($collection);
$charStream->shouldReceive('flushContents')
->once();
$charStream->shouldReceive('importByteStream')
->once()
->with($os);
$charStream->shouldReceive('readBytes')
->once()
->andReturn(array($ordinal));
$charStream->shouldReceive('readBytes')
->zeroOrMoreTimes()
->andReturn(false);
$encoder = new Swift_Mime_ContentEncoder_QpContentEncoder($charStream);
$encoder->encodeByteStream($os, $is);
$this->assertIdenticalBinary($char, $collection->content);
}
}
public function testLinearWhiteSpaceAtLineEndingIsEncoded()
{
/* -- RFC 2045, 6.7 --
(3) (White Space) Octets with values of 9 and 32 MAY be
represented as US-ASCII TAB (HT) and SPACE characters,
respectively, but MUST NOT be so represented at the end
of an encoded line. Any TAB (HT) or SPACE characters
on an encoded line MUST thus be followed on that line
by a printable character. In particular, an "=" at the
end of an encoded line, indicating a soft line break
(see rule #5) may follow one or more TAB (HT) or SPACE
characters. It follows that an octet with decimal
value 9 or 32 appearing at the end of an encoded line
must be represented according to Rule #1. This rule is
necessary because some MTAs (Message Transport Agents,
programs which transport messages from one user to
another, or perform a portion of such transfers) are
known to pad lines of text with SPACEs, and others are
known to remove "white space" characters from the end
of a line. Therefore, when decoding a Quoted-Printable
body, any trailing white space on a line must be
deleted, as it will necessarily have been added by
intermediate transport agents.
*/
$HT = chr(0x09); //9
$SPACE = chr(0x20); //32
//HT
$os = $this->_createOutputByteStream(true);
$charStream = $this->_createCharacterStream();
$is = $this->_createInputByteStream();
$collection = new Swift_StreamCollector();
$is->shouldReceive('write')
->zeroOrMoreTimes()
->andReturnUsing($collection);
$charStream->shouldReceive('flushContents')
->once();
$charStream->shouldReceive('importByteStream')
->once()
->with($os);
$charStream->shouldReceive('readBytes')
->once()
->andReturn(array(ord('a')));
$charStream->shouldReceive('readBytes')
->once()
->andReturn(array(0x09));
$charStream->shouldReceive('readBytes')
->once()
->andReturn(array(0x09));
$charStream->shouldReceive('readBytes')
->once()
->andReturn(array(0x0D));
$charStream->shouldReceive('readBytes')
->once()
->andReturn(array(0x0A));
$charStream->shouldReceive('readBytes')
->once()
->andReturn(array(ord('b')));
$charStream->shouldReceive('readBytes')
->zeroOrMoreTimes()
->andReturn(false);
$encoder = new Swift_Mime_ContentEncoder_QpContentEncoder($charStream);
$encoder->encodeByteStream($os, $is);
$this->assertEquals("a\t=09\r\nb", $collection->content);
//SPACE
$os = $this->_createOutputByteStream(true);
$charStream = $this->_createCharacterStream();
$is = $this->_createInputByteStream();
$collection = new Swift_StreamCollector();
$is->shouldReceive('write')
->zeroOrMoreTimes()
->andReturnUsing($collection);
$charStream->shouldReceive('flushContents')
->once();
$charStream->shouldReceive('importByteStream')
->once()
->with($os);
$charStream->shouldReceive('readBytes')
->once()
->andReturn(array(ord('a')));
$charStream->shouldReceive('readBytes')
->once()
->andReturn(array(0x20));
$charStream->shouldReceive('readBytes')
->once()
->andReturn(array(0x20));
$charStream->shouldReceive('readBytes')
->once()
->andReturn(array(0x0D));
$charStream->shouldReceive('readBytes')
->once()
->andReturn(array(0x0A));
$charStream->shouldReceive('readBytes')
->once()
->andReturn(array(ord('b')));
$charStream->shouldReceive('readBytes')
->zeroOrMoreTimes()
->andReturn(false);
$encoder = new Swift_Mime_ContentEncoder_QpContentEncoder($charStream);
$encoder->encodeByteStream($os, $is);
$this->assertEquals("a =20\r\nb", $collection->content);
}
public function testCRLFIsLeftAlone()
{
/*
(4) (Line Breaks) A line break in a text body, represented
as a CRLF sequence in the text canonical form, must be
represented by a (RFC 822) line break, which is also a
CRLF sequence, in the Quoted-Printable encoding. Since
the canonical representation of media types other than
text do not generally include the representation of
line breaks as CRLF sequences, no hard line breaks
(i.e. line breaks that are intended to be meaningful
and to be displayed to the user) can occur in the
quoted-printable encoding of such types. Sequences
like "=0D", "=0A", "=0A=0D" and "=0D=0A" will routinely
appear in non-text data represented in quoted-
printable, of course.
Note that many implementations may elect to encode the
local representation of various content types directly
rather than converting to canonical form first,
encoding, and then converting back to local
representation. In particular, this may apply to plain
text material on systems that use newline conventions
other than a CRLF terminator sequence. Such an
implementation optimization is permissible, but only
when the combined canonicalization-encoding step is
equivalent to performing the three steps separately.
*/
$os = $this->_createOutputByteStream(true);
$charStream = $this->_createCharacterStream();
$is = $this->_createInputByteStream();
$collection = new Swift_StreamCollector();
$is->shouldReceive('write')
->zeroOrMoreTimes()
->andReturnUsing($collection);
$charStream->shouldReceive('flushContents')
->once();
$charStream->shouldReceive('importByteStream')
->once()
->with($os);
$charStream->shouldReceive('readBytes')
->once()
->andReturn(array(ord('a')));
$charStream->shouldReceive('readBytes')
->once()
->andReturn(array(0x0D));
$charStream->shouldReceive('readBytes')
->once()
->andReturn(array(0x0A));
$charStream->shouldReceive('readBytes')
->once()
->andReturn(array(ord('b')));
$charStream->shouldReceive('readBytes')
->once()
->andReturn(array(0x0D));
$charStream->shouldReceive('readBytes')
->once()
->andReturn(array(0x0A));
$charStream->shouldReceive('readBytes')
->once()
->andReturn(array(ord('c')));
$charStream->shouldReceive('readBytes')
->once()
->andReturn(array(0x0D));
$charStream->shouldReceive('readBytes')
->once()
->andReturn(array(0x0A));
$charStream->shouldReceive('readBytes')
->zeroOrMoreTimes()
->andReturn(false);
$encoder = new Swift_Mime_ContentEncoder_QpContentEncoder($charStream);
$encoder->encodeByteStream($os, $is);
$this->assertEquals("a\r\nb\r\nc\r\n", $collection->content);
}
public function testLinesLongerThan76CharactersAreSoftBroken()
{
/*
(5) (Soft Line Breaks) The Quoted-Printable encoding
REQUIRES that encoded lines be no more than 76
characters long. If longer lines are to be encoded
with the Quoted-Printable encoding, "soft" line breaks
must be used. An equal sign as the last character on a
encoded line indicates such a non-significant ("soft")
line break in the encoded text.
*/
$os = $this->_createOutputByteStream(true);
$charStream = $this->_createCharacterStream();
$is = $this->_createInputByteStream();
$collection = new Swift_StreamCollector();
$is->shouldReceive('write')
->zeroOrMoreTimes()
->andReturnUsing($collection);
$charStream->shouldReceive('flushContents')
->once();
$charStream->shouldReceive('importByteStream')
->once()
->with($os);
for ($seq = 0; $seq <= 140; ++$seq) {
$charStream->shouldReceive('readBytes')
->once()
->andReturn(array(ord('a')));
}
$charStream->shouldReceive('readBytes')
->zeroOrMoreTimes()
->andReturn(false);
$encoder = new Swift_Mime_ContentEncoder_QpContentEncoder($charStream);
$encoder->encodeByteStream($os, $is);
$this->assertEquals(str_repeat('a', 75)."=\r\n".str_repeat('a', 66), $collection->content);
}
public function testMaxLineLengthCanBeSpecified()
{
$os = $this->_createOutputByteStream(true);
$charStream = $this->_createCharacterStream();
$is = $this->_createInputByteStream();
$collection = new Swift_StreamCollector();
$is->shouldReceive('write')
->zeroOrMoreTimes()
->andReturnUsing($collection);
$charStream->shouldReceive('flushContents')
->once();
$charStream->shouldReceive('importByteStream')
->once()
->with($os);
for ($seq = 0; $seq <= 100; ++$seq) {
$charStream->shouldReceive('readBytes')
->once()
->andReturn(array(ord('a')));
}
$charStream->shouldReceive('readBytes')
->zeroOrMoreTimes()
->andReturn(false);
$encoder = new Swift_Mime_ContentEncoder_QpContentEncoder($charStream);
$encoder->encodeByteStream($os, $is, 0, 54);
$this->assertEquals(str_repeat('a', 53)."=\r\n".str_repeat('a', 48), $collection->content);
}
public function testBytesBelowPermittedRangeAreEncoded()
{
/*
According to Rule (1 & 2)
*/
foreach (range(0, 32) as $ordinal) {
$char = chr($ordinal);
$os = $this->_createOutputByteStream(true);
$charStream = $this->_createCharacterStream();
$is = $this->_createInputByteStream();
$collection = new Swift_StreamCollector();
$is->shouldReceive('write')
->zeroOrMoreTimes()
->andReturnUsing($collection);
$charStream->shouldReceive('flushContents')
->once();
$charStream->shouldReceive('importByteStream')
->once()
->with($os);
$charStream->shouldReceive('readBytes')
->once()
->andReturn(array($ordinal));
$charStream->shouldReceive('readBytes')
->zeroOrMoreTimes()
->andReturn(false);
$encoder = new Swift_Mime_ContentEncoder_QpContentEncoder($charStream);
$encoder->encodeByteStream($os, $is);
$this->assertEquals(sprintf('=%02X', $ordinal), $collection->content);
}
}
public function testDecimalByte61IsEncoded()
{
/*
According to Rule (1 & 2)
*/
$char = chr(61);
$os = $this->_createOutputByteStream(true);
$charStream = $this->_createCharacterStream();
$is = $this->_createInputByteStream();
$collection = new Swift_StreamCollector();
$is->shouldReceive('write')
->zeroOrMoreTimes()
->andReturnUsing($collection);
$charStream->shouldReceive('flushContents')
->once();
$charStream->shouldReceive('importByteStream')
->once()
->with($os);
$charStream->shouldReceive('readBytes')
->once()
->andReturn(array(61));
$charStream->shouldReceive('readBytes')
->zeroOrMoreTimes()
->andReturn(false);
$encoder = new Swift_Mime_ContentEncoder_QpContentEncoder($charStream);
$encoder->encodeByteStream($os, $is);
$this->assertEquals(sprintf('=%02X', 61), $collection->content);
}
public function testBytesAbovePermittedRangeAreEncoded()
{
/*
According to Rule (1 & 2)
*/
foreach (range(127, 255) as $ordinal) {
$char = chr($ordinal);
$os = $this->_createOutputByteStream(true);
$charStream = $this->_createCharacterStream();
$is = $this->_createInputByteStream();
$collection = new Swift_StreamCollector();
$is->shouldReceive('write')
->zeroOrMoreTimes()
->andReturnUsing($collection);
$charStream->shouldReceive('flushContents')
->once();
$charStream->shouldReceive('importByteStream')
->once()
->with($os);
$charStream->shouldReceive('readBytes')
->once()
->andReturn(array($ordinal));
$charStream->shouldReceive('readBytes')
->zeroOrMoreTimes()
->andReturn(false);
$encoder = new Swift_Mime_ContentEncoder_QpContentEncoder($charStream);
$encoder->encodeByteStream($os, $is);
$this->assertEquals(sprintf('=%02X', $ordinal), $collection->content);
}
}
public function testFirstLineLengthCanBeDifferent()
{
$os = $this->_createOutputByteStream(true);
$charStream = $this->_createCharacterStream();
$is = $this->_createInputByteStream();
$collection = new Swift_StreamCollector();
$is->shouldReceive('write')
->zeroOrMoreTimes()
->andReturnUsing($collection);
$charStream->shouldReceive('flushContents')
->once();
$charStream->shouldReceive('importByteStream')
->once()
->with($os);
for ($seq = 0; $seq <= 140; ++$seq) {
$charStream->shouldReceive('readBytes')
->once()
->andReturn(array(ord('a')));
}
$charStream->shouldReceive('readBytes')
->zeroOrMoreTimes()
->andReturn(false);
$encoder = new Swift_Mime_ContentEncoder_QpContentEncoder($charStream);
$encoder->encodeByteStream($os, $is, 22);
$this->assertEquals(
str_repeat('a', 53)."=\r\n".str_repeat('a', 75)."=\r\n".str_repeat('a', 13),
$collection->content
);
}
public function testObserverInterfaceCanChangeCharset()
{
$stream = $this->_createCharacterStream();
$stream->shouldReceive('setCharacterSet')
->once()
->with('windows-1252');
$encoder = new Swift_Mime_ContentEncoder_QpContentEncoder($stream);
$encoder->charsetChanged('windows-1252');
}
public function testTextIsPreWrapped()
{
$encoder = $this->createEncoder();
$input = str_repeat('a', 70)."\r\n".
str_repeat('a', 70)."\r\n".
str_repeat('a', 70);
$os = new Swift_ByteStream_ArrayByteStream();
$is = new Swift_ByteStream_ArrayByteStream();
$is->write($input);
$encoder->encodeByteStream($is, $os);
$this->assertEquals(
$input, $os->read(PHP_INT_MAX)
);
}
private function _createCharacterStream($stub = false)
{
return $this->getMockery('Swift_CharacterStream')->shouldIgnoreMissing();
}
private function createEncoder()
{
$factory = new Swift_CharacterReaderFactory_SimpleCharacterReaderFactory();
$charStream = new Swift_CharacterStream_NgCharacterStream($factory, 'utf-8');
return new Swift_Mime_ContentEncoder_QpContentEncoder($charStream);
}
private function _createOutputByteStream($stub = false)
{
return $this->getMockery('Swift_OutputByteStream')->shouldIgnoreMissing();
}
private function _createInputByteStream($stub = false)
{
return $this->getMockery('Swift_InputByteStream')->shouldIgnoreMissing();
}
}
<?php
class Swift_Mime_EmbeddedFileTest extends Swift_Mime_AttachmentTest
{
public function testNestingLevelIsAttachment()
{
//Overridden
}
public function testNestingLevelIsEmbedded()
{
$file = $this->_createEmbeddedFile($this->_createHeaderSet(),
$this->_createEncoder(), $this->_createCache()
);
$this->assertEquals(
Swift_Mime_MimeEntity::LEVEL_RELATED, $file->getNestingLevel()
);
}
public function testIdIsAutoGenerated()
{
$headers = $this->_createHeaderSet(array(), false);
$headers->shouldReceive('addIdHeader')
->once()
->with('Content-ID', '/^.*?@.*?$/D');
$file = $this->_createEmbeddedFile($headers, $this->_createEncoder(),
$this->_createCache()
);
}
public function testDefaultDispositionIsInline()
{
$headers = $this->_createHeaderSet(array(), false);
$headers->shouldReceive('addParameterizedHeader')
->once()
->with('Content-Disposition', 'inline');
$headers->shouldReceive('addParameterizedHeader')
->zeroOrMoreTimes();
$file = $this->_createEmbeddedFile($headers, $this->_createEncoder(),
$this->_createCache()
);
}
protected function _createAttachment($headers, $encoder, $cache, $mimeTypes = array())
{
return $this->_createEmbeddedFile($headers, $encoder, $cache, $mimeTypes);
}
private function _createEmbeddedFile($headers, $encoder, $cache)
{
return new Swift_Mime_EmbeddedFile($headers, $encoder, $cache, new Swift_Mime_Grammar());
}
}
<?php
class Swift_Mime_HeaderEncoder_Base64HeaderEncoderTest extends \PHPUnit_Framework_TestCase
{
//Most tests are already covered in Base64EncoderTest since this subclass only
// adds a getName() method
public function testNameIsB()
{
$encoder = new Swift_Mime_HeaderEncoder_Base64HeaderEncoder();
$this->assertEquals('B', $encoder->getName());
}
}
<?php
class Swift_Mime_HeaderEncoder_QpHeaderEncoderTest extends \SwiftMailerTestCase
{
//Most tests are already covered in QpEncoderTest since this subclass only
// adds a getName() method
public function testNameIsQ()
{
$encoder = $this->_createEncoder(
$this->_createCharacterStream(true)
);
$this->assertEquals('Q', $encoder->getName());
}
public function testSpaceAndTabNeverAppear()
{
/* -- RFC 2047, 4.
Only a subset of the printable ASCII characters may be used in
'encoded-text'. Space and tab characters are not allowed, so that
the beginning and end of an 'encoded-word' are obvious.
*/
$charStream = $this->_createCharacterStream();
$charStream->shouldReceive('readBytes')
->atLeast()->times(6)
->andReturn(array(ord('a')), array(0x20), array(0x09), array(0x20), array(ord('b')), false);
$encoder = $this->_createEncoder($charStream);
$this->assertNotRegExp('~[ \t]~', $encoder->encodeString("a \t b"),
'%s: encoded-words in headers cannot contain LWSP as per RFC 2047.'
);
}
public function testSpaceIsRepresentedByUnderscore()
{
/* -- RFC 2047, 4.2.
(2) The 8-bit hexadecimal value 20 (e.g., ISO-8859-1 SPACE) may be
represented as "_" (underscore, ASCII 95.). (This character may
not pass through some internetwork mail gateways, but its use
will greatly enhance readability of "Q" encoded data with mail
readers that do not support this encoding.) Note that the "_"
always represents hexadecimal 20, even if the SPACE character
occupies a different code position in the character set in use.
*/
$charStream = $this->_createCharacterStream();
$charStream->shouldReceive('readBytes')
->once()
->andReturn(array(ord('a')));
$charStream->shouldReceive('readBytes')
->once()
->andReturn(array(0x20));
$charStream->shouldReceive('readBytes')
->once()
->andReturn(array(ord('b')));
$charStream->shouldReceive('readBytes')
->zeroOrMoreTimes()
->andReturn(false);
$encoder = $this->_createEncoder($charStream);
$this->assertEquals('a_b', $encoder->encodeString('a b'),
'%s: Spaces can be represented by more readable underscores as per RFC 2047.'
);
}
public function testEqualsAndQuestionAndUnderscoreAreEncoded()
{
/* -- RFC 2047, 4.2.
(3) 8-bit values which correspond to printable ASCII characters other
than "=", "?", and "_" (underscore), MAY be represented as those
characters. (But see section 5 for restrictions.) In
particular, SPACE and TAB MUST NOT be represented as themselves
within encoded words.
*/
$charStream = $this->_createCharacterStream();
$charStream->shouldReceive('readBytes')
->once()
->andReturn(array(ord('=')));
$charStream->shouldReceive('readBytes')
->once()
->andReturn(array(ord('?')));
$charStream->shouldReceive('readBytes')
->once()
->andReturn(array(ord('_')));
$charStream->shouldReceive('readBytes')
->zeroOrMoreTimes()
->andReturn(false);
$encoder = $this->_createEncoder($charStream);
$this->assertEquals('=3D=3F=5F', $encoder->encodeString('=?_'),
'%s: Chars =, ? and _ (underscore) may not appear as per RFC 2047.'
);
}
public function testParensAndQuotesAreEncoded()
{
/* -- RFC 2047, 5 (2).
A "Q"-encoded 'encoded-word' which appears in a 'comment' MUST NOT
contain the characters "(", ")" or "
*/
$charStream = $this->_createCharacterStream();
$charStream->shouldReceive('readBytes')
->once()
->andReturn(array(ord('(')));
$charStream->shouldReceive('readBytes')
->once()
->andReturn(array(ord('"')));
$charStream->shouldReceive('readBytes')
->once()
->andReturn(array(ord(')')));
$charStream->shouldReceive('readBytes')
->zeroOrMoreTimes()
->andReturn(false);
$encoder = $this->_createEncoder($charStream);
$this->assertEquals('=28=22=29', $encoder->encodeString('(")'),
'%s: Chars (, " (DQUOTE) and ) may not appear as per RFC 2047.'
);
}
public function testOnlyCharactersAllowedInPhrasesAreUsed()
{
/* -- RFC 2047, 5.
(3) As a replacement for a 'word' entity within a 'phrase', for example,
one that precedes an address in a From, To, or Cc header. The ABNF
definition for 'phrase' from RFC 822 thus becomes:
phrase = 1*( encoded-word / word )
In this case the set of characters that may be used in a "Q"-encoded
'encoded-word' is restricted to: <upper and lower case ASCII
letters, decimal digits, "!", "*", "+", "-", "/", "=", and "_"
(underscore, ASCII 95.)>. An 'encoded-word' that appears within a
'phrase' MUST be separated from any adjacent 'word', 'text' or
'special' by 'linear-white-space'.
*/
$allowedBytes = array_merge(
range(ord('a'), ord('z')), range(ord('A'), ord('Z')),
range(ord('0'), ord('9')),
array(ord('!'), ord('*'), ord('+'), ord('-'), ord('/'))
);
foreach (range(0x00, 0xFF) as $byte) {
$char = pack('C', $byte);
$charStream = $this->_createCharacterStream();
$charStream->shouldReceive('readBytes')
->once()
->andReturn(array($byte));
$charStream->shouldReceive('readBytes')
->zeroOrMoreTimes()
->andReturn(false);
$encoder = $this->_createEncoder($charStream);
$encodedChar = $encoder->encodeString($char);
if (in_array($byte, $allowedBytes)) {
$this->assertEquals($char, $encodedChar,
'%s: Character '.$char.' should not be encoded.'
);
} elseif (0x20 == $byte) {
//Special case
$this->assertEquals('_', $encodedChar,
'%s: Space character should be replaced.'
);
} else {
$this->assertEquals(sprintf('=%02X', $byte), $encodedChar,
'%s: Byte '.$byte.' should be encoded.'
);
}
}
}
public function testEqualsNeverAppearsAtEndOfLine()
{
/* -- RFC 2047, 5 (3).
The 'encoded-text' in an 'encoded-word' must be self-contained;
'encoded-text' MUST NOT be continued from one 'encoded-word' to
another. This implies that the 'encoded-text' portion of a "B"
'encoded-word' will be a multiple of 4 characters long; for a "Q"
'encoded-word', any "=" character that appears in the 'encoded-text'
portion will be followed by two hexadecimal characters.
*/
$input = str_repeat('a', 140);
$charStream = $this->_createCharacterStream();
$output = '';
$seq = 0;
for (; $seq < 140; ++$seq) {
$charStream->shouldReceive('readBytes')
->once()
->andReturn(array(ord('a')));
if (75 == $seq) {
$output .= "\r\n"; // =\r\n
}
$output .= 'a';
}
$charStream->shouldReceive('readBytes')
->zeroOrMoreTimes()
->andReturn(false);
$encoder = $this->_createEncoder($charStream);
$this->assertEquals($output, $encoder->encodeString($input));
}
private function _createEncoder($charStream)
{
return new Swift_Mime_HeaderEncoder_QpHeaderEncoder($charStream);
}
private function _createCharacterStream($stub = false)
{
return $this->getMockery('Swift_CharacterStream')->shouldIgnoreMissing();
}
}
<?php
class Swift_Mime_Headers_DateHeaderTest extends \PHPUnit_Framework_TestCase
{
/* --
The following tests refer to RFC 2822, section 3.6.1 and 3.3.
*/
public function testTypeIsDateHeader()
{
$header = $this->_getHeader('Date');
$this->assertEquals(Swift_Mime_Header::TYPE_DATE, $header->getFieldType());
}
public function testGetTimestamp()
{
$timestamp = time();
$header = $this->_getHeader('Date');
$header->setTimestamp($timestamp);
$this->assertSame($timestamp, $header->getTimestamp());
}
public function testTimestampCanBeSetBySetter()
{
$timestamp = time();
$header = $this->_getHeader('Date');
$header->setTimestamp($timestamp);
$this->assertSame($timestamp, $header->getTimestamp());
}
public function testIntegerTimestampIsConvertedToRfc2822Date()
{
$timestamp = time();
$header = $this->_getHeader('Date');
$header->setTimestamp($timestamp);
$this->assertEquals(date('r', $timestamp), $header->getFieldBody());
}
public function testSetBodyModel()
{
$timestamp = time();
$header = $this->_getHeader('Date');
$header->setFieldBodyModel($timestamp);
$this->assertEquals(date('r', $timestamp), $header->getFieldBody());
}
public function testGetBodyModel()
{
$timestamp = time();
$header = $this->_getHeader('Date');
$header->setTimestamp($timestamp);
$this->assertEquals($timestamp, $header->getFieldBodyModel());
}
public function testToString()
{
$timestamp = time();
$header = $this->_getHeader('Date');
$header->setTimestamp($timestamp);
$this->assertEquals('Date: '.date('r', $timestamp)."\r\n",
$header->toString()
);
}
private function _getHeader($name)
{
return new Swift_Mime_Headers_DateHeader($name, new Swift_Mime_Grammar());
}
}
<?php
class Swift_Mime_Headers_IdentificationHeaderTest extends \PHPUnit_Framework_TestCase
{
public function testTypeIsIdHeader()
{
$header = $this->_getHeader('Message-ID');
$this->assertEquals(Swift_Mime_Header::TYPE_ID, $header->getFieldType());
}
public function testValueMatchesMsgIdSpec()
{
/* -- RFC 2822, 3.6.4.
message-id = "Message-ID:" msg-id CRLF
in-reply-to = "In-Reply-To:" 1*msg-id CRLF
references = "References:" 1*msg-id CRLF
msg-id = [CFWS] "<" id-left "@" id-right ">" [CFWS]
id-left = dot-atom-text / no-fold-quote / obs-id-left
id-right = dot-atom-text / no-fold-literal / obs-id-right
no-fold-quote = DQUOTE *(qtext / quoted-pair) DQUOTE
no-fold-literal = "[" *(dtext / quoted-pair) "]"
*/
$header = $this->_getHeader('Message-ID');
$header->setId('id-left@id-right');
$this->assertEquals('<id-left@id-right>', $header->getFieldBody());
}
public function testIdCanBeRetrievedVerbatim()
{
$header = $this->_getHeader('Message-ID');
$header->setId('id-left@id-right');
$this->assertEquals('id-left@id-right', $header->getId());
}
public function testMultipleIdsCanBeSet()
{
$header = $this->_getHeader('References');
$header->setIds(array('a@b', 'x@y'));
$this->assertEquals(array('a@b', 'x@y'), $header->getIds());
}
public function testSettingMultipleIdsProducesAListValue()
{
/* -- RFC 2822, 3.6.4.
The "References:" and "In-Reply-To:" field each contain one or more
unique message identifiers, optionally separated by CFWS.
.. SNIP ..
in-reply-to = "In-Reply-To:" 1*msg-id CRLF
references = "References:" 1*msg-id CRLF
*/
$header = $this->_getHeader('References');
$header->setIds(array('a@b', 'x@y'));
$this->assertEquals('<a@b> <x@y>', $header->getFieldBody());
}
public function testIdLeftCanBeQuoted()
{
/* -- RFC 2822, 3.6.4.
id-left = dot-atom-text / no-fold-quote / obs-id-left
*/
$header = $this->_getHeader('References');
$header->setId('"ab"@c');
$this->assertEquals('"ab"@c', $header->getId());
$this->assertEquals('<"ab"@c>', $header->getFieldBody());
}
public function testIdLeftCanContainAnglesAsQuotedPairs()
{
/* -- RFC 2822, 3.6.4.
no-fold-quote = DQUOTE *(qtext / quoted-pair) DQUOTE
*/
$header = $this->_getHeader('References');
$header->setId('"a\\<\\>b"@c');
$this->assertEquals('"a\\<\\>b"@c', $header->getId());
$this->assertEquals('<"a\\<\\>b"@c>', $header->getFieldBody());
}
public function testIdLeftCanBeDotAtom()
{
$header = $this->_getHeader('References');
$header->setId('a.b+&%$.c@d');
$this->assertEquals('a.b+&%$.c@d', $header->getId());
$this->assertEquals('<a.b+&%$.c@d>', $header->getFieldBody());
}
public function testInvalidIdLeftThrowsException()
{
try {
$header = $this->_getHeader('References');
$header->setId('a b c@d');
$this->fail(
'Exception should be thrown since "a b c" is not valid id-left.'
);
} catch (Exception $e) {
}
}
public function testIdRightCanBeDotAtom()
{
/* -- RFC 2822, 3.6.4.
id-right = dot-atom-text / no-fold-literal / obs-id-right
*/
$header = $this->_getHeader('References');
$header->setId('a@b.c+&%$.d');
$this->assertEquals('a@b.c+&%$.d', $header->getId());
$this->assertEquals('<a@b.c+&%$.d>', $header->getFieldBody());
}
public function testIdRightCanBeLiteral()
{
/* -- RFC 2822, 3.6.4.
no-fold-literal = "[" *(dtext / quoted-pair) "]"
*/
$header = $this->_getHeader('References');
$header->setId('a@[1.2.3.4]');
$this->assertEquals('a@[1.2.3.4]', $header->getId());
$this->assertEquals('<a@[1.2.3.4]>', $header->getFieldBody());
}
public function testInvalidIdRightThrowsException()
{
try {
$header = $this->_getHeader('References');
$header->setId('a@b c d');
$this->fail(
'Exception should be thrown since "b c d" is not valid id-right.'
);
} catch (Exception $e) {
}
}
public function testMissingAtSignThrowsException()
{
/* -- RFC 2822, 3.6.4.
msg-id = [CFWS] "<" id-left "@" id-right ">" [CFWS]
*/
try {
$header = $this->_getHeader('References');
$header->setId('abc');
$this->fail(
'Exception should be thrown since "abc" is does not contain @.'
);
} catch (Exception $e) {
}
}
public function testSetBodyModel()
{
$header = $this->_getHeader('Message-ID');
$header->setFieldBodyModel('a@b');
$this->assertEquals(array('a@b'), $header->getIds());
}
public function testGetBodyModel()
{
$header = $this->_getHeader('Message-ID');
$header->setId('a@b');
$this->assertEquals(array('a@b'), $header->getFieldBodyModel());
}
public function testStringValue()
{
$header = $this->_getHeader('References');
$header->setIds(array('a@b', 'x@y'));
$this->assertEquals('References: <a@b> <x@y>'."\r\n", $header->toString());
}
private function _getHeader($name)
{
return new Swift_Mime_Headers_IdentificationHeader($name, new Swift_Mime_Grammar());
}
}
<?php
class Swift_Mime_Headers_MailboxHeaderTest extends \SwiftMailerTestCase
{
/* -- RFC 2822, 3.6.2 for all tests.
*/
private $_charset = 'utf-8';
public function testTypeIsMailboxHeader()
{
$header = $this->_getHeader('To', $this->_getEncoder('Q', true));
$this->assertEquals(Swift_Mime_Header::TYPE_MAILBOX, $header->getFieldType());
}
public function testMailboxIsSetForAddress()
{
$header = $this->_getHeader('From', $this->_getEncoder('Q', true));
$header->setAddresses('chris@swiftmailer.org');
$this->assertEquals(array('chris@swiftmailer.org'),
$header->getNameAddressStrings()
);
}
public function testMailboxIsRenderedForNameAddress()
{
$header = $this->_getHeader('From', $this->_getEncoder('Q', true));
$header->setNameAddresses(array('chris@swiftmailer.org' => 'Chris Corbyn'));
$this->assertEquals(
array('Chris Corbyn <chris@swiftmailer.org>'), $header->getNameAddressStrings()
);
}
public function testAddressCanBeReturnedForAddress()
{
$header = $this->_getHeader('From', $this->_getEncoder('Q', true));
$header->setAddresses('chris@swiftmailer.org');
$this->assertEquals(array('chris@swiftmailer.org'), $header->getAddresses());
}
public function testAddressCanBeReturnedForNameAddress()
{
$header = $this->_getHeader('From', $this->_getEncoder('Q', true));
$header->setNameAddresses(array('chris@swiftmailer.org' => 'Chris Corbyn'));
$this->assertEquals(array('chris@swiftmailer.org'), $header->getAddresses());
}
public function testQuotesInNameAreQuoted()
{
$header = $this->_getHeader('From', $this->_getEncoder('Q', true));
$header->setNameAddresses(array(
'chris@swiftmailer.org' => 'Chris Corbyn, "DHE"',
));
$this->assertEquals(
array('"Chris Corbyn, \"DHE\"" <chris@swiftmailer.org>'),
$header->getNameAddressStrings()
);
}
public function testEscapeCharsInNameAreQuoted()
{
$header = $this->_getHeader('From', $this->_getEncoder('Q', true));
$header->setNameAddresses(array(
'chris@swiftmailer.org' => 'Chris Corbyn, \\escaped\\',
));
$this->assertEquals(
array('"Chris Corbyn, \\\\escaped\\\\" <chris@swiftmailer.org>'),
$header->getNameAddressStrings()
);
}
public function testGetMailboxesReturnsNameValuePairs()
{
$header = $this->_getHeader('From', $this->_getEncoder('Q', true));
$header->setNameAddresses(array(
'chris@swiftmailer.org' => 'Chris Corbyn, DHE',
));
$this->assertEquals(
array('chris@swiftmailer.org' => 'Chris Corbyn, DHE'), $header->getNameAddresses()
);
}
public function testMultipleAddressesCanBeSetAndFetched()
{
$header = $this->_getHeader('From', $this->_getEncoder('Q', true));
$header->setAddresses(array(
'chris@swiftmailer.org', 'mark@swiftmailer.org',
));
$this->assertEquals(
array('chris@swiftmailer.org', 'mark@swiftmailer.org'),
$header->getAddresses()
);
}
public function testMultipleAddressesAsMailboxes()
{
$header = $this->_getHeader('From', $this->_getEncoder('Q', true));
$header->setAddresses(array(
'chris@swiftmailer.org', 'mark@swiftmailer.org',
));
$this->assertEquals(
array('chris@swiftmailer.org' => null, 'mark@swiftmailer.org' => null),
$header->getNameAddresses()
);
}
public function testMultipleAddressesAsMailboxStrings()
{
$header = $this->_getHeader('From', $this->_getEncoder('Q', true));
$header->setAddresses(array(
'chris@swiftmailer.org', 'mark@swiftmailer.org',
));
$this->assertEquals(
array('chris@swiftmailer.org', 'mark@swiftmailer.org'),
$header->getNameAddressStrings()
);
}
public function testMultipleNamedMailboxesReturnsMultipleAddresses()
{
$header = $this->_getHeader('From', $this->_getEncoder('Q', true));
$header->setNameAddresses(array(
'chris@swiftmailer.org' => 'Chris Corbyn',
'mark@swiftmailer.org' => 'Mark Corbyn',
));
$this->assertEquals(
array('chris@swiftmailer.org', 'mark@swiftmailer.org'),
$header->getAddresses()
);
}
public function testMultipleNamedMailboxesReturnsMultipleMailboxes()
{
$header = $this->_getHeader('From', $this->_getEncoder('Q', true));
$header->setNameAddresses(array(
'chris@swiftmailer.org' => 'Chris Corbyn',
'mark@swiftmailer.org' => 'Mark Corbyn',
));
$this->assertEquals(array(
'chris@swiftmailer.org' => 'Chris Corbyn',
'mark@swiftmailer.org' => 'Mark Corbyn',
),
$header->getNameAddresses()
);
}
public function testMultipleMailboxesProducesMultipleMailboxStrings()
{
$header = $this->_getHeader('From', $this->_getEncoder('Q', true));
$header->setNameAddresses(array(
'chris@swiftmailer.org' => 'Chris Corbyn',
'mark@swiftmailer.org' => 'Mark Corbyn',
));
$this->assertEquals(array(
'Chris Corbyn <chris@swiftmailer.org>',
'Mark Corbyn <mark@swiftmailer.org>',
),
$header->getNameAddressStrings()
);
}
public function testSetAddressesOverwritesAnyMailboxes()
{
$header = $this->_getHeader('From', $this->_getEncoder('Q', true));
$header->setNameAddresses(array(
'chris@swiftmailer.org' => 'Chris Corbyn',
'mark@swiftmailer.org' => 'Mark Corbyn',
));
$this->assertEquals(
array('chris@swiftmailer.org' => 'Chris Corbyn',
'mark@swiftmailer.org' => 'Mark Corbyn', ),
$header->getNameAddresses()
);
$this->assertEquals(
array('chris@swiftmailer.org', 'mark@swiftmailer.org'),
$header->getAddresses()
);
$header->setAddresses(array('chris@swiftmailer.org', 'mark@swiftmailer.org'));
$this->assertEquals(
array('chris@swiftmailer.org' => null, 'mark@swiftmailer.org' => null),
$header->getNameAddresses()
);
$this->assertEquals(
array('chris@swiftmailer.org', 'mark@swiftmailer.org'),
$header->getAddresses()
);
}
public function testNameIsEncodedIfNonAscii()
{
$name = 'C'.pack('C', 0x8F).'rbyn';
$encoder = $this->_getEncoder('Q');
$encoder->shouldReceive('encodeString')
->once()
->with($name, \Mockery::any(), \Mockery::any(), \Mockery::any())
->andReturn('C=8Frbyn');
$header = $this->_getHeader('From', $encoder);
$header->setNameAddresses(array('chris@swiftmailer.org' => 'Chris '.$name));
$addresses = $header->getNameAddressStrings();
$this->assertEquals(
'Chris =?'.$this->_charset.'?Q?C=8Frbyn?= <chris@swiftmailer.org>',
array_shift($addresses)
);
}
public function testEncodingLineLengthCalculations()
{
/* -- RFC 2047, 2.
An 'encoded-word' may not be more than 75 characters long, including
'charset', 'encoding', 'encoded-text', and delimiters.
*/
$name = 'C'.pack('C', 0x8F).'rbyn';
$encoder = $this->_getEncoder('Q');
$encoder->shouldReceive('encodeString')
->once()
->with($name, \Mockery::any(), \Mockery::any(), \Mockery::any())
->andReturn('C=8Frbyn');
$header = $this->_getHeader('From', $encoder);
$header->setNameAddresses(array('chris@swiftmailer.org' => 'Chris '.$name));
$header->getNameAddressStrings();
}
public function testGetValueReturnsMailboxStringValue()
{
$header = $this->_getHeader('From', $this->_getEncoder('Q', true));
$header->setNameAddresses(array(
'chris@swiftmailer.org' => 'Chris Corbyn',
));
$this->assertEquals(
'Chris Corbyn <chris@swiftmailer.org>', $header->getFieldBody()
);
}
public function testGetValueReturnsMailboxStringValueForMultipleMailboxes()
{
$header = $this->_getHeader('From', $this->_getEncoder('Q', true));
$header->setNameAddresses(array(
'chris@swiftmailer.org' => 'Chris Corbyn',
'mark@swiftmailer.org' => 'Mark Corbyn',
));
$this->assertEquals(
'Chris Corbyn <chris@swiftmailer.org>, Mark Corbyn <mark@swiftmailer.org>',
$header->getFieldBody()
);
}
public function testRemoveAddressesWithSingleValue()
{
$header = $this->_getHeader('From', $this->_getEncoder('Q', true));
$header->setNameAddresses(array(
'chris@swiftmailer.org' => 'Chris Corbyn',
'mark@swiftmailer.org' => 'Mark Corbyn',
));
$header->removeAddresses('chris@swiftmailer.org');
$this->assertEquals(array('mark@swiftmailer.org'),
$header->getAddresses()
);
}
public function testRemoveAddressesWithList()
{
$header = $this->_getHeader('From', $this->_getEncoder('Q', true));
$header->setNameAddresses(array(
'chris@swiftmailer.org' => 'Chris Corbyn',
'mark@swiftmailer.org' => 'Mark Corbyn',
));
$header->removeAddresses(
array('chris@swiftmailer.org', 'mark@swiftmailer.org')
);
$this->assertEquals(array(), $header->getAddresses());
}
public function testSetBodyModel()
{
$header = $this->_getHeader('From', $this->_getEncoder('Q', true));
$header->setFieldBodyModel('chris@swiftmailer.org');
$this->assertEquals(array('chris@swiftmailer.org' => null), $header->getNameAddresses());
}
public function testGetBodyModel()
{
$header = $this->_getHeader('From', $this->_getEncoder('Q', true));
$header->setAddresses(array('chris@swiftmailer.org'));
$this->assertEquals(array('chris@swiftmailer.org' => null), $header->getFieldBodyModel());
}
public function testToString()
{
$header = $this->_getHeader('From', $this->_getEncoder('Q', true));
$header->setNameAddresses(array(
'chris@swiftmailer.org' => 'Chris Corbyn',
'mark@swiftmailer.org' => 'Mark Corbyn',
));
$this->assertEquals(
'From: Chris Corbyn <chris@swiftmailer.org>, '.
'Mark Corbyn <mark@swiftmailer.org>'."\r\n",
$header->toString()
);
}
private function _getHeader($name, $encoder)
{
$header = new Swift_Mime_Headers_MailboxHeader($name, $encoder, new Swift_Mime_Grammar());
$header->setCharset($this->_charset);
return $header;
}
private function _getEncoder($type, $stub = false)
{
$encoder = $this->getMockery('Swift_Mime_HeaderEncoder')->shouldIgnoreMissing();
$encoder->shouldReceive('getName')
->zeroOrMoreTimes()
->andReturn($type);
return $encoder;
}
}
<?php
class Swift_Mime_Headers_ParameterizedHeaderTest extends \SwiftMailerTestCase
{
private $_charset = 'utf-8';
private $_lang = 'en-us';
public function testTypeIsParameterizedHeader()
{
$header = $this->_getHeader('Content-Type',
$this->_getHeaderEncoder('Q', true), $this->_getParameterEncoder(true)
);
$this->assertEquals(Swift_Mime_Header::TYPE_PARAMETERIZED, $header->getFieldType());
}
public function testValueIsReturnedVerbatim()
{
$header = $this->_getHeader('Content-Type',
$this->_getHeaderEncoder('Q', true), $this->_getParameterEncoder(true)
);
$header->setValue('text/plain');
$this->assertEquals('text/plain', $header->getValue());
}
public function testParametersAreAppended()
{
/* -- RFC 2045, 5.1
parameter := attribute "=" value
attribute := token
; Matching of attributes
; is ALWAYS case-insensitive.
value := token / quoted-string
token := 1*<any (US-ASCII) CHAR except SPACE, CTLs,
or tspecials>
tspecials := "(" / ")" / "<" / ">" / "@" /
"," / ";" / ":" / "\" / <">
"/" / "[" / "]" / "?" / "="
; Must be in quoted-string,
; to use within parameter values
*/
$header = $this->_getHeader('Content-Type',
$this->_getHeaderEncoder('Q', true), $this->_getParameterEncoder(true)
);
$header->setValue('text/plain');
$header->setParameters(array('charset' => 'utf-8'));
$this->assertEquals('text/plain; charset=utf-8', $header->getFieldBody());
}
public function testSpaceInParamResultsInQuotedString()
{
$header = $this->_getHeader('Content-Disposition',
$this->_getHeaderEncoder('Q', true), $this->_getParameterEncoder(true)
);
$header->setValue('attachment');
$header->setParameters(array('filename' => 'my file.txt'));
$this->assertEquals('attachment; filename="my file.txt"',
$header->getFieldBody()
);
}
public function testLongParamsAreBrokenIntoMultipleAttributeStrings()
{
/* -- RFC 2231, 3.
The asterisk character ("*") followed
by a decimal count is employed to indicate that multiple parameters
are being used to encapsulate a single parameter value. The count
starts at 0 and increments by 1 for each subsequent section of the
parameter value. Decimal values are used and neither leading zeroes
nor gaps in the sequence are allowed.
The original parameter value is recovered by concatenating the
various sections of the parameter, in order. For example, the
content-type field
Content-Type: message/external-body; access-type=URL;
URL*0="ftp://";
URL*1="cs.utk.edu/pub/moore/bulk-mailer/bulk-mailer.tar"
is semantically identical to
Content-Type: message/external-body; access-type=URL;
URL="ftp://cs.utk.edu/pub/moore/bulk-mailer/bulk-mailer.tar"
Note that quotes around parameter values are part of the value
syntax; they are NOT part of the value itself. Furthermore, it is
explicitly permitted to have a mixture of quoted and unquoted
continuation fields.
*/
$value = str_repeat('a', 180);
$encoder = $this->_getParameterEncoder();
$encoder->shouldReceive('encodeString')
->once()
->with($value, \Mockery::any(), 63, \Mockery::any())
->andReturn(str_repeat('a', 63)."\r\n".
str_repeat('a', 63)."\r\n".str_repeat('a', 54));
$header = $this->_getHeader('Content-Disposition',
$this->_getHeaderEncoder('Q', true), $encoder
);
$header->setValue('attachment');
$header->setParameters(array('filename' => $value));
$header->setMaxLineLength(78);
$this->assertEquals(
'attachment; '.
'filename*0*=utf-8\'\''.str_repeat('a', 63).";\r\n ".
'filename*1*='.str_repeat('a', 63).";\r\n ".
'filename*2*='.str_repeat('a', 54),
$header->getFieldBody()
);
}
public function testEncodedParamDataIncludesCharsetAndLanguage()
{
/* -- RFC 2231, 4.
Asterisks ("*") are reused to provide the indicator that language and
character set information is present and encoding is being used. A
single quote ("'") is used to delimit the character set and language
information at the beginning of the parameter value. Percent signs
("%") are used as the encoding flag, which agrees with RFC 2047.
Specifically, an asterisk at the end of a parameter name acts as an
indicator that character set and language information may appear at
the beginning of the parameter value. A single quote is used to
separate the character set, language, and actual value information in
the parameter value string, and an percent sign is used to flag
octets encoded in hexadecimal. For example:
Content-Type: application/x-stuff;
title*=us-ascii'en-us'This%20is%20%2A%2A%2Afun%2A%2A%2A
Note that it is perfectly permissible to leave either the character
set or language field blank. Note also that the single quote
delimiters MUST be present even when one of the field values is
omitted.
*/
$value = str_repeat('a', 20).pack('C', 0x8F).str_repeat('a', 10);
$encoder = $this->_getParameterEncoder();
$encoder->shouldReceive('encodeString')
->once()
->with($value, 12, 62, \Mockery::any())
->andReturn(str_repeat('a', 20).'%8F'.str_repeat('a', 10));
$header = $this->_getHeader('Content-Disposition',
$this->_getHeaderEncoder('Q', true), $encoder
);
$header->setValue('attachment');
$header->setParameters(array('filename' => $value));
$header->setMaxLineLength(78);
$header->setLanguage($this->_lang);
$this->assertEquals(
'attachment; filename*='.$this->_charset."'".$this->_lang."'".
str_repeat('a', 20).'%8F'.str_repeat('a', 10),
$header->getFieldBody()
);
}
public function testMultipleEncodedParamLinesAreFormattedCorrectly()
{
/* -- RFC 2231, 4.1.
Character set and language information may be combined with the
parameter continuation mechanism. For example:
Content-Type: application/x-stuff
title*0*=us-ascii'en'This%20is%20even%20more%20
title*1*=%2A%2A%2Afun%2A%2A%2A%20
title*2="isn't it!"
Note that:
(1) Language and character set information only appear at
the beginning of a given parameter value.
(2) Continuations do not provide a facility for using more
than one character set or language in the same
parameter value.
(3) A value presented using multiple continuations may
contain a mixture of encoded and unencoded segments.
(4) The first segment of a continuation MUST be encoded if
language and character set information are given.
(5) If the first segment of a continued parameter value is
encoded the language and character set field delimiters
MUST be present even when the fields are left blank.
*/
$value = str_repeat('a', 20).pack('C', 0x8F).str_repeat('a', 60);
$encoder = $this->_getParameterEncoder();
$encoder->shouldReceive('encodeString')
->once()
->with($value, 12, 62, \Mockery::any())
->andReturn(str_repeat('a', 20).'%8F'.str_repeat('a', 28)."\r\n".
str_repeat('a', 32));
$header = $this->_getHeader('Content-Disposition',
$this->_getHeaderEncoder('Q', true), $encoder
);
$header->setValue('attachment');
$header->setParameters(array('filename' => $value));
$header->setMaxLineLength(78);
$header->setLanguage($this->_lang);
$this->assertEquals(
'attachment; filename*0*='.$this->_charset."'".$this->_lang."'".
str_repeat('a', 20).'%8F'.str_repeat('a', 28).";\r\n ".
'filename*1*='.str_repeat('a', 32),
$header->getFieldBody()
);
}
public function testToString()
{
$header = $this->_getHeader('Content-Type',
$this->_getHeaderEncoder('Q', true), $this->_getParameterEncoder(true)
);
$header->setValue('text/html');
$header->setParameters(array('charset' => 'utf-8'));
$this->assertEquals('Content-Type: text/html; charset=utf-8'."\r\n",
$header->toString()
);
}
public function testValueCanBeEncodedIfNonAscii()
{
$value = 'fo'.pack('C', 0x8F).'bar';
$encoder = $this->_getHeaderEncoder('Q');
$encoder->shouldReceive('encodeString')
->once()
->with($value, \Mockery::any(), \Mockery::any(), \Mockery::any())
->andReturn('fo=8Fbar');
$header = $this->_getHeader('X-Foo', $encoder, $this->_getParameterEncoder(true));
$header->setValue($value);
$header->setParameters(array('lookslike' => 'foobar'));
$this->assertEquals('X-Foo: =?utf-8?Q?fo=8Fbar?=; lookslike=foobar'."\r\n",
$header->toString()
);
}
public function testValueAndParamCanBeEncodedIfNonAscii()
{
$value = 'fo'.pack('C', 0x8F).'bar';
$encoder = $this->_getHeaderEncoder('Q');
$encoder->shouldReceive('encodeString')
->once()
->with($value, \Mockery::any(), \Mockery::any(), \Mockery::any())
->andReturn('fo=8Fbar');
$paramEncoder = $this->_getParameterEncoder();
$paramEncoder->shouldReceive('encodeString')
->once()
->with($value, \Mockery::any(), \Mockery::any(), \Mockery::any())
->andReturn('fo%8Fbar');
$header = $this->_getHeader('X-Foo', $encoder, $paramEncoder);
$header->setValue($value);
$header->setParameters(array('says' => $value));
$this->assertEquals("X-Foo: =?utf-8?Q?fo=8Fbar?=; says*=utf-8''fo%8Fbar\r\n",
$header->toString()
);
}
public function testParamsAreEncodedWithEncodedWordsIfNoParamEncoderSet()
{
$value = 'fo'.pack('C', 0x8F).'bar';
$encoder = $this->_getHeaderEncoder('Q');
$encoder->shouldReceive('encodeString')
->once()
->with($value, \Mockery::any(), \Mockery::any(), \Mockery::any())
->andReturn('fo=8Fbar');
$header = $this->_getHeader('X-Foo', $encoder, null);
$header->setValue('bar');
$header->setParameters(array('says' => $value));
$this->assertEquals("X-Foo: bar; says=\"=?utf-8?Q?fo=8Fbar?=\"\r\n",
$header->toString()
);
}
public function testLanguageInformationAppearsInEncodedWords()
{
/* -- RFC 2231, 5.
5. Language specification in Encoded Words
RFC 2047 provides support for non-US-ASCII character sets in RFC 822
message header comments, phrases, and any unstructured text field.
This is done by defining an encoded word construct which can appear
in any of these places. Given that these are fields intended for
display, it is sometimes necessary to associate language information
with encoded words as well as just the character set. This
specification extends the definition of an encoded word to allow the
inclusion of such information. This is simply done by suffixing the
character set specification with an asterisk followed by the language
tag. For example:
From: =?US-ASCII*EN?Q?Keith_Moore?= <moore@cs.utk.edu>
*/
$value = 'fo'.pack('C', 0x8F).'bar';
$encoder = $this->_getHeaderEncoder('Q');
$encoder->shouldReceive('encodeString')
->once()
->with($value, \Mockery::any(), \Mockery::any(), \Mockery::any())
->andReturn('fo=8Fbar');
$paramEncoder = $this->_getParameterEncoder();
$paramEncoder->shouldReceive('encodeString')
->once()
->with($value, \Mockery::any(), \Mockery::any(), \Mockery::any())
->andReturn('fo%8Fbar');
$header = $this->_getHeader('X-Foo', $encoder, $paramEncoder);
$header->setLanguage('en');
$header->setValue($value);
$header->setParameters(array('says' => $value));
$this->assertEquals("X-Foo: =?utf-8*en?Q?fo=8Fbar?=; says*=utf-8'en'fo%8Fbar\r\n",
$header->toString()
);
}
public function testSetBodyModel()
{
$header = $this->_getHeader('Content-Type',
$this->_getHeaderEncoder('Q', true), $this->_getParameterEncoder(true)
);
$header->setFieldBodyModel('text/html');
$this->assertEquals('text/html', $header->getValue());
}
public function testGetBodyModel()
{
$header = $this->_getHeader('Content-Type',
$this->_getHeaderEncoder('Q', true), $this->_getParameterEncoder(true)
);
$header->setValue('text/plain');
$this->assertEquals('text/plain', $header->getFieldBodyModel());
}
public function testSetParameter()
{
$header = $this->_getHeader('Content-Type',
$this->_getHeaderEncoder('Q', true), $this->_getParameterEncoder(true)
);
$header->setParameters(array('charset' => 'utf-8', 'delsp' => 'yes'));
$header->setParameter('delsp', 'no');
$this->assertEquals(array('charset' => 'utf-8', 'delsp' => 'no'),
$header->getParameters()
);
}
public function testGetParameter()
{
$header = $this->_getHeader('Content-Type',
$this->_getHeaderEncoder('Q', true), $this->_getParameterEncoder(true)
);
$header->setParameters(array('charset' => 'utf-8', 'delsp' => 'yes'));
$this->assertEquals('utf-8', $header->getParameter('charset'));
}
private function _getHeader($name, $encoder, $paramEncoder)
{
$header = new Swift_Mime_Headers_ParameterizedHeader($name, $encoder,
$paramEncoder, new Swift_Mime_Grammar()
);
$header->setCharset($this->_charset);
return $header;
}
private function _getHeaderEncoder($type, $stub = false)
{
$encoder = $this->getMockery('Swift_Mime_HeaderEncoder')->shouldIgnoreMissing();
$encoder->shouldReceive('getName')
->zeroOrMoreTimes()
->andReturn($type);
return $encoder;
}
private function _getParameterEncoder($stub = false)
{
return $this->getMockery('Swift_Encoder')->shouldIgnoreMissing();
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment