Skip to content

Commit

Permalink
Add test for PR #95
Browse files Browse the repository at this point in the history
  • Loading branch information
derickr committed Nov 5, 2024
1 parent 1ba2285 commit fc981b4
Show file tree
Hide file tree
Showing 2 changed files with 138 additions and 0 deletions.
64 changes: 64 additions & 0 deletions tests/parser/data/various/test-html-text-and-text-attachment
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
MIME-Version: 1.0
Date: Tue, 27 Aug 2024 09:28:55 +1000
Message-ID: <[email protected]>
Subject: test txt attachment
From: Sam Lee <[email protected]>
To: [email protected]
Content-Type: multipart/mixed; boundary="0000000000000f1e9806209e7d06"

--0000000000000f1e9806209e7d06
Content-Type: multipart/alternative; boundary="0000000000000f1e9606209e7d04"

--0000000000000f1e9606209e7d04
Content-Type: text/plain; charset="UTF-8"

test

--
Sam Lee


Big Business

He/Him/His

--0000000000000f1e9606209e7d04
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable


--0000000000000f1e9606209e7d04--
--0000000000000f1e9806209e7d06
Content-Type: text/plain; charset="UTF-8"; name="2_load_xss.html.txt"
Content-Disposition: attachment; filename="2_load_xss.html.txt"
Content-Transfer-Encoding: base64
X-Attachment-Id: f_m0bmqmih2
Content-ID: <f_m0bmqmih2>

77u/PGh0bWw+DQo8Zm9ybSBlbmN0eXBlPSJhcHBsaWNhdGlvbi94LXd3dy1mb3JtLXVybGVuY29k
ZWQiIG1ldGhvZD0iUE9TVCIgYWN0aW9uPSJodHRwOi8vbG9jYWxob3N0L3dwLWFkbWluL2FkbWlu
LnBocD9wYWdlPUNpdmlDUk0mcT1jaXZpY3JtJTJGYWRtaW4lMkZja2VkaXRvciI+DQo8aW5wdXQg
dHlwZT0idGV4dCIgdmFsdWU9Im1vb25vIiBuYW1lPSJjb25maWdfc2tpbiI+IDxicj4NCjxpbnB1
dCB0eXBlPSJ0ZXh0IiB2YWx1ZT0iQ0tFRElUT1IuZWRpdG9yQ29uZmlnID0gZnVuY3Rpb24oIGNv
bmZpZyApIHt9OyIgbmFtZT0iY29uZmlnIj4gPGJyPg0KPGlucHV0IHR5cGU9InRleHQiIHZhbHVl
PSIiIG5hbWU9ImNvbmZpZ19leHRyYVBsdWdpbnMiPiA8YnI+DQo8aW5wdXQgdHlwZT0idGV4dCIg
dmFsdWU9Ii4uLy4uLy4uLy4uLy4uL3VwbG9hZHMvY2l2aWNybS9wZXJzaXN0L2NybS1ja2VkaXRv
ci14c3MuanMiIG5hbWU9ImNvbmZpZ19jdXN0b21Db25maWciPiA8YnI+DQo8aW5wdXQgdHlwZT0i
c3VibWl0IiB2YWx1ZT0iUlVOIFBPQyI+DQo8L2Zvcm0+DQo8L2h0bWw+
--0000000000000f1e9806209e7d06
Content-Type: application/msword; name="form_03.doc"
Content-Disposition: attachment; filename="form_03.doc"
Content-Transfer-Encoding: base64
X-Attachment-Id: f_m0bmqhqx1
Content-ID: <f_m0bmqhqx1>


--0000000000000f1e9806209e7d06
Content-Type: application/pdf; name="2932_1 Ward Grouped Mayor-Lismore.pdf"
Content-Disposition: attachment; filename="2932_1 Ward Grouped Mayor-Lismore.pdf"
Content-Transfer-Encoding: base64
X-Attachment-Id: f_m0bmqhpv0
Content-ID: <f_m0bmqhpv0>


