Server IP : 127.0.0.2 / Your IP : 18.216.60.85 Web Server : Apache/2.4.18 (Ubuntu) System : User : www-data ( ) PHP Version : 7.0.33-0ubuntu0.16.04.16 Disable Function : disk_free_space,disk_total_space,diskfreespace,dl,exec,fpaththru,getmyuid,getmypid,highlight_file,ignore_user_abord,leak,listen,link,opcache_get_configuration,opcache_get_status,passthru,pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,php_uname,phpinfo,posix_ctermid,posix_getcwd,posix_getegid,posix_geteuid,posix_getgid,posix_getgrgid,posix_getgrnam,posix_getgroups,posix_getlogin,posix_getpgid,posix_getpgrp,posix_getpid,posix,_getppid,posix_getpwnam,posix_getpwuid,posix_getrlimit,posix_getsid,posix_getuid,posix_isatty,posix_kill,posix_mkfifo,posix_setegid,posix_seteuid,posix_setgid,posix_setpgid,posix_setsid,posix_setuid,posix_times,posix_ttyname,posix_uname,pclose,popen,proc_open,proc_close,proc_get_status,proc_nice,proc_terminate,shell_exec,source,show_source,system,virtual MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : ON | Sudo : ON | Pkexec : ON Directory : /var/www/html/vendor/swiftmailer/swiftmailer/tests/bug/Swift/ |
Upload File : |
<?php class Swift_Bug51Test extends \SwiftMailerTestCase { private $_attachmentFile; private $_outputFile; protected function setUp() { $this->_attachmentFile = sys_get_temp_dir().'/attach.rand.bin'; file_put_contents($this->_attachmentFile, ''); $this->_outputFile = sys_get_temp_dir().'/attach.out.bin'; file_put_contents($this->_outputFile, ''); } protected function tearDown() { unlink($this->_attachmentFile); unlink($this->_outputFile); } public function testAttachmentsDoNotGetTruncatedUsingToByteStream() { //Run 100 times with 10KB attachments for ($i = 0; $i < 10; ++$i) { $message = $this->_createMessageWithRandomAttachment( 10000, $this->_attachmentFile ); file_put_contents($this->_outputFile, ''); $message->toByteStream( new Swift_ByteStream_FileByteStream($this->_outputFile, true) ); $emailSource = file_get_contents($this->_outputFile); $this->assertAttachmentFromSourceMatches( file_get_contents($this->_attachmentFile), $emailSource ); } } public function testAttachmentsDoNotGetTruncatedUsingToString() { //Run 100 times with 10KB attachments for ($i = 0; $i < 10; ++$i) { $message = $this->_createMessageWithRandomAttachment( 10000, $this->_attachmentFile ); $emailSource = $message->toString(); $this->assertAttachmentFromSourceMatches( file_get_contents($this->_attachmentFile), $emailSource ); } } public function assertAttachmentFromSourceMatches($attachmentData, $source) { $encHeader = 'Content-Transfer-Encoding: base64'; $base64declaration = strpos($source, $encHeader); $attachmentDataStart = strpos($source, "\r\n\r\n", $base64declaration); $attachmentDataEnd = strpos($source, "\r\n--", $attachmentDataStart); if (false === $attachmentDataEnd) { $attachmentBase64 = trim(substr($source, $attachmentDataStart)); } else { $attachmentBase64 = trim(substr( $source, $attachmentDataStart, $attachmentDataEnd - $attachmentDataStart )); } $this->assertIdenticalBinary($attachmentData, base64_decode($attachmentBase64)); } private function _fillFileWithRandomBytes($byteCount, $file) { // I was going to use dd with if=/dev/random but this way seems more // cross platform even if a hella expensive!! file_put_contents($file, ''); $fp = fopen($file, 'wb'); for ($i = 0; $i < $byteCount; ++$i) { $byteVal = rand(0, 255); fwrite($fp, pack('i', $byteVal)); } fclose($fp); } private function _createMessageWithRandomAttachment($size, $attachmentPath) { $this->_fillFileWithRandomBytes($size, $attachmentPath); $message = Swift_Message::newInstance() ->setSubject('test') ->setBody('test') ->setFrom('a@b.c') ->setTo('d@e.f') ->attach(Swift_Attachment::fromPath($attachmentPath)) ; return $message; } }