2017-10-22 21:45:10 +02:00
< ? php
use PHPUnit\Framework\TestCase ;
2023-06-07 07:33:20 +02:00
require_once dirname ( dirname ( __FILE__ )) . '/system/helper/mime.php' ;
2017-10-22 21:45:10 +02:00
final class SplitMessageTest extends TestCase {
public function providerTestSplitMessage () {
return [
2023-06-07 07:33:20 +02:00
[ " From: aaa \r \n To:bbb \r \n Subject: test \r \n \r \n This is a test " ,
2023-06-07 19:28:15 +02:00
array ( 'from' => 'aaa' , 'to' => 'bbb' , 'cc' => '' , 'date' => '' , 'subject' => 'test' , 'content-type' => array ( 'type' => 'text/plain' )),
2023-06-07 07:33:20 +02:00
" This is a test " ],
2017-10-22 21:45:10 +02:00
2023-06-07 07:33:20 +02:00
[ " From: aaa \r \n Sender: alala@aaa \r \n To:bbb \r \n CC ccc \r \n Subject: test \r \n \r \n This is a test " ,
array ( 'sender' => 'alala@aaa' , 'from' => 'aaa' , 'to' => 'bbb' , 'cc' => '' , 'date' => '' , 'subject' => 'test' , 'content-type' => array ( 'type' => 'text/plain' )),
" This is a test " ],
2017-10-22 21:45:10 +02:00
2023-06-07 07:33:20 +02:00
[ " From: aaa \n To:bbb \n Subject: test \n \n This is a test " ,
2023-06-07 19:28:15 +02:00
array ( 'from' => 'aaa' , 'to' => 'bbb' , 'cc' => '' , 'date' => '' , 'subject' => 'test' , 'content-type' => array ( 'type' => 'text/plain' )),
2023-06-07 07:33:20 +02:00
" This is a test " ],
2017-10-22 21:45:10 +02:00
2023-06-07 07:33:20 +02:00
[ " From: aaa \r \n To:bbb \r \n Subject: test \r \n \r \n \r \n \r \n This is a test \n Aaa \n " ,
2023-06-07 19:28:15 +02:00
array ( 'from' => 'aaa' , 'to' => 'bbb' , 'cc' => '' , 'date' => '' , 'subject' => 'test' , 'content-type' => array ( 'type' => 'text/plain' )),
2023-06-07 07:33:20 +02:00
" \r \n \r \n This is a test \r \n Aaa \r \n " ],
2017-10-22 21:45:10 +02:00
2023-06-07 07:33:20 +02:00
[ " From: aaa \r \n To:bbb \r \n Subject: test \r \n Content-type: text/html \r \n \r \n \r \n This is a test \n Aaa \n " ,
2023-06-07 19:28:15 +02:00
array ( 'from' => 'aaa' , 'to' => 'bbb' , 'cc' => '' , 'date' => '' , 'subject' => 'test' , 'content-type' => array ( 'type' => 'text/html' )),
2023-06-07 07:33:20 +02:00
" \r \n This is a test \r \n Aaa \r \n " ],
2017-10-22 21:45:10 +02:00
2023-06-07 07:33:20 +02:00
[ " From: aaa \n To:bbb \n Subject: test \n Content-Type: text/plain \n \n This is a test " ,
2023-06-07 19:28:15 +02:00
array ( 'from' => 'aaa' , 'to' => 'bbb' , 'cc' => '' , 'date' => '' , 'subject' => 'test' , 'content-type' => array ( 'type' => 'text/plain' )),
2023-06-07 07:33:20 +02:00
" This is a test " ],
2017-10-22 21:45:10 +02:00
2023-06-07 07:33:20 +02:00
[ " From: aaa \n To:bbb \n Subject: test \n Date: Sun, 17 Apr 2016 22:40:03 +0800 \n DKIM-Signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d=chemoltravel.hu; s=ml; \n \t t=1471888357; bh=A/l/HLQe3HM4Xc4jFxAmhaWVCMU=; \n \t h=Date:To:From:Subject:Sender:From:To:Subject:Date; \n \t b=JlEqXiAKBOoT/YyXKTMsXnEphh2J6sXxgNmbKbGybjo3cU1rgQEL0m1h26gl5AaBP \n Content-Type: text/plain \n \n This is a test " ,
2023-06-07 19:28:15 +02:00
array ( 'from' => 'aaa' , 'to' => 'bbb' , 'cc' => '' , 'subject' => 'test' , 'date' => 'Sun, 17 Apr 2016 22:40:03 +0800' , 'dkim-signature' => 'v=1; a=rsa-sha1; c=relaxed/relaxed; d=chemoltravel.hu; s=ml; t=1471888357; bh=A/l/HLQe3HM4Xc4jFxAmhaWVCMU=; h=Date:To:From:Subject:Sender:From:To:Subject:Date; b=JlEqXiAKBOoT/YyXKTMsXnEphh2J6sXxgNmbKbGybjo3cU1rgQEL0m1h26gl5AaBP' , 'content-type' => array ( 'type' => 'text/plain' )),
2023-06-07 07:33:20 +02:00
" This is a test " ],
2017-10-22 21:45:10 +02:00
2023-06-07 07:33:20 +02:00
[ " From: aaa \n To:bbb \n Subject: test \n Content-Type: text/PLAIN \n \n This is a test " ,
2023-06-07 19:28:15 +02:00
array ( 'from' => 'aaa' , 'to' => 'bbb' , 'cc' => '' , 'date' => '' , 'subject' => 'test' , 'content-type' => array ( 'type' => 'text/plain' )),
2023-06-07 07:33:20 +02:00
" This is a test " ],
2017-10-22 21:45:10 +02:00
2023-06-07 07:33:20 +02:00
[ " From: aaa \n To:bbb \n Subject: test \n Content-Type: text/plain; charset= \" ISO-8859-1 \" \n \n This is a test " ,
2023-06-07 19:28:15 +02:00
array ( 'from' => 'aaa' , 'to' => 'bbb' , 'cc' => '' , 'date' => '' , 'subject' => 'test' , 'content-type' => array ( 'type' => 'text/plain' , 'charset' => 'ISO-8859-1' )),
2023-06-07 07:33:20 +02:00
" This is a test " ],
2017-10-22 21:45:10 +02:00
2023-06-07 07:33:20 +02:00
[ " From: aaa \n To:bbb \n Subject: test \n MIME-Version: 1.0 \n Content-Type: multipart/alternative; boundary= \" _=_SWIFT_v4_1460476188_145aa333fc0127705a7e904aab6d1957_=_ \" \n \n This is a test " ,
2023-06-07 19:28:15 +02:00
array ( 'from' => 'aaa' , 'to' => 'bbb' , 'cc' => '' , 'date' => '' , 'subject' => 'test' , 'mime-version' => '1.0' , 'content-type' => array ( 'type' => 'multipart/alternative' , 'boundary' => '_=_SWIFT_v4_1460476188_145aa333fc0127705a7e904aab6d1957_=_' )),
2023-06-07 07:33:20 +02:00
" This is a test " ],
2017-10-22 21:45:10 +02:00
2023-06-07 07:33:20 +02:00
[ " From: aaa \n To:bbb \n Subject: test \n MIME-Version: 1.0 \n Content-Type: multipart/alternative; \n boundary= \" _=_SWIFT_v4_1460476188_145aa333fc0127705a7e904aab6d1957_=_ \" \n \n This is a test " ,
2023-06-07 19:28:15 +02:00
array ( 'from' => 'aaa' , 'to' => 'bbb' , 'cc' => '' , 'date' => '' , 'subject' => 'test' , 'mime-version' => '1.0' , 'content-type' => array ( 'type' => 'multipart/alternative' , 'boundary' => '_=_SWIFT_v4_1460476188_145aa333fc0127705a7e904aab6d1957_=_' )),
2023-06-07 07:33:20 +02:00
" This is a test " ],
2017-10-22 21:45:10 +02:00
2023-06-07 07:33:20 +02:00
[ " From: aaa \n To:bbb \n Subject: test \n MIME-Version: 1.0 \n Content-Type: multipart/related; \n \t type= \" multipart/alternative \" ; \n \t boundary= \" ----=_NextPart_000_0006_01D195BC.69E26510 \" \n \n This is a test " ,
2023-06-07 19:28:15 +02:00
array ( 'from' => 'aaa' , 'to' => 'bbb' , 'cc' => '' , 'date' => '' , 'subject' => 'test' , 'mime-version' => '1.0' , 'content-type' => array ( 'type' => 'multipart/alternative' , 'boundary' => '----=_NextPart_000_0006_01D195BC.69E26510' )),
2023-06-07 07:33:20 +02:00
" This is a test " ],
2017-10-22 21:45:10 +02:00
2023-06-07 07:33:20 +02:00
];
}
2017-10-22 21:45:10 +02:00
/**
* @ dataProvider providerTestSplitMessage
*/
public function test_split_message ( $input , $expected_headers , $expected_body ) {
Piler_Mime_Decode :: splitMessage ( $input , $headers , $body );
$this -> assertEquals ( $headers , $expected_headers );
$this -> assertEquals ( $body , $expected_body );
}
}