N°1285 & N°1278: Updated swiftmailer to v5.4.9

SVN:trunk[5754]
This commit is contained in:
Stephen Abello
2018-04-27 14:06:51 +00:00
parent 76759f1847
commit d956682b9f
172 changed files with 2102 additions and 2051 deletions

View File

@@ -1,6 +1,108 @@
Changelog
=========
5.4.9 (2018-01-23)
------------------
* no changes, last version of the 5.x series
5.4.8 (2017-05-01)
------------------
* fixed encoding inheritance in addPart()
* fixed sorting MIME children when their types are equal
5.4.7 (2017-04-20)
------------------
* fixed NTLMAuthenticator clobbering bcmath scale
5.4.6 (2017-02-13)
------------------
* removed exceptions thrown in destructors as they lead to fatal errors
* switched to use sha256 by default in DKIM as per the RFC
* fixed an 'Undefined variable: pipes' PHP notice
* fixed long To headers when using the mail transport
* fixed NTLMAuthenticator when no domain is passed with the username
* prevented fatal error during unserialization of a message
* fixed a PHP warning when sending a message that has a length of a multiple of 8192
5.4.5 (2016-12-29)
------------------
* SECURITY FIX: fixed CVE-2016-10074 by disallowing potentially unsafe shell characters
Prior to 5.4.5, the mail transport (Swift_Transport_MailTransport) was vulnerable to passing
arbitrary shell arguments if the "From", "ReturnPath" or "Sender" header came
from a non-trusted source, potentially allowing Remote Code Execution
* deprecated the mail transport
5.4.4 (2016-11-23)
------------------
* reverted escaping command-line args to mail (PHP mail() function already does it)
5.4.3 (2016-07-08)
------------------
* fixed SimpleHeaderSet::has()/get() when the 0 index is removed
* removed the need to have mcrypt installed
* fixed broken MIME header encoding with quotes/colons and non-ascii chars
* allowed mail transport send for messages without To header
* fixed PHP 7 support
5.4.2 (2016-05-01)
------------------
* fixed support for IPv6 sockets
* added auto-retry when sending messages from the memory spool
* fixed consecutive read calls in Swift_ByteStream_FileByteStream
* added support for iso-8859-15 encoding
* fixed PHP mail extra params on missing reversePath
* added methods to set custom stream context options
* fixed charset changes in QpContentEncoderProxy
* added return-path header to the ignoredHeaders list of DKIMSigner
* fixed crlf for subject using mail
* fixed add soft line break only when necessary
* fixed escaping command-line args to mail
5.4.1 (2015-06-06)
------------------
* made Swiftmailer exceptions confirm to PHP base exception constructor signature
* fixed MAIL FROM & RCPT TO headers to be RFC compliant
5.4.0 (2015-03-14)
------------------
* added the possibility to add extra certs to PKCS#7 signature
* fix base64 encoding with streams
* added a new RESULT_SPOOLED status for SpoolTransport
* fixed getBody() on attachments when called more than once
* removed dots from generated filenames in filespool
5.3.1 (2014-12-05)
------------------
* fixed cloning of messages with attachments
5.3.0 (2014-10-04)
------------------
* fixed cloning when using signers
* reverted removal of Swift_Encoding
* drop support for PHP 5.2.x
5.2.2 (2014-09-20)
------------------
* fixed Japanese support
* fixed the memory spool when the message changes when in the pool
* added support for cloning messages
* fixed PHP warning in the redirect plugin
* changed the way to and cc-ed email are sent to only use one transaction
5.2.1 (2014-06-13)
------------------

View File

@@ -1,4 +1,4 @@
Copyright (c) 2013 Fabien Potencier
Copyright (c) 2013-2016 Fabien Potencier
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal

View File

@@ -4,9 +4,8 @@ Swift Mailer
Swift Mailer is a component based mailing solution for PHP 5.
It is released under the MIT license.
Homepage: http://swiftmailer.org
Documentation: http://swiftmailer.org/docs
Mailing List: http://groups.google.com/group/swiftmailer
Homepage: https://swiftmailer.symfony.com/
Documentation: https://swiftmailer.symfony.com/docs/introduction.html
Bugs: https://github.com/swiftmailer/swiftmailer/issues
Repository: https://github.com/swiftmailer/swiftmailer

View File

@@ -1 +1 @@
Swift-5.2.1
Swift-5.4.9

View File