--0000000000000f1e9806209e7d06--
74 changes: 74 additions & 0 deletions tests/parser/parser_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -1863,5 +1863,79 @@ public function testSpaceBeforeFileName()
}
}

public function testVarious14a()
{
$parser = new ezcMailParser();
$parser->options->parseTextAttachmentsAsFiles = false;

$set = new SingleFileSet( 'various/test-html-text-and-text-attachment' );
$mail = $parser->parseMail( $set );
$this->assertEquals( 1, count( $mail ) );
$mail = $mail[0];
$parts = $mail->body->getParts();

$this->assertEquals( 4, count( $parts ) );
$this->assertEquals( 'ezcMailMultipartAlternative', get_class( $parts[0] ) );

$this->assertEquals( 'ezcMailText', get_class( $parts[1] ) );
$this->assertEquals( 'plain', $parts[1]->subType );

$this->assertEquals( 'ezcMailFile', get_class( $parts[2] ) );
$this->assertEquals( 'form_03.doc', basename( $parts[2]->fileName ) );
$this->assertEquals( 'application', $parts[2]->contentType );
$this->assertEquals( 'msword', $parts[2]->mimeType );

$this->assertEquals( 'ezcMailFile', get_class( $parts[3] ) );
$this->assertEquals( '2932_1 Ward Grouped Mayor-Lismore.pdf', basename( $parts[3]->fileName ) );
$this->assertEquals( 'application', $parts[3]->contentType );
$this->assertEquals( 'pdf', $parts[3]->mimeType );

$alternativeParts = $parts[0]->getParts();
$this->assertEquals( 2, count( $alternativeParts ) );
$this->assertEquals( 'ezcMailText', get_class( $alternativeParts[0] ) );
$this->assertEquals( 'plain', $alternativeParts[0]->subType );
$this->assertEquals( 'ezcMailText', get_class( $alternativeParts[1] ) );
$this->assertEquals( 'html', $alternativeParts[1]->subType );
}

public function testVarious14b()
{
$parser = new ezcMailParser();
$parser->options->parseTextAttachmentsAsFiles = true;

$set = new SingleFileSet( 'various/test-html-text-and-text-attachment' );
$mail = $parser->parseMail( $set );
$this->assertEquals( 1, count( $mail ) );
$mail = $mail[0];
$parts = $mail->body->getParts();

$this->assertEquals( 4, count( $parts ) );
$this->assertEquals( 'ezcMailMultipartAlternative', get_class( $parts[0] ) );

$this->assertEquals( 'ezcMailFile', get_class( $parts[1] ) );
$this->assertEquals( '2_load_xss.html.txt', basename( $parts[1]->fileName ) );
$this->assertEquals( 'text', $parts[1]->contentType );
$this->assertEquals( 'plain', $parts[1]->mimeType );

$this->assertEquals( 'ezcMailFile', get_class( $parts[2] ) );
$this->assertEquals( 'form_03.doc', basename( $parts[2]->fileName ) );
$this->assertEquals( 'application', $parts[2]->contentType );
$this->assertEquals( 'msword', $parts[2]->mimeType );

$this->assertEquals( 'ezcMailFile', get_class( $parts[3] ) );
$this->assertEquals( '2932_1 Ward Grouped Mayor-Lismore.pdf', basename( $parts[3]->fileName ) );
$this->assertEquals( 'application', $parts[3]->contentType );
$this->assertEquals( 'pdf', $parts[3]->mimeType );

$alternativeParts = $parts[0]->getParts();
$this->assertEquals( 2, count( $alternativeParts ) );
$this->assertEquals( 'ezcMailFile', get_class( $alternativeParts[0] ) );
$this->assertEquals( 'text', $alternativeParts[0]->contentType );
$this->assertEquals( 'plain', $alternativeParts[0]->mimeType );

$this->assertEquals( 'ezcMailFile', get_class( $alternativeParts[1] ) );
$this->assertEquals( 'application', $alternativeParts[1]->contentType );
$this->assertEquals( 'html', $alternativeParts[1]->mimeType );
}
}
?>

0 comments on commit fc981b4

Please sign in to comment.