Find this useful? Enter your email to receive occasional updates for securing PHP code.

Signing you up...

Thank you for signing up!

PHP Decode

<?php declare(strict_types=1); /** * MailTransportTest file * * CakePHP(tm) : Rapid De..

Decoded Output download

<?php
declare(strict_types=1);

/**
 * MailTransportTest file
 *
 * CakePHP(tm) : Rapid Development Framework (https://cakephp.org)
 * Copyright (c) Cake Software Foundation, Inc. (https://cakefoundation.org)
 *
 * Licensed under The MIT License
 * For full copyright and license information, please see the LICENSE.txt
 * Redistributions of files must retain the above copyright notice
 *
 * @copyright     Copyright (c) Cake Software Foundation, Inc. (https://cakefoundation.org)
 * @link          https://cakephp.org CakePHP(tm) Project
 * @since         2.0.0
 * @license       https://opensource.org/licenses/mit-license.php MIT License
 */
namespace Cake\Test\TestCase\Mailer\Transport;

use Cake\Core\Exception\CakeException;
use Cake\Mailer\Message;
use Cake\TestSuite\TestCase;

/**
 * Test case
 */
class MailTransportTest extends TestCase
{
    /**
     * @var \Cake\Mailer\Transport\MailTransport|\PHPUnit\Framework\MockObject\MockObject
     */
    protected $MailTransport;

    /**
     * Setup
     */
    public function setUp(): void
    {
        parent::setUp();
        $this->MailTransport = $this->getMockBuilder('Cake\Mailer\Transport\MailTransport')
            ->onlyMethods(['_mail'])
            ->getMock();
        $this->MailTransport->setConfig(['additionalParameters' => '-f']);
    }

    /**
     * testSendWithoutRecipient method
     */
    public function testSendWithoutRecipient(): void
    {
        $this->expectException(CakeException::class);
        $this->expectExceptionMessage('You must specify at least one recipient. Use one of `setTo`, `setCc` or `setBcc` to define a recipient.');

        $message = new Message();
        $this->MailTransport->send($message);
    }

