Skip to content

Commit

Permalink
Merged pull request #83
Browse files Browse the repository at this point in the history
  • Loading branch information
derickr committed Jun 13, 2020
2 parents fd1ac5c + a180ac4 commit 00f15f5
Show file tree
Hide file tree
Showing 13 changed files with 176 additions and 69 deletions.
12 changes: 4 additions & 8 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,22 +1,18 @@
language: php

php:
- 5.3
- 5.4
- 5.5
- 5.6
- 7.0
- 7.1
- 7.2
- 7.3
- nightly
- hhvm

matrix:
allow_failures:
- php: nightly
- php: hhvm

before_script:
- composer self-update
- composer update

script:
- phpunit
- vendor/bin/phpunit
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
"zetacomponents/base": "~1.8"
},
"require-dev": {
"phpunit/phpunit": "~7.5",
"zetacomponents/unit-test": "*"
}
}
2 changes: 1 addition & 1 deletion phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit bootstrap="./tests/bootstrap.php" colors="true">
<phpunit bootstrap="./tests/bootstrap.php" colors="true" beStrictAboutTestsThatDoNotTestAnything="false">
<testsuites>
<testsuite name="Zeta Components Mail">
<directory suffix="_test.php">./tests</directory>
Expand Down
15 changes: 10 additions & 5 deletions src/parser/parts/file_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 @@ -142,7 +142,12 @@ public function __construct( $mainType, $subType, ezcMailHeadersHolder $headers
}

// clean file name (replace unsafe characters with underscores)
$fileName = strtr( $fileName, "/\\\0\"|?*<:;>+[]", '______________' );
$fileName = preg_replace( '/[^A-Za-z0-9-. ]/', '_', $fileName );

if ( strlen( $fileName ) > 200 )
{
$fileName = substr( $fileName, 0, 200 ) . '.' . pathinfo( $fileName, PATHINFO_EXTENSION );
}

$this->fp = $this->openFile( $fileName ); // propagate exception
}
Expand Down Expand Up @@ -172,8 +177,8 @@ private function openFile( $fileName )
ezcMailParserShutdownHandler::registerForRemoval( $dirName );
$this->fileName = $dirName . $fileName;

$fp = fopen( $this->fileName, 'w' );
if ( $this->fp === false )
$fp = @fopen( $this->fileName, 'w' );
if ( $fp === false )
{
throw new ezcBaseFileNotFoundException( $this->fileName );
}
Expand Down
10 changes: 8 additions & 2 deletions src/tools.php
Original file line number Diff line number Diff line change
Expand Up @@ -608,9 +608,15 @@ function( $matches )

// Try it as latin 1 string
$text = preg_replace( '/=\?([^?]+)\?/', '=?iso-8859-1?', $origtext );
$text = iconv_mime_decode( $text, 0, $charset );
$text = @iconv_mime_decode( $text, 0, $charset );

return $text;
if ( $text !== false )
{
return $text;
}

// Return text as-is
return $origtext;
}

