Skip to content

Commit

Permalink
Merge branch 'master' into mimesign
Browse files Browse the repository at this point in the history
  • Loading branch information
Synchro committed Mar 6, 2015
2 parents e16b86b + 3e3617d commit d17e641
Show file tree
Hide file tree
Showing 22 changed files with 327 additions and 180 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
docs/phpdoc/
test/message.txt
test/testbootstrap.php
test/*.pem
.idea
build/
19 changes: 4 additions & 15 deletions .scrutinizer.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
build:
environment:
php: '5.6.0'

before_commands:
- "composer install --prefer-source"

tools:
# Code Coverage
external_code_coverage:
enabled: true
timeout: 300
Expand All @@ -14,10 +17,8 @@ tools:
- 'test/*'
- 'vendor/*'


php_code_coverage:
enabled: false
test_command: phpunit
filter:
excluded_paths:
- 'docs/*'
Expand All @@ -26,11 +27,8 @@ tools:
- 'test/*'
- 'vendor/*'


# Code Sniffer
php_code_sniffer:
enabled: true
command: phpcs
config:
standard: PSR2
sniffs:
Expand All @@ -45,23 +43,19 @@ tools:
- 'test/*'
- 'vendor/*'


# Copy/Paste Detector
php_cpd:
enabled: true
command: phpcpd
excluded_dirs:
- docs
- examples
- extras
- test
- vendor


# PHP CS Fixer (http://http://cs.sensiolabs.org/).
php_cs_fixer:
enabled: true
command: php-cs-fixer
config:
level: psr2
filter:
Expand All @@ -72,23 +66,19 @@ tools:
- 'test/*'
- 'vendor/*'


# Analyzes the size and structure of a PHP project.
php_loc:
enabled: true
command: phploc
excluded_dirs:
- docs
- examples
- extras
- test
- vendor


# PHP Mess Detector (http://phpmd.org).
php_mess_detector:
enabled: true
command: phpmd
config:
rulesets:
- codesize
Expand All @@ -108,7 +98,6 @@ tools:
# Analyzes the size and structure of a PHP project.
php_pdepend:
enabled: true
command: pdepend
excluded_dirs:
- docs
- examples
Expand Down
6 changes: 4 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
language: php
php:
- 7.0
- 5.6
- 5.5
- 5.4
- 5.3
- hhvm

matrix:
allow_failures:
- php: hhvm
allow_failures:
- php: 7.0
- php: hhvm

before_install:
- sudo apt-get update -qq
Expand Down
5 changes: 4 additions & 1 deletion changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
* Avoid `error_log` Debugoutput naming clash
* Add ability to parse server capabilities in response to EHLO (useful for SendGrid etc)
* Amended default values for WordWrap to match RFC
* Remove html2text converter class, provide new mechanism for injecting converters
* Remove html2text converter class (has incompatible license)
* Provide new mechanism for injecting html to text converters
* Improve pointers to docs and support in README
* Add example file upload script
* Refactor and major cleanup of EasyPeasyICS, now a lot more usable
Expand All @@ -17,6 +18,8 @@
* Add Bulgarian translation (Thanks to @mialy)
* Add Armenian translation (Thanks to Hrayr Grigoryan)
* Add Slovenian translation (Thanks to Klemen Tušar)
* More efficient word wrapping
* Add support for S/MIME signing with additional CA certificate (thanks to @IgitBuh)
* Fix incorrect MIME structure when using S/MIME signing and isMail() (#372)

## Version 5.2.9 (Sept 25th 2014)
Expand Down
92 changes: 66 additions & 26 deletions class.phpmailer.php
Original file line number Diff line number Diff line change
Expand Up @@ -536,6 +536,13 @@ class PHPMailer
*/
protected $sign_key_file = '';

/**
* The optional S/MIME extra certificates ("CA Chain") file path.
* @type string
* @access protected
*/
protected $sign_extracerts_file = '';