    /**
     * testSend method
     */
    public function testSendData(): void
    {
        $eol = "
";

        $message = new Message();
        $message->setFrom('[email protected]', 'CakePHP Test');
        $message->setReturnPath('[email protected]', 'CakePHP Return');
        $message->setTo('[email protected]', 'CakePHP');
        $message->setReplyTo(['[email protected]' => 'Mark Story', '[email protected]' => 'Juan Basso']);
        $message->setCc(['[email protected]' => 'Mark Story', '[email protected]' => 'Juan Basso']);
        $message->setBcc('[email protected]');
        $message->setMessageId('<4d9946cf-0a44-4907-88fe-1d0ccbdd56cb@localhost>');
        $longNonAscii = 'Fo Br Bz Fo Br Bz Fo Br Bz Fo Br Bz';
        $message->setSubject($longNonAscii);
        $date = date(DATE_RFC2822);
        $message->setHeaders([
            'X-Mailer' => 'CakePHP Email',
            'Date' => $date,
            'X-add' => mb_encode_mimeheader($longNonAscii, 'utf8', 'B'),
        ]);
        $message->setBody(['text' => "First Line
Second Line
.Third Line"]);

        $encoded = '=?UTF-8?B?Rm/DuCBCw6VyIELDqXogRm/DuCBCw6VyIELDqXogRm/DuCBCw6VyIELDqXog?=';
        $encoded .= ' =?UTF-8?B?Rm/DuCBCw6VyIELDqXo=?=';

        $data = "From: CakePHP Test <[email protected]>{$eol}";
        $data .= "Reply-To: Mark Story <[email protected]>, Juan Basso <[email protected]>{$eol}";
        $data .= "Return-Path: CakePHP Return <[email protected]>{$eol}";
        $data .= "Cc: Mark Story <[email protected]>, Juan Basso <[email protected]>{$eol}";
        $data .= "Bcc: [email protected]{$eol}";
        $data .= "X-Mailer: CakePHP Email{$eol}";
        $data .= 'Date: ' . $date . $eol;
        $data .= 'X-add: ' . $encoded . $eol;
        $data .= "Message-ID: <4d9946cf-0a44-4907-88fe-1d0ccbdd56cb@localhost>{$eol}";
        $data .= "MIME-Version: 1.0{$eol}";
        $data .= "Content-Type: text/plain; charset=UTF-8{$eol}";
        $data .= 'Content-Transfer-Encoding: 8bit';

        $this->MailTransport->expects($this->once())->method('_mail')
            ->with(
                'CakePHP <[email protected]>',
                $encoded,
                implode($eol, ['First Line', 'Second Line', '.Third Line', '', '']),
                $data,
                '-f'
            );

        $result = $this->MailTransport->send($message);

        $this->assertStringContainsString('Subject: ', $result['headers']);
        $this->assertStringContainsString('To: ', $result['headers']);
    }
}
 ?>

Did this file decode correctly?

Original Code

<?php
declare(strict_types=1);

/**
 * MailTransportTest file
 *
 * CakePHP(tm) : Rapid Development Framework (https://cakephp.org)
 * Copyright (c) Cake Software Foundation, Inc. (https://cakefoundation.org)
 *
 * Licensed under The MIT License
 * For full copyright and license information, please see the LICENSE.txt
 * Redistributions of files must retain the above copyright notice
 *
 * @copyright     Copyright (c) Cake Software Foundation, Inc. (https://cakefoundation.org)
 * @link          https://cakephp.org CakePHP(tm) Project
 * @since         2.0.0
 * @license       https://opensource.org/licenses/mit-license.php MIT License
 */
namespace Cake\Test\TestCase\Mailer\Transport;

use Cake\Core\Exception\CakeException;
use Cake\Mailer\Message;
use Cake\TestSuite\TestCase;

/**
 * Test case
 */
class MailTransportTest extends TestCase
{
    /**
     * @var \Cake\Mailer\Transport\MailTransport|\PHPUnit\Framework\MockObject\MockObject
     */
    protected $MailTransport;

    /**
     * Setup
     */
    public function setUp(): void
    {
        parent::setUp();
        $this->MailTransport = $this->getMockBuilder('Cake\Mailer\Transport\MailTransport')
            ->onlyMethods(['_mail'])
            ->getMock();
        $this->MailTransport->setConfig(['additionalParameters' => '-f']);
    }

    /**
     * testSendWithoutRecipient method
     */
    public function testSendWithoutRecipient(): void
    {
        $this->expectException(CakeException::class);
        $this->expectExceptionMessage('You must specify at least one recipient. Use one of `setTo`, `setCc` or `setBcc` to define a recipient.');

        $message = new Message();
        $this->MailTransport->send($message);
    }

    /**
     * testSend method
     */
    public function testSendData(): void
    {
        $eol = "\r\n";

        $message = new Message();
        $message->setFrom('[email protected]', 'CakePHP Test');
        $message->setReturnPath('[email protected]', 'CakePHP Return');
        $message->setTo('[email protected]', 'CakePHP');
        $message->setReplyTo(['[email protected]' => 'Mark Story', '[email protected]' => 'Juan Basso']);
        $message->setCc(['[email protected]' => 'Mark Story', '[email protected]' => 'Juan Basso']);
        $message->setBcc('[email protected]');
        $message->setMessageId('<4d9946cf-0a44-4907-88fe-1d0ccbdd56cb@localhost>');
        $longNonAscii = 'Fo Br Bz Fo Br Bz Fo Br Bz Fo Br Bz';
        $message->setSubject($longNonAscii);
        $date = date(DATE_RFC2822);
        $message->setHeaders([
            'X-Mailer' => 'CakePHP Email',
            'Date' => $date,
            'X-add' => mb_encode_mimeheader($longNonAscii, 'utf8', 'B'),
        ]);
        $message->setBody(['text' => "First Line\nSecond Line\n.Third Line"]);

        $encoded = '=?UTF-8?B?Rm/DuCBCw6VyIELDqXogRm/DuCBCw6VyIELDqXogRm/DuCBCw6VyIELDqXog?=';
        $encoded .= ' =?UTF-8?B?Rm/DuCBCw6VyIELDqXo=?=';

        $data = "From: CakePHP Test <[email protected]>{$eol}";
        $data .= "Reply-To: Mark Story <[email protected]>, Juan Basso <[email protected]>{$eol}";
        $data .= "Return-Path: CakePHP Return <[email protected]>{$eol}";
        $data .= "Cc: Mark Story <[email protected]>, Juan Basso <[email protected]>{$eol}";
        $data .= "Bcc: [email protected]{$eol}";
        $data .= "X-Mailer: CakePHP Email{$eol}";
        $data .= 'Date: ' . $date . $eol;
        $data .= 'X-add: ' . $encoded . $eol;
        $data .= "Message-ID: <4d9946cf-0a44-4907-88fe-1d0ccbdd56cb@localhost>{$eol}";
        $data .= "MIME-Version: 1.0{$eol}";
        $data .= "Content-Type: text/plain; charset=UTF-8{$eol}";
        $data .= 'Content-Transfer-Encoding: 8bit';

        $this->MailTransport->expects($this->once())->method('_mail')
            ->with(
                'CakePHP <[email protected]>',
                $encoded,
                implode($eol, ['First Line', 'Second Line', '.Third Line', '', '']),
                $data,
                '-f'
            );

        $result = $this->MailTransport->send($message);

        $this->assertStringContainsString('Subject: ', $result['headers']);
        $this->assertStringContainsString('To: ', $result['headers']);
    }
}

Function Calls

None

Variables

None

Stats

MD5 1745420583450d2713d87068102b2655
Eval Count 0
Decode Time 73 ms