@@ -11,18 +11,17 @@
/**
* General utility class in Swift Mailer, not to be instantiated.
*
* @package Swift
*
* @author Chris Corbyn
*/
abstract class Swift
{
public static $initialized = false;
public static $inits = array();
/** Swift Mailer Version number generated during dist release process */
const VERSION = '@SWIFT_VERSION_NUMBER@';
public static $initialized = false;
public static $inits = array();
/**
* Registers an initializer callable that will be called the first time
* a SwiftMailer class is autoloaded.
@@ -48,7 +47,7 @@ abstract class Swift
return;
}
$path = dirname(__FILE__).'/'.str_replace('_', '/', $class).'.php';
$path = __DIR__.'/'.str_replace('_', '/', $class).'.php';
if (!file_exists($path)) {
return;

View File

@@ -11,9 +11,7 @@
/**
* Attachment class for attaching files to a {@link Swift_Mime_Message}.
*
* @package Swift
* @subpackage Mime
* @author Chris Corbyn
* @author Chris Corbyn
*/
class Swift_Attachment extends Swift_Mime_Attachment
{

View File

@@ -11,9 +11,7 @@
/**
* Provides the base functionality for an InputStream supporting filters.
*
* @package Swift
* @subpackage ByteStream
* @author Chris Corbyn
* @author Chris Corbyn
*/
abstract class Swift_ByteStream_AbstractFilterableInputStream implements Swift_InputByteStream, Swift_Filterable
{
@@ -24,6 +22,8 @@ abstract class Swift_ByteStream_AbstractFilterableInputStream implements Swift_I
/**
* StreamFilters.
*
* @var Swift_StreamFilter[]
*/
private $_filters = array();
@@ -77,9 +77,9 @@ abstract class Swift_ByteStream_AbstractFilterableInputStream implements Swift_I
*
* @param string $bytes
*
* @return int
*
* @throws Swift_IoException
*
* @return int
*/
public function write($bytes)
{
@@ -157,8 +157,6 @@ abstract class Swift_ByteStream_AbstractFilterableInputStream implements Swift_I
}
}
// -- Private methods
/** Run $bytes through all filters */
private function _filter($bytes)
{

View File

@@ -11,9 +11,7 @@
/**
* Allows reading and writing of bytes to and from an array.
*
* @package Swift
* @subpackage ByteStream
* @author Chris Corbyn
* @author Chris Corbyn
*/
class Swift_ByteStream_ArrayByteStream implements Swift_InputByteStream, Swift_OutputByteStream
{
@@ -25,7 +23,7 @@ class Swift_ByteStream_ArrayByteStream implements Swift_InputByteStream, Swift_O
private $_array = array();
/**
* The size of the stack
* The size of the stack.
*
* @var int
*/
@@ -72,7 +70,7 @@ class Swift_ByteStream_ArrayByteStream implements Swift_InputByteStream, Swift_O
* remaining bytes are given instead. If no bytes are remaining at all, boolean
* false is returned.
*
* @param int $length
* @param int $length
*
* @return string
*/
@@ -84,9 +82,7 @@ class Swift_ByteStream_ArrayByteStream implements Swift_InputByteStream, Swift_O
// Don't use array slice
$end = $length + $this->_offset;
$end = $this->_arraySize<$end
?$this->_arraySize
:$end;
$end = $this->_arraySize < $end ? $this->_arraySize : $end;
$ret = '';
for (; $this->_offset < $end; ++$this->_offset) {
$ret .= $this->_array[$this->_offset];
@@ -154,7 +150,7 @@ class Swift_ByteStream_ArrayByteStream implements Swift_InputByteStream, Swift_O
/**
* Move the internal read pointer to $byteOffset in the stream.
*
* @param int $byteOffset
* @param int $byteOffset
*
* @return bool
*/

View File

@@ -11,9 +11,7 @@
/**
* Allows reading and writing of bytes to and from a file.
*
* @package Swift
* @subpackage ByteStream
* @author Chris Corbyn
* @author Chris Corbyn
*/
class Swift_ByteStream_FileByteStream extends Swift_ByteStream_AbstractFilterableInputStream implements Swift_FileStream
{
@@ -41,8 +39,8 @@ class Swift_ByteStream_FileByteStream extends Swift_ByteStream_AbstractFilterabl
/**
* Create a new FileByteStream for $path.
*
* @param string $path
* @param bool $writable if true
* @param string $path
* @param bool $writable if true
*/
public function __construct($path, $writable = false)
{
@@ -75,11 +73,11 @@ class Swift_ByteStream_FileByteStream extends Swift_ByteStream_AbstractFilterabl
* remaining bytes are given instead. If no bytes are remaining at all, boolean
* false is returned.
*
* @param int $length
*
* @return string|bool
* @param int $length
*
* @throws Swift_IoException
*
* @return string|bool
*/
public function read($length)
{
@@ -93,13 +91,13 @@ class Swift_ByteStream_FileByteStream extends Swift_ByteStream_AbstractFilterabl
ini_set('magic_quotes_runtime', 1);
}
$this->_offset = ftell($fp);
// If we read one byte after reaching the end of the file
// feof() will return false and an empty string is returned
if ($bytes === '' && feof($fp)) {
$this->_resetReadHandle();
return false;
$this->_resetReadHandle();
return false;
}
return $bytes;
@@ -113,7 +111,7 @@ class Swift_ByteStream_FileByteStream extends Swift_ByteStream_AbstractFilterabl
/**
* Move the internal read pointer to $byteOffset in the stream.
*
* @param int $byteOffset
* @param int $byteOffset
*
* @return bool
*/
@@ -125,8 +123,6 @@ class Swift_ByteStream_FileByteStream extends Swift_ByteStream_AbstractFilterabl
$this->_offset = $byteOffset;
}
// -- Private methods
/** Just write the bytes to the file */
protected function _commit($bytes)
{
@@ -143,12 +139,14 @@ class Swift_ByteStream_FileByteStream extends Swift_ByteStream_AbstractFilterabl
private function _getReadHandle()
{
if (!isset($this->_reader)) {
if (!$this->_reader = fopen($this->_path, 'rb')) {
$pointer = @fopen($this->_path, 'rb');
if (!$pointer) {
throw new Swift_IoException(
'Unable to open file for reading [' . $this->_path . ']'
'Unable to open file for reading ['.$this->_path.']'
);
}
if ($this->_offset <> 0) {
$this->_reader = $pointer;
if ($this->_offset != 0) {
$this->_getReadStreamSeekableStatus();
$this->_seekReadStreamToPosition($this->_offset);
}
@@ -163,7 +161,7 @@ class Swift_ByteStream_FileByteStream extends Swift_ByteStream_AbstractFilterabl
if (!isset($this->_writer)) {
if (!$this->_writer = fopen($this->_path, $this->_mode)) {
throw new Swift_IoException(
'Unable to open file for writing [' . $this->_path . ']'
'Unable to open file for writing ['.$this->_path.']'
);
}
}
@@ -190,13 +188,13 @@ class Swift_ByteStream_FileByteStream extends Swift_ByteStream_AbstractFilterabl
/** Streams in a readOnly stream ensuring copy if needed */
private function _seekReadStreamToPosition($offset)
{
if ($this->_seekable===null) {
if ($this->_seekable === null) {
$this->_getReadStreamSeekableStatus();
}
if ($this->_seekable === false) {
$currentPos = ftell($this->_reader);
if ($currentPos<$offset) {
$toDiscard = $offset-$currentPos;
if ($currentPos < $offset) {
$toDiscard = $offset - $currentPos;
fread($this->_reader, $toDiscard);
return;
@@ -220,7 +218,7 @@ class Swift_ByteStream_FileByteStream extends Swift_ByteStream_AbstractFilterabl
fclose($this->_reader);
$source = fopen($this->_path, 'rb');
if (!$source) {
throw new Swift_IoException('Unable to open file for copying [' . $this->_path . ']');
throw new Swift_IoException('Unable to open file for copying ['.$this->_path.']');
}
fseek($tmpFile, 0, SEEK_SET);
while (!feof($source)) {

View File

@@ -9,9 +9,7 @@
*/
/**
* @package Swift
* @subpackage ByteStream
* @author Romain-Geissler
* @author Romain-Geissler
*/
class Swift_ByteStream_TemporaryFileByteStream extends Swift_ByteStream_FileByteStream
{

View File

@@ -11,10 +11,8 @@
/**
* Analyzes characters for a specific character set.
*
* @package Swift
* @subpackage Encoder
* @author Chris Corbyn
* @author Xavier De Cock <xdecock@gmail.com>
* @author Chris Corbyn
* @author Xavier De Cock <xdecock@gmail.com>
*/
interface Swift_CharacterReader
{
@@ -23,12 +21,12 @@ interface Swift_CharacterReader
const MAP_TYPE_POSITIONS = 0x03;
/**
* Returns the complete character map
* Returns the complete character map.
*
* @param string $string
* @param int $startOffset
* @param array $currentMap
* @param mixed $ignoredChars
* @param string $string
* @param int $startOffset
* @param array $currentMap
* @param mixed $ignoredChars
*
* @return int
*/
@@ -50,8 +48,8 @@ interface Swift_CharacterReader
* A value of zero means this is already a valid character.
* A value of -1 means this cannot possibly be a valid character.
*
* @param integer[] $bytes
* @param int $size
* @param int[] $bytes
* @param int $size
*
* @return int
*/

View File

@@ -11,10 +11,8 @@
/**
* Provides fixed-width byte sizes for reading fixed-width character sets.
*
* @package Swift
* @subpackage Encoder
* @author Chris Corbyn
* @author Xavier De Cock <xdecock@gmail.com>
* @author Chris Corbyn
* @author Xavier De Cock <xdecock@gmail.com>
*/
class Swift_CharacterReader_GenericFixedWidthReader implements Swift_CharacterReader
{
@@ -28,7 +26,7 @@ class Swift_CharacterReader_GenericFixedWidthReader implements Swift_CharacterRe
/**
* Creates a new GenericFixedWidthReader using $width bytes per character.
*
* @param int $width
* @param int $width
*/
public function __construct($width)
{
@@ -38,10 +36,10 @@ class Swift_CharacterReader_GenericFixedWidthReader implements Swift_CharacterRe
/**
* Returns the complete character map.
*
* @param string $string
* @param int $startOffset
* @param array $currentMap
* @param mixed $ignoredChars
* @param string $string
* @param int $startOffset
* @param array $currentMap
* @param mixed $ignoredChars
*
* @return int
*/
@@ -50,7 +48,7 @@ class Swift_CharacterReader_GenericFixedWidthReader implements Swift_CharacterRe
$strlen = strlen($string);
// % and / are CPU intensive, so, maybe find a better way
$ignored = $strlen % $this->_width;
$ignoredChars = substr($string, - $ignored);
$ignoredChars = $ignored ? substr($string, -$ignored) : '';
$currentMap = $this->_width;
return ($strlen - $ignored) / $this->_width;
@@ -75,8 +73,8 @@ class Swift_CharacterReader_GenericFixedWidthReader implements Swift_CharacterRe
* A value of zero means this is already a valid character.
* A value of -1 means this cannot possibly be a valid character.
*
* @param string $bytes
* @param int $size
* @param string $bytes
* @param int $size
*
* @return int
*/
@@ -84,7 +82,7 @@ class Swift_CharacterReader_GenericFixedWidthReader implements Swift_CharacterRe
{
$needed = $this->_width - $size;
return ($needed > -1) ? $needed : -1;
return $needed > -1 ? $needed : -1;
}
/**

View File

@@ -11,29 +11,28 @@
/**
* Analyzes US-ASCII characters.
*
* @package Swift
* @subpackage Encoder
* @author Chris Corbyn
* @author Chris Corbyn
*/
class Swift_CharacterReader_UsAsciiReader implements Swift_CharacterReader
{
/**
* Returns the complete character map.
*
* @param string $string
* @param int $startOffset
* @param array $currentMap
* @param string $ignoredChars
* @param string $string
* @param int $startOffset
* @param array $currentMap
* @param string $ignoredChars
*
* @return int
*/
public function getCharPositions($string, $startOffset, &$currentMap, &$ignoredChars)
{
$strlen=strlen($string);
$ignoredChars='';
$strlen = strlen($string);
$ignoredChars = '';
for ($i = 0; $i < $strlen; ++$i) {
if ($string[$i]>"\x07F") { // Invalid char
$currentMap[$i+$startOffset]=$string[$i];
if ($string[$i] > "\x07F") {
// Invalid char
$currentMap[$i + $startOffset] = $string[$i];
}
}
@@ -41,9 +40,9 @@ class Swift_CharacterReader_UsAsciiReader implements Swift_CharacterReader
}
/**
* Returns mapType
* Returns mapType.
*
* @return int mapType
* @return int mapType
*/
public function getMapType()
{
@@ -58,8 +57,8 @@ class Swift_CharacterReader_UsAsciiReader implements Swift_CharacterReader
* A value of zero means this is already a valid character.
* A value of -1 means this cannot possibly be a valid character.
*
* @param string $bytes
* @param int $size
* @param string $bytes
* @param int $size
*
* @return int
*/
@@ -68,9 +67,9 @@ class Swift_CharacterReader_UsAsciiReader implements Swift_CharacterReader
$byte = reset($bytes);
if (1 == count($bytes) && $byte >= 0x00 && $byte <= 0x7F) {
return 0;
} else {
return -1;
}
return -1;
}
/**

View File

@@ -11,89 +11,87 @@
/**
* Analyzes UTF-8 characters.
*
* @package Swift
* @subpackage Encoder
* @author Chris Corbyn
* @author Xavier De Cock <xdecock@gmail.com>
* @author Chris Corbyn
* @author Xavier De Cock <xdecock@gmail.com>
*/
class Swift_CharacterReader_Utf8Reader implements Swift_CharacterReader
{
/** Pre-computed for optimization */
private static $length_map=array(
private static $length_map = array(
// N=0,1,2,3,4,5,6,7,8,9,A,B,C,D,E,F,
1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, // 0x0N
1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, // 0x1N
1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, // 0x2N
1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, // 0x3N
1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, // 0x4N
1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, // 0x5N
1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, // 0x6N
1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, // 0x7N
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, // 0x8N
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, // 0x9N
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, // 0xAN
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, // 0xBN
2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2, // 0xCN
2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2, // 0xDN
3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3, // 0xEN
4,4,4,4,4,4,4,4,5,5,5,5,6,6,0,0 // 0xFN
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 0x0N
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 0x1N
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 0x2N
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 0x3N
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 0x4N
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 0x5N
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 0x6N
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 0x7N
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 0x8N
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 0x9N
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 0xAN
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 0xBN
2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, // 0xCN
2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, // 0xDN
3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, // 0xEN
4, 4, 4, 4, 4, 4, 4, 4, 5, 5, 5, 5, 6, 6, 0, 0, // 0xFN
);
private static $s_length_map=array(
"\x00"=>1, "\x01"=>1, "\x02"=>1, "\x03"=>1, "\x04"=>1, "\x05"=>1, "\x06"=>1, "\x07"=>1,
"\x08"=>1, "\x09"=>1, "\x0a"=>1, "\x0b"=>1, "\x0c"=>1, "\x0d"=>1, "\x0e"=>1, "\x0f"=>1,
"\x10"=>1, "\x11"=>1, "\x12"=>1, "\x13"=>1, "\x14"=>1, "\x15"=>1, "\x16"=>1, "\x17"=>1,
"\x18"=>1, "\x19"=>1, "\x1a"=>1, "\x1b"=>1, "\x1c"=>1, "\x1d"=>1, "\x1e"=>1, "\x1f"=>1,
"\x20"=>1, "\x21"=>1, "\x22"=>1, "\x23"=>1, "\x24"=>1, "\x25"=>1, "\x26"=>1, "\x27"=>1,
"\x28"=>1, "\x29"=>1, "\x2a"=>1, "\x2b"=>1, "\x2c"=>1, "\x2d"=>1, "\x2e"=>1, "\x2f"=>1,
"\x30"=>1, "\x31"=>1, "\x32"=>1, "\x33"=>1, "\x34"=>1, "\x35"=>1, "\x36"=>1, "\x37"=>1,
"\x38"=>1, "\x39"=>1, "\x3a"=>1, "\x3b"=>1, "\x3c"=>1, "\x3d"=>1, "\x3e"=>1, "\x3f"=>1,
"\x40"=>1, "\x41"=>1, "\x42"=>1, "\x43"=>1, "\x44"=>1, "\x45"=>1, "\x46"=>1, "\x47"=>1,
"\x48"=>1, "\x49"=>1, "\x4a"=>1, "\x4b"=>1, "\x4c"=>1, "\x4d"=>1, "\x4e"=>1, "\x4f"=>1,
"\x50"=>1, "\x51"=>1, "\x52"=>1, "\x53"=>1, "\x54"=>1, "\x55"=>1, "\x56"=>1, "\x57"=>1,
"\x58"=>1, "\x59"=>1, "\x5a"=>1, "\x5b"=>1, "\x5c"=>1, "\x5d"=>1, "\x5e"=>1, "\x5f"=>1,
"\x60"=>1, "\x61"=>1, "\x62"=>1, "\x63"=>1, "\x64"=>1, "\x65"=>1, "\x66"=>1, "\x67"=>1,
"\x68"=>1, "\x69"=>1, "\x6a"=>1, "\x6b"=>1, "\x6c"=>1, "\x6d"=>1, "\x6e"=>1, "\x6f"=>1,
"\x70"=>1, "\x71"=>1, "\x72"=>1, "\x73"=>1, "\x74"=>1, "\x75"=>1, "\x76"=>1, "\x77"=>1,
"\x78"=>1, "\x79"=>1, "\x7a"=>1, "\x7b"=>1, "\x7c"=>1, "\x7d"=>1, "\x7e"=>1, "\x7f"=>1,
"\x80"=>0, "\x81"=>0, "\x82"=>0, "\x83"=>0, "\x84"=>0, "\x85"=>0, "\x86"=>0, "\x87"=>0,
"\x88"=>0, "\x89"=>0, "\x8a"=>0, "\x8b"=>0, "\x8c"=>0, "\x8d"=>0, "\x8e"=>0, "\x8f"=>0,
"\x90"=>0, "\x91"=>0, "\x92"=>0, "\x93"=>0, "\x94"=>0, "\x95"=>0, "\x96"=>0, "\x97"=>0,
"\x98"=>0, "\x99"=>0, "\x9a"=>0, "\x9b"=>0, "\x9c"=>0, "\x9d"=>0, "\x9e"=>0, "\x9f"=>0,
"\xa0"=>0, "\xa1"=>0, "\xa2"=>0, "\xa3"=>0, "\xa4"=>0, "\xa5"=>0, "\xa6"=>0, "\xa7"=>0,
"\xa8"=>0, "\xa9"=>0, "\xaa"=>0, "\xab"=>0, "\xac"=>0, "\xad"=>0, "\xae"=>0, "\xaf"=>0,
"\xb0"=>0, "\xb1"=>0, "\xb2"=>0, "\xb3"=>0, "\xb4"=>0, "\xb5"=>0, "\xb6"=>0, "\xb7"=>0,
"\xb8"=>0, "\xb9"=>0, "\xba"=>0, "\xbb"=>0, "\xbc"=>0, "\xbd"=>0, "\xbe"=>0, "\xbf"=>0,
"\xc0"=>2, "\xc1"=>2, "\xc2"=>2, "\xc3"=>2, "\xc4"=>2, "\xc5"=>2, "\xc6"=>2, "\xc7"=>2,
"\xc8"=>2, "\xc9"=>2, "\xca"=>2, "\xcb"=>2, "\xcc"=>2, "\xcd"=>2, "\xce"=>2, "\xcf"=>2,
"\xd0"=>2, "\xd1"=>2, "\xd2"=>2, "\xd3"=>2, "\xd4"=>2, "\xd5"=>2, "\xd6"=>2, "\xd7"=>2,
"\xd8"=>2, "\xd9"=>2, "\xda"=>2, "\xdb"=>2, "\xdc"=>2, "\xdd"=>2, "\xde"=>2, "\xdf"=>2,
"\xe0"=>3, "\xe1"=>3, "\xe2"=>3, "\xe3"=>3, "\xe4"=>3, "\xe5"=>3, "\xe6"=>3, "\xe7"=>3,
"\xe8"=>3, "\xe9"=>3, "\xea"=>3, "\xeb"=>3, "\xec"=>3, "\xed"=>3, "\xee"=>3, "\xef"=>3,
"\xf0"=>4, "\xf1"=>4, "\xf2"=>4, "\xf3"=>4, "\xf4"=>4, "\xf5"=>4, "\xf6"=>4, "\xf7"=>4,
"\xf8"=>5, "\xf9"=>5, "\xfa"=>5, "\xfb"=>5, "\xfc"=>6, "\xfd"=>6, "\xfe"=>0, "\xff"=>0,
private static $s_length_map = array(
"\x00" => 1, "\x01" => 1, "\x02" => 1, "\x03" => 1, "\x04" => 1, "\x05" => 1, "\x06" => 1, "\x07" => 1,
"\x08" => 1, "\x09" => 1, "\x0a" => 1, "\x0b" => 1, "\x0c" => 1, "\x0d" => 1, "\x0e" => 1, "\x0f" => 1,
"\x10" => 1, "\x11" => 1, "\x12" => 1, "\x13" => 1, "\x14" => 1, "\x15" => 1, "\x16" => 1, "\x17" => 1,
"\x18" => 1, "\x19" => 1, "\x1a" => 1, "\x1b" => 1, "\x1c" => 1, "\x1d" => 1, "\x1e" => 1, "\x1f" => 1,
"\x20" => 1, "\x21" => 1, "\x22" => 1, "\x23" => 1, "\x24" => 1, "\x25" => 1, "\x26" => 1, "\x27" => 1,
"\x28" => 1, "\x29" => 1, "\x2a" => 1, "\x2b" => 1, "\x2c" => 1, "\x2d" => 1, "\x2e" => 1, "\x2f" => 1,
"\x30" => 1, "\x31" => 1, "\x32" => 1, "\x33" => 1, "\x34" => 1, "\x35" => 1, "\x36" => 1, "\x37" => 1,
"\x38" => 1, "\x39" => 1, "\x3a" => 1, "\x3b" => 1, "\x3c" => 1, "\x3d" => 1, "\x3e" => 1, "\x3f" => 1,
"\x40" => 1, "\x41" => 1, "\x42" => 1, "\x43" => 1, "\x44" => 1, "\x45" => 1, "\x46" => 1, "\x47" => 1,
"\x48" => 1, "\x49" => 1, "\x4a" => 1, "\x4b" => 1, "\x4c" => 1, "\x4d" => 1, "\x4e" => 1, "\x4f" => 1,
"\x50" => 1, "\x51" => 1, "\x52" => 1, "\x53" => 1, "\x54" => 1, "\x55" => 1, "\x56" => 1, "\x57" => 1,
"\x58" => 1, "\x59" => 1, "\x5a" => 1, "\x5b" => 1, "\x5c" => 1, "\x5d" => 1, "\x5e" => 1, "\x5f" => 1,
"\x60" => 1, "\x61" => 1, "\x62" => 1, "\x63" => 1, "\x64" => 1, "\x65" => 1, "\x66" => 1, "\x67" => 1,
"\x68" => 1, "\x69" => 1, "\x6a" => 1, "\x6b" => 1, "\x6c" => 1, "\x6d" => 1, "\x6e" => 1, "\x6f" => 1,
"\x70" => 1, "\x71" => 1, "\x72" => 1, "\x73" => 1, "\x74" => 1, "\x75" => 1, "\x76" => 1, "\x77" => 1,
"\x78" => 1, "\x79" => 1, "\x7a" => 1, "\x7b" => 1, "\x7c" => 1, "\x7d" => 1, "\x7e" => 1, "\x7f" => 1,
"\x80" => 0, "\x81" => 0, "\x82" => 0, "\x83" => 0, "\x84" => 0, "\x85" => 0, "\x86" => 0, "\x87" => 0,
"\x88" => 0, "\x89" => 0, "\x8a" => 0, "\x8b" => 0, "\x8c" => 0, "\x8d" => 0, "\x8e" => 0, "\x8f" => 0,
"\x90" => 0, "\x91" => 0, "\x92" => 0, "\x93" => 0, "\x94" => 0, "\x95" => 0, "\x96" => 0, "\x97" => 0,
"\x98" => 0, "\x99" => 0, "\x9a" => 0, "\x9b" => 0, "\x9c" => 0, "\x9d" => 0, "\x9e" => 0, "\x9f" => 0,
"\xa0" => 0, "\xa1" => 0, "\xa2" => 0, "\xa3" => 0, "\xa4" => 0, "\xa5" => 0, "\xa6" => 0, "\xa7" => 0,
"\xa8" => 0, "\xa9" => 0, "\xaa" => 0, "\xab" => 0, "\xac" => 0, "\xad" => 0, "\xae" => 0, "\xaf" => 0,
"\xb0" => 0, "\xb1" => 0, "\xb2" => 0, "\xb3" => 0, "\xb4" => 0, "\xb5" => 0, "\xb6" => 0, "\xb7" => 0,
"\xb8" => 0, "\xb9" => 0, "\xba" => 0, "\xbb" => 0, "\xbc" => 0, "\xbd" => 0, "\xbe" => 0, "\xbf" => 0,
"\xc0" => 2, "\xc1" => 2, "\xc2" => 2, "\xc3" => 2, "\xc4" => 2, "\xc5" => 2, "\xc6" => 2, "\xc7" => 2,
"\xc8" => 2, "\xc9" => 2, "\xca" => 2, "\xcb" => 2, "\xcc" => 2, "\xcd" => 2, "\xce" => 2, "\xcf" => 2,
"\xd0" => 2, "\xd1" => 2, "\xd2" => 2, "\xd3" => 2, "\xd4" => 2, "\xd5" => 2, "\xd6" => 2, "\xd7" => 2,
"\xd8" => 2, "\xd9" => 2, "\xda" => 2, "\xdb" => 2, "\xdc" => 2, "\xdd" => 2, "\xde" => 2, "\xdf" => 2,
"\xe0" => 3, "\xe1" => 3, "\xe2" => 3, "\xe3" => 3, "\xe4" => 3, "\xe5" => 3, "\xe6" => 3, "\xe7" => 3,
"\xe8" => 3, "\xe9" => 3, "\xea" => 3, "\xeb" => 3, "\xec" => 3, "\xed" => 3, "\xee" => 3, "\xef" => 3,
"\xf0" => 4, "\xf1" => 4, "\xf2" => 4, "\xf3" => 4, "\xf4" => 4, "\xf5" => 4, "\xf6" => 4, "\xf7" => 4,
"\xf8" => 5, "\xf9" => 5, "\xfa" => 5, "\xfb" => 5, "\xfc" => 6, "\xfd" => 6, "\xfe" => 0, "\xff" => 0,
);
/**
* Returns the complete character map.
*
* @param string $string
* @param int $startOffset
* @param array $currentMap
* @param mixed $ignoredChars
* @param string $string
* @param int $startOffset
* @param array $currentMap
* @param mixed $ignoredChars
*
* @return int
*/
public function getCharPositions($string, $startOffset, &$currentMap, &$ignoredChars)
{
if (!isset($currentMap['i']) || ! isset($currentMap['p'])) {
if (!isset($currentMap['i']) || !isset($currentMap['p'])) {
$currentMap['p'] = $currentMap['i'] = array();
}
$strlen=strlen($string);
$charPos=count($currentMap['p']);
$foundChars=0;
$invalid=false;
$strlen = strlen($string);
$charPos = count($currentMap['p']);
$foundChars = 0;
$invalid = false;
for ($i = 0; $i < $strlen; ++$i) {
$char = $string[$i];
$size = self::$s_length_map[$char];
@@ -136,7 +134,7 @@ class Swift_CharacterReader_Utf8Reader implements Swift_CharacterReader
/**
* Returns mapType.
*
* @return int mapType
* @return int mapType
*/
public function getMapType()
{
@@ -151,22 +149,19 @@ class Swift_CharacterReader_Utf8Reader implements Swift_CharacterReader
* A value of zero means this is already a valid character.
* A value of -1 means this cannot possibly be a valid character.
*
* @param string $bytes
* @param int $size
* @param string $bytes
* @param int $size
*
* @return int
*/
public function validateByteSequence($bytes, $size)
{
if ($size<1) {
if ($size < 1) {
return -1;
}
$needed = self::$length_map[$bytes[0]] - $size;
return ($needed > -1)
? $needed
: -1
;
return $needed > -1 ? $needed : -1;
}
/**

View File

@@ -11,9 +11,7 @@
/**
* A factory for creating CharacterReaders.
*
* @package Swift
* @subpackage Encoder
* @author Chris Corbyn
* @author Chris Corbyn
*/
interface Swift_CharacterReaderFactory
{

View File

@@ -11,9 +11,7 @@
/**
* Standard factory for creating CharacterReaders.
*
* @package Swift
* @subpackage Encoder
* @author Chris Corbyn
* @author Chris Corbyn
*/
class Swift_CharacterReaderFactory_SimpleCharacterReaderFactory implements Swift_CharacterReaderFactory
{
@@ -53,24 +51,24 @@ class Swift_CharacterReaderFactory_SimpleCharacterReaderFactory implements Swift
$prefix = 'Swift_CharacterReader_';
$singleByte = array(
'class' => $prefix . 'GenericFixedWidthReader',
'constructor' => array(1)
'class' => $prefix.'GenericFixedWidthReader',
'constructor' => array(1),
);
$doubleByte = array(
'class' => $prefix . 'GenericFixedWidthReader',
'constructor' => array(2)
'class' => $prefix.'GenericFixedWidthReader',
'constructor' => array(2),
);
$fourBytes = array(
'class' => $prefix . 'GenericFixedWidthReader',
'constructor' => array(4)
'class' => $prefix.'GenericFixedWidthReader',
'constructor' => array(4),
);
// Utf-8
self::$_map['utf-?8'] = array(
'class' => $prefix . 'Utf8Reader',
'constructor' => array()
'class' => $prefix.'Utf8Reader',
'constructor' => array(),
);
//7-8 bit charsets
@@ -107,7 +105,7 @@ class Swift_CharacterReaderFactory_SimpleCharacterReaderFactory implements Swift
{
$charset = trim(strtolower($charset));
foreach (self::$_map as $pattern => $spec) {
$re = '/^' . $pattern . '$/D';
$re = '/^'.$pattern.'$/D';
if (preg_match($re, $charset)) {
if (!array_key_exists($pattern, self::$_loaded)) {
$reflector = new ReflectionClass($spec['class']);

View File

@@ -15,9 +15,7 @@
* Classes implementing this interface may use a subsystem which requires less
* memory than working with large strings of data.
*
* @package Swift
* @subpackage CharacterStream
* @author Chris Corbyn
* @author Chris Corbyn
*/
interface Swift_CharacterStream
{
@@ -54,7 +52,7 @@ interface Swift_CharacterStream
* Read $length characters from the stream and move the internal pointer
* $length further into the stream.
*
* @param int $length
* @param int $length
*
* @return string
*/
@@ -64,7 +62,7 @@ interface Swift_CharacterStream
* Read $length characters from the stream and return a 1-dimensional array
* containing there octet values.
*
* @param int $length
* @param int $length
*
* @return int[]
*/
@@ -80,7 +78,7 @@ interface Swift_CharacterStream
/**
* Move the internal pointer to $charOffset in the stream.
*
* @param int $charOffset
* @param int $charOffset
*/
public function setPointer($charOffset);

View File

@@ -11,9 +11,7 @@
/**
* A CharacterStream implementation which stores characters in an internal array.
*
* @package Swift
* @subpackage CharacterStream
* @author Chris Corbyn
* @author Chris Corbyn
*/
class Swift_CharacterStream_ArrayCharacterStream implements Swift_CharacterStream
{
@@ -97,8 +95,7 @@ class Swift_CharacterStream_ArrayCharacterStream implements Swift_CharacterStrea
$need = $this->_charReader
->validateByteSequence($c, $size);
if ($need > 0 &&
false !== $bytes = $os->read($need))
{
false !== $bytes = $os->read($need)) {
for ($i = 0, $len = strlen($bytes); $i < $len; ++$i) {
$c[] = self::$_byteMap[$bytes[$i]];
}
@@ -124,7 +121,7 @@ class Swift_CharacterStream_ArrayCharacterStream implements Swift_CharacterStrea
* Read $length characters from the stream and move the internal pointer
* $length further into the stream.
*
* @param int $length
* @param int $length
*
* @return string
*/
@@ -156,9 +153,9 @@ class Swift_CharacterStream_ArrayCharacterStream implements Swift_CharacterStrea
* Read $length characters from the stream and return a 1-dimensional array
* containing there octet values.
*
* @param int $length
* @param int $length
*
* @return integer[]
* @return int[]
*/
public function readBytes($length)
{
@@ -247,7 +244,7 @@ class Swift_CharacterStream_ArrayCharacterStream implements Swift_CharacterStrea
/**
* Move the internal pointer to $charOffset in the stream.
*
* @param int $charOffset
* @param int $charOffset
*/
public function setPointer($charOffset)
{

View File

@@ -11,11 +11,8 @@
/**
* A CharacterStream implementation which stores characters in an internal array.
*
* @package Swift
* @subpackage CharacterStream
* @author Xavier De Cock <xdecock@gmail.com>
* @author Xavier De Cock <xdecock@gmail.com>
*/
class Swift_CharacterStream_NgCharacterStream implements Swift_CharacterStream
{
/**
@@ -47,7 +44,7 @@ class Swift_CharacterStream_NgCharacterStream implements Swift_CharacterStream
private $_datas = '';
/**
* Number of bytes in the stream
* Number of bytes in the stream.
*
* @var int
*/
@@ -137,10 +134,11 @@ class Swift_CharacterStream_NgCharacterStream implements Swift_CharacterStream
public function importByteStream(Swift_OutputByteStream $os)
{
$this->flushContents();
$blocks=512;
$blocks = 512;
$os->setReadPointer(0);
while(false!==($read = $os->read($blocks)))
while (false !== ($read = $os->read($blocks))) {
$this->write($read);
}
}
/**
@@ -157,22 +155,20 @@ class Swift_CharacterStream_NgCharacterStream implements Swift_CharacterStream
/**
* @see Swift_CharacterStream::read()
*
* @param int $length
* @param int $length
*
* @return string
*/
public function read($length)
{
if ($this->_currentPos>=$this->_charCount) {
return false;
if ($this->_currentPos >= $this->_charCount) {
return false;
}
$ret=false;
$length = ($this->_currentPos+$length > $this->_charCount)
? $this->_charCount - $this->_currentPos
: $length;
switch ($this->_mapType) {
$ret = false;
$length = $this->_currentPos + $length > $this->_charCount ? $this->_charCount - $this->_currentPos : $length;
switch ($this->_mapType) {
case Swift_CharacterReader::MAP_TYPE_FIXED_LEN:
$len = $length*$this->_map;
$len = $length * $this->_map;
$ret = substr($this->_datas,
$this->_currentPos * $this->_map,
$len);
@@ -180,13 +176,9 @@ class Swift_CharacterStream_NgCharacterStream implements Swift_CharacterStream
break;
case Swift_CharacterReader::MAP_TYPE_INVALID:
$end = $this->_currentPos + $length;
$end = $end > $this->_charCount
?$this->_charCount
:$end;
$ret = '';
for (; $this->_currentPos < $length; ++$this->_currentPos) {
if (isset ($this->_map[$this->_currentPos])) {
if (isset($this->_map[$this->_currentPos])) {
$ret .= '?';
} else {
$ret .= $this->_datas[$this->_currentPos];
@@ -196,13 +188,11 @@ class Swift_CharacterStream_NgCharacterStream implements Swift_CharacterStream
case Swift_CharacterReader::MAP_TYPE_POSITIONS:
$end = $this->_currentPos + $length;
$end = $end > $this->_charCount
?$this->_charCount
:$end;
$end = $end > $this->_charCount ? $this->_charCount : $end;
$ret = '';
$start = 0;
if ($this->_currentPos>0) {
$start = $this->_map['p'][$this->_currentPos-1];
if ($this->_currentPos > 0) {
$start = $this->_map['p'][$this->_currentPos - 1];
}
$to = $start;
for (; $this->_currentPos < $end; ++$this->_currentPos) {
@@ -223,14 +213,14 @@ class Swift_CharacterStream_NgCharacterStream implements Swift_CharacterStream
/**
* @see Swift_CharacterStream::readBytes()
*
* @param int $length
* @param int $length
*
* @return integer[]
* @return int[]
*/
public function readBytes($length)
{
$read=$this->read($length);
if ($read!==false) {
$read = $this->read($length);
if ($read !== false) {
$ret = array_map('ord', str_split($read, 1));
return $ret;
@@ -242,12 +232,12 @@ class Swift_CharacterStream_NgCharacterStream implements Swift_CharacterStream
/**
* @see Swift_CharacterStream::setPointer()
*
* @param int $charOffset
* @param int $charOffset
*/
public function setPointer($charOffset)
{
if ($this->_charCount<$charOffset) {
$charOffset=$this->_charCount;
if ($this->_charCount < $charOffset) {
$charOffset = $this->_charCount;
}
$this->_currentPos = $charOffset;
}
@@ -265,13 +255,13 @@ class Swift_CharacterStream_NgCharacterStream implements Swift_CharacterStream
$this->_map = array();
$this->_mapType = $this->_charReader->getMapType();
}
$ignored='';
$ignored = '';
$this->_datas .= $chars;
$this->_charCount += $this->_charReader->getCharPositions(substr($this->_datas, $this->_datasSize), $this->_datasSize, $this->_map, $ignored);
if ($ignored!==false) {
$this->_datasSize=strlen($this->_datas)-strlen($ignored);
if ($ignored !== false) {
$this->_datasSize = strlen($this->_datas) - strlen($ignored);
} else {
$this->_datasSize=strlen($this->_datas);
$this->_datasSize = strlen($this->_datas);
}
}
}

View File

@@ -11,8 +11,7 @@
/**
* Base class for Spools (implements time and message limits).
*
* @package Swift
* @author Fabien Potencier
* @author Fabien Potencier
*/
abstract class Swift_ConfigurableSpool implements Swift_Spool
{
@@ -25,7 +24,7 @@ abstract class Swift_ConfigurableSpool implements Swift_Spool
/**
* Sets the maximum number of messages to send per flush.
*
* @param int $limit
* @param int $limit
*/
public function setMessageLimit($limit)
{
@@ -35,7 +34,7 @@ abstract class Swift_ConfigurableSpool implements Swift_Spool
/**
* Gets the maximum number of messages to send per flush.
*
* @return int The limit
* @return int The limit
*/
public function getMessageLimit()
{
@@ -45,7 +44,7 @@ abstract class Swift_ConfigurableSpool implements Swift_Spool
/**
* Sets the time limit (in seconds) per flush.
*
* @param int $limit The limit
* @param int $limit The limit
*/
public function setTimeLimit($limit)
{
@@ -55,7 +54,7 @@ abstract class Swift_ConfigurableSpool implements Swift_Spool
/**
* Gets the time limit (in seconds) per flush.
*
* @return int The limit
* @return int The limit
*/
public function getTimeLimit()
{

View File

@@ -11,8 +11,7 @@
/**
* Dependency Injection container.
*
* @package Swift
* @author Chris Corbyn
* @author Chris Corbyn
*/
class Swift_DependencyContainer
{
@@ -42,12 +41,14 @@ class Swift_DependencyContainer
*
* Use {@link getInstance()} instead.
*/
public function __construct() { }
public function __construct()
{
}
/**
* Returns a singleton of the DependencyContainer.
*
* @return Swift_DependencyContainer
* @return self
*/
public static function getInstance()
{
@@ -90,15 +91,15 @@ class Swift_DependencyContainer
*
* @param string $itemName
*
* @return mixed
*
* @throws Swift_DependencyException If the dependency is not found
*
* @return mixed
*/
public function lookup($itemName)
{
if (!$this->has($itemName)) {
throw new Swift_DependencyException(
'Cannot lookup dependency "' . $itemName . '" since it is not registered.'
'Cannot lookup dependency "'.$itemName.'" since it is not registered.'
);
}
@@ -137,16 +138,17 @@ class Swift_DependencyContainer
* This method returns the current DependencyContainer instance because it
* requires the use of the fluid interface to set the specific details for the
* dependency.
*
* @see asNewInstanceOf(), asSharedInstanceOf(), asValue()
*
* @param string $itemName
*
* @return Swift_DependencyContainer
* @return $this
*/
public function register($itemName)
{
$this->_store[$itemName] = array();
$this->_endPoint =& $this->_store[$itemName];
$this->_endPoint = &$this->_store[$itemName];
return $this;
}
@@ -158,11 +160,11 @@ class Swift_DependencyContainer
*
* @param mixed $value
*
* @return Swift_DependencyContainer
* @return $this
*/
public function asValue($value)
{
$endPoint =& $this->_getEndPoint();
$endPoint = &$this->_getEndPoint();
$endPoint['lookupType'] = self::TYPE_VALUE;
$endPoint['value'] = $value;
@@ -174,11 +176,11 @@ class Swift_DependencyContainer
*
* @param string $lookup
*
* @return Swift_DependencyContainer
* @return $this
*/
public function asAliasOf($lookup)
{
$endPoint =& $this->_getEndPoint();
$endPoint = &$this->_getEndPoint();
$endPoint['lookupType'] = self::TYPE_ALIAS;
$endPoint['ref'] = $lookup;
@@ -196,11 +198,11 @@ class Swift_DependencyContainer
*
* @param string $className
*
* @return Swift_DependencyContainer
* @return $this
*/
public function asNewInstanceOf($className)
{
$endPoint =& $this->_getEndPoint();
$endPoint = &$this->_getEndPoint();
$endPoint['lookupType'] = self::TYPE_INSTANCE;
$endPoint['className'] = $className;
@@ -214,11 +216,11 @@ class Swift_DependencyContainer
*
* @param string $className
*
* @return Swift_DependencyContainer
* @return $this
*/
public function asSharedInstanceOf($className)
{
$endPoint =& $this->_getEndPoint();
$endPoint = &$this->_getEndPoint();
$endPoint['lookupType'] = self::TYPE_SHARED;
$endPoint['className'] = $className;
@@ -234,11 +236,11 @@ class Swift_DependencyContainer
*
* @param array $lookups
*
* @return Swift_DependencyContainer
* @return $this
*/
public function withDependencies(array $lookups)
{
$endPoint =& $this->_getEndPoint();
$endPoint = &$this->_getEndPoint();
$endPoint['args'] = array();
foreach ($lookups as $lookup) {
$this->addConstructorLookup($lookup);
@@ -255,11 +257,11 @@ class Swift_DependencyContainer
*
* @param mixed $value
*
* @return Swift_DependencyContainer
* @return $this
*/
public function addConstructorValue($value)
{
$endPoint =& $this->_getEndPoint();
$endPoint = &$this->_getEndPoint();
if (!isset($endPoint['args'])) {
$endPoint['args'] = array();
}
@@ -276,11 +278,11 @@ class Swift_DependencyContainer
*
* @param string $lookup
*
* @return Swift_DependencyContainer
* @return $this
*/
public function addConstructorLookup($lookup)
{
$endPoint =& $this->_getEndPoint();
$endPoint = &$this->_getEndPoint();
if (!isset($this->_endPoint['args'])) {
$endPoint['args'] = array();
}
@@ -289,8 +291,6 @@ class Swift_DependencyContainer
return $this;
}
// -- Private methods
/** Get the literal value with $itemName */
private function _getValue($itemName)
{
@@ -311,9 +311,9 @@ class Swift_DependencyContainer
return $reflector->newInstanceArgs(
$this->createDependenciesFor($itemName)
);
} else {
return $reflector->newInstance();
}
return $reflector->newInstance();
}
/** Create and register a shared instance of $itemName */
@@ -366,8 +366,8 @@ class Swift_DependencyContainer
}
return $collection;
} else {
return $this->lookup($item);
}
return $this->lookup($item);
}
}

View File

@@ -11,8 +11,7 @@
/**
* DependencyException gets thrown when a requested dependency is missing.
*
* @package Swift
* @author Chris Corbyn
* @author Chris Corbyn
*/
class Swift_DependencyException extends Swift_SwiftException
{

View File

@@ -11,9 +11,7 @@
/**
* An embedded file, in a multipart message.
*
* @package Swift
* @subpackage Mime
* @author Chris Corbyn
* @author Chris Corbyn
*/
class Swift_EmbeddedFile extends Swift_Mime_EmbeddedFile
{

View File

@@ -10,8 +10,7 @@
/**
* Interface for all Encoder schemes.
* @package Swift
* @subpackage Encoder
*
* @author Chris Corbyn
*/
interface Swift_Encoder extends Swift_Mime_CharsetObserver
@@ -19,9 +18,9 @@ interface Swift_Encoder extends Swift_Mime_CharsetObserver
/**
* Encode a given string to produce an encoded string.
*
* @param string $string
* @param int $firstLineOffset if first line needs to be shorter
* @param int $maxLineLength - 0 indicates the default length for this encoding
* @param string $string
* @param int $firstLineOffset if first line needs to be shorter
* @param int $maxLineLength - 0 indicates the default length for this encoding
*
* @return string
*/

View File

@@ -11,9 +11,7 @@
/**
* Handles Base 64 Encoding in Swift Mailer.
*
* @package Swift
* @subpackage Encoder
* @author Chris Corbyn
* @author Chris Corbyn
*/
class Swift_Encoder_Base64Encoder implements Swift_Encoder
{
@@ -24,9 +22,9 @@ class Swift_Encoder_Base64Encoder implements Swift_Encoder
* If the first line needs to be shorter, indicate the difference with
* $firstLineOffset.
*
* @param string $string to encode
* @param int $firstLineOffset
* @param int $maxLineLength optional, 0 indicates the default of 76 bytes
* @param string $string to encode
* @param int $firstLineOffset
* @param int $maxLineLength optional, 0 indicates the default of 76 bytes
*
* @return string
*/
@@ -42,13 +40,13 @@ class Swift_Encoder_Base64Encoder implements Swift_Encoder
if (0 != $firstLineOffset) {
$firstLine = substr(
$encodedString, 0, $maxLineLength - $firstLineOffset
) . "\r\n";
)."\r\n";
$encodedString = substr(
$encodedString, $maxLineLength - $firstLineOffset
);
}
return $firstLine . trim(chunk_split($encodedString, $maxLineLength, "\r\n"));
return $firstLine.trim(chunk_split($encodedString, $maxLineLength, "\r\n"));
}
/**

View File

@@ -13,9 +13,7 @@
*
* Possibly the most accurate RFC 2045 QP implementation found in PHP.
*
* @package Swift
* @subpackage Encoder
* @author Chris Corbyn
* @author Chris Corbyn
*/
class Swift_Encoder_QpEncoder implements Swift_Encoder
{
@@ -39,26 +37,26 @@ class Swift_Encoder_QpEncoder implements Swift_Encoder
* @var string[]
*/
protected static $_qpMap = array(
0 => '=00', 1 => '=01', 2 => '=02', 3 => '=03', 4 => '=04',
5 => '=05', 6 => '=06', 7 => '=07', 8 => '=08', 9 => '=09',
10 => '=0A', 11 => '=0B', 12 => '=0C', 13 => '=0D', 14 => '=0E',
15 => '=0F', 16 => '=10', 17 => '=11', 18 => '=12', 19 => '=13',
20 => '=14', 21 => '=15', 22 => '=16', 23 => '=17', 24 => '=18',
25 => '=19', 26 => '=1A', 27 => '=1B', 28 => '=1C', 29 => '=1D',
30 => '=1E', 31 => '=1F', 32 => '=20', 33 => '=21', 34 => '=22',
35 => '=23', 36 => '=24', 37 => '=25', 38 => '=26', 39 => '=27',
40 => '=28', 41 => '=29', 42 => '=2A', 43 => '=2B', 44 => '=2C',
45 => '=2D', 46 => '=2E', 47 => '=2F', 48 => '=30', 49 => '=31',
50 => '=32', 51 => '=33', 52 => '=34', 53 => '=35', 54 => '=36',
55 => '=37', 56 => '=38', 57 => '=39', 58 => '=3A', 59 => '=3B',
60 => '=3C', 61 => '=3D', 62 => '=3E', 63 => '=3F', 64 => '=40',
65 => '=41', 66 => '=42', 67 => '=43', 68 => '=44', 69 => '=45',
70 => '=46', 71 => '=47', 72 => '=48', 73 => '=49', 74 => '=4A',
75 => '=4B', 76 => '=4C', 77 => '=4D', 78 => '=4E', 79 => '=4F',
80 => '=50', 81 => '=51', 82 => '=52', 83 => '=53', 84 => '=54',
85 => '=55', 86 => '=56', 87 => '=57', 88 => '=58', 89 => '=59',
90 => '=5A', 91 => '=5B', 92 => '=5C', 93 => '=5D', 94 => '=5E',
95 => '=5F', 96 => '=60', 97 => '=61', 98 => '=62', 99 => '=63',
0 => '=00', 1 => '=01', 2 => '=02', 3 => '=03', 4 => '=04',
5 => '=05', 6 => '=06', 7 => '=07', 8 => '=08', 9 => '=09',
10 => '=0A', 11 => '=0B', 12 => '=0C', 13 => '=0D', 14 => '=0E',
15 => '=0F', 16 => '=10', 17 => '=11', 18 => '=12', 19 => '=13',
20 => '=14', 21 => '=15', 22 => '=16', 23 => '=17', 24 => '=18',
25 => '=19', 26 => '=1A', 27 => '=1B', 28 => '=1C', 29 => '=1D',
30 => '=1E', 31 => '=1F', 32 => '=20', 33 => '=21', 34 => '=22',
35 => '=23', 36 => '=24', 37 => '=25', 38 => '=26', 39 => '=27',
40 => '=28', 41 => '=29', 42 => '=2A', 43 => '=2B', 44 => '=2C',
45 => '=2D', 46 => '=2E', 47 => '=2F', 48 => '=30', 49 => '=31',
50 => '=32', 51 => '=33', 52 => '=34', 53 => '=35', 54 => '=36',
55 => '=37', 56 => '=38', 57 => '=39', 58 => '=3A', 59 => '=3B',
60 => '=3C', 61 => '=3D', 62 => '=3E', 63 => '=3F', 64 => '=40',
65 => '=41', 66 => '=42', 67 => '=43', 68 => '=44', 69 => '=45',
70 => '=46', 71 => '=47', 72 => '=48', 73 => '=49', 74 => '=4A',
75 => '=4B', 76 => '=4C', 77 => '=4D', 78 => '=4E', 79 => '=4F',
80 => '=50', 81 => '=51', 82 => '=52', 83 => '=53', 84 => '=54',
85 => '=55', 86 => '=56', 87 => '=57', 88 => '=58', 89 => '=59',
90 => '=5A', 91 => '=5B', 92 => '=5C', 93 => '=5D', 94 => '=5E',
95 => '=5F', 96 => '=60', 97 => '=61', 98 => '=62', 99 => '=63',
100 => '=64', 101 => '=65', 102 => '=66', 103 => '=67', 104 => '=68',
105 => '=69', 106 => '=6A', 107 => '=6B', 108 => '=6C', 109 => '=6D',
110 => '=6E', 111 => '=6F', 112 => '=70', 113 => '=71', 114 => '=72',
@@ -90,7 +88,7 @@ class Swift_Encoder_QpEncoder implements Swift_Encoder
240 => '=F0', 241 => '=F1', 242 => '=F2', 243 => '=F3', 244 => '=F4',
245 => '=F5', 246 => '=F6', 247 => '=F7', 248 => '=F8', 249 => '=F9',
250 => '=FA', 251 => '=FB', 252 => '=FC', 253 => '=FD', 254 => '=FE',
255 => '=FF'
255 => '=FF',
);
protected static $_safeMapShare = array();
@@ -143,8 +141,7 @@ class Swift_Encoder_QpEncoder implements Swift_Encoder
protected function initSafeMap()
{
foreach (array_merge(
array(0x09, 0x20), range(0x21, 0x3C), range(0x3E, 0x7E)) as $byte)
{
array(0x09, 0x20), range(0x21, 0x3C), range(0x3E, 0x7E)) as $byte) {
$this->_safeMap[$byte] = chr($byte);
}
}
@@ -156,9 +153,9 @@ class Swift_Encoder_QpEncoder implements Swift_Encoder
* If the first line needs to be shorter, indicate the difference with
* $firstLineOffset.
*
* @param string $string to encode
* @param int $firstLineOffset, optional
* @param int $maxLineLength, optional 0 indicates the default of 76 chars
* @param string $string to encode
* @param int $firstLineOffset, optional
* @param int $maxLineLength, optional 0 indicates the default of 76 chars
*
* @return string
*/
@@ -173,8 +170,8 @@ class Swift_Encoder_QpEncoder implements Swift_Encoder
$lines = array();
$lNo = 0;
$lines[$lNo] = '';
$currentLine =& $lines[$lNo++];
$size=$lineLen=0;
$currentLine = &$lines[$lNo++];
$size = $lineLen = 0;
$this->_charStream->flushContents();
$this->_charStream->importString($string);
@@ -201,14 +198,25 @@ class Swift_Encoder_QpEncoder implements Swift_Encoder
}
$enc = $this->_encodeByteSequence($bytes, $size);
if ($currentLine && $lineLen+$size >= $thisLineLength) {
$i = strpos($enc, '=0D=0A');
$newLineLength = $lineLen + ($i === false ? $size : $i);
if ($currentLine && $newLineLength >= $thisLineLength) {
$lines[$lNo] = '';
$currentLine =& $lines[$lNo++];
$currentLine = &$lines[$lNo++];
$thisLineLength = $maxLineLength;
$lineLen=0;
$lineLen = 0;
}
$lineLen+=$size;
$currentLine .= $enc;
if ($i === false) {
$lineLen += $size;
} else {
// 6 is the length of '=0D=0A'.
$lineLen = $size - strrpos($enc, '=0D=0A') - 6;
}
}
return $this->_standardize(implode("=\r\n", $lines));
@@ -224,27 +232,25 @@ class Swift_Encoder_QpEncoder implements Swift_Encoder
$this->_charStream->setCharacterSet($charset);
}
// -- Protected methods
/**
* Encode the given byte array into a verbatim QP form.
*
* @param integer[] $bytes
* @param int $size
* @param int[] $bytes
* @param int $size
*
* @return string
*/
protected function _encodeByteSequence(array $bytes, &$size)
{
$ret = '';
$size=0;
$size = 0;
foreach ($bytes as $b) {
if (isset($this->_safeMap[$b])) {
$ret .= $this->_safeMap[$b];
++$size;
} else {
$ret .= self::$_qpMap[$b];
$size+=3;
$size += 3;
}
}
@@ -254,9 +260,9 @@ class Swift_Encoder_QpEncoder implements Swift_Encoder
/**
* Get the next sequence of bytes to read from the char stream.
*
* @param int $size number of bytes to read
* @param int $size number of bytes to read
*
* @return integer[]
* @return int[]
*/
protected function _nextSequence($size = 4)
{
@@ -272,7 +278,7 @@ class Swift_Encoder_QpEncoder implements Swift_Encoder
*/
protected function _standardize($string)
{
$string = str_replace(array("\t=0D=0A", " =0D=0A", "=0D=0A"),
$string = str_replace(array("\t=0D=0A", ' =0D=0A', '=0D=0A'),
array("=09\r\n", "=20\r\n", "\r\n"), $string
);
switch ($end = ord(substr($string, -1))) {
@@ -283,4 +289,12 @@ class Swift_Encoder_QpEncoder implements Swift_Encoder
return $string;
}
/**
* Make a deep copy of object.
*/
public function __clone()
{
$this->_charStream = clone $this->_charStream;
}
}

View File

@@ -11,9 +11,7 @@
/**
* Handles RFC 2231 specified Encoding in Swift Mailer.
*
* @package Swift
* @subpackage Encoder
* @author Chris Corbyn
* @author Chris Corbyn
*/
class Swift_Encoder_Rfc2231Encoder implements Swift_Encoder
{
@@ -38,17 +36,18 @@ class Swift_Encoder_Rfc2231Encoder implements Swift_Encoder
* Takes an unencoded string and produces a string encoded according to
* RFC 2231 from it.
*
* @param string $string
* @param int $firstLineOffset
* @param int $maxLineLength optional, 0 indicates the default of 75 bytes
* @param string $string
* @param int $firstLineOffset
* @param int $maxLineLength optional, 0 indicates the default of 75 bytes
*
* @return string
*/
public function encodeString($string, $firstLineOffset = 0, $maxLineLength = 0)
{
$lines = array(); $lineCount = 0;
$lines = array();
$lineCount = 0;
$lines[] = '';
$currentLine =& $lines[$lineCount++];
$currentLine = &$lines[$lineCount++];
if (0 >= $maxLineLength) {
$maxLineLength = 75;
@@ -62,10 +61,9 @@ class Swift_Encoder_Rfc2231Encoder implements Swift_Encoder
while (false !== $char = $this->_charStream->read(4)) {
$encodedChar = rawurlencode($char);
if (0 != strlen($currentLine)
&& strlen($currentLine . $encodedChar) > $thisLineLength)
{
&& strlen($currentLine.$encodedChar) > $thisLineLength) {
$lines[] = '';
$currentLine =& $lines[$lineCount++];
$currentLine = &$lines[$lineCount++];
$thisLineLength = $maxLineLength;
}
$currentLine .= $encodedChar;
@@ -83,4 +81,12 @@ class Swift_Encoder_Rfc2231Encoder implements Swift_Encoder
{
$this->_charStream->setCharacterSet($charset);
}
/**
* Make a deep copy of object.
*/
public function __clone()
{
$this->_charStream = clone $this->_charStream;
}
}

View File

@@ -11,9 +11,7 @@
/**
* Provides quick access to each encoding type.
*
* @package Swift
* @subpackage Encoder
* @author Chris Corbyn
* @author Chris Corbyn
*/
class Swift_Encoding
{
@@ -57,8 +55,6 @@ class Swift_Encoding
return self::_lookup('mime.base64contentencoder');
}
// -- Private Static Methods
private static function _lookup($key)
{
return Swift_DependencyContainer::getInstance()->lookup($key);

View File

@@ -11,9 +11,7 @@
/**
* Generated when a command is sent over an SMTP connection.
*
* @package Swift
* @subpackage Events
* @author Chris Corbyn
* @author Chris Corbyn
*/
class Swift_Events_CommandEvent extends Swift_Events_EventObject
{
@@ -27,7 +25,7 @@ class Swift_Events_CommandEvent extends Swift_Events_EventObject
/**
* An array of codes which a successful response will contain.
*
* @var integer[]
* @var int[]
*/
private $_successCodes = array();
@@ -58,7 +56,7 @@ class Swift_Events_CommandEvent extends Swift_Events_EventObject
/**
* Get the numeric response codes which indicate success for this command.
*
* @return integer[]
* @return int[]
*/
public function getSuccessCodes()
{

View File

@@ -11,9 +11,7 @@
/**
* Listens for Transports to send commands to the server.
*
* @package Swift
* @subpackage Events
* @author Chris Corbyn
* @author Chris Corbyn
*/
interface Swift_Events_CommandListener extends Swift_Events_EventListener
{

View File

@@ -11,9 +11,7 @@
/**
* The minimum interface for an Event.
*
* @package Swift
* @subpackage Events
* @author Chris Corbyn
* @author Chris Corbyn
*/
interface Swift_Events_Event
{
@@ -27,7 +25,7 @@ interface Swift_Events_Event
/**
* Prevent this Event from bubbling any further up the stack.
*
* @param bool $cancel, optional
* @param bool $cancel, optional
*/
public function cancelBubble($cancel = true);

View File

@@ -11,9 +11,7 @@
/**
* Interface for the EventDispatcher which handles the event dispatching layer.
*
* @package Swift
* @subpackage Events
* @author Chris Corbyn
* @author Chris Corbyn
*/
interface Swift_Events_EventDispatcher
{

View File

@@ -11,9 +11,7 @@
/**
* An identity interface which all EventListeners must extend.
*
* @package Swift
* @subpackage Events
* @author Chris Corbyn
* @author Chris Corbyn
*/
interface Swift_Events_EventListener
{

View File

@@ -11,9 +11,7 @@
/**
* A base Event which all Event classes inherit from.
*
* @package Swift
* @subpackage Events
* @author Chris Corbyn
* @author Chris Corbyn
*/
class Swift_Events_EventObject implements Swift_Events_Event
{
@@ -46,7 +44,7 @@ class Swift_Events_EventObject implements Swift_Events_Event
/**
* Prevent this Event from bubbling any further up the stack.
*
* @param bool $cancel, optional
* @param bool $cancel, optional
*/
public function cancelBubble($cancel = true)
{

View File

@@ -11,9 +11,7 @@
/**
* Generated when a response is received on a SMTP connection.
*
* @package Swift
* @subpackage Events
* @author Chris Corbyn
* @author Chris Corbyn
*/
class Swift_Events_ResponseEvent extends Swift_Events_EventObject
{
@@ -64,5 +62,4 @@ class Swift_Events_ResponseEvent extends Swift_Events_EventObject
{
return $this->_valid;
}
}

View File

@@ -11,9 +11,7 @@
/**
* Listens for responses from a remote SMTP server.
*
* @package Swift
* @subpackage Events
* @author Chris Corbyn
* @author Chris Corbyn
*/
interface Swift_Events_ResponseListener extends Swift_Events_EventListener
{

View File

@@ -11,15 +11,16 @@
/**
* Generated when a message is being sent.
*
* @package Swift
* @subpackage Events
* @author Chris Corbyn
* @author Chris Corbyn
*/
class Swift_Events_SendEvent extends Swift_Events_EventObject
{
/** Sending has yet to occur */
const RESULT_PENDING = 0x0001;
/** Email is spooled, ready to be sent */
const RESULT_SPOOLED = 0x0011;
/** Sending was successful */
const RESULT_SUCCESS = 0x0010;
@@ -106,7 +107,7 @@ class Swift_Events_SendEvent extends Swift_Events_EventObject
/**
* Set the result of sending.
*
* @param int $result
* @param int $result
*/
public function setResult($result)
{

View File

@@ -11,9 +11,7 @@
/**
* Listens for Messages being sent from within the Transport system.
*
* @package Swift
* @subpackage Events
* @author Chris Corbyn
* @author Chris Corbyn
*/
interface Swift_Events_SendListener extends Swift_Events_EventListener
{

View File

@@ -11,9 +11,7 @@
/**
* The EventDispatcher which handles the event dispatching layer.
*
* @package Swift
* @subpackage Events
* @author Chris Corbyn
* @author Chris Corbyn
*/
class Swift_Events_SimpleEventDispatcher implements Swift_Events_EventDispatcher
{
@@ -36,7 +34,7 @@ class Swift_Events_SimpleEventDispatcher implements Swift_Events_EventDispatcher
'Swift_Events_ResponseEvent' => 'Swift_Events_ResponseListener',
'Swift_Events_SendEvent' => 'Swift_Events_SendListener',
'Swift_Events_TransportChangeEvent' => 'Swift_Events_TransportChangeListener',
'Swift_Events_TransportExceptionEvent' => 'Swift_Events_TransportExceptionListener'
'Swift_Events_TransportExceptionEvent' => 'Swift_Events_TransportExceptionListener',
);
}
@@ -134,8 +132,6 @@ class Swift_Events_SimpleEventDispatcher implements Swift_Events_EventDispatcher
$this->_bubble($evt, $target);
}
// -- Private methods
/** Queue listeners on a stack ready for $evt to be bubbled up it */
private function _prepareBubbleQueue(Swift_Events_EventObject $evt)
{
@@ -143,8 +139,7 @@ class Swift_Events_SimpleEventDispatcher implements Swift_Events_EventDispatcher
$evtClass = get_class($evt);
foreach ($this->_listeners as $listener) {
if (array_key_exists($evtClass, $this->_eventMap)
&& ($listener instanceof $this->_eventMap[$evtClass]))
{
&& ($listener instanceof $this->_eventMap[$evtClass])) {
$this->_bubbleQueue[] = $listener;
}
}

View File

@@ -11,9 +11,7 @@
/**
* Generated when the state of a Transport is changed (i.e. stopped/started).
*
* @package Swift
* @subpackage Events
* @author Chris Corbyn
* @author Chris Corbyn
*/
class Swift_Events_TransportChangeEvent extends Swift_Events_EventObject
{

View File

@@ -11,9 +11,7 @@
/**
* Listens for changes within the Transport system.
*
* @package Swift
* @subpackage Events
* @author Chris Corbyn
* @author Chris Corbyn
*/
interface Swift_Events_TransportChangeListener extends Swift_Events_EventListener
{

View File

@@ -11,9 +11,7 @@
/**
* Generated when a TransportException is thrown from the Transport system.
*
* @package Swift
* @subpackage Events
* @author Chris Corbyn
* @author Chris Corbyn
*/
class Swift_Events_TransportExceptionEvent extends Swift_Events_EventObject
{

View File

@@ -11,9 +11,7 @@
/**
* Listens for Exceptions thrown from within the Transport system.
*
* @package Swift
* @subpackage Events
* @author Chris Corbyn
* @author Chris Corbyn
*/
interface Swift_Events_TransportExceptionListener extends Swift_Events_EventListener
{

View File

@@ -11,9 +11,7 @@
/**
* Contains a list of redundant Transports so when one fails, the next is used.
*
* @package Swift
* @subpackage Transport
* @author Chris Corbyn
* @author Chris Corbyn
*/
class Swift_FailoverTransport extends Swift_Transport_FailoverTransport
{
@@ -38,7 +36,7 @@ class Swift_FailoverTransport extends Swift_Transport_FailoverTransport
*
* @param Swift_Transport[] $transports
*
* @return Swift_FailoverTransport
* @return self
*/
public static function newInstance($transports = array())
{

View File

@@ -11,9 +11,8 @@
/**
* Stores Messages on the filesystem.
*
* @package Swift
* @author Fabien Potencier
* @author Xavier De Cock <xdecock@gmail.com>
* @author Fabien Potencier
* @author Xavier De Cock <xdecock@gmail.com>
*/
class Swift_FileSpool extends Swift_ConfigurableSpool
{
@@ -21,11 +20,11 @@ class Swift_FileSpool extends Swift_ConfigurableSpool
private $_path;
/**
* File WriteRetry Limit
* File WriteRetry Limit.
*
* @var int
*/
private $_retryLimit=10;
private $_retryLimit = 10;
/**
* Create a new FileSpool.
@@ -40,7 +39,7 @@ class Swift_FileSpool extends Swift_ConfigurableSpool
if (!file_exists($this->_path)) {
if (!mkdir($this->_path, 0777, true)) {
throw new Swift_IoException('Unable to create Path ['.$this->_path.']');
throw new Swift_IoException(sprintf('Unable to create path "%s".', $this->_path));
}
}
}
@@ -74,11 +73,11 @@ class Swift_FileSpool extends Swift_ConfigurableSpool
*
* Default, is ten and allows over 64^20 different fileNames
*
* @param int $limit
* @param int $limit
*/
public function setRetryLimit($limit)
{
$this->_retryLimit=$limit;
$this->_retryLimit = $limit;
}
/**
@@ -86,17 +85,17 @@ class Swift_FileSpool extends Swift_ConfigurableSpool
*
* @param Swift_Mime_Message $message The message to store
*
* @return bool
*
* @throws Swift_IoException
*
* @return bool
*/
public function queueMessage(Swift_Mime_Message $message)
{
$ser = serialize($message);
$fileName = $this->_path . '/' . $this->getRandomString(10);
$fileName = $this->_path.'/'.$this->getRandomString(10);
for ($i = 0; $i < $this->_retryLimit; ++$i) {
/* We try an exclusive creation of the file. This is an atomic operation, it avoid locking mechanism */
$fp = @fopen($fileName . '.message', 'x');
$fp = @fopen($fileName.'.message', 'x');
if (false !== $fp) {
if (false === fwrite($fp, $ser)) {
return false;
@@ -109,23 +108,23 @@ class Swift_FileSpool extends Swift_ConfigurableSpool
}
}
throw new Swift_IoException('Unable to create a file for enqueuing Message');
throw new Swift_IoException(sprintf('Unable to create a file for enqueuing Message in "%s".', $this->_path));
}
/**
* Execute a recovery if for any reason a process is sending for too long.
*
* @param int $timeout in second Defaults is for very slow smtp responses
* @param int $timeout in second Defaults is for very slow smtp responses
*/
public function recover($timeout = 900)
{
foreach (new DirectoryIterator($this->_path) as $file) {
$file = $file->getRealPath();
if (substr($file, - 16) == '.message.sending') {
if (substr($file, -16) == '.message.sending') {
$lockedtime = filectime($file);
if ((time() - $lockedtime) > $timeout) {
rename($file, substr($file, 0, - 8));
rename($file, substr($file, 0, -8));
}
}
}
@@ -137,7 +136,7 @@ class Swift_FileSpool extends Swift_ConfigurableSpool
* @param Swift_Transport $transport A transport instance
* @param string[] $failedRecipients An array of failures by-reference
*
* @return int The number of sent e-mail's
* @return int The number of sent e-mail's
*/
public function flushQueue(Swift_Transport $transport, &$failedRecipients = null)
{
@@ -190,14 +189,14 @@ class Swift_FileSpool extends Swift_ConfigurableSpool
/**
* Returns a random string needed to generate a fileName for the queue.
*
* @param int $count
* @param int $count
*
* @return string
*/
protected function getRandomString($count)
{
// This string MUST stay FS safe, avoid special chars
$base = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_-.";
$base = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_-';
$ret = '';
$strlen = strlen($base);
for ($i = 0; $i < $count; ++$i) {

View File

@@ -11,9 +11,7 @@
/**
* An OutputByteStream which specifically reads from a file.
*
* @package Swift
* @subpackage ByteStream
* @author Chris Corbyn
* @author Chris Corbyn
*/
interface Swift_FileStream extends Swift_OutputByteStream
{

View File

@@ -11,8 +11,7 @@
/**
* Allows StreamFilters to operate on a stream.
*
* @package Swift
* @author Chris Corbyn
* @author Chris Corbyn
*/
interface Swift_Filterable
{

View File

@@ -11,9 +11,7 @@
/**
* An image, embedded in a multipart message.
*
* @package Swift
* @subpackage Mime
* @author Chris Corbyn
* @author Chris Corbyn
*/
class Swift_Image extends Swift_EmbeddedFile
{
@@ -38,7 +36,7 @@ class Swift_Image extends Swift_EmbeddedFile
* @param string $filename
* @param string $contentType
*
* @return Swift_Image
* @return self
*/
public static function newInstance($data = null, $filename = null, $contentType = null)
{
@@ -50,14 +48,10 @@ class Swift_Image extends Swift_EmbeddedFile
*
* @param string $path
*
* @return Swift_Image
* @return self
*/
public static function fromPath($path)
{
$image = self::newInstance()->setFile(
new Swift_ByteStream_FileByteStream($path)
);
return $image;
return self::newInstance()->setFile(new Swift_ByteStream_FileByteStream($path));
}
}

View File

@@ -14,9 +14,7 @@
* Classes implementing this interface may use a subsystem which requires less
* memory than working with large strings of data.
*
* @package Swift
* @subpackage ByteStream
* @author Chris Corbyn
* @author Chris Corbyn
*/
interface Swift_InputByteStream
{
@@ -32,9 +30,9 @@ interface Swift_InputByteStream
*
* @param string $bytes
*
* @return int
*
* @throws Swift_IoException
*
* @return int
*/
public function write($bytes);

View File

@@ -11,18 +11,19 @@
/**
* I/O Exception class.
*
* @package Swift
* @author Chris Corbyn
* @author Chris Corbyn
*/
class Swift_IoException extends Swift_SwiftException
{
/**
* Create a new IoException with $message.
*
* @param string $message
* @param string $message
* @param int $code
* @param Exception $previous
*/
public function __construct($message)
public function __construct($message, $code = 0, Exception $previous = null)
{
parent::__construct($message);
parent::__construct($message, $code, $previous);
}
}

View File

@@ -11,9 +11,7 @@
/**
* Provides a mechanism for storing data using two keys.
*
* @package Swift
* @subpackage KeyCache
* @author Chris Corbyn
* @author Chris Corbyn
*/
interface Swift_KeyCache
{
@@ -28,10 +26,10 @@ interface Swift_KeyCache
*
* @see MODE_WRITE, MODE_APPEND
*
* @param string $nsKey
* @param string $itemKey
* @param string $string
* @param int $mode
* @param string $nsKey
* @param string $itemKey
* @param string $string
* @param int $mode
*/
public function setString($nsKey, $itemKey, $string, $mode);

View File

@@ -11,9 +11,7 @@
/**
* A basic KeyCache backed by an array.
*
* @package Swift
* @subpackage KeyCache
* @author Chris Corbyn
* @author Chris Corbyn
*/
class Swift_KeyCache_ArrayKeyCache implements Swift_KeyCache
{
@@ -47,10 +45,10 @@ class Swift_KeyCache_ArrayKeyCache implements Swift_KeyCache
*
* @see MODE_WRITE, MODE_APPEND
*
* @param string $nsKey
* @param string $itemKey
* @param string $string
* @param int $mode
* @param string $nsKey
* @param string $itemKey
* @param string $string
* @param int $mode
*/
public function setString($nsKey, $itemKey, $string, $mode)
{
@@ -67,8 +65,8 @@ class Swift_KeyCache_ArrayKeyCache implements Swift_KeyCache
break;
default:
throw new Swift_SwiftException(
'Invalid mode [' . $mode . '] used to set nsKey='.
$nsKey . ', itemKey=' . $itemKey
'Invalid mode ['.$mode.'] used to set nsKey='.
$nsKey.', itemKey='.$itemKey
);
}
}
@@ -99,8 +97,8 @@ class Swift_KeyCache_ArrayKeyCache implements Swift_KeyCache
break;
default:
throw new Swift_SwiftException(
'Invalid mode [' . $mode . '] used to set nsKey='.
$nsKey . ', itemKey=' . $itemKey
'Invalid mode ['.$mode.'] used to set nsKey='.
$nsKey.', itemKey='.$itemKey
);
}
}
@@ -194,8 +192,6 @@ class Swift_KeyCache_ArrayKeyCache implements Swift_KeyCache
unset($this->_contents[$nsKey]);
}
// -- Private methods
/**
* Initialize the namespace of $nsKey if needed.
*

View File

@@ -11,9 +11,7 @@
/**
* A KeyCache which streams to and from disk.
*
* @package Swift
* @subpackage KeyCache
* @author Chris Corbyn
* @author Chris Corbyn
*/
class Swift_KeyCache_DiskKeyCache implements Swift_KeyCache
{
@@ -76,10 +74,10 @@ class Swift_KeyCache_DiskKeyCache implements Swift_KeyCache
*
* @see MODE_WRITE, MODE_APPEND
*
* @param string $nsKey
* @param string $itemKey
* @param string $string
* @param int $mode
* @param string $nsKey
* @param string $itemKey
* @param string $string
* @param int $mode
*
* @throws Swift_IoException
*/
@@ -95,8 +93,8 @@ class Swift_KeyCache_DiskKeyCache implements Swift_KeyCache
break;
default:
throw new Swift_SwiftException(
'Invalid mode [' . $mode . '] used to set nsKey='.
$nsKey . ', itemKey=' . $itemKey
'Invalid mode ['.$mode.'] used to set nsKey='.
$nsKey.', itemKey='.$itemKey
);
break;
}
@@ -128,8 +126,8 @@ class Swift_KeyCache_DiskKeyCache implements Swift_KeyCache
break;
default:
throw new Swift_SwiftException(
'Invalid mode [' . $mode . '] used to set nsKey='.
$nsKey . ', itemKey=' . $itemKey
'Invalid mode ['.$mode.'] used to set nsKey='.
$nsKey.', itemKey='.$itemKey
);
break;
}
@@ -169,9 +167,9 @@ class Swift_KeyCache_DiskKeyCache implements Swift_KeyCache
* @param string $nsKey
* @param string $itemKey
*
* @return string
*
* @throws Swift_IoException
*
* @return string
*/
public function getString($nsKey, $itemKey)
{
@@ -228,7 +226,7 @@ class Swift_KeyCache_DiskKeyCache implements Swift_KeyCache
*/
public function hasKey($nsKey, $itemKey)
{
return is_file($this->_path . '/' . $nsKey . '/' . $itemKey);
return is_file($this->_path.'/'.$nsKey.'/'.$itemKey);
}
/**
@@ -241,7 +239,7 @@ class Swift_KeyCache_DiskKeyCache implements Swift_KeyCache
{
if ($this->hasKey($nsKey, $itemKey)) {
$this->_freeHandle($nsKey, $itemKey);
unlink($this->_path . '/' . $nsKey . '/' . $itemKey);
unlink($this->_path.'/'.$nsKey.'/'.$itemKey);
}
}
@@ -253,18 +251,16 @@ class Swift_KeyCache_DiskKeyCache implements Swift_KeyCache
public function clearAll($nsKey)
{
if (array_key_exists($nsKey, $this->_keys)) {
foreach ($this->_keys[$nsKey] as $itemKey=>$null) {
foreach ($this->_keys[$nsKey] as $itemKey => $null) {
$this->clearKey($nsKey, $itemKey);
}
if (is_dir($this->_path . '/' . $nsKey)) {
rmdir($this->_path . '/' . $nsKey);
if (is_dir($this->_path.'/'.$nsKey)) {
rmdir($this->_path.'/'.$nsKey);
}
unset($this->_keys[$nsKey]);
}
}
// -- Private methods
/**
* Initialize the namespace of $nsKey if needed.
*
@@ -272,10 +268,10 @@ class Swift_KeyCache_DiskKeyCache implements Swift_KeyCache
*/
private function _prepareCache($nsKey)
{
$cacheDir = $this->_path . '/' . $nsKey;
$cacheDir = $this->_path.'/'.$nsKey;
if (!is_dir($cacheDir)) {
if (!mkdir($cacheDir)) {
throw new Swift_IoException('Failed to create cache directory ' . $cacheDir);
throw new Swift_IoException('Failed to create cache directory '.$cacheDir);
}
$this->_keys[$nsKey] = array();
}
@@ -284,20 +280,17 @@ class Swift_KeyCache_DiskKeyCache implements Swift_KeyCache
/**
* Get a file handle on the cache item.
*
* @param string $nsKey
* @param string $itemKey
* @param int $position
* @param string $nsKey
* @param string $itemKey
* @param int $position
*
* @return resource
*/
private function _getHandle($nsKey, $itemKey, $position)
{
if (!isset($this->_keys[$nsKey][$itemKey])) {
$openMode = $this->hasKey($nsKey, $itemKey)
? 'r+b'
: 'w+b'
;
$fp = fopen($this->_path . '/' . $nsKey . '/' . $itemKey, $openMode);
$openMode = $this->hasKey($nsKey, $itemKey) ? 'r+b' : 'w+b';
$fp = fopen($this->_path.'/'.$nsKey.'/'.$itemKey, $openMode);
$this->_keys[$nsKey][$itemKey] = $fp;
}
if (self::POSITION_START == $position) {
@@ -321,7 +314,7 @@ class Swift_KeyCache_DiskKeyCache implements Swift_KeyCache
*/
public function __destruct()
{
foreach ($this->_keys as $nsKey=>$null) {
foreach ($this->_keys as $nsKey => $null) {
$this->clearAll($nsKey);
}
}

View File

@@ -11,9 +11,7 @@
/**
* Writes data to a KeyCache using a stream.
*
* @package Swift
* @subpackage KeyCache
* @author Chris Corbyn
* @author Chris Corbyn
*/
interface Swift_KeyCache_KeyCacheInputStream extends Swift_InputByteStream
{

View File

@@ -11,9 +11,7 @@
/**
* A null KeyCache that does not cache at all.
*
* @package Swift
* @subpackage KeyCache
* @author Chris Corbyn
* @author Chris Corbyn
*/
class Swift_KeyCache_NullKeyCache implements Swift_KeyCache
{
@@ -22,10 +20,10 @@ class Swift_KeyCache_NullKeyCache implements Swift_KeyCache
*
* @see MODE_WRITE, MODE_APPEND
*
* @param string $nsKey
* @param string $itemKey
* @param string $string
* @param int $mode
* @param string $nsKey
* @param string $itemKey
* @param string $string
* @param int $mode
*/
public function setString($nsKey, $itemKey, $string, $mode)
{

View File

@@ -11,9 +11,7 @@
/**
* Writes data to a KeyCache using a stream.
*
* @package Swift
* @subpackage KeyCache
* @author Chris Corbyn
* @author Chris Corbyn
*/
class Swift_KeyCache_SimpleKeyCacheInputStream implements Swift_KeyCache_KeyCacheInputStream
{

View File

@@ -11,9 +11,7 @@
/**
* Redundantly and rotationally uses several Transport implementations when sending.
*
* @package Swift
* @subpackage Transport
* @author Chris Corbyn
* @author Chris Corbyn
*/
class Swift_LoadBalancedTransport extends Swift_Transport_LoadBalancedTransport
{
@@ -38,7 +36,7 @@ class Swift_LoadBalancedTransport extends Swift_Transport_LoadBalancedTransport
*
* @param array $transports
*
* @return Swift_LoadBalancedTransport
* @return self
*/
public static function newInstance($transports = array())
{

View File

@@ -11,9 +11,9 @@
/**
* Sends Messages using the mail() function.
*
* @package Swift
* @subpackage Transport
* @author Chris Corbyn
* @author Chris Corbyn
*
* @deprecated since 5.4.5 (to be removed in 6.0)
*/
class Swift_MailTransport extends Swift_Transport_MailTransport
{
@@ -38,7 +38,7 @@ class Swift_MailTransport extends Swift_Transport_MailTransport
*
* @param string $extraParams To be passed to mail()
*
* @return Swift_MailTransport
* @return self
*/
public static function newInstance($extraParams = '-f%s')
{

View File

@@ -11,8 +11,7 @@
/**
* Swift Mailer class.
*
* @package Swift
* @author Chris Corbyn
* @author Chris Corbyn
*/
class Swift_Mailer
{
@@ -34,7 +33,7 @@ class Swift_Mailer
*
* @param Swift_Transport $transport
*
* @return Swift_Mailer
* @return self
*/
public static function newInstance(Swift_Transport $transport)
{
@@ -70,7 +69,7 @@ class Swift_Mailer
* @param Swift_Mime_Message $message
* @param array $failedRecipients An array of failures by-reference
*
* @return int
* @return int The number of successful recipients. Can be 0 which indicates failure
*/
public function send(Swift_Mime_Message $message, &$failedRecipients = null)
{

View File

@@ -11,9 +11,7 @@
/**
* Wraps a standard PHP array in an iterator.
*
* @package Swift
* @subpackage Mailer
* @author Chris Corbyn
* @author Chris Corbyn
*/
class Swift_Mailer_ArrayRecipientIterator implements Swift_Mailer_RecipientIterator
{
@@ -46,7 +44,7 @@ class Swift_Mailer_ArrayRecipientIterator implements Swift_Mailer_RecipientItera
/**
* Returns an array where the keys are the addresses of recipients and the
* values are the names. e.g. ('foo@bar' => 'Foo') or ('foo@bar' => NULL)
* values are the names. e.g. ('foo@bar' => 'Foo') or ('foo@bar' => NULL).
*
* @return array
*/

View File

@@ -11,9 +11,7 @@
/**
* Provides an abstract way of specifying recipients for batch sending.
*
* @package Swift
* @subpackage Mailer
* @author Chris Corbyn
* @author Chris Corbyn
*/
interface Swift_Mailer_RecipientIterator
{
@@ -26,7 +24,7 @@ interface Swift_Mailer_RecipientIterator
/**
* Returns an array where the keys are the addresses of recipients and the
* values are the names. e.g. ('foo@bar' => 'Foo') or ('foo@bar' => NULL)
* values are the names. e.g. ('foo@bar' => 'Foo') or ('foo@bar' => NULL).
*
* @return array
*/

View File

@@ -11,12 +11,12 @@
/**
* Stores Messages in memory.
*
* @package Swift
* @author Fabien Potencier
* @author Fabien Potencier
*/
class Swift_MemorySpool implements Swift_Spool
{
protected $messages = array();
private $flushRetries = 3;
/**
* Tests if this Transport mechanism has started.
@@ -42,16 +42,25 @@ class Swift_MemorySpool implements Swift_Spool
{
}
/**
* @param int $retries
*/
public function setFlushRetries($retries)
{
$this->flushRetries = $retries;
}
/**
* Stores a message in the queue.
*
* @param Swift_Mime_Message $message The message to store
*
* @return bool Whether the operation has succeeded
* @return bool Whether the operation has succeeded
*/
public function queueMessage(Swift_Mime_Message $message)
{
$this->messages[] = $message;
//clone the message to make sure it is not changed while in the queue
$this->messages[] = clone $message;
return true;
}
@@ -62,7 +71,7 @@ class Swift_MemorySpool implements Swift_Spool
* @param Swift_Transport $transport A transport instance
* @param string[] $failedRecipients An array of failures by-reference
*
* @return int The number of sent emails
* @return int The number of sent emails
*/
public function flushQueue(Swift_Transport $transport, &$failedRecipients = null)
{
@@ -75,8 +84,25 @@ class Swift_MemorySpool implements Swift_Spool
}
$count = 0;
while ($message = array_pop($this->messages)) {
$count += $transport->send($message, $failedRecipients);
$retries = $this->flushRetries;
while ($retries--) {
try {
while ($message = array_pop($this->messages)) {
$count += $transport->send($message, $failedRecipients);
}
} catch (Swift_TransportException $exception) {
if ($retries) {
// re-queue the message at the end of the queue to give a chance
// to the other messages to be sent, in case the failure was due to
// this message and not just the transport failing
array_unshift($this->messages, $message);
// wait half a second before we try again
usleep(500000);
} else {
throw $exception;
}
}
}
return $count;

View File

@@ -11,9 +11,7 @@
/**
* The Message class for building emails.
*
* @package Swift
* @subpackage Mime
* @author Chris Corbyn
* @author Chris Corbyn
*/
class Swift_Message extends Swift_Mime_SimpleMessage
{
@@ -32,7 +30,7 @@ class Swift_Message extends Swift_Mime_SimpleMessage
*/
private $savedMessage = array();
/**
/**
* Create a new Message.
*
* Details may be optionally passed into the constructor.
@@ -70,7 +68,7 @@ class Swift_Message extends Swift_Mime_SimpleMessage
* @param string $contentType
* @param string $charset
*
* @return Swift_Message
* @return $this
*/
public static function newInstance($subject = null, $body = null, $contentType = null, $charset = null)
{
@@ -84,20 +82,19 @@ class Swift_Message extends Swift_Mime_SimpleMessage
* @param string $contentType
* @param string $charset
*
* @return Swift_Mime_SimpleMessage
* @return $this
*/
public function addPart($body, $contentType = null, $charset = null)
{
return $this->attach(Swift_MimePart::newInstance(
$body, $contentType, $charset
));
return $this->attach(Swift_MimePart::newInstance($body, $contentType, $charset)->setEncoder($this->getEncoder()));
}
/**
* Attach a new signature handler to the message.
* Detach a signature handler from a message.
*
* @param Swift_Signer $signer
* @return Swift_Message
*
* @return $this
*/
public function attachSigner(Swift_Signer $signer)
{
@@ -106,7 +103,7 @@ class Swift_Message extends Swift_Mime_SimpleMessage
} elseif ($signer instanceof Swift_Signers_BodySigner) {
$this->bodySigners[] = $signer;
}
return $this;
}
@@ -114,7 +111,8 @@ class Swift_Message extends Swift_Mime_SimpleMessage
* Attach a new signature handler to the message.
*
* @param Swift_Signer $signer
* @return Swift_Message
*
* @return $this
*/
public function detachSigner(Swift_Signer $signer)
{
@@ -122,6 +120,7 @@ class Swift_Message extends Swift_Mime_SimpleMessage
foreach ($this->headerSigners as $k => $headerSigner) {
if ($headerSigner === $signer) {
unset($this->headerSigners[$k]);
return $this;
}
}
@@ -129,14 +128,15 @@ class Swift_Message extends Swift_Mime_SimpleMessage
foreach ($this->bodySigners as $k => $bodySigner) {
if ($bodySigner === $signer) {
unset($this->bodySigners[$k]);
return $this;
}
}
}
return $this;
}
return $this;
}
/**
* Get this message as a complete string.
*
@@ -144,21 +144,21 @@ class Swift_Message extends Swift_Mime_SimpleMessage
*/
public function toString()
{
if (empty($this->headerSigners) && empty($this->bodySigners)) {
return parent::toString();
}
if (empty($this->headerSigners) && empty($this->bodySigners)) {
return parent::toString();
}
$this->saveMessage();
$this->doSign();
$string = parent::toString();
$this->restoreMessage();
return $string;
return $string;
}
/**
* Write this message to a {@link Swift_InputByteStream}.
*
@@ -168,106 +168,122 @@ class Swift_Message extends Swift_Mime_SimpleMessage
{
if (empty($this->headerSigners) && empty($this->bodySigners)) {
parent::toByteStream($is);
return;
}
$this->saveMessage();
$this->doSign();
parent::toByteStream($is);
$this->restoreMessage();
}
public function __wakeup()
{
Swift_DependencyContainer::getInstance()->createDependenciesFor('mime.message');
}
/* -- Protected Methods -- */
/**
* loops through signers and apply the signatures
* loops through signers and apply the signatures.
*/
protected function doSign()
{
foreach ($this->bodySigners as $signer) {
$altered = $signer->getAlteredHeaders();
$this->saveHeaders($altered);
$signer->signMessage($this);
}
foreach ($this->headerSigners as $signer) {
$altered = $signer->getAlteredHeaders();
$this->saveHeaders($altered);
$signer->reset();
$signer->setHeaders($this->getHeaders());
$signer->startBody();
$this->_bodyToByteStream($signer);
$signer->endBody();
$signer->addSignature($this->getHeaders());
}
foreach ($this->bodySigners as $signer) {
$altered = $signer->getAlteredHeaders();
$this->saveHeaders($altered);
$signer->signMessage($this);
}
foreach ($this->headerSigners as $signer) {
$altered = $signer->getAlteredHeaders();
$this->saveHeaders($altered);
$signer->reset();
$signer->setHeaders($this->getHeaders());
$signer->startBody();
$this->_bodyToByteStream($signer);
$signer->endBody();
$signer->addSignature($this->getHeaders());
}
}
/**
* save the message before any signature is applied
* save the message before any signature is applied.
*/
protected function saveMessage()
{
$this->savedMessage = array('headers'=> array());
$this->savedMessage['body'] = $this->getBody();
$this->savedMessage['children'] = $this->getChildren();
if (count($this->savedMessage['children']) > 0 && $this->getBody() != '') {
$this->setChildren(array_merge(array($this->_becomeMimePart()), $this->savedMessage['children']));
$this->setBody('');
}
$this->savedMessage = array('headers' => array());
$this->savedMessage['body'] = $this->getBody();
$this->savedMessage['children'] = $this->getChildren();
if (count($this->savedMessage['children']) > 0 && $this->getBody() != '') {
$this->setChildren(array_merge(array($this->_becomeMimePart()), $this->savedMessage['children']));
$this->setBody('');
}
}
/**
* save the original headers
* save the original headers.
*
* @param array $altered
*/
protected function saveHeaders(array $altered)
{
foreach ($altered as $head) {
$lc = strtolower($head);
if (!isset($this->savedMessage['headers'][$lc])) {
$this->savedMessage['headers'][$lc] = $this->getHeaders()->getAll($head);
}
}
foreach ($altered as $head) {
$lc = strtolower($head);
if (!isset($this->savedMessage['headers'][$lc])) {
$this->savedMessage['headers'][$lc] = $this->getHeaders()->getAll($head);
}
}
}
/**
* Remove or restore altered headers
* Remove or restore altered headers.
*/
protected function restoreHeaders()
{
foreach ($this->savedMessage['headers'] as $name => $savedValue) {
$headers = $this->getHeaders()->getAll($name);
foreach ($headers as $key => $value) {
if (!isset($savedValue[$key])) {
$this->getHeaders()->remove($name, $key);
}
}
}
foreach ($this->savedMessage['headers'] as $name => $savedValue) {
$headers = $this->getHeaders()->getAll($name);
foreach ($headers as $key => $value) {
if (!isset($savedValue[$key])) {
$this->getHeaders()->remove($name, $key);
}
}
}
}
/**
* Restore message body
* Restore message body.
*/
protected function restoreMessage()
{
$this->setBody($this->savedMessage['body']);
$this->setChildren($this->savedMessage['children']);
$this->restoreHeaders();
$this->savedMessage = array();
$this->setBody($this->savedMessage['body']);
$this->setChildren($this->savedMessage['children']);
$this->restoreHeaders();
$this->savedMessage = array();
}
/**
* Clone Message Signers.
*
* @see Swift_Mime_SimpleMimeEntity::__clone()
*/
public function __clone()
{
parent::__clone();
foreach ($this->bodySigners as $key => $bodySigner) {
$this->bodySigners[$key] = clone $bodySigner;
}
foreach ($this->headerSigners as $key => $headerSigner) {
$this->headerSigners[$key] = clone $headerSigner;
}
}
}

View File

@@ -11,9 +11,7 @@
/**
* An attachment, in a multipart message.
*
* @package Swift
* @subpackage Mime
* @author Chris Corbyn
* @author Chris Corbyn
*/
class Swift_Mime_Attachment extends Swift_Mime_SimpleMimeEntity
{
@@ -66,14 +64,12 @@ class Swift_Mime_Attachment extends Swift_Mime_SimpleMimeEntity
*
* @param string $disposition
*
* @return Swift_Mime_Attachment
* @return $this
*/
public function setDisposition($disposition)
{
if (!$this->_setHeaderFieldModel('Content-Disposition', $disposition)) {
$this->getHeaders()->addParameterizedHeader(
'Content-Disposition', $disposition
);
$this->getHeaders()->addParameterizedHeader('Content-Disposition', $disposition);
}
return $this;
@@ -94,7 +90,7 @@ class Swift_Mime_Attachment extends Swift_Mime_SimpleMimeEntity
*
* @param string $filename
*
* @return Swift_Mime_Attachment
* @return $this
*/
public function setFilename($filename)
{
@@ -117,9 +113,9 @@ class Swift_Mime_Attachment extends Swift_Mime_SimpleMimeEntity
/**
* Set the file size of this attachment.
*
* @param int $size
* @param int $size
*
* @return Swift_Mime_Attachment
* @return $this
*/
public function setSize($size)
{
@@ -134,16 +130,14 @@ class Swift_Mime_Attachment extends Swift_Mime_SimpleMimeEntity
* @param Swift_FileStream $file
* @param string $contentType optional
*
* @return Swift_Mime_Attachment
* @return $this
*/
public function setFile(Swift_FileStream $file, $contentType = null)
{
$this->setFilename(basename($file->getPath()));
$this->setBody($file, $contentType);
if (!isset($contentType)) {
$extension = strtolower(substr(
$file->getPath(), strrpos($file->getPath(), '.') + 1
));
$extension = strtolower(substr($file->getPath(), strrpos($file->getPath(), '.') + 1));
if (array_key_exists($extension, $this->_mimeTypes)) {
$this->setContentType($this->_mimeTypes[$extension]);

View File

@@ -11,9 +11,7 @@
/**
* Observes changes in an Mime entity's character set.
*
* @package Swift
* @subpackage Mime
* @author Chris Corbyn
* @author Chris Corbyn
*/
interface Swift_Mime_CharsetObserver
{

View File

@@ -11,9 +11,7 @@
/**
* Interface for all Transfer Encoding schemes.
*
* @package Swift
* @subpackage Mime
* @author Chris Corbyn
* @author Chris Corbyn
*/
interface Swift_Mime_ContentEncoder extends Swift_Encoder
{

View File

@@ -11,9 +11,7 @@
/**
* Handles Base 64 Transfer Encoding in Swift Mailer.
*
* @package Swift
* @subpackage Mime
* @author Chris Corbyn
* @author Chris Corbyn
*/
class Swift_Mime_ContentEncoder_Base64ContentEncoder extends Swift_Encoder_Base64Encoder implements Swift_Mime_ContentEncoder
{
@@ -32,14 +30,47 @@ class Swift_Mime_ContentEncoder_Base64ContentEncoder extends Swift_Encoder_Base6
}
$remainder = 0;
$base64ReadBufferRemainderBytes = null;
while (false !== $bytes = $os->read(8190)) {
$encoded = base64_encode($bytes);
// To reduce memory usage, the output buffer is streamed to the input buffer like so:
// Output Stream => base64encode => wrap line length => Input Stream
// HOWEVER it's important to note that base64_encode() should only be passed whole triplets of data (except for the final chunk of data)
// otherwise it will assume the input data has *ended* and it will incorrectly pad/terminate the base64 data mid-stream.
// We use $base64ReadBufferRemainderBytes to carry over 1-2 "remainder" bytes from the each chunk from OutputStream and pre-pend those onto the
// chunk of bytes read in the next iteration.
// When the OutputStream is empty, we must flush any remainder bytes.
while (true) {
$readBytes = $os->read(8192);
$atEOF = ($readBytes === false);
if ($atEOF) {
$streamTheseBytes = $base64ReadBufferRemainderBytes;
} else {
$streamTheseBytes = $base64ReadBufferRemainderBytes.$readBytes;
}
$base64ReadBufferRemainderBytes = null;
$bytesLength = strlen($streamTheseBytes);
if ($bytesLength === 0) { // no data left to encode
break;
}
// if we're not on the last block of the ouput stream, make sure $streamTheseBytes ends with a complete triplet of data
// and carry over remainder 1-2 bytes to the next loop iteration
if (!$atEOF) {
$excessBytes = $bytesLength % 3;
if ($excessBytes !== 0) {
$base64ReadBufferRemainderBytes = substr($streamTheseBytes, -$excessBytes);
$streamTheseBytes = substr($streamTheseBytes, 0, $bytesLength - $excessBytes);
}
}
$encoded = base64_encode($streamTheseBytes);
$encodedTransformed = '';
$thisMaxLineLength = $maxLineLength - $remainder - $firstLineOffset;
while ($thisMaxLineLength < strlen($encoded)) {
$encodedTransformed .= substr($encoded, 0, $thisMaxLineLength) . "\r\n";
$encodedTransformed .= substr($encoded, 0, $thisMaxLineLength)."\r\n";
$firstLineOffset = 0;
$encoded = substr($encoded, $thisMaxLineLength);
$thisMaxLineLength = $maxLineLength;
@@ -53,6 +84,10 @@ class Swift_Mime_ContentEncoder_Base64ContentEncoder extends Swift_Encoder_Base6
}
$is->write($encodedTransformed);
if ($atEOF) {
break;
}
}
}

View File

@@ -11,9 +11,7 @@
/**
* Handles Quoted Printable (QP) Transfer Encoding in Swift Mailer using the PHP core function.
*
* @package Swift
* @subpackage Mime
* @author Lars Strojny
* @author Lars Strojny
*/
class Swift_Mime_ContentEncoder_NativeQpContentEncoder implements Swift_Mime_ContentEncoder
{
@@ -79,13 +77,13 @@ class Swift_Mime_ContentEncoder_NativeQpContentEncoder implements Swift_Mime_Con
/**
* Encode a given string to produce an encoded string.
*
* @param string $string
* @param int $firstLineOffset if first line needs to be shorter
* @param int $maxLineLength 0 indicates the default length for this encoding
*
* @return string
* @param string $string
* @param int $firstLineOffset if first line needs to be shorter
* @param int $maxLineLength 0 indicates the default length for this encoding
*
* @throws RuntimeException
*
* @return string
*/
public function encodeString($string, $firstLineOffset = 0, $maxLineLength = 0)
{
@@ -109,7 +107,7 @@ class Swift_Mime_ContentEncoder_NativeQpContentEncoder implements Swift_Mime_Con
// transform CR or LF to CRLF
$string = preg_replace('~=0D(?!=0A)|(?<!=0D)=0A~', '=0D=0A', $string);
// transform =0D=0A to CRLF
$string = str_replace(array("\t=0D=0A", " =0D=0A", "=0D=0A"), array("=09\r\n", "=20\r\n", "\r\n"), $string);
$string = str_replace(array("\t=0D=0A", ' =0D=0A', '=0D=0A'), array("=09\r\n", "=20\r\n", "\r\n"), $string);
switch ($end = ord(substr($string, -1))) {
case 0x09:

View File

@@ -11,9 +11,7 @@
/**
* Handles binary/7/8-bit Transfer Encoding in Swift Mailer.
*
* @package Swift
* @subpackage Mime
* @author Chris Corbyn
* @author Chris Corbyn
*/
class Swift_Mime_ContentEncoder_PlainContentEncoder implements Swift_Mime_ContentEncoder
{
@@ -34,8 +32,8 @@ class Swift_Mime_ContentEncoder_PlainContentEncoder implements Swift_Mime_Conten
/**
* Creates a new PlainContentEncoder with $name (probably 7bit or 8bit).
*
* @param string $name
* @param bool $canonical If canonicalization transformation should be done.
* @param string $name
* @param bool $canonical If canonicalization transformation should be done.
*/
public function __construct($name, $canonical = false)
{
@@ -46,9 +44,9 @@ class Swift_Mime_ContentEncoder_PlainContentEncoder implements Swift_Mime_Conten
/**
* Encode a given string to produce an encoded string.
*
* @param string $string
* @param int $firstLineOffset ignored
* @param int $maxLineLength - 0 means no wrapping will occur
* @param string $string
* @param int $firstLineOffset ignored
* @param int $maxLineLength - 0 means no wrapping will occur
*
* @return string
*/
@@ -73,7 +71,7 @@ class Swift_Mime_ContentEncoder_PlainContentEncoder implements Swift_Mime_Conten
{
$leftOver = '';
while (false !== $bytes = $os->read(8192)) {
$toencode = $leftOver . $bytes;
$toencode = $leftOver.$bytes;
if ($this->_canonical) {
$toencode = $this->_canonicalize($toencode);
}
@@ -106,14 +104,12 @@ class Swift_Mime_ContentEncoder_PlainContentEncoder implements Swift_Mime_Conten
{
}
// -- Private methods
/**
* A safer (but weaker) wordwrap for unicode.
*
* @param string $string
* @param int $length
* @param string $le
* @param string $string
* @param int $length
* @param string $le
*
* @return string
*/
@@ -130,17 +126,16 @@ class Swift_Mime_ContentEncoder_PlainContentEncoder implements Swift_Mime_Conten
foreach ($originalLines as $originalLine) {
$lines[] = '';
$currentLine =& $lines[$lineCount++];
$currentLine = &$lines[$lineCount++];
//$chunks = preg_split('/(?<=[\ \t,\.!\?\-&\+\/])/', $originalLine);
$chunks = preg_split('/(?<=\s)/', $originalLine);
foreach ($chunks as $chunk) {
if (0 != strlen($currentLine)
&& strlen($currentLine . $chunk) > $length)
{
&& strlen($currentLine.$chunk) > $length) {
$lines[] = '';
$currentLine =& $lines[$lineCount++];
$currentLine = &$lines[$lineCount++];
}
$currentLine .= $chunk;
}

View File

@@ -11,9 +11,7 @@
/**
* Handles Quoted Printable (QP) Transfer Encoding in Swift Mailer.
*
* @package Swift
* @subpackage Mime
* @author Chris Corbyn
* @author Chris Corbyn
*/
class Swift_Mime_ContentEncoder_QpContentEncoder extends Swift_Encoder_QpEncoder implements Swift_Mime_ContentEncoder
{
@@ -76,7 +74,7 @@ class Swift_Mime_ContentEncoder_QpContentEncoder extends Swift_Encoder_QpEncoder
$currentLine = '';
$prepend = '';
$size=$lineLen=0;
$size = $lineLen = 0;
while (false !== $bytes = $this->_nextSequence()) {
// If we're filtering the input
@@ -97,18 +95,29 @@ class Swift_Mime_ContentEncoder_QpContentEncoder extends Swift_Encoder_QpEncoder
}
$enc = $this->_encodeByteSequence($bytes, $size);
if ($currentLine && $lineLen+$size >= $thisLineLength) {
$is->write($prepend . $this->_standardize($currentLine));
$i = strpos($enc, '=0D=0A');
$newLineLength = $lineLen + ($i === false ? $size : $i);
if ($currentLine && $newLineLength >= $thisLineLength) {
$is->write($prepend.$this->_standardize($currentLine));
$currentLine = '';
$prepend = "=\r\n";
$thisLineLength = $maxLineLength;
$lineLen=0;
$lineLen = 0;
}
$lineLen+=$size;
$currentLine .= $enc;
if ($i === false) {
$lineLen += $size;
} else {
// 6 is the length of '=0D=0A'.
$lineLen = $size - strrpos($enc, '=0D=0A') - 6;
}
}
if (strlen($currentLine)) {
$is->write($prepend . $this->_standardize($currentLine));
$is->write($prepend.$this->_standardize($currentLine));
}
}

View File

@@ -13,9 +13,7 @@
*
* Switches on the best QP encoder implementation for current charset.
*
* @package Swift
* @subpackage Mime
* @author Jean-François Simon <jeanfrancois.simon@sensiolabs.com>
* @author Jean-François Simon <jeanfrancois.simon@sensiolabs.com>
*/
class Swift_Mime_ContentEncoder_QpContentEncoderProxy implements Swift_Mime_ContentEncoder
{
@@ -48,12 +46,22 @@ class Swift_Mime_ContentEncoder_QpContentEncoderProxy implements Swift_Mime_Cont
$this->charset = $charset;
}
/**
* Make a deep copy of object.
*/
public function __clone()
{
$this->safeEncoder = clone $this->safeEncoder;
$this->nativeEncoder = clone $this->nativeEncoder;
}
/**
* {@inheritdoc}
*/
public function charsetChanged($charset)
{
$this->charset = $charset;
$this->safeEncoder->charsetChanged($charset);
}
/**

View File

@@ -11,19 +11,18 @@
/**
* Handles raw Transfer Encoding in Swift Mailer.
*
* @package Swift
* @subpackage Mime
*
* @author Sebastiaan Stok <s.stok@rollerscapes.net>
* @author Sebastiaan Stok <s.stok@rollerscapes.net>
*/
class Swift_Mime_ContentEncoder_RawContentEncoder implements Swift_Mime_ContentEncoder
{
/**
* Encode a given string to produce an encoded string.
*
* @param string $string
* @param int $firstLineOffset ignored
* @param int $maxLineLength ignored
* @param string $string
* @param int $firstLineOffset ignored
* @param int $maxLineLength ignored
*
* @return string
*/
public function encodeString($string, $firstLineOffset = 0, $maxLineLength = 0)

View File

@@ -11,9 +11,7 @@
/**
* An embedded file, in a multipart message.
*
* @package Swift
* @subpackage Mime
* @author Chris Corbyn
* @author Chris Corbyn
*/
class Swift_Mime_EmbeddedFile extends Swift_Mime_Attachment
{

View File

@@ -11,9 +11,7 @@
/**
* Observes changes for a Mime entity's ContentEncoder.
*
* @package Swift
* @subpackage Mime
* @author Chris Corbyn
* @author Chris Corbyn
*/
interface Swift_Mime_EncodingObserver
{

View File

@@ -11,8 +11,6 @@
/**
* Defines the grammar to use for validation, implements the RFC 2822 (and friends) ABNF grammar definitions.
*
* @package Swift
* @subpackage Mime
* @author Fabien Potencier
* @author Chris Corbyn
*/
@@ -53,7 +51,7 @@ class Swift_Mime_Grammar
self::$_specials = array(
'(', ')', '<', '>', '[', ']',
':', ';', '@', ',', '.', '"'
':', ';', '@', ',', '.', '"',
);
/*** Refer to RFC 2822 for ABNF grammar ***/
@@ -62,62 +60,62 @@ class Swift_Mime_Grammar
self::$_grammar['NO-WS-CTL'] = '[\x01-\x08\x0B\x0C\x0E-\x19\x7F]';
self::$_grammar['WSP'] = '[ \t]';
self::$_grammar['CRLF'] = '(?:\r\n)';
self::$_grammar['FWS'] = '(?:(?:' . self::$_grammar['WSP'] . '*' .
self::$_grammar['CRLF'] . ')?' . self::$_grammar['WSP'] . ')';
self::$_grammar['FWS'] = '(?:(?:'.self::$_grammar['WSP'].'*'.
self::$_grammar['CRLF'].')?'.self::$_grammar['WSP'].')';
self::$_grammar['text'] = '[\x00-\x08\x0B\x0C\x0E-\x7F]';
self::$_grammar['quoted-pair'] = '(?:\\\\' . self::$_grammar['text'] . ')';
self::$_grammar['ctext'] = '(?:' . self::$_grammar['NO-WS-CTL'] .
self::$_grammar['quoted-pair'] = '(?:\\\\'.self::$_grammar['text'].')';
self::$_grammar['ctext'] = '(?:'.self::$_grammar['NO-WS-CTL'].
'|[\x21-\x27\x2A-\x5B\x5D-\x7E])';
// Uses recursive PCRE (?1) -- could be a weak point??
self::$_grammar['ccontent'] = '(?:' . self::$_grammar['ctext'] . '|' .
self::$_grammar['quoted-pair'] . '|(?1))';
self::$_grammar['comment'] = '(\((?:' . self::$_grammar['FWS'] . '|' .
self::$_grammar['ccontent']. ')*' . self::$_grammar['FWS'] . '?\))';
self::$_grammar['CFWS'] = '(?:(?:' . self::$_grammar['FWS'] . '?' .
self::$_grammar['comment'] . ')*(?:(?:' . self::$_grammar['FWS'] . '?' .
self::$_grammar['comment'] . ')|' . self::$_grammar['FWS'] . '))';
self::$_grammar['qtext'] = '(?:' . self::$_grammar['NO-WS-CTL'] .
self::$_grammar['ccontent'] = '(?:'.self::$_grammar['ctext'].'|'.
self::$_grammar['quoted-pair'].'|(?1))';
self::$_grammar['comment'] = '(\((?:'.self::$_grammar['FWS'].'|'.
self::$_grammar['ccontent'].')*'.self::$_grammar['FWS'].'?\))';
self::$_grammar['CFWS'] = '(?:(?:'.self::$_grammar['FWS'].'?'.
self::$_grammar['comment'].')*(?:(?:'.self::$_grammar['FWS'].'?'.
self::$_grammar['comment'].')|'.self::$_grammar['FWS'].'))';
self::$_grammar['qtext'] = '(?:'.self::$_grammar['NO-WS-CTL'].
'|[\x21\x23-\x5B\x5D-\x7E])';
self::$_grammar['qcontent'] = '(?:' . self::$_grammar['qtext'] . '|' .
self::$_grammar['quoted-pair'] . ')';
self::$_grammar['quoted-string'] = '(?:' . self::$_grammar['CFWS'] . '?"' .
'(' . self::$_grammar['FWS'] . '?' . self::$_grammar['qcontent'] . ')*' .
self::$_grammar['FWS'] . '?"' . self::$_grammar['CFWS'] . '?)';
self::$_grammar['qcontent'] = '(?:'.self::$_grammar['qtext'].'|'.
self::$_grammar['quoted-pair'].')';
self::$_grammar['quoted-string'] = '(?:'.self::$_grammar['CFWS'].'?"'.
'('.self::$_grammar['FWS'].'?'.self::$_grammar['qcontent'].')*'.
self::$_grammar['FWS'].'?"'.self::$_grammar['CFWS'].'?)';
self::$_grammar['atext'] = '[a-zA-Z0-9!#\$%&\'\*\+\-\/=\?\^_`\{\}\|~]';
self::$_grammar['atom'] = '(?:' . self::$_grammar['CFWS'] . '?' .
self::$_grammar['atext'] . '+' . self::$_grammar['CFWS'] . '?)';
self::$_grammar['dot-atom-text'] = '(?:' . self::$_grammar['atext'] . '+' .
'(\.' . self::$_grammar['atext'] . '+)*)';
self::$_grammar['dot-atom'] = '(?:' . self::$_grammar['CFWS'] . '?' .
self::$_grammar['dot-atom-text'] . '+' . self::$_grammar['CFWS'] . '?)';
self::$_grammar['word'] = '(?:' . self::$_grammar['atom'] . '|' .
self::$_grammar['quoted-string'] . ')';
self::$_grammar['phrase'] = '(?:' . self::$_grammar['word'] . '+?)';
self::$_grammar['no-fold-quote'] = '(?:"(?:' . self::$_grammar['qtext'] .
'|' . self::$_grammar['quoted-pair'] . ')*")';
self::$_grammar['dtext'] = '(?:' . self::$_grammar['NO-WS-CTL'] .
self::$_grammar['atom'] = '(?:'.self::$_grammar['CFWS'].'?'.
self::$_grammar['atext'].'+'.self::$_grammar['CFWS'].'?)';
self::$_grammar['dot-atom-text'] = '(?:'.self::$_grammar['atext'].'+'.
'(\.'.self::$_grammar['atext'].'+)*)';
self::$_grammar['dot-atom'] = '(?:'.self::$_grammar['CFWS'].'?'.
self::$_grammar['dot-atom-text'].'+'.self::$_grammar['CFWS'].'?)';
self::$_grammar['word'] = '(?:'.self::$_grammar['atom'].'|'.
self::$_grammar['quoted-string'].')';
self::$_grammar['phrase'] = '(?:'.self::$_grammar['word'].'+?)';
self::$_grammar['no-fold-quote'] = '(?:"(?:'.self::$_grammar['qtext'].
'|'.self::$_grammar['quoted-pair'].')*")';
self::$_grammar['dtext'] = '(?:'.self::$_grammar['NO-WS-CTL'].
'|[\x21-\x5A\x5E-\x7E])';
self::$_grammar['no-fold-literal'] = '(?:\[(?:' . self::$_grammar['dtext'] .
'|' . self::$_grammar['quoted-pair'] . ')*\])';
self::$_grammar['no-fold-literal'] = '(?:\[(?:'.self::$_grammar['dtext'].
'|'.self::$_grammar['quoted-pair'].')*\])';
// Message IDs
self::$_grammar['id-left'] = '(?:' . self::$_grammar['dot-atom-text'] . '|' .
self::$_grammar['no-fold-quote'] . ')';
self::$_grammar['id-right'] = '(?:' . self::$_grammar['dot-atom-text'] . '|' .
self::$_grammar['no-fold-literal'] . ')';
self::$_grammar['id-left'] = '(?:'.self::$_grammar['dot-atom-text'].'|'.
self::$_grammar['no-fold-quote'].')';
self::$_grammar['id-right'] = '(?:'.self::$_grammar['dot-atom-text'].'|'.
self::$_grammar['no-fold-literal'].')';
// Addresses, mailboxes and paths
self::$_grammar['local-part'] = '(?:' . self::$_grammar['dot-atom'] . '|' .
self::$_grammar['quoted-string'] . ')';
self::$_grammar['dcontent'] = '(?:' . self::$_grammar['dtext'] . '|' .
self::$_grammar['quoted-pair'] . ')';
self::$_grammar['domain-literal'] = '(?:' . self::$_grammar['CFWS'] . '?\[(' .
self::$_grammar['FWS'] . '?' . self::$_grammar['dcontent'] . ')*?' .
self::$_grammar['FWS'] . '?\]' . self::$_grammar['CFWS'] . '?)';
self::$_grammar['domain'] = '(?:' . self::$_grammar['dot-atom'] . '|' .
self::$_grammar['domain-literal'] . ')';
self::$_grammar['addr-spec'] = '(?:' . self::$_grammar['local-part'] . '@' .
self::$_grammar['domain'] . ')';
self::$_grammar['local-part'] = '(?:'.self::$_grammar['dot-atom'].'|'.
self::$_grammar['quoted-string'].')';
self::$_grammar['dcontent'] = '(?:'.self::$_grammar['dtext'].'|'.
self::$_grammar['quoted-pair'].')';
self::$_grammar['domain-literal'] = '(?:'.self::$_grammar['CFWS'].'?\[('.
self::$_grammar['FWS'].'?'.self::$_grammar['dcontent'].')*?'.
self::$_grammar['FWS'].'?\]'.self::$_grammar['CFWS'].'?)';
self::$_grammar['domain'] = '(?:'.self::$_grammar['dot-atom'].'|'.
self::$_grammar['domain-literal'].')';
self::$_grammar['addr-spec'] = '(?:'.self::$_grammar['local-part'].'@'.
self::$_grammar['domain'].')';
}
/**
@@ -131,11 +129,11 @@ class Swift_Mime_Grammar
{
if (array_key_exists($name, self::$_grammar)) {
return self::$_grammar[$name];
} else {
throw new Swift_RfcComplianceException(
"No such grammar '" . $name . "' defined."
);
}
throw new Swift_RfcComplianceException(
"No such grammar '".$name."' defined."
);
}
/**
@@ -170,7 +168,7 @@ class Swift_Mime_Grammar
public function escapeSpecials($token, $include = array(), $exclude = array())
{
foreach (array_merge(array('\\'), array_diff(self::$_specials, $exclude), $include) as $char) {
$token = str_replace($char, '\\' . $char, $token);
$token = str_replace($char, '\\'.$char, $token);
}
return $token;

View File

@@ -11,9 +11,7 @@
/**
* A MIME Header.
*
* @package Swift
* @subpackage Mime
* @author Chris Corbyn
* @author Chris Corbyn
*/
interface Swift_Mime_Header
{

View File

@@ -11,9 +11,7 @@
/**
* Interface for all Header Encoding schemes.
*
* @package Swift
* @subpackage Mime
* @author Chris Corbyn
* @author Chris Corbyn
*/
interface Swift_Mime_HeaderEncoder extends Swift_Encoder
{

View File

@@ -11,9 +11,7 @@
/**
* Handles Base64 (B) Header Encoding in Swift Mailer.
*
* @package Swift
* @subpackage Mime
* @author Chris Corbyn
* @author Chris Corbyn
*/
class Swift_Mime_HeaderEncoder_Base64HeaderEncoder extends Swift_Encoder_Base64Encoder implements Swift_Mime_HeaderEncoder
{
@@ -34,10 +32,10 @@ class Swift_Mime_HeaderEncoder_Base64HeaderEncoder extends Swift_Encoder_Base64E
* If the charset is iso-2022-jp, it uses mb_encode_mimeheader instead of
* default encodeString, otherwise pass to the parent method.
*
* @param string $string string to encode
* @param int $firstLineOffset
* @param int $maxLineLength optional, 0 indicates the default of 76 bytes
* @param string $charset
* @param string $string string to encode
* @param int $firstLineOffset
* @param int $maxLineLength optional, 0 indicates the default of 76 bytes
* @param string $charset
*
* @return string
*/

View File

@@ -11,9 +11,7 @@
/**
* Handles Quoted Printable (Q) Header Encoding in Swift Mailer.
*
* @package Swift
* @subpackage Mime
* @author Chris Corbyn
* @author Chris Corbyn
*/
class Swift_Mime_HeaderEncoder_QpHeaderEncoder extends Swift_Encoder_QpEncoder implements Swift_Mime_HeaderEncoder
{
@@ -52,9 +50,9 @@ class Swift_Mime_HeaderEncoder_QpHeaderEncoder extends Swift_Encoder_QpEncoder i
/**
* Takes an unencoded string and produces a QP encoded string from it.
*
* @param string $string string to encode
* @param int $firstLineOffset optional
* @param int $maxLineLength optional, 0 indicates the default of 76 chars
* @param string $string string to encode
* @param int $firstLineOffset optional
* @param int $maxLineLength optional, 0 indicates the default of 76 chars
*
* @return string
*/

View File

@@ -11,9 +11,7 @@
/**
* Creates MIME headers.
*
* @package Swift
* @subpackage Mime
* @author Chris Corbyn
* @author Chris Corbyn
*/
interface Swift_Mime_HeaderFactory extends Swift_Mime_CharsetObserver
{
@@ -30,8 +28,8 @@ interface Swift_Mime_HeaderFactory extends Swift_Mime_CharsetObserver
/**
* Create a new Date header using $timestamp (UNIX time).
*
* @param string $name
* @param int $timestamp
* @param string $name
* @param int $timestamp
*
* @return Swift_Mime_Header
*/

View File

@@ -11,9 +11,7 @@
/**
* A collection of MIME headers.
*
* @package Swift
* @subpackage Mime
* @author Chris Corbyn
* @author Chris Corbyn
*/
interface Swift_Mime_HeaderSet extends Swift_Mime_CharsetObserver
{
@@ -28,8 +26,8 @@ interface Swift_Mime_HeaderSet extends Swift_Mime_CharsetObserver
/**
* Add a new Date header using $timestamp (UNIX time).
*
* @param string $name
* @param int $timestamp
* @param string $name
* @param int $timestamp
*/
public function addDateHeader($name, $timestamp = null);
@@ -71,8 +69,8 @@ interface Swift_Mime_HeaderSet extends Swift_Mime_CharsetObserver
*
* If multiple headers match, the actual one may be specified by $index.
*
* @param string $name
* @param int $index
* @param string $name
* @param int $index
*
* @return bool
*/
@@ -97,8 +95,8 @@ interface Swift_Mime_HeaderSet extends Swift_Mime_CharsetObserver
* If multiple headers match, the actual one may be specified by $index.
* Returns NULL if none present.
*
* @param string $name
* @param int $index
* @param string $name
* @param int $index
*
* @return Swift_Mime_Header
*/
@@ -114,19 +112,19 @@ interface Swift_Mime_HeaderSet extends Swift_Mime_CharsetObserver
public function getAll($name = null);
/**
* Return the name of all Headers
* Return the name of all Headers.
*
* @return array
*/
public function listAll();
/**
/**
* Remove the header with the given $name if it's set.
*
* If multiple headers match, the actual one may be specified by $index.
*
* @param string $name
* @param int $index
* @param string $name
* @param int $index
*/
public function remove($name, $index = 0);
@@ -140,7 +138,7 @@ interface Swift_Mime_HeaderSet extends Swift_Mime_CharsetObserver
/**
* Create a new instance of this HeaderSet.
*
* @return Swift_Mime_HeaderSet
* @return self
*/
public function newInstance();

View File

@@ -11,9 +11,7 @@
/**
* An abstract base MIME Header.
*
* @package Swift
* @subpackage Mime
* @author Chris Corbyn
* @author Chris Corbyn
*/
abstract class Swift_Mime_Headers_AbstractHeader implements Swift_Mime_Header
{
@@ -179,7 +177,7 @@ abstract class Swift_Mime_Headers_AbstractHeader implements Swift_Mime_Header
/**
* Set the maximum length of lines in the header (excluding EOL).
*
* @param int $lineLength
* @param int $lineLength
*/
public function setMaxLineLength($lineLength)
{
@@ -200,9 +198,9 @@ abstract class Swift_Mime_Headers_AbstractHeader implements Swift_Mime_Header
/**
* Get this Header rendered as a RFC 2822 compliant string.
*
* @return string
*
* @throws Swift_RfcComplianceException
*
* @return string
*/
public function toString()
{
@@ -221,8 +219,6 @@ abstract class Swift_Mime_Headers_AbstractHeader implements Swift_Mime_Header
return $this->toString();
}
// -- Points of extension
/**
* Set the name of this Header field.
*
@@ -249,18 +245,19 @@ abstract class Swift_Mime_Headers_AbstractHeader implements Swift_Mime_Header
// Treat token as exactly what was given
$phraseStr = $string;
// If it's not valid
if (!preg_match('/^' . $this->getGrammar()->getDefinition('phrase') . '$/D', $phraseStr)) {
if (!preg_match('/^'.$this->getGrammar()->getDefinition('phrase').'$/D', $phraseStr)) {
// .. but it is just ascii text, try escaping some characters
// and make it a quoted-string
if (preg_match('/^' . $this->getGrammar()->getDefinition('text') . '*$/D', $phraseStr)) {
if (preg_match('/^'.$this->getGrammar()->getDefinition('text').'*$/D', $phraseStr)) {
$phraseStr = $this->getGrammar()->escapeSpecials(
$phraseStr, array('"'), $this->getGrammar()->getSpecials()
);
$phraseStr = '"' . $phraseStr . '"';
} else { // ... otherwise it needs encoding
$phraseStr = '"'.$phraseStr.'"';
} else {
// ... otherwise it needs encoding
// Determine space remaining on line if first line
if ($shorten) {
$usedLength = strlen($header->getFieldName() . ': ');
$usedLength = strlen($header->getFieldName().': ');
} else {
$usedLength = 0;
}
@@ -299,7 +296,7 @@ abstract class Swift_Mime_Headers_AbstractHeader implements Swift_Mime_Header
}
if (-1 == $usedLength) {
$usedLength = strlen($header->getFieldName() . ': ') + strlen($value);
$usedLength = strlen($header->getFieldName().': ') + strlen($value);
}
$value .= $this->getTokenAsEncodedWord($token, $usedLength);
@@ -358,8 +355,8 @@ abstract class Swift_Mime_Headers_AbstractHeader implements Swift_Mime_Header
/**
* Get a token as an encoded word for safe insertion into headers.
*
* @param string $token token to encode
* @param int $firstLineOffset optional
* @param string $token token to encode
* @param int $firstLineOffset optional
*
* @return string
*/
@@ -368,13 +365,14 @@ abstract class Swift_Mime_Headers_AbstractHeader implements Swift_Mime_Header
// Adjust $firstLineOffset to account for space needed for syntax
$charsetDecl = $this->_charset;
if (isset($this->_lang)) {
$charsetDecl .= '*' . $this->_lang;
$charsetDecl .= '*'.$this->_lang;
}
$encodingWrapperLength = strlen(
'=?' . $charsetDecl . '?' . $this->_encoder->getName() . '??='
'=?'.$charsetDecl.'?'.$this->_encoder->getName().'??='
);
if ($firstLineOffset >= 75) { //Does this logic need to be here?
if ($firstLineOffset >= 75) {
//Does this logic need to be here?
$firstLineOffset = 0;
}
@@ -384,11 +382,12 @@ abstract class Swift_Mime_Headers_AbstractHeader implements Swift_Mime_Header
)
);
if (strtolower($this->_charset) !== 'iso-2022-jp') { // special encoding for iso-2022-jp using mb_encode_mimeheader
if (strtolower($this->_charset) !== 'iso-2022-jp') {
// special encoding for iso-2022-jp using mb_encode_mimeheader
foreach ($encodedTextLines as $lineNum => $line) {
$encodedTextLines[$lineNum] = '=?' . $charsetDecl .
'?' . $this->_encoder->getName() .
'?' . $line . '?=';
$encodedTextLines[$lineNum] = '=?'.$charsetDecl.
'?'.$this->_encoder->getName().
'?'.$line.'?=';
}
}
@@ -430,7 +429,7 @@ abstract class Swift_Mime_Headers_AbstractHeader implements Swift_Mime_Header
/**
* Clear the cached value if $condition is met.
*
* @param bool $condition
* @param bool $condition
*/
protected function clearCachedValueIf($condition)
{
@@ -439,8 +438,6 @@ abstract class Swift_Mime_Headers_AbstractHeader implements Swift_Mime_Header
}
}
// -- Private methods
/**
* Generate a list of all tokens in the final header.
*
@@ -450,7 +447,7 @@ abstract class Swift_Mime_Headers_AbstractHeader implements Swift_Mime_Header
*/
protected function toTokens($string = null)
{
if (is_null($string)) {
if (null === $string) {
$string = $this->getFieldBody();
}
@@ -463,6 +460,7 @@ abstract class Swift_Mime_Headers_AbstractHeader implements Swift_Mime_Header
$tokens[] = $newToken;
}
}
return $tokens;
}
@@ -478,18 +476,17 @@ abstract class Swift_Mime_Headers_AbstractHeader implements Swift_Mime_Header
{
$lineCount = 0;
$headerLines = array();
$headerLines[] = $this->_name . ': ';
$currentLine =& $headerLines[$lineCount++];
$headerLines[] = $this->_name.': ';
$currentLine = &$headerLines[$lineCount++];
// Build all tokens back into compliant header
foreach ($tokens as $i => $token) {
// Line longer than specified maximum or token was just a new line
if (("\r\n" == $token) ||
($i > 0 && strlen($currentLine . $token) > $this->_lineLength)
&& 0 < strlen($currentLine))
{
($i > 0 && strlen($currentLine.$token) > $this->_lineLength)
&& 0 < strlen($currentLine)) {
$headerLines[] = '';
$currentLine =& $headerLines[$lineCount++];
$currentLine = &$headerLines[$lineCount++];
}
// Append token to the line
@@ -499,6 +496,6 @@ abstract class Swift_Mime_Headers_AbstractHeader implements Swift_Mime_Header
}
// Implode with FWS (RFC 2822, 2.2.3)
return implode("\r\n", $headerLines) . "\r\n";
return implode("\r\n", $headerLines)."\r\n";
}
}

View File

@@ -11,9 +11,7 @@
/**
* A Date MIME Header for Swift Mailer.
*
* @package Swift
* @subpackage Mime
* @author Chris Corbyn
* @author Chris Corbyn
*/
class Swift_Mime_Headers_DateHeader extends Swift_Mime_Headers_AbstractHeader
{
@@ -61,7 +59,7 @@ class Swift_Mime_Headers_DateHeader extends Swift_Mime_Headers_AbstractHeader
*
* This method takes a UNIX timestamp.
*
* @param int $model
* @param int $model
*/
public function setFieldBodyModel($model)
{
@@ -93,11 +91,11 @@ class Swift_Mime_Headers_DateHeader extends Swift_Mime_Headers_AbstractHeader
/**
* Set the UNIX timestamp of the Date in this Header.
*
* @param int $timestamp
* @param int $timestamp
*/
public function setTimestamp($timestamp)
{
if (!is_null($timestamp)) {
if (null !== $timestamp) {
$timestamp = (int) $timestamp;
}
$this->clearCachedValueIf($this->_timestamp != $timestamp);

View File

@@ -11,9 +11,7 @@
/**
* An ID MIME Header for something like Message-ID or Content-ID.
*
* @package Swift
* @subpackage Mime
* @author Chris Corbyn
* @author Chris Corbyn
*/
class Swift_Mime_Headers_IdentificationHeader extends Swift_Mime_Headers_AbstractHeader
{
@@ -141,9 +139,9 @@ class Swift_Mime_Headers_IdentificationHeader extends Swift_Mime_Headers_Abstrac
*
* @see toString()
*
* @return string
*
* @throws Swift_RfcComplianceException
*
* @return string
*/
public function getFieldBody()
{
@@ -151,7 +149,7 @@ class Swift_Mime_Headers_IdentificationHeader extends Swift_Mime_Headers_Abstrac
$angleAddrs = array();
foreach ($this->_ids as $id) {
$angleAddrs[] = '<' . $id . '>';
$angleAddrs[] = '<'.$id.'>';
}
$this->setCachedValue(implode(' ', $angleAddrs));
@@ -170,13 +168,12 @@ class Swift_Mime_Headers_IdentificationHeader extends Swift_Mime_Headers_Abstrac
private function _assertValidId($id)
{
if (!preg_match(
'/^' . $this->getGrammar()->getDefinition('id-left') . '@' .
$this->getGrammar()->getDefinition('id-right') . '$/D',
'/^'.$this->getGrammar()->getDefinition('id-left').'@'.
$this->getGrammar()->getDefinition('id-right').'$/D',
$id
))
{
)) {
throw new Swift_RfcComplianceException(
'Invalid ID given <' . $id . '>'
'Invalid ID given <'.$id.'>'
);
}
}

View File

@@ -11,9 +11,7 @@
/**
* A Mailbox Address MIME Header for something like From or Sender.
*
* @package Swift
* @subpackage Mime
* @author Chris Corbyn
* @author Chris Corbyn
*/
class Swift_Mime_Headers_MailboxHeader extends Swift_Mime_Headers_AbstractHeader
{
@@ -70,9 +68,9 @@ class Swift_Mime_Headers_MailboxHeader extends Swift_Mime_Headers_AbstractHeader
*
* This method returns an associative array like {@link getNameAddresses()}
*
* @return array
*
* @throws Swift_RfcComplianceException
*
* @return array
*/
public function getFieldBodyModel()
{
@@ -130,9 +128,9 @@ class Swift_Mime_Headers_MailboxHeader extends Swift_Mime_Headers_AbstractHeader
* @see getNameAddresses()
* @see toString()
*
* @return string[]
*
* @throws Swift_RfcComplianceException
*
* @return string[]
*/
public function getNameAddressStrings()
{
@@ -226,22 +224,20 @@ class Swift_Mime_Headers_MailboxHeader extends Swift_Mime_Headers_AbstractHeader
*
* @see toString()
*
* @return string
*
* @throws Swift_RfcComplianceException
*
* @return string
*/
public function getFieldBody()
{
// Compute the string value of the header only if needed
if (is_null($this->getCachedValue())) {
if (null === $this->getCachedValue()) {
$this->setCachedValue($this->createMailboxListString($this->_mailboxes));
}
return $this->getCachedValue();
}
// -- Points of extension
/**
* Normalizes a user-input list of mailboxes into consistent key=>value pairs.
*
@@ -254,7 +250,8 @@ class Swift_Mime_Headers_MailboxHeader extends Swift_Mime_Headers_AbstractHeader
$actualMailboxes = array();
foreach ($mailboxes as $key => $value) {
if (is_string($key)) { //key is email addr
if (is_string($key)) {
//key is email addr
$address = $key;
$name = $value;
} else {
@@ -271,16 +268,14 @@ class Swift_Mime_Headers_MailboxHeader extends Swift_Mime_Headers_AbstractHeader
/**
* Produces a compliant, formatted display-name based on the string given.
*
* @param string $displayName as displayed
* @param bool $shorten the first line to make remove for header name
* @param string $displayName as displayed
* @param bool $shorten the first line to make remove for header name
*
* @return string
*/
protected function createDisplayNameString($displayName, $shorten = false)
{
return $this->createPhrase($this, $displayName,
$this->getCharset(), $this->getEncoder(), $shorten
);
return $this->createPhrase($this, $displayName, $this->getCharset(), $this->getEncoder(), $shorten);
}
/**
@@ -288,9 +283,9 @@ class Swift_Mime_Headers_MailboxHeader extends Swift_Mime_Headers_AbstractHeader
*
* @param string[] $mailboxes
*
* @return string
*
* @throws Swift_RfcComplianceException
*
* @return string
*/
protected function createMailboxListString(array $mailboxes)
{
@@ -300,8 +295,9 @@ class Swift_Mime_Headers_MailboxHeader extends Swift_Mime_Headers_AbstractHeader
/**
* Redefine the encoding requirements for mailboxes.
*
* Commas and semicolons are used to separate
* multiple addresses, and should therefore be encoded
* All "specials" must be encoded as the full header value will not be quoted
*
* @see RFC 2822 3.2.1
*
* @param string $token
*
@@ -309,11 +305,9 @@ class Swift_Mime_Headers_MailboxHeader extends Swift_Mime_Headers_AbstractHeader
*/
protected function tokenNeedsEncoding($token)
{
return preg_match('/[,;]/', $token) || parent::tokenNeedsEncoding($token);
return preg_match('/[()<>\[\]:;@\,."]/', $token) || parent::tokenNeedsEncoding($token);
}
// -- Private methods
/**
* Return an array of strings conforming the the name-addr spec of RFC 2822.
*
@@ -327,9 +321,9 @@ class Swift_Mime_Headers_MailboxHeader extends Swift_Mime_Headers_AbstractHeader
foreach ($mailboxes as $email => $name) {
$mailboxStr = $email;
if (!is_null($name)) {
if (null !== $name) {
$nameStr = $this->createDisplayNameString($name, empty($strings));
$mailboxStr = $nameStr . ' <' . $mailboxStr . '>';
$mailboxStr = $nameStr.' <'.$mailboxStr.'>';
}
$strings[] = $mailboxStr;
}
@@ -346,11 +340,10 @@ class Swift_Mime_Headers_MailboxHeader extends Swift_Mime_Headers_AbstractHeader
*/
private function _assertValidAddress($address)
{
if (!preg_match('/^' . $this->getGrammar()->getDefinition('addr-spec') . '$/D',
$address))
{
if (!preg_match('/^'.$this->getGrammar()->getDefinition('addr-spec').'$/D',
$address)) {
throw new Swift_RfcComplianceException(
'Address in mailbox given [' . $address .
'Address in mailbox given ['.$address.
'] does not comply with RFC 2822, 3.6.2.'
);
}

View File

@@ -9,11 +9,9 @@
*/
/**
* An OpenDKIM Specific Header using only raw header datas without encoding
* An OpenDKIM Specific Header using only raw header datas without encoding.
*
* @package Swift
* @subpackage Mime
* @author De Cock Xavier <xdecock@gmail.com>
* @author De Cock Xavier <xdecock@gmail.com>
*/
class Swift_Mime_Headers_OpenDKIMHeader implements Swift_Mime_Header
{
@@ -23,19 +21,16 @@ class Swift_Mime_Headers_OpenDKIMHeader implements Swift_Mime_Header
* @var string
*/
private $_value;
/**
* The name of this Header
* The name of this Header.
*
* @var string
*/
private $_fieldName;
/**
* Creates a new SimpleHeader with $name.
*
* @param string $name
* @param Swift_Mime_HeaderEncoder $encoder
* @param Swift_Mime_Grammar $grammar
/**
* @param string $name
*/
public function __construct($name)
{
@@ -108,7 +103,7 @@ class Swift_Mime_Headers_OpenDKIMHeader implements Swift_Mime_Header
{
return $this->_value;
}
/**
* Get this Header rendered as a RFC 2822 compliant string.
*
@@ -116,24 +111,23 @@ class Swift_Mime_Headers_OpenDKIMHeader implements Swift_Mime_Header
*/
public function toString()
{
return $this->_fieldName.': '.$this->_value;
return $this->_fieldName.': '.$this->_value;
}
/**
* Set the Header FieldName
* @see Swift_Mime_Header::getFieldName()
*/
public function getFieldName()
{
* Set the Header FieldName.
*
* @see Swift_Mime_Header::getFieldName()
*/
public function getFieldName()
{
return $this->_fieldName;
}
/**
* Ignored
/**
* Ignored.
*/
public function setCharset($charset)
public function setCharset($charset)
{
}
}

View File

@@ -11,9 +11,7 @@
/**
* An abstract base MIME Header.
*
* @package Swift
* @subpackage Mime
* @author Chris Corbyn
* @author Chris Corbyn
*/
class Swift_Mime_Headers_ParameterizedHeader extends Swift_Mime_Headers_UnstructuredHeader implements Swift_Mime_ParameterizedHeader
{
@@ -100,9 +98,7 @@ class Swift_Mime_Headers_ParameterizedHeader extends Swift_Mime_Headers_Unstruct
{
$params = $this->getParameters();
return array_key_exists($parameter, $params)
? $params[$parameter]
: null;
return array_key_exists($parameter, $params) ? $params[$parameter] : null;
}
/**
@@ -135,17 +131,15 @@ class Swift_Mime_Headers_ParameterizedHeader extends Swift_Mime_Headers_Unstruct
{
$body = parent::getFieldBody();
foreach ($this->_params as $name => $value) {
if (!is_null($value)) {
if (null !== $value) {
// Add the parameter
$body .= '; ' . $this->_createParameter($name, $value);
$body .= '; '.$this->_createParameter($name, $value);
}
}
return $body;
}
// -- Protected methods
/**
* Generate a list of all tokens in the final header.
*
@@ -162,11 +156,11 @@ class Swift_Mime_Headers_ParameterizedHeader extends Swift_Mime_Headers_Unstruct
// Try creating any parameters
foreach ($this->_params as $name => $value) {
if (!is_null($value)) {
if (null !== $value) {
// Add the semi-colon separator
$tokens[count($tokens)-1] .= ';';
$tokens[count($tokens) - 1] .= ';';
$tokens = array_merge($tokens, $this->generateTokenLines(
' ' . $this->_createParameter($name, $value)
' '.$this->_createParameter($name, $value)
));
}
}
@@ -174,8 +168,6 @@ class Swift_Mime_Headers_ParameterizedHeader extends Swift_Mime_Headers_Unstruct
return $tokens;
}
// -- Private methods
/**
* Render a RFC 2047 compliant header parameter from the $name and $value.
*
@@ -190,19 +182,19 @@ class Swift_Mime_Headers_ParameterizedHeader extends Swift_Mime_Headers_Unstruct
$encoded = false;
// Allow room for parameter name, indices, "=" and DQUOTEs
$maxValueLength = $this->getMaxLineLength() - strlen($name . '=*N"";') - 1;
$maxValueLength = $this->getMaxLineLength() - strlen($name.'=*N"";') - 1;
$firstLineOffset = 0;
// If it's not already a valid parameter value...
if (!preg_match('/^' . self::TOKEN_REGEX . '$/D', $value)) {
if (!preg_match('/^'.self::TOKEN_REGEX.'$/D', $value)) {
// TODO: text, or something else??
// ... and it's not ascii
if (!preg_match('/^' . $this->getGrammar()->getDefinition('text') . '*$/D', $value)) {
if (!preg_match('/^'.$this->getGrammar()->getDefinition('text').'*$/D', $value)) {
$encoded = true;
// Allow space for the indices, charset and language
$maxValueLength = $this->getMaxLineLength() - strlen($name . '*N*="";') - 1;
$maxValueLength = $this->getMaxLineLength() - strlen($name.'*N*="";') - 1;
$firstLineOffset = strlen(
$this->getCharset() . "'" . $this->getLanguage() . "'"
$this->getCharset()."'".$this->getLanguage()."'"
);
}
}
@@ -213,7 +205,8 @@ class Swift_Mime_Headers_ParameterizedHeader extends Swift_Mime_Headers_Unstruct
$value = $this->_paramEncoder->encodeString(
$origValue, $firstLineOffset, $maxValueLength, $this->getCharset()
);
} else { // We have to go against RFC 2183/2231 in some areas for interoperability
} else {
// We have to go against RFC 2183/2231 in some areas for interoperability
$value = $this->getTokenAsEncodedWord($origValue);
$encoded = false;
}
@@ -225,13 +218,13 @@ class Swift_Mime_Headers_ParameterizedHeader extends Swift_Mime_Headers_Unstruct
if (count($valueLines) > 1) {
$paramLines = array();
foreach ($valueLines as $i => $line) {
$paramLines[] = $name . '*' . $i .
$paramLines[] = $name.'*'.$i.
$this->_getEndOfParameterValue($line, true, $i == 0);
}
return implode(";\r\n ", $paramLines);
} else {
return $name . $this->_getEndOfParameterValue(
return $name.$this->_getEndOfParameterValue(
$valueLines[0], $encoded, true
);
}
@@ -240,26 +233,26 @@ class Swift_Mime_Headers_ParameterizedHeader extends Swift_Mime_Headers_Unstruct
/**
* Returns the parameter value from the "=" and beyond.
*
* @param string $value to append
* @param bool $encoded
* @param bool $firstLine
* @param string $value to append
* @param bool $encoded
* @param bool $firstLine
*
* @return string
*/
private function _getEndOfParameterValue($value, $encoded = false, $firstLine = false)
{
if (!preg_match('/^' . self::TOKEN_REGEX . '$/D', $value)) {
$value = '"' . $value . '"';
if (!preg_match('/^'.self::TOKEN_REGEX.'$/D', $value)) {
$value = '"'.$value.'"';
}
$prepend = '=';
if ($encoded) {
$prepend = '*=';
if ($firstLine) {
$prepend = '*=' . $this->getCharset() . "'" . $this->getLanguage() .
$prepend = '*='.$this->getCharset()."'".$this->getLanguage().
"'";
}
}
return $prepend . $value;
return $prepend.$value;
}
}

View File

@@ -11,9 +11,7 @@
/**
* A Path Header in Swift Mailer, such a Return-Path.
*
* @package Swift
* @subpackage Mime
* @author Chris Corbyn
* @author Chris Corbyn
*/
class Swift_Mime_Headers_PathHeader extends Swift_Mime_Headers_AbstractHeader
{
@@ -82,7 +80,7 @@ class Swift_Mime_Headers_PathHeader extends Swift_Mime_Headers_AbstractHeader
*/
public function setAddress($address)
{
if (is_null($address)) {
if (null === $address) {
$this->_address = null;
} elseif ('' == $address) {
$this->_address = '';
@@ -119,7 +117,7 @@ class Swift_Mime_Headers_PathHeader extends Swift_Mime_Headers_AbstractHeader
{
if (!$this->getCachedValue()) {
if (isset($this->_address)) {
$this->setCachedValue('<' . $this->_address . '>');
$this->setCachedValue('<'.$this->_address.'>');
}
}
@@ -135,9 +133,8 @@ class Swift_Mime_Headers_PathHeader extends Swift_Mime_Headers_AbstractHeader
*/
private function _assertValidAddress($address)
{
if (!preg_match('/^' . $this->getGrammar()->getDefinition('addr-spec') . '$/D',
$address))
{
if (!preg_match('/^'.$this->getGrammar()->getDefinition('addr-spec').'$/D',
$address)) {
throw new Swift_RfcComplianceException(
'Address set in PathHeader does not comply with addr-spec of RFC 2822.'
);

View File

@@ -11,9 +11,7 @@
/**
* A Simple MIME Header.
*
* @package Swift
* @subpackage Mime
* @author Chris Corbyn
* @author Chris Corbyn
*/
class Swift_Mime_Headers_UnstructuredHeader extends Swift_Mime_Headers_AbstractHeader
{

View File

@@ -11,9 +11,7 @@
/**
* A Message (RFC 2822) object.
*
* @package Swift
* @subpackage Mime
* @author Chris Corbyn
* @author Chris Corbyn
*/
interface Swift_Mime_Message extends Swift_Mime_MimeEntity
{
@@ -41,7 +39,7 @@ interface Swift_Mime_Message extends Swift_Mime_MimeEntity
/**
* Set the origination date of the message as a UNIX timestamp.
*
* @param int $date
* @param int $date
*/
public function setDate($date);

View File

@@ -11,9 +11,7 @@
/**
* A MIME entity, such as an attachment.
*
* @package Swift
* @subpackage Mime
* @author Chris Corbyn
* @author Chris Corbyn
*/
interface Swift_Mime_MimeEntity extends Swift_Mime_CharsetObserver, Swift_Mime_EncodingObserver
{
@@ -33,6 +31,7 @@ interface Swift_Mime_MimeEntity extends Swift_Mime_CharsetObserver, Swift_Mime_E
* Get the level at which this entity shall be nested in final document.
*
* The lower the value, the more outermost the entity will be nested.
*
* @see LEVEL_TOP, LEVEL_MIXED, LEVEL_RELATED, LEVEL_ALTERNATIVE
*
* @return int
@@ -41,6 +40,7 @@ interface Swift_Mime_MimeEntity extends Swift_Mime_CharsetObserver, Swift_Mime_E
/**
* Get the qualified content-type of this mime entity.
*
* @return string
*/
public function getContentType();
@@ -80,7 +80,7 @@ interface Swift_Mime_MimeEntity extends Swift_Mime_CharsetObserver, Swift_Mime_E
/**
* Get the collection of Headers in this Mime entity.
*
* @return Swift_Mime_Header[]
* @return Swift_Mime_HeaderSet
*/
public function getHeaders();

View File

@@ -11,9 +11,7 @@
/**
* A MIME part, in a multipart message.
*
* @package Swift
* @subpackage Mime
* @author Chris Corbyn
* @author Chris Corbyn
*/
class Swift_Mime_MimePart extends Swift_Mime_SimpleMimeEntity
{
@@ -42,7 +40,7 @@ class Swift_Mime_MimePart extends Swift_Mime_SimpleMimeEntity
{
parent::__construct($headers, $encoder, $cache, $grammar);
$this->setContentType('text/plain');
if (!is_null($charset)) {
if (null !== $charset) {
$this->setCharset($charset);
}
}
@@ -55,7 +53,7 @@ class Swift_Mime_MimePart extends Swift_Mime_SimpleMimeEntity
* @param string $contentType optional
* @param string $charset optional
*
* @return Swift_Mime_MimePart
* @return $this
*/
public function setBody($body, $contentType = null, $charset = null)
{
@@ -84,7 +82,7 @@ class Swift_Mime_MimePart extends Swift_Mime_SimpleMimeEntity
*
* @param string $charset
*
* @return Swift_Mime_MimePart
* @return $this
*/
public function setCharset($charset)
{
@@ -113,7 +111,7 @@ class Swift_Mime_MimePart extends Swift_Mime_SimpleMimeEntity
*
* @param string $format
*
* @return Swift_Mime_MimePart
* @return $this
*/
public function setFormat($format)
{
@@ -130,17 +128,15 @@ class Swift_Mime_MimePart extends Swift_Mime_SimpleMimeEntity
*/
public function getDelSp()
{
return ($this->_getHeaderParameter('Content-Type', 'delsp') == 'yes')
? true
: false;
return 'yes' == $this->_getHeaderParameter('Content-Type', 'delsp') ? true : false;
}
/**
* Turn delsp on or off for this entity.
*
* @param bool $delsp
* @param bool $delsp
*
* @return Swift_Mime_MimePart
* @return $this
*/
public function setDelSp($delsp = true)
{
@@ -173,8 +169,6 @@ class Swift_Mime_MimePart extends Swift_Mime_SimpleMimeEntity
$this->setCharset($charset);
}
// -- Protected methods
/** Fix the content-type and encoding of this entity */
protected function _fixHeaders()
{
@@ -200,12 +194,12 @@ class Swift_Mime_MimePart extends Swift_Mime_SimpleMimeEntity
protected function _convertString($string)
{
$charset = strtolower($this->getCharset());
if (!in_array($charset, array('utf-8', 'iso-8859-1', ''))) {
if (!in_array($charset, array('utf-8', 'iso-8859-1', 'iso-8859-15', ''))) {
// mb_convert_encoding must be the first one to check, since iconv cannot convert some words.
if (function_exists('mb_convert_encoding')) {
$string = mb_convert_encoding($string, 'utf-8', $charset);
$string = mb_convert_encoding($string, $charset, 'utf-8');
} elseif (function_exists('iconv')) {
$string = iconv($charset, 'utf-8//TRANSLIT//IGNORE', $string);
$string = iconv('utf-8//TRANSLIT//IGNORE', $charset, $string);
} else {
throw new Swift_SwiftException('No suitable convert encoding function (use UTF-8 as your charset or install the mbstring or iconv extension).');
}

View File

@@ -11,9 +11,7 @@
/**
* A MIME Header with parameters.
*
* @package Swift
* @subpackage Mime
* @author Chris Corbyn
* @author Chris Corbyn
*/
interface Swift_Mime_ParameterizedHeader extends Swift_Mime_Header
{

View File

@@ -11,9 +11,7 @@
/**
* Creates MIME headers.
*
* @package Swift
* @subpackage Mime
* @author Chris Corbyn
* @author Chris Corbyn
*/
class Swift_Mime_SimpleHeaderFactory implements Swift_Mime_HeaderFactory
{
@@ -66,8 +64,9 @@ class Swift_Mime_SimpleHeaderFactory implements Swift_Mime_HeaderFactory
/**
* Create a new Date header using $timestamp (UNIX time).
* @param string $name
* @param int|null $timestamp
*
* @param string $name
* @param int|null $timestamp
*
* @return Swift_Mime_Header
*/
@@ -113,12 +112,7 @@ class Swift_Mime_SimpleHeaderFactory implements Swift_Mime_HeaderFactory
public function createParameterizedHeader($name, $value = null,
$params = array())
{
$header = new Swift_Mime_Headers_ParameterizedHeader($name,
$this->_encoder, (strtolower($name) == 'content-disposition')
? $this->_paramEncoder
: null,
$this->_grammar
);
$header = new Swift_Mime_Headers_ParameterizedHeader($name, $this->_encoder, strtolower($name) == 'content-disposition' ? $this->_paramEncoder : null, $this->_grammar);
if (isset($value)) {
$header->setFieldBodyModel($value);
}
@@ -180,7 +174,14 @@ class Swift_Mime_SimpleHeaderFactory implements Swift_Mime_HeaderFactory
$this->_paramEncoder->charsetChanged($charset);
}
// -- Private methods
/**
* Make a deep copy of object.
*/
public function __clone()
{
$this->_encoder = clone $this->_encoder;
$this->_paramEncoder = clone $this->_paramEncoder;
}
/** Apply the charset to the Header */
private function _setHeaderCharset(Swift_Mime_Header $header)

View File

@@ -11,9 +11,7 @@
/**
* A collection of MIME headers.
*
* @package Swift
* @subpackage Mime
* @author Chris Corbyn
* @author Chris Corbyn
*/
class Swift_Mime_SimpleHeaderSet implements Swift_Mime_HeaderSet
{
@@ -73,8 +71,8 @@ class Swift_Mime_SimpleHeaderSet implements Swift_Mime_HeaderSet
/**
* Add a new Date header using $timestamp (UNIX time).
*
* @param string $name
* @param int $timestamp
* @param string $name
* @param int $timestamp
*/
public function addDateHeader($name, $timestamp = null)
{
@@ -133,8 +131,8 @@ class Swift_Mime_SimpleHeaderSet implements Swift_Mime_HeaderSet
*
* If multiple headers match, the actual one may be specified by $index.
*
* @param string $name
* @param int $index
* @param string $name
* @param int $index
*
* @return bool
*/
@@ -142,7 +140,16 @@ class Swift_Mime_SimpleHeaderSet implements Swift_Mime_HeaderSet
{
$lowerName = strtolower($name);
return array_key_exists($lowerName, $this->_headers) && array_key_exists($index, $this->_headers[$lowerName]);
if (!array_key_exists($lowerName, $this->_headers)) {
return false;
}
if (func_num_args() < 2) {
// index was not specified, so we only need to check that there is at least one header value set
return (bool) count($this->_headers[$lowerName]);
}
return array_key_exists($index, $this->_headers[$lowerName]);
}
/**
@@ -168,17 +175,25 @@ class Swift_Mime_SimpleHeaderSet implements Swift_Mime_HeaderSet
* If multiple headers match, the actual one may be specified by $index.
* Returns NULL if none present.
*
* @param string $name
* @param int $index
* @param string $name
* @param int $index
*
* @return Swift_Mime_Header
*/
public function get($name, $index = 0)
{
if ($this->has($name, $index)) {
$lowerName = strtolower($name);
$name = strtolower($name);
return $this->_headers[$lowerName][$index];
if (func_num_args() < 2) {
if ($this->has($name)) {
$values = array_values($this->_headers[$name]);
return array_shift($values);
}
} else {
if ($this->has($name, $index)) {
return $this->_headers[$name][$index];
}
}
}
@@ -209,7 +224,7 @@ class Swift_Mime_SimpleHeaderSet implements Swift_Mime_HeaderSet
}
/**
* Return the name of all Headers
* Return the name of all Headers.
*
* @return array
*/
@@ -223,13 +238,13 @@ class Swift_Mime_SimpleHeaderSet implements Swift_Mime_HeaderSet
return array_keys($headers);
}
/**
/**
* Remove the header with the given $name if it's set.
*
* If multiple headers match, the actual one may be specified by $index.
*
* @param string $name
* @param int $index
* @param string $name
* @param int $index
*/
public function remove($name, $index = 0)
{
@@ -251,7 +266,7 @@ class Swift_Mime_SimpleHeaderSet implements Swift_Mime_HeaderSet
/**
* Create a new instance of this HeaderSet.
*
* @return Swift_Mime_HeaderSet
* @return self
*/
public function newInstance()
{
@@ -327,8 +342,6 @@ class Swift_Mime_SimpleHeaderSet implements Swift_Mime_HeaderSet
return $this->toString();
}
// -- Private methods
/** Save a Header to the internal collection */
private function _storeHeader($name, Swift_Mime_Header $header, $offset = null)
{
@@ -353,12 +366,13 @@ class Swift_Mime_SimpleHeaderSet implements Swift_Mime_HeaderSet
{
$lowerA = strtolower($a);
$lowerB = strtolower($b);
$aPos = array_key_exists($lowerA, $this->_order)
? $this->_order[$lowerA]
: -1;
$bPos = array_key_exists($lowerB, $this->_order)
? $this->_order[$lowerB]
: -1;
$aPos = array_key_exists($lowerA, $this->_order) ? $this->_order[$lowerA] : -1;
$bPos = array_key_exists($lowerB, $this->_order) ? $this->_order[$lowerB] : -1;
if (-1 === $aPos && -1 === $bPos) {
// just be sure to be determinist here
return $a > $b ? -1 : 1;
}
if ($aPos == -1) {
return 1;
@@ -366,7 +380,7 @@ class Swift_Mime_SimpleHeaderSet implements Swift_Mime_HeaderSet
return -1;
}
return ($aPos < $bPos) ? -1 : 1;
return $aPos < $bPos ? -1 : 1;
}
/** Test if the given Header is always displayed */
@@ -384,4 +398,17 @@ class Swift_Mime_SimpleHeaderSet implements Swift_Mime_HeaderSet
}
}
}
/**
* Make a deep copy of object.
*/
public function __clone()
{
$this->_factory = clone $this->_factory;
foreach ($this->_headers as $groupKey => $headerGroup) {
foreach ($headerGroup as $key => $header) {
$this->_headers[$groupKey][$key] = clone $header;
}
}
}
}

View File

@@ -11,12 +11,16 @@
/**
* The default email message class.
*
* @package Swift
* @subpackage Mime
* @author Chris Corbyn
* @author Chris Corbyn
*/
class Swift_Mime_SimpleMessage extends Swift_Mime_MimePart implements Swift_Mime_Message
{
const PRIORITY_HIGHEST = 1;
const PRIORITY_HIGH = 2;
const PRIORITY_NORMAL = 3;
const PRIORITY_LOW = 4;
const PRIORITY_LOWEST = 5;
/**
* Create a new SimpleMessage with $headers, $encoder and $cache.
*
@@ -45,7 +49,7 @@ class Swift_Mime_SimpleMessage extends Swift_Mime_MimePart implements Swift_Mime
'Bcc',
'MIME-Version',
'Content-Type',
'Content-Transfer-Encoding'
'Content-Transfer-Encoding',
));
$this->getHeaders()->setAlwaysDisplayed(array('Date', 'Message-ID', 'From'));
$this->getHeaders()->addTextHeader('MIME-Version', '1.0');
@@ -69,7 +73,7 @@ class Swift_Mime_SimpleMessage extends Swift_Mime_MimePart implements Swift_Mime
*
* @param string $subject
*
* @return Swift_Mime_SimpleMessage
* @return $this
*/
public function setSubject($subject)
{
@@ -93,9 +97,9 @@ class Swift_Mime_SimpleMessage extends Swift_Mime_MimePart implements Swift_Mime
/**
* Set the date at which this message was created.
*
* @param int $date
* @param int $date
*
* @return Swift_Mime_SimpleMessage
* @return $this
*/
public function setDate($date)
{
@@ -121,7 +125,7 @@ class Swift_Mime_SimpleMessage extends Swift_Mime_MimePart implements Swift_Mime
*
* @param string $address
*
* @return Swift_Mime_SimpleMessage
* @return $this
*/
public function setReturnPath($address)
{
@@ -150,7 +154,7 @@ class Swift_Mime_SimpleMessage extends Swift_Mime_MimePart implements Swift_Mime
* @param string $address
* @param string $name optional
*
* @return Swift_Mime_SimpleMessage
* @return $this
*/
public function setSender($address, $name = null)
{
@@ -183,7 +187,7 @@ class Swift_Mime_SimpleMessage extends Swift_Mime_MimePart implements Swift_Mime
* @param string $address
* @param string $name optional
*
* @return Swift_Mime_SimpleMessage
* @return $this
*/
public function addFrom($address, $name = null)
{
@@ -201,10 +205,10 @@ class Swift_Mime_SimpleMessage extends Swift_Mime_MimePart implements Swift_Mime
* If $name is passed and the first parameter is a string, this name will be
* associated with the address.
*
* @param string $addresses
* @param string $name optional
* @param string|array $addresses
* @param string $name optional
*
* @return Swift_Mime_SimpleMessage
* @return $this
*/
public function setFrom($addresses, $name = null)
{
@@ -222,7 +226,7 @@ class Swift_Mime_SimpleMessage extends Swift_Mime_MimePart implements Swift_Mime
/**
* Get the from address of this message.
*
* @return string
* @return mixed
*/
public function getFrom()
{
@@ -237,7 +241,7 @@ class Swift_Mime_SimpleMessage extends Swift_Mime_MimePart implements Swift_Mime
* @param string $address
* @param string $name optional
*
* @return Swift_Mime_SimpleMessage
* @return $this
*/
public function addReplyTo($address, $name = null)
{
@@ -255,10 +259,10 @@ class Swift_Mime_SimpleMessage extends Swift_Mime_MimePart implements Swift_Mime
* If $name is passed and the first parameter is a string, this name will be
* associated with the address.
*
* @param string $addresses
* @param mixed $addresses
* @param string $name optional
*
* @return Swift_Mime_SimpleMessage
* @return $this
*/
public function setReplyTo($addresses, $name = null)
{
@@ -291,7 +295,7 @@ class Swift_Mime_SimpleMessage extends Swift_Mime_MimePart implements Swift_Mime
* @param string $address
* @param string $name optional
*
* @return Swift_Mime_SimpleMessage
* @return $this
*/
public function addTo($address, $name = null)
{
@@ -313,7 +317,7 @@ class Swift_Mime_SimpleMessage extends Swift_Mime_MimePart implements Swift_Mime
* @param mixed $addresses
* @param string $name optional
*
* @return Swift_Mime_SimpleMessage
* @return $this
*/
public function setTo($addresses, $name = null)
{
@@ -346,7 +350,7 @@ class Swift_Mime_SimpleMessage extends Swift_Mime_MimePart implements Swift_Mime
* @param string $address
* @param string $name optional
*
* @return Swift_Mime_SimpleMessage
* @return $this
*/
public function addCc($address, $name = null)
{
@@ -365,7 +369,7 @@ class Swift_Mime_SimpleMessage extends Swift_Mime_MimePart implements Swift_Mime
* @param mixed $addresses
* @param string $name optional
*
* @return Swift_Mime_SimpleMessage
* @return $this
*/
public function setCc($addresses, $name = null)
{
@@ -398,7 +402,7 @@ class Swift_Mime_SimpleMessage extends Swift_Mime_MimePart implements Swift_Mime
* @param string $address
* @param string $name optional
*
* @return Swift_Mime_SimpleMessage
* @return $this
*/
public function addBcc($address, $name = null)
{
@@ -417,7 +421,7 @@ class Swift_Mime_SimpleMessage extends Swift_Mime_MimePart implements Swift_Mime
* @param mixed $addresses
* @param string $name optional
*
* @return Swift_Mime_SimpleMessage
* @return $this
*/
public function setBcc($addresses, $name = null)
{
@@ -447,18 +451,18 @@ class Swift_Mime_SimpleMessage extends Swift_Mime_MimePart implements Swift_Mime
*
* The value is an integer where 1 is the highest priority and 5 is the lowest.
*
* @param int $priority
* @param int $priority
*
* @return Swift_Mime_SimpleMessage
* @return $this
*/
public function setPriority($priority)
{
$priorityMap = array(
1 => 'Highest',
2 => 'High',
3 => 'Normal',
4 => 'Low',
5 => 'Lowest'
self::PRIORITY_HIGHEST => 'Highest',
self::PRIORITY_HIGH => 'High',
self::PRIORITY_NORMAL => 'Normal',
self::PRIORITY_LOW => 'Low',
self::PRIORITY_LOWEST => 'Lowest',
);
$pMapKeys = array_keys($priorityMap);
if ($priority > max($pMapKeys)) {
@@ -467,8 +471,7 @@ class Swift_Mime_SimpleMessage extends Swift_Mime_MimePart implements Swift_Mime
$priority = min($pMapKeys);
}
if (!$this->_setHeaderFieldModel('X-Priority',
sprintf('%d (%s)', $priority, $priorityMap[$priority])))
{
sprintf('%d (%s)', $priority, $priorityMap[$priority]))) {
$this->getHeaders()->addTextHeader('X-Priority',
sprintf('%d (%s)', $priority, $priorityMap[$priority]));
}
@@ -494,11 +497,11 @@ class Swift_Mime_SimpleMessage extends Swift_Mime_MimePart implements Swift_Mime
}
/**
* Ask for a delivery receipt from the recipient to be sent to $addresses
* Ask for a delivery receipt from the recipient to be sent to $addresses.
*
* @param array $addresses
*
* @return Swift_Mime_SimpleMessage
* @return $this
*/
public function setReadReceiptTo($addresses)
{
@@ -525,7 +528,7 @@ class Swift_Mime_SimpleMessage extends Swift_Mime_MimePart implements Swift_Mime
*
* @param Swift_Mime_MimeEntity $entity
*
* @return Swift_Mime_SimpleMessage
* @return $this
*/
public function attach(Swift_Mime_MimeEntity $entity)
{
@@ -539,7 +542,7 @@ class Swift_Mime_SimpleMessage extends Swift_Mime_MimePart implements Swift_Mime
*
* @param Swift_Mime_MimeEntity $entity
*
* @return Swift_Mime_SimpleMessage
* @return $this
*/
public function detach(Swift_Mime_MimeEntity $entity)
{
@@ -566,7 +569,7 @@ class Swift_Mime_SimpleMessage extends Swift_Mime_MimePart implements Swift_Mime
{
$this->attach($entity);
return 'cid:' . $entity->getId();
return 'cid:'.$entity->getId();
}
/**
@@ -615,8 +618,6 @@ class Swift_Mime_SimpleMessage extends Swift_Mime_MimePart implements Swift_Mime
}
}
// -- Protected methods
/** @see Swift_Mime_SimpleMimeEntity::_getIdField() */
protected function _getIdField()
{
@@ -638,8 +639,6 @@ class Swift_Mime_SimpleMessage extends Swift_Mime_MimePart implements Swift_Mime
return $part;
}
// -- Private methods
/** Get the highest nesting level nested inside this message */
private function _getTopNestingLevel()
{

View File

@@ -11,9 +11,7 @@
/**
* A MIME entity, in a multipart message.
*
* @package Swift
* @subpackage Mime
* @author Chris Corbyn
* @author Chris Corbyn
*/
class Swift_Mime_SimpleMimeEntity implements Swift_Mime_MimeEntity
{
@@ -36,7 +34,7 @@ class Swift_Mime_SimpleMimeEntity implements Swift_Mime_MimeEntity
private $_compositeRanges = array(
'multipart/mixed' => array(self::LEVEL_TOP, self::LEVEL_MIXED),
'multipart/alternative' => array(self::LEVEL_MIXED, self::LEVEL_ALTERNATIVE),
'multipart/related' => array(self::LEVEL_ALTERNATIVE, self::LEVEL_RELATED)
'multipart/related' => array(self::LEVEL_ALTERNATIVE, self::LEVEL_RELATED),
);
/** A set of filter rules to define what level an entity should be nested at */
@@ -61,7 +59,7 @@ class Swift_Mime_SimpleMimeEntity implements Swift_Mime_MimeEntity
private $_alternativePartOrder = array(
'text/plain' => 1,
'text/html' => 2,
'multipart/related' => 3
'multipart/related' => 3,
);
/** The CID of this entity */
@@ -106,9 +104,9 @@ class Swift_Mime_SimpleMimeEntity implements Swift_Mime_MimeEntity
(self::LEVEL_ALTERNATIVE + self::LEVEL_RELATED) => array(
self::LEVEL_ALTERNATIVE => array(
'text/plain' => self::LEVEL_ALTERNATIVE,
'text/html' => self::LEVEL_RELATED
)
)
'text/html' => self::LEVEL_RELATED,
),
),
);
$this->_id = $this->getRandomId();
@@ -163,7 +161,7 @@ class Swift_Mime_SimpleMimeEntity implements Swift_Mime_MimeEntity
*
* @param string $type
*
* @return Swift_Mime_SimpleMimeEntity
* @return $this
*/
public function setContentType($type)
{
@@ -194,7 +192,7 @@ class Swift_Mime_SimpleMimeEntity implements Swift_Mime_MimeEntity
*
* @param string $id
*
* @return Swift_Mime_SimpleMimeEntity
* @return $this
*/
public function setId($id)
{
@@ -225,7 +223,7 @@ class Swift_Mime_SimpleMimeEntity implements Swift_Mime_MimeEntity
*
* @param string $description
*
* @return Swift_Mime_SimpleMimeEntity
* @return $this
*/
public function setDescription($description)
{
@@ -251,9 +249,9 @@ class Swift_Mime_SimpleMimeEntity implements Swift_Mime_MimeEntity
*
* Though not enforced by the library, lines should not exceed 1000 chars.
*
* @param int $length
* @param int $length
*
* @return Swift_Mime_SimpleMimeEntity
* @return $this
*/
public function setMaxLineLength($length)
{
@@ -265,7 +263,7 @@ class Swift_Mime_SimpleMimeEntity implements Swift_Mime_MimeEntity
/**
* Get all children added to this entity.
*
* @return array of Swift_Mime_Entity
* @return Swift_Mime_MimeEntity[]
*/
public function getChildren()
{
@@ -275,27 +273,24 @@ class Swift_Mime_SimpleMimeEntity implements Swift_Mime_MimeEntity
/**
* Set all children of this entity.
*
* @param array $children Swift_Mime_Entity instances
* @param int $compoundLevel For internal use only
* @param Swift_Mime_MimeEntity[] $children
* @param int $compoundLevel For internal use only
*
* @return Swift_Mime_SimpleMimeEntity
* @return $this
*/
public function setChildren(array $children, $compoundLevel = null)
{
// TODO: Try to refactor this logic
$compoundLevel = isset($compoundLevel)
? $compoundLevel
: $this->_getCompoundLevel($children)
;
$compoundLevel = isset($compoundLevel) ? $compoundLevel : $this->_getCompoundLevel($children);
$immediateChildren = array();
$grandchildren = array();
$newContentType = $this->_userContentType;
foreach ($children as $child) {
$level = $this->_getNeededChildLevel($child, $compoundLevel);
if (empty($immediateChildren)) { //first iteration
if (empty($immediateChildren)) {
//first iteration
$immediateChildren = array($child);
} else {
$nextLevel = $this->_getNeededChildLevel($immediateChildren[0], $compoundLevel);
@@ -312,16 +307,15 @@ class Swift_Mime_SimpleMimeEntity implements Swift_Mime_MimeEntity
}
}
if (!empty($immediateChildren)) {
if ($immediateChildren) {
$lowestLevel = $this->_getNeededChildLevel($immediateChildren[0], $compoundLevel);
// Determine which composite media type is needed to accommodate the
// immediate children
foreach ($this->_compositeRanges as $mediaType => $range) {
if ($lowestLevel > $range[0]
&& $lowestLevel <= $range[1])
{
if ($lowestLevel > $range[0] && $lowestLevel <= $range[1]) {
$newContentType = $mediaType;
break;
}
}
@@ -351,9 +345,7 @@ class Swift_Mime_SimpleMimeEntity implements Swift_Mime_MimeEntity
*/
public function getBody()
{
return ($this->_body instanceof Swift_OutputByteStream)
? $this->_readStream($this->_body)
: $this->_body;
return $this->_body instanceof Swift_OutputByteStream ? $this->_readStream($this->_body) : $this->_body;
}
/**
@@ -363,7 +355,7 @@ class Swift_Mime_SimpleMimeEntity implements Swift_Mime_MimeEntity
* @param mixed $body
* @param string $contentType optional
*
* @return Swift_Mime_SimpleMimeEntity
* @return $this
*/
public function setBody($body, $contentType = null)
{
@@ -394,7 +386,7 @@ class Swift_Mime_SimpleMimeEntity implements Swift_Mime_MimeEntity
*
* @param Swift_Mime_ContentEncoder $encoder
*
* @return Swift_Mime_SimpleMimeEntity
* @return $this
*/
public function setEncoder(Swift_Mime_ContentEncoder $encoder)
{
@@ -417,7 +409,7 @@ class Swift_Mime_SimpleMimeEntity implements Swift_Mime_MimeEntity
public function getBoundary()
{
if (!isset($this->_boundary)) {
$this->_boundary = '_=_swift_v4_' . time() . '_' . md5(getmypid().mt_rand().uniqid('', true)) . '_=_';
$this->_boundary = '_=_swift_v4_'.time().'_'.md5(getmypid().mt_rand().uniqid('', true)).'_=_';
}
return $this->_boundary;
@@ -428,9 +420,9 @@ class Swift_Mime_SimpleMimeEntity implements Swift_Mime_MimeEntity
*
* @param string $boundary
*
* @return Swift_Mime_SimpleMimeEntity
*
* @throws Swift_RfcComplianceException
*
* @return $this
*/
public function setBoundary($boundary)
{
@@ -488,22 +480,18 @@ class Swift_Mime_SimpleMimeEntity implements Swift_Mime_MimeEntity
if ($this->_cache->hasKey($this->_cacheKey, 'body')) {
$body = $this->_cache->getString($this->_cacheKey, 'body');
} else {
$body = "\r\n" . $this->_encoder->encodeString($this->getBody(), 0,
$this->getMaxLineLength()
);
$this->_cache->setString($this->_cacheKey, 'body', $body,
Swift_KeyCache::MODE_WRITE
);
$body = "\r\n".$this->_encoder->encodeString($this->getBody(), 0, $this->getMaxLineLength());
$this->_cache->setString($this->_cacheKey, 'body', $body, Swift_KeyCache::MODE_WRITE);
}
$string .= $body;
}
if (!empty($this->_immediateChildren)) {
foreach ($this->_immediateChildren as $child) {
$string .= "\r\n\r\n--" . $this->getBoundary() . "\r\n";
$string .= "\r\n\r\n--".$this->getBoundary()."\r\n";
$string .= $child->toString();
}
$string .= "\r\n\r\n--" . $this->getBoundary() . "--\r\n";
$string .= "\r\n\r\n--".$this->getBoundary()."--\r\n";
}
return $string;
@@ -570,17 +558,15 @@ class Swift_Mime_SimpleMimeEntity implements Swift_Mime_MimeEntity
if (!empty($this->_immediateChildren)) {
foreach ($this->_immediateChildren as $child) {
$is->write("\r\n\r\n--" . $this->getBoundary() . "\r\n");
$is->write("\r\n\r\n--".$this->getBoundary()."\r\n");
$child->toByteStream($is);
}
$is->write("\r\n\r\n--" . $this->getBoundary() . "--\r\n");
$is->write("\r\n\r\n--".$this->getBoundary()."--\r\n");
}
}
// -- Protected methods
/**
* Get the name of the header that provides the ID of this entity
* Get the name of the header that provides the ID of this entity.
*/
protected function _getIdField()
{
@@ -595,7 +581,6 @@ class Swift_Mime_SimpleMimeEntity implements Swift_Mime_MimeEntity
if ($this->_headers->has($field)) {
return $this->_headers->get($field)->getFieldBodyModel();
}
return null; // Returning null is equivalent to no return, but is easier to read!!
}
/**
@@ -607,9 +592,9 @@ class Swift_Mime_SimpleMimeEntity implements Swift_Mime_MimeEntity
$this->_headers->get($field)->setFieldBodyModel($model);
return true;
} else {
return false;
}
return false;
}
/**
@@ -631,9 +616,9 @@ class Swift_Mime_SimpleMimeEntity implements Swift_Mime_MimeEntity
$this->_headers->get($field)->setParameter($parameter, $value);
return true;
} else {
return false;
}
return false;
}
/**
@@ -687,21 +672,19 @@ class Swift_Mime_SimpleMimeEntity implements Swift_Mime_MimeEntity
*/
protected function getRandomId()
{
$idLeft = md5(getmypid() . '.' . time() . '.' . uniqid(mt_rand(), true));
$idLeft = md5(getmypid().'.'.time().'.'.uniqid(mt_rand(), true));
$idRight = !empty($_SERVER['SERVER_NAME']) ? $_SERVER['SERVER_NAME'] : 'swift.generated';
$id = $idLeft . '@' . $idRight;
$id = $idLeft.'@'.$idRight;
try {
$this->_assertValidId($id);
} catch (Swift_RfcComplianceException $e) {
$id = $idLeft . '@swift.generated';
$id = $idLeft.'@swift.generated';
}
return $id;
}
// -- Private methods
private function _readStream(Swift_OutputByteStream $os)
{
$string = '';
@@ -709,6 +692,8 @@ class Swift_Mime_SimpleMimeEntity implements Swift_Mime_MimeEntity
$string .= $bytes;
}
$os->setReadPointer(0);
return $string;
}
@@ -721,10 +706,7 @@ class Swift_Mime_SimpleMimeEntity implements Swift_Mime_MimeEntity
private function _assertValidBoundary($boundary)
{
if (!preg_match(
'/^[a-z0-9\'\(\)\+_\-,\.\/:=\?\ ]{0,69}[a-z0-9\'\(\)\+_\-,\.\/:=\?]$/Di',
$boundary))
{
if (!preg_match('/^[a-z0-9\'\(\)\+_\-,\.\/:=\?\ ]{0,69}[a-z0-9\'\(\)\+_\-,\.\/:=\?]$/Di', $boundary)) {
throw new Swift_RfcComplianceException('Mime boundary set is not RFC 2046 compliant.');
}
}
@@ -763,19 +745,16 @@ class Swift_Mime_SimpleMimeEntity implements Swift_Mime_MimeEntity
$realLevel = $child->getNestingLevel();
$lowercaseType = strtolower($child->getContentType());
if (isset($filter[$realLevel])
&& isset($filter[$realLevel][$lowercaseType]))
{
if (isset($filter[$realLevel]) && isset($filter[$realLevel][$lowercaseType])) {
return $filter[$realLevel][$lowercaseType];
} else {
return $realLevel;
}
return $realLevel;
}
private function _createChild()
{
return new self($this->_headers->newInstance(),
$this->_encoder, $this->_cache, $this->_grammar);
return new self($this->_headers->newInstance(), $this->_encoder, $this->_cache, $this->_grammar);
}
private function _notifyEncoderChanged(Swift_Mime_ContentEncoder $encoder)
@@ -807,34 +786,33 @@ class Swift_Mime_SimpleMimeEntity implements Swift_Mime_MimeEntity
// Sort in order of preference, if there is one
if ($shouldSort) {
usort($this->_immediateChildren, array($this, '_childSortAlgorithm'));
// Group the messages by order of preference
$sorted = array();
foreach ($this->_immediateChildren as $child) {
$type = $child->getContentType();
$level = array_key_exists($type, $this->_alternativePartOrder) ? $this->_alternativePartOrder[$type] : max($this->_alternativePartOrder) + 1;
if (empty($sorted[$level])) {
$sorted[$level] = array();
}
$sorted[$level][] = $child;
}
ksort($sorted);
$this->_immediateChildren = array_reduce($sorted, 'array_merge', array());
}
}
private function _childSortAlgorithm($a, $b)
{
$typePrefs = array();
$types = array(
strtolower($a->getContentType()),
strtolower($b->getContentType())
);
foreach ($types as $type) {
$typePrefs[] = (array_key_exists($type, $this->_alternativePartOrder))
? $this->_alternativePartOrder[$type]
: (max($this->_alternativePartOrder) + 1);
}
return ($typePrefs[0] >= $typePrefs[1]) ? 1 : -1;
}
// -- Destructor
/**
* Empties it's own contents from the cache.
*/
public function __destruct()
{
$this->_cache->clearAll($this->_cacheKey);
if ($this->_cache instanceof Swift_KeyCache) {
$this->_cache->clearAll($this->_cacheKey);
}
}
/**
@@ -846,15 +824,23 @@ class Swift_Mime_SimpleMimeEntity implements Swift_Mime_MimeEntity
*/
private function _assertValidId($id)
{
if (!preg_match(
'/^' . $this->_grammar->getDefinition('id-left') . '@' .
$this->_grammar->getDefinition('id-right') . '$/D',
$id
))
{
throw new Swift_RfcComplianceException(
'Invalid ID given <' . $id . '>'
);
if (!preg_match('/^'.$this->_grammar->getDefinition('id-left').'@'.$this->_grammar->getDefinition('id-right').'$/D', $id)) {
throw new Swift_RfcComplianceException('Invalid ID given <'.$id.'>');
}
}
/**
* Make a deep copy of object.
*/
public function __clone()
{
$this->_headers = clone $this->_headers;
$this->_encoder = clone $this->_encoder;
$this->_cacheKey = md5(uniqid(getmypid().mt_rand(), true));
$children = array();
foreach ($this->_children as $pos => $child) {
$children[$pos] = clone $child;
}
$this->setChildren($children);
}
}

View File

@@ -11,9 +11,7 @@
/**
* A MIME part, in a multipart message.
*
* @package Swift
* @subpackage Mime
* @author Chris Corbyn
* @author Chris Corbyn
*/
class Swift_MimePart extends Swift_Mime_MimePart
{
@@ -52,7 +50,7 @@ class Swift_MimePart extends Swift_Mime_MimePart
* @param string $contentType
* @param string $charset
*
* @return Swift_Mime_MimePart
* @return self
*/
public static function newInstance($body = null, $contentType = null, $charset = null)
{

View File

@@ -11,14 +11,10 @@
/**
* Pretends messages have been sent, but just ignores them.
*
* @package Swift
* @author Fabien Potencier
* @author Fabien Potencier
*/
class Swift_NullTransport extends Swift_Transport_NullTransport
{
/**
* Create a new NullTransport.
*/
public function __construct()
{
call_user_func_array(
@@ -31,7 +27,7 @@ class Swift_NullTransport extends Swift_Transport_NullTransport
/**
* Create a new NullTransport instance.
*
* @return Swift_NullTransport
* @return self
*/
public static function newInstance()
{

View File

@@ -14,9 +14,7 @@
* Classes implementing this interface may use a subsystem which requires less
* memory than working with large strings of data.
*
* @package Swift
* @subpackage ByteStream
* @author Chris Corbyn
* @author Chris Corbyn
*/
interface Swift_OutputByteStream
{
@@ -27,22 +25,22 @@ interface Swift_OutputByteStream
* 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
*
* @return string|bool
* @param int $length
*
* @throws Swift_IoException
*
* @return string|bool
*/
public function read($length);
/**
* Move the internal read pointer to $byteOffset in the stream.
*
* @param int $byteOffset
*
* @return bool
* @param int $byteOffset
*
* @throws Swift_IoException
*
* @return bool
*/
public function setReadPointer($byteOffset);
}

Some files were not shown because too many files have changed in this diff Show More