Skip to content

Commit

Permalink
PHP 8.1 and PHPUnit 8.0 compatibility fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
derickr committed Aug 6, 2021
1 parent 11d049c commit 35c5253
Show file tree
Hide file tree
Showing 9 changed files with 103 additions and 45 deletions.
55 changes: 55 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
name: CI

on:
# Run on all pushes and on all pull requests.
push:
pull_request:
# Allow manually triggering the workflow.
workflow_dispatch:

jobs:
test:
runs-on: ubuntu-latest

strategy:
fail-fast: false
# Keys:
# - experimental: Whether the build is "allowed to fail".
matrix:
php: ['7.2', '7.3', '7.4', '8.0']
experimental: [false]

include:
- php: '8.1'
experimental: true

name: "PHP: ${{ matrix.php }}"

continue-on-error: ${{ matrix.experimental }}

steps:
- name: Checkout code
uses: actions/checkout@v2

- name: Install PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php }}
ini-values: error_reporting=-1, display_errors=On, log_errors_max_len=0
coverage: none
tools: none

# Install dependencies and handle caching in one go.
# @link https://github.com/marketplace/actions/install-composer-dependencies
- name: "Install Composer dependencies (PHP < 8.1)"
if: ${{ matrix.php < '8.1' }}
uses: "ramsey/composer-install@v1"

- name: "Install Composer dependencies (PHP 8.1)"
if: ${{ matrix.php >= '8.1' }}
uses: "ramsey/composer-install@v1"
with:
composer-options: --ignore-platform-reqs

- name: Run unit tests
run: vendor/bin/phpunit
18 changes: 0 additions & 18 deletions .travis.yml

This file was deleted.