/**
* The S/MIME password for the key.
* Used only if the key is encrypted.
Expand Down Expand Up @@ -1218,7 +1225,11 @@ protected function smtpSend($header, $body)
if (!$this->smtpConnect()) {
throw new phpmailerException($this->lang('smtp_connect_failed'), self::STOP_CRITICAL);
}
$smtp_from = ($this->Sender == '') ? $this->From : $this->Sender;
if ('' == $this->Sender) {
$smtp_from = $this->From;
} else {
$smtp_from = $this->Sender;
}
if (!$this->smtp->mail($smtp_from)) {
$this->setError($this->lang('from_failed') . $smtp_from . ' : ' . implode(',', $this->smtp->getError()));
throw new phpmailerException($this->ErrorInfo, self::STOP_CRITICAL);
Expand Down Expand Up @@ -1496,28 +1507,35 @@ public function addrFormat($addr)
*/
public function wrapText($message, $length, $qp_mode = false)
{
$soft_break = ($qp_mode) ? sprintf(' =%s', $this->LE) : $this->LE;
if ($qp_mode) {
$soft_break = sprintf(' =%s', $this->LE);
} else {
$soft_break = $this->LE;
}
// If utf-8 encoding is used, we will need to make sure we don't
// split multibyte characters when we wrap
$is_utf8 = (strtolower($this->CharSet) == 'utf-8');
$lelen = strlen($this->LE);
$crlflen = strlen(self::CRLF);

$message = $this->fixEOL($message);
//Remove a trailing line break
if (substr($message, -$lelen) == $this->LE) {
$message = substr($message, 0, -$lelen);
}

$line = explode($this->LE, $message); // Magic. We know fixEOL uses $LE
//Split message into lines
$lines = explode($this->LE, $message);
//Message will be rebuilt in here
$message = '';
for ($i = 0; $i < count($line); $i++) {
$line_part = explode(' ', $line[$i]);
foreach ($lines as $line) {
$words = explode(' ', $line);
$buf = '';
for ($e = 0; $e < count($line_part); $e++) {
$word = $line_part[$e];
$firstword = true;
foreach ($words as $word) {
if ($qp_mode and (strlen($word) > $length)) {
$space_left = $length - strlen($buf) - $crlflen;
if ($e != 0) {
if (!$firstword) {
if ($space_left > 20) {
$len = $space_left;
if ($is_utf8) {
Expand Down Expand Up @@ -1559,13 +1577,17 @@ public function wrapText($message, $length, $qp_mode = false)
}
} else {
$buf_o = $buf;
$buf .= ($e == 0) ? $word : (' ' . $word);
if (!$firstword) {
$buf .= ' ';
}
$buf .= $word;

if (strlen($buf) > $length and $buf_o != '') {
$message .= $buf_o . $soft_break;
$buf = $word;
}
}
$firstword = false;
}
$message .= $buf . self::CRLF;
}
Expand All @@ -1575,11 +1597,11 @@ public function wrapText($message, $length, $qp_mode = false)

/**
* Find the last character boundary prior to $maxLength in a utf-8
* quoted (printable) encoded string.
* quoted-printable encoded string.
* Original written by Colin Brown.
* @access public
* @param string $encodedText utf-8 QP text
* @param integer $maxLength find last character boundary prior to this length
* @param integer $maxLength Find the last character boundary prior to this length
* @return integer
*/
public function utf8CharBoundary($encodedText, $maxLength)
Expand All @@ -1594,17 +1616,21 @@ public function utf8CharBoundary($encodedText, $maxLength)
// Check the encoded byte value (the 2 chars after the '=')
$hex = substr($encodedText, $maxLength - $lookBack + $encodedCharPos + 1, 2);
$dec = hexdec($hex);
if ($dec < 128) { // Single byte character.
if ($dec < 128) {
// Single byte character.
// If the encoded char was found at pos 0, it will fit
// otherwise reduce maxLength to start of the encoded char
$maxLength = ($encodedCharPos == 0) ? $maxLength :
$maxLength - ($lookBack - $encodedCharPos);
if ($encodedCharPos > 0) {
$maxLength = $maxLength - ($lookBack - $encodedCharPos);
}
$foundSplitPos = true;
} elseif ($dec >= 192) { // First byte of a multi byte character
} elseif ($dec >= 192) {
// First byte of a multi byte character
// Reduce maxLength to split at start of character
$maxLength = $maxLength - ($lookBack - $encodedCharPos);
$foundSplitPos = true;
} elseif ($dec < 192) { // Middle byte of a multi byte character, look further back
} elseif ($dec < 192) {
// Middle byte of a multi byte character, look further back
$lookBack += 3;
}
} else {
Expand All @@ -1616,7 +1642,10 @@ public function utf8CharBoundary($encodedText, $maxLength)
}

/**
* Set the body wrapping.
* Apply word wrapping to the message body.
* Wraps the message body to the number of chars set in the WordWrap property.
* You should only do this to plain-text bodies as wrapping HTML tags may break them.
* This is called automatically by createBody(), so you don't need to call it yourself.
* @access public
* @return void
*/
Expand Down Expand Up @@ -1726,10 +1755,10 @@ public function createHeader()
}

// Add custom headers
for ($index = 0; $index < count($this->CustomHeader); $index++) {
foreach ($this->CustomHeader as $header) {
$result .= $this->headerLine(
trim($this->CustomHeader[$index][0]),
$this->encodeHeader(trim($this->CustomHeader[$index][1]))
trim($header[0]),
$this->encodeHeader(trim($header[1]))
);
}
if (!$this->sign_key_file) {
Expand Down Expand Up @@ -1949,7 +1978,9 @@ public function createBody()
$signed,
'file://' . realpath($this->sign_cert_file),
array('file://' . realpath($this->sign_key_file), $this->sign_key_pass),
null
null,
PKCS7_DETACHED,
$this->sign_extracerts_file
)
) {
@unlink($file);
Expand Down Expand Up @@ -2256,7 +2287,7 @@ protected function encodeFile($path, $encoding = 'base64')
//Doesn't exist in PHP 5.4, but we don't need to check because
//get_magic_quotes_runtime always returns false in 5.4+
//so it will never get here
ini_set('magic_quotes_runtime', 0);
ini_set('magic_quotes_runtime', false);
}
}
$file_buffer = file_get_contents($path);
Expand All @@ -2265,7 +2296,7 @@ protected function encodeFile($path, $encoding = 'base64')
if (version_compare(PHP_VERSION, '5.3.0', '<')) {
set_magic_quotes_runtime($magic_quotes);
} else {
ini_set('magic_quotes_runtime', ($magic_quotes?'1':'0'));
ini_set('magic_quotes_runtime', $magic_quotes);
}
}
return $file_buffer;
Expand Down Expand Up @@ -3098,7 +3129,10 @@ public static function _mime_types($ext = '')
'avi' => 'video/x-msvideo',
'movie' => 'video/x-sgi-movie'
);
return (array_key_exists(strtolower($ext), $mimes) ? $mimes[strtolower($ext)]: 'application/octet-stream');
if (array_key_exists(strtolower($ext), $mimes)) {
return $mimes[strtolower($ext)];
}
return 'application/octet-stream';
}

/**
Expand Down Expand Up @@ -3224,12 +3258,14 @@ public static function normalizeBreaks($text, $breaktype = "\r\n")
* @param string $cert_filename
* @param string $key_filename
* @param string $key_pass Password for private key
* @param string $extracerts_filename Optional path to chain certificate
*/
public function sign($cert_filename, $key_filename, $key_pass)
public function sign($cert_filename, $key_filename, $key_pass, $extracerts_filename = '')
{
$this->sign_cert_file = $cert_filename;
$this->sign_key_file = $key_filename;
$this->sign_key_pass = $key_pass;
$this->sign_extracerts_file = $extracerts_filename;
}

/**
Expand Down Expand Up @@ -3364,7 +3400,11 @@ public function DKIM_Add($headers_line, $subject, $body)
$body = $this->DKIM_BodyC($body);
$DKIMlen = strlen($body); // Length of body
$DKIMb64 = base64_encode(pack('H*', sha1($body))); // Base64 of packed binary SHA-1 hash of body
$ident = ($this->DKIM_identity == '') ? '' : ' i=' . $this->DKIM_identity . ';';
if ('' == $this->DKIM_identity) {
$ident = '';
} else {
$ident = ' i=' . $this->DKIM_identity . ';';
}
$dkimhdrs = 'DKIM-Signature: v=1; a=' .
$DKIMsignatureType . '; q=' .
$DKIMquery . '; l=' .
Expand Down
Loading

0 comments on commit d17e641

Please sign in to comment.