/**
Expand Down
6 changes: 3 additions & 3 deletions tests/composer_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -410,7 +410,7 @@ public function testMailHtmlWithImagesNoExtensionWithFileInfo()
$this->mail->addTo( new ezcMailAddress( '[email protected]', 'Frederik Holljen' ) );
$this->mail->subject = "HTML message with embeded files and images.";
$this->mail->htmlText = "<html>Some text before the simage: <img src=\"file://"
. realpath( $fileName ) . " />Here is some text after the image. Here is the <a href=\"file://"
. realpath( $fileName ) . "\" />Here is some text after the image. Here is the <a href=\"file://"
. dirname( __FILE__ )
. "/parts/data/fly.jpg\">file.</a></html>";
$this->mail->addAttachment( dirname( __FILE__) . "/parts/data/fly.jpg" );
Expand Down Expand Up @@ -733,7 +733,7 @@ public function testContentDispositionCustomAttachmentName()
$contentType = 'application/octet-stream';
}

$this->assertEquals( $contentType . '; name="custom_attachment_name.jpg"', $parts[1]->getHeader( "Content-Type" ) );
$this->assertEquals( $contentType . '; charset=binary; name="custom_attachment_name.jpg"', $parts[1]->getHeader( "Content-Type" ) );
$this->assertEquals( $file->contentDisposition, $parts[1]->contentDisposition );
}

Expand Down 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() ) <= 62733 );
$this->assertEquals( true, 62701 <= strlen( $this->mail->generate() ) && strlen( $this->mail->generate() ) <= 62740 );
}

/**
Expand Down
41 changes: 9 additions & 32 deletions tests/interfaces/part_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -199,10 +199,9 @@ public function testSetHeaderWithEncoding()
$this->part->setHeader( "X-Related-Movie", 'James Bond - Шпион, который меня любил', 'iso-8859-5' );
$this->assertEquals( 'James Bond - Шпион, который меня любил', $this->part->getHeader( 'X-Related-Movie' ) );

$expected = "X-Related-Movie: =?iso-8859-5?Q?James=20Bond?==?iso-8859-5?Q?=20?=" . ezcMailTools::lineBreak() .
" =?iso-8859-5?Q?-=20=D0=A8=D0=BF=D0=B8=D0=BE=D0=BD,=20=D0=BA=D0=BE=D1?=" . ezcMailTools::lineBreak() .
" =?iso-8859-5?Q?=82=D0=BE=D1=80=D1=8B=D0=B9=20=D0=BC=D0=B5=D0?=" . ezcMailTools::lineBreak() .
" =?iso-8859-5?Q?=BD=D1=8F=20=D0=BB=D1=8E=D0=B1=D0=B8=D0=BB?=" . ezcMailTools::lineBreak();
$expected = "X-Related-Movie: =?iso-8859-5?Q?James=20Bond=20-=20=D0=A8=D0=BF=D0=B8=D0=BE=D0=BD,?=" . ezcMailTools::lineBreak() .
" =?iso-8859-5?Q?=20=D0=BA=D0=BE=D1=82=D0=BE=D1=80=D1=8B=D0=B9=20=D0=BC=D0?=" . ezcMailTools::lineBreak() .
" =?iso-8859-5?Q?=B5=D0=BD=D1=8F=20=D0=BB=D1=8E=D0=B1=D0=B8=D0=BB?=" . ezcMailTools::lineBreak();

$this->assertEquals( $expected, $this->part->generateHeaders() );
}
Expand All @@ -218,11 +217,9 @@ public function testSetHeaderWithEncodingMultiByte()
$this->part->setHeader( 'X-Subject', $str, 'utf-8' );
$this->assertSame( $str, $this->part->getHeader( 'X-Subject' ) );

$expected = "X-Subject: Folder =?UTF-8?Q?=22=C3=A3=C2=83=C2=AD=C3=A3=C2=82=C2=B0=C3=A3=C2=82?=" . ezcMailTools::lineBreak() .
" =?UTF-8?Q?=C2=A4=C3=A3=C2=83=C2=B3=C3=A5=C2=89=C2=8D=C3=A3=C2=83=C2=88?=" . ezcMailTools::lineBreak() .
" =?UTF-8?Q?=C3=A3=C2=83=C2=83=C3=A3=C2=83=C2=97=22=20=C3=A3=C2=81=C2=AF?=" . ezcMailTools::lineBreak() .
" =?UTF-8?Q?=C3=A6=C2=9B=C2=B4=C3=A6=C2=96=C2=B0=C3=A3=C2=81=C2=95=C3=A3?=" . ezcMailTools::lineBreak() .
" =?UTF-8?Q?=C2=82=C2=8C=C3=A3=C2=81=C2=BE?=" . ezcMailTools::lineBreak();
$expected = "X-Subject: =?utf-8?Q?Folder=20\"=E3=83=AD=E3=82=B0=E3=82=A4=E3=83=B3=E5=89=8D?=" . ezcMailTools::lineBreak() .
" =?utf-8?Q?=E3=83=88=E3=83=83=E3=83=97\"=20=E3=81=AF=E6=9B=B4=E6=96=B0?=" . ezcMailTools::lineBreak() .
" =?utf-8?Q?=E3=81=95=E3=82=8C=E3=81=BE?=" . ezcMailTools::lineBreak();
$this->assertSame( $expected, $this->part->generateHeaders() );
}

Expand All @@ -233,33 +230,13 @@ public function testSetHeadersWithEncoding()
$this->assertEquals( 'James Bond - Из России с любовью', $this->part->getHeader( 'X-Related-Movie' ) );

$expected = "X-Related-City: Moscow" . ezcMailTools::lineBreak() .
"X-Related-Movie: =?iso-8859-5?Q?James=20Bond=20-=20=D0=98=D0=B7=20?=" . ezcMailTools::lineBreak() .
" =?iso-8859-5?Q?=D0=A0=D0=BE=D1=81=D1=81=D0=B8=D0=B8=20=D1=81?=" . ezcMailTools::lineBreak() .
" =?iso-8859-5?Q?=20=D0=BB=D1=8E=D0=B1=D0=BE=D0=B2=D1=8C=D1=8E?=" . ezcMailTools::lineBreak();
"X-Related-Movie: =?iso-8859-5?Q?James=20Bond=20-=20=D0=98=D0=B7=20=D0=A0=D0=BE=D1=81?=" . ezcMailTools::lineBreak() .
" =?iso-8859-5?Q?=D1=81=D0=B8=D0=B8=20=D1=81=20=D0=BB=D1=8E=D0=B1=D0=BE=D0?=" . ezcMailTools::lineBreak() .
" =?iso-8859-5?Q?=B2=D1=8C=D1=8E?=" . ezcMailTools::lineBreak();

$this->assertEquals( $expected, $this->part->generateHeaders() );
}

public function testMockSetHeaderWithEncodingNoCharsetReturnDefault()
{
$part = $this->getMock( 'ezcMailPart', array( 'setHeaderCharset', 'generateBody' ), array() );

$part->expects( $this->any() )
->method( 'setHeaderCharset' )
->will( $this->returnValue( false ) );

$part->expects( $this->any() )
->method( 'generateBody' )
->will( $this->returnValue( false ) );

$part->setHeader( "X-Related-Movie", 'James Bond - Шпион, который меня любил', 'iso-8859-5' );
$this->assertEquals( 'James Bond - Шпион, который меня любил', $part->getHeader( 'X-Related-Movie' ) );

$expected = "X-Related-Movie: James Bond - Шпион, который меня любил" . ezcMailTools::lineBreak();

$this->assertEquals( $expected, $part->generateHeaders() );
}

public static function suite()
{
return new PHPUnit\Framework\TestSuite( "ezcMailPartTest" );
Expand Down
3 changes: 1 addition & 2 deletions tests/mail_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -323,9 +323,8 @@ public function testMessageID1()
$this->mail->addTo( new ezcMailAddress( '[email protected]', 'Frederik Holljen' ) );
$this->mail->subject = "æøå";
$this->mail->body = new ezcMailText( "Dette er body ßßæøååå" );

$this->mail->generateHeaders();
$expected = '<'. date( 'YmdGHjs' ) . '.' . getmypid() . '.7@ez.no>';
$expected = '<'. date( 'YmdGHjs' ) . '.' . getmypid() . '.60@ez.no>';
$this->assertEquals( $expected, $this->mail->getHeader( 'Message-Id' ) );
}

Expand Down
4 changes: 2 additions & 2 deletions tests/parser/data/classes/custom_classes.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
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
Return-Path: <[email protected]>
X-Original-To: [email protected]
Delivered-To: [email protected]
Received: from smtp.ez.no (blackboy.ez.no [194.248.150.22])
by mta1.ez.no (Postfix) with ESMTP id 99508362508
for <[email protected]>; Fri, 23 Nov 2007 13:29:23 +0100 (CET)
Received: from [10.0.2.184] (popeye.ez.no [85.19.74.66])
by smtp.ez.no (Postfix) with ESMTP id D611AAB54C
for <[email protected]>; Fri, 23 Nov 2007 13:26:40 +0100 (CET)
Message-ID: <[email protected]>
Date: Fri, 23 Nov 2007 13:30:14 +0100
From: Alexandru Stanoi <[email protected]>
User-Agent: Thunderbird 1.5.0.12 (X11/20070604)
MIME-Version: 1.0
To: Alexandru Stanoi <[email protected]>
Subject: TEST: HTML attachment
Content-Type: multipart/mixed;
boundary="1234567890"


--1234567890
Content-Type: text/html; charset=iso-8859-1
Content-Transfer-Encoding: 7bit

<html>
<body marginwidth="0" marginheight="0" leftmargin="0" topmargin="0"
bgcolor="#FFFFFF">
<table border="0" width="640" cellspacing="0" cellpadding="0"><tr><td>
<img src="cid:cam_data/photo067" alt="cam_data/photo067.jpg"><br><br>
</td></tr></table>
</body></html>

--1234567890
Content-Type: image/jpeg; name=""
Content-Transfer-Encoding: base64
Content-ID: <cam_data/photo067>
Content-Disposition: attachment; filename=" "

/9j/4AAQSkZJRgABAgEAkACQAAD/
2wCEAAwICQoJBwwKCQoNDAwOER0TERAQESQZGxUdKiUsLCkl
KSgvNEM5LzE/
MigpOk87P0VHS0xLLThSWFFJV0NJS0gBDA0NEQ8RIhMTIkgwKTBISEhISEhISEhI
SEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISP/
AABEIAPABQAMBIQACEQED
EQH/3QAEABT/
xAGiAAABBQEBAQEBAQAAAAAAAAAAAQIDBAUGBwgJCgsQAAIBAwMCBAMFBQQEAAAB
fQECAwAEEQUSITFBBhNRYQcicRQygZGhCCNCscEVUtHwJDNicoIJChYXGBkaJSYnKCkqNDU2Nzg5
OkNERUZHSElKU1RVVldYWVpjZGVmZ2hpanN0dXZ3eHl6g4SFhoeIiYqSk5SVlpeYmZqio6Slpqeo
qaqys7S1tre4ubrCw8TFxsfIycrS09TV1tfY2drh4uPk5ebn6Onq8fLz9PX29/
j5+gEAAwEBAQEB
AQEBAQAAAAAAAAECAwQFBgcICQoLEQACAQIEBAMEBwUEBAABAncAAQIDEQQFITEGEkFRB2FxEyIy
gQgUQpGhscEJIzNS8BVictEKFiQ04SXxFxgZGiYnKCkqNTY3ODk6Q0RFRkdISUpTVFVWV1hZWmNk
ZWZnaG

--1234567890--
55 changes: 55 additions & 0 deletions tests/parser/data/various/attachment_with_long_filename.mail
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
Return-Path: <[email protected]>
X-Original-To: [email protected]
Delivered-To: [email protected]
Received: from smtp.ez.no (blackboy.ez.no [194.248.150.22])
by mta1.ez.no (Postfix) with ESMTP id 99508362508
for <[email protected]>; Fri, 23 Nov 2007 13:29:23 +0100 (CET)
Received: from [10.0.2.184] (popeye.ez.no [85.19.74.66])
by smtp.ez.no (Postfix) with ESMTP id D611AAB54C
for <[email protected]>; Fri, 23 Nov 2007 13:26:40 +0100 (CET)
Message-ID: <[email protected]>
Date: Fri, 23 Nov 2007 13:30:14 +0100
From: Alexandru Stanoi <[email protected]>
User-Agent: Thunderbird 1.5.0.12 (X11/20070604)
MIME-Version: 1.0
To: Alexandru Stanoi <[email protected]>
Subject: TEST: HTML attachment
Content-Type: multipart/mixed;
boundary="1234567890"


--1234567890
Content-Type: text/html; charset=iso-8859-1
Content-Transfer-Encoding: 7bit

<html>
<body marginwidth="0" marginheight="0" leftmargin="0" topmargin="0"
bgcolor="#FFFFFF">
<table border="0" width="640" cellspacing="0" cellpadding="0"><tr><td>
<img src="cid:cam_data/photo067" alt="cam_data/photo067.jpg"><br><br>
</td></tr></table>
</body></html>

--1234567890
Content-Type: image/jpeg; name=""
Content-Transfer-Encoding: base64
Content-ID: <cam_data/photo067>
Content-Disposition: attachment; filename="SOMETHINGVERYLONG_SOMETHINGVERYLONG_SOMETHINGVERYLONG_SOMETHINGVERYLONG_SOMETHINGVERYLONG_SOMETHINGVERYLONG_SOMETHINGVERYLONG_SOMETHINGVERYLONG_SOMETHINGVERYLONG_SOMETHINGVERYLONG_SOMETHINGVERYLONG_SOMETHINGVERYLONG_SOMETHINGVERYLONG_SOMETHINGVERYLONG_SOMETHINGVERYLONG_SOMETHINGVERYLONG_SOMETHINGVERYLONG_SOMETHINGVERYLONG_SOMETHINGVERYLONG_SOMETHINGVERYLONG_SOMETHINGVERYLONG_SOMETHINGVERYLONG_SOMETHINGVERYLONG_SOMETHINGVERYLONG_SOMETHINGVERYLONG_SOMETHINGVERYLONG_SOMETHINGVERYLONG_SOMETHINGVERYLONG_SOMETHINGVERYLONG_SOMETHINGVERYLONG_SOMETHINGVERYLONG_SOMETHINGVERYLONG_SOMETHINGVERYLONG_SOMETHINGVERYLONG_SOMETHINGVERYLONG_SOMETHINGVERYLONG_SOMETHINGVERYLONG_SOMETHINGVERYLONG_SOMETHINGVERYLONG_SOMETHINGVERYLONG_SOMETHINGVERYLONG_SOMETHINGVERYLONG_.jpg"

/9j/4AAQSkZJRgABAgEAkACQAAD/
2wCEAAwICQoJBwwKCQoNDAwOER0TERAQESQZGxUdKiUsLCkl
KSgvNEM5LzE/
MigpOk87P0VHS0xLLThSWFFJV0NJS0gBDA0NEQ8RIhMTIkgwKTBISEhISEhISEhI
SEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISP/
AABEIAPABQAMBIQACEQED
EQH/3QAEABT/
xAGiAAABBQEBAQEBAQAAAAAAAAAAAQIDBAUGBwgJCgsQAAIBAwMCBAMFBQQEAAAB
fQECAwAEEQUSITFBBhNRYQcicRQygZGhCCNCscEVUtHwJDNicoIJChYXGBkaJSYnKCkqNDU2Nzg5
OkNERUZHSElKU1RVVldYWVpjZGVmZ2hpanN0dXZ3eHl6g4SFhoeIiYqSk5SVlpeYmZqio6Slpqeo
qaqys7S1tre4ubrCw8TFxsfIycrS09TV1tfY2drh4uPk5ebn6Onq8fLz9PX29/
j5+gEAAwEBAQEB
AQEBAQAAAAAAAAECAwQFBgcICQoLEQACAQIEBAMEBwUEBAABAncAAQIDEQQFITEGEkFRB2FxEyIy
gQgUQpGhscEJIzNS8BVictEKFiQ04SXxFxgZGiYnKCkqNTY3ODk6Q0RFRkdISUpTVFVWV1hZWmNk
ZWZnaG

--1234567890--
Loading

0 comments on commit 00f15f5

Please sign in to comment.