<commit_before><?php

/**
 * This class allows users to view an email in the browser
 *
 * @package     Nails
 * @subpackage  module-email
 * @category    Controller
 * @author      Nails Dev Team
 * @link
 */

use Nails\Common\Service\Asset;
use Nails\Common\Service\HttpCodes;
use Nails\Common\Service\Output;
use Nails\Common\Service\Uri;
use Nails\Email\Constants;
use Nails\Email\Controller\Base;
use Nails\Email\Service\Emailer;
use Nails\Environment;
use Nails\Factory;

/**
 * Class View
 */
class View extends Base
{
    /**
     * Handle view online requests
     */
    public function index()
    {
        /** @var Uri $oUri */
        $oUri = Factory::service('Uri');
        /** @var Emailer $oEmailer */
        $oEmailer = Factory::service('Emailer', Constants::MODULE_SLUG);
        $sRef     = $oUri->segment(3);
        $sGuid    = $oUri->segment(4);
        $sHash    = $oUri->segment(5);

        // --------------------------------------------------------------------------

        //  Fetch the email
        if (is_numeric($sRef)) {
            $oEmail = $oEmailer->getById($sRef);
        } else {
            $oEmail = $oEmailer->getByRef($sRef);
        }

        if (!$oEmail || !$oEmailer->validateHash($oEmail->ref, $sGuid, $sHash)) {

            /**
             * Using this to generate a JSON 404 as the standard show404() will attempt to
             * render the module's header/footer and it looks like a btoken email template.
             */

            /** @var HttpCodes $oHttpCodes */
            $oHttpCodes = Factory::service('HttpCodes');
            /** @var Output $oOutput */
            $oOutput = Factory::service('Output');

            $oOutput
                ->setStatusHeader($oHttpCodes::STATUS_NOT_FOUND)
                ->setContentType('application/json')
                ->setOutput(json_encode([
                    'status' => $oHttpCodes::STATUS_NOT_FOUND,
                    'error'  => 'Failed to validate email URL',
                ]));
            return;
        }

        if (Environment::is(Environment::ENV_DEV)) {

            /** @var Asset $oAsset */
            $oAsset = Factory::service('Asset');
            $oAsset->load('debugger.min.css', Constants::MODULE_SLUG);

            Factory::service('View')
                ->setData([<commit_msg>Clear Assets for ViewOnly email<commit_after><?php

/**
 * This class allows users to view an email in the browser
 *
 * @package     Nails
 * @subpackage  module-email
 * @category    Controller
 * @author      Nails Dev Team
 * @link
 */

use Nails\Common\Service\Asset;
use Nails\Common\Service\HttpCodes;
use Nails\Common\Service\Output;
use Nails\Common\Service\Uri;
use Nails\Email\Constants;
use Nails\Email\Controller\Base;
use Nails\Email\Service\Emailer;
use Nails\Environment;
use Nails\Factory;

/**
 * Class View
 */
class View extends Base
{
    /**
     * Handle view online requests
     */
    public function index()
    {
        /** @var Uri $oUri */
        $oUri = Factory::service('Uri');
        /** @var Emailer $oEmailer */
        $oEmailer = Factory::service('Emailer', Constants::MODULE_SLUG);
        $sRef     = $oUri->segment(3);
        $sGuid    = $oUri->segment(4);
        $sHash    = $oUri->segment(5);

        // --------------------------------------------------------------------------

        //  Fetch the email
        if (is_numeric($sRef)) {
            $oEmail = $oEmailer->getById($sRef);
        } else {
            $oEmail = $oEmailer->getByRef($sRef);
        }

        if (!$oEmail || !$oEmailer->validateHash($oEmail->ref, $sGuid, $sHash)) {

            /**
             * Using this to generate a JSON 404 as the standard show404() will attempt to
             * render the module's header/footer and it looks like a btoken email template.
             */

            /** @var HttpCodes $oHttpCodes */
            $oHttpCodes = Factory::service('HttpCodes');
            /** @var Output $oOutput */
            $oOutput = Factory::service('Output');

            $oOutput
                ->setStatusHeader($oHttpCodes::STATUS_NOT_FOUND)
                ->setContentType('application/json')
                ->setOutput(json_encode([
                    'status' => $oHttpCodes::STATUS_NOT_FOUND,
                    'error'  => 'Failed to validate email URL',
                ]));
            return;
        }

        if (Environment::is(Environment::ENV_DEV)) {

            /** @var Asset $oAsset */
            $oAsset = Factory::service('Asset');
            $oAsset
                ->clear()
                ->load('debugger.min.css', Constants::MODULE_SLUG);

            Factory::service('View')
                ->setData([
{'fraction_non_alphanumeric': 0.16486543759271033, 'fraction_numerical': 0.003814367450731087, 'mean_word_length': 1.744186046511628, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 32, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6170068', 'n_tokens_mistral': 1356, 'n_tokens_neox': 1321, 'n_words': 297}