2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
"zetacomponents/base": "~1.8"
},
"require-dev": {
"phpunit/phpunit": "~7.5",
"phpunit/phpunit": "~8.0",
"zetacomponents/unit-test": "*"
}
}
6 changes: 5 additions & 1 deletion src/parser/headers_holder.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ public function __construct( array $map = array() )
* @param string $key
* @return bool
*/
#[\ReturnTypeWillChange]
public function offsetExists( $key )
{
return array_key_exists( strtolower( $key ), $this->lookup );
Expand All @@ -84,6 +85,7 @@ public function offsetExists( $key )
* @param string $key
* @return mixed
*/
#[\ReturnTypeWillChange]
public function offsetGet( $key )
{
$key = strtolower( $key );
Expand All @@ -103,6 +105,7 @@ public function offsetGet( $key )
* @param string $key
* @param mixed $value
*/
#[\ReturnTypeWillChange]
public function offsetSet( $key, $value )
{
$lowerKey = strtolower( $key );
Expand All @@ -125,14 +128,15 @@ private function trimRecursive($value) {
if (is_array($value)) {
return array_map(array($this, 'trimRecursive'), $value);
}
return trim($value);
return trim((string) $value);
}

/**
* Unsets the key $key.
*
* @param string $key
*/
#[\ReturnTypeWillChange]
public function offsetUnset( $key )
{
$key = strtolower( $key );
Expand Down
29 changes: 18 additions & 11 deletions src/parser/parts/file_parser.php
Original file line number Diff line number Diff line change
Expand Up @@ -120,9 +120,10 @@ public function __construct( $mainType, $subType, ezcMailHeadersHolder $headers
// figure out the base filename
// search Content-Disposition first as specified by RFC 2183
$matches = array();
if ( preg_match( '/\s*filename=\s?"?([^;"]*);?/i',
$this->headers['Content-Disposition'], $matches ) )
{
if (
$this->headers['Content-Disposition'] &&
preg_match( '/\s*filename=\s?"?([^;"]*);?/i', $this->headers['Content-Disposition'], $matches )
) {
$fileName = trim( $matches[1], '"' );
}
// fallback to the name parameter in Content-Type as specified by RFC 2046 4.5.1
Expand Down Expand Up @@ -215,6 +216,11 @@ public function __destruct()
*/
private function appendStreamFilters( $line )
{
if ( ! is_string( $this->headers['Content-Transfer-Encoding'] ) )
{
return;
}

// append the correct decoding filter
switch ( strtolower( $this->headers['Content-Transfer-Encoding'] ) )
{
Expand Down Expand Up @@ -318,15 +324,16 @@ public function finish()

// set inline disposition mode if set.
$matches = array();
if ( preg_match( '/^\s*inline;?/i',
$this->headers['Content-Disposition'], $matches ) )
{
$filePart->dispositionType = ezcMailFile::DISPLAY_INLINE;
}
if ( preg_match( '/^\s*attachment;?/i',
$this->headers['Content-Disposition'], $matches ) )
if ( $this->headers['Content-Disposition'] )
{
$filePart->dispositionType = ezcMailFile::DISPLAY_ATTACHMENT;
if ( preg_match( '/^\s*inline;?/i', $this->headers['Content-Disposition'], $matches ) )
{
$filePart->dispositionType = ezcMailFile::DISPLAY_INLINE;
}
if ( preg_match( '/^\s*attachment;?/i', $this->headers['Content-Disposition'], $matches ) )
{
$filePart->dispositionType = ezcMailFile::DISPLAY_ATTACHMENT;
}
}
$filePart->size = filesize( $this->fileName );
return $filePart;
Expand Down
22 changes: 15 additions & 7 deletions src/parser/parts/text_parser.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
*
* http://www.apache.org/licenses/LICENSE-2.0
*
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
Expand Down Expand Up @@ -104,14 +104,22 @@ public function finish()
}
}

$encoding = strtolower( $this->headers['Content-Transfer-Encoding'] );
if ( $encoding == ezcMail::QUOTED_PRINTABLE )
if ( $this->text === null )
{
$this->text = quoted_printable_decode( $this->text );
$this->text = '';
}
else if ( $encoding == ezcMail::BASE64 )

if ( $this->headers['Content-Transfer-Encoding'] )
{
$this->text = base64_decode( $this->text );
$encoding = strtolower( $this->headers['Content-Transfer-Encoding'] );
if ( $encoding == ezcMail::QUOTED_PRINTABLE )
{
$this->text = quoted_printable_decode( $this->text );
}
else if ( $encoding == ezcMail::BASE64 )
{
$this->text = base64_decode( $this->text );
}
}

$this->text = ezcMailCharsetConverter::convertToUTF8( $this->text, $charset );
Expand Down
10 changes: 5 additions & 5 deletions src/parser/rfc2231_implementation.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
*
* http://www.apache.org/licenses/LICENSE-2.0
*
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
Expand Down Expand Up @@ -108,11 +108,11 @@ public static function parseHeader( $header )
}

$result[1][$paramName] = array( 'value' => $parts[0]['value'] );
if ( strlen( $charset ) > 0 )
if ( $charset && strlen( $charset ) > 0 )
{
$result[1][$paramName]['charset'] = $charset;
}
if ( strlen( $language ) > 0 )
if ( $language && strlen( $language ) > 0 )
{
$result[1][$paramName]['language'] = $language;
}
Expand Down Expand Up @@ -170,7 +170,7 @@ public static function parseContentDisposition( $header, ezcMailContentDispositi
{
$cd->displayFileName = ezcMailTools::mimeDecode( $cd->displayFileName );
}

if ( isset( $data['language'] ) )
{
$cd->fileNameLanguage = $data['language'];
Expand Down
4 changes: 3 additions & 1 deletion src/tools.php
Original file line number Diff line number Diff line change
Expand Up @@ -459,7 +459,9 @@ protected static function validateEmailAddressMx( $address )

for ( $i = 0; $i < $numberOfMx; $i++ )
{
if ( $socket = @fsockopen( $mx[$i], 25, $errno = 0, $errstr = 0, $timeoutOpen ) )
$errno = 0;
$errstr = 0;
if ( $socket = @fsockopen( $mx[$i], 25, $errno, $errstr, $timeoutOpen ) )
{
$response = fgets( $socket );
stream_set_timeout( $socket, $timeoutConnection );
Expand Down
2 changes: 1 addition & 1 deletion tests/composer_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -908,7 +908,7 @@ public function testMailSafeModeComposerAutomaticImageIncludeDefault()
$this->mail->subject = "HTML message with embeded files and images.";
$this->mail->htmlText = "<html>Some text before the simage: <img src=\"file://" . dirname( __FILE__ ) . "/parts/data/fly.jpg\" /> Here is the picture.";
$this->mail->build();
$this->assertEquals( true, 62701 <= strlen( $this->mail->generate() ) && strlen( $this->mail->generate() ) <= 62740 );
$this->assertEquals( true, 62701 <= strlen( $this->mail->generate() ) && strlen( $this->mail->generate() ) <= 62743 );
}

/**
Expand Down

0 comments on commit 35c5253

Please sign in to comment.