<commit_before><?php

/*
 * This file is part of WordPlate.
 *
 * (c) <NAME> <<EMAIL>>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

declare(strict_types=1);

namespace WordPlate\Mail;

use PHPMailer;
use phpmailerException;

/**
 * This is the mail class.
 *
 * @author <NAME> <<EMAIL>>
 * @author <NAME> <<EMAIL>>
 */
final class Mail
{

    /**
     * Processed attachments.
     *
     * @var array
     */
    protected $attachments;

    /**
     * Initialize.
     *
     * @return void
     */
    public function initialize()
    {
        add_action('phpmailer_init', [$this, 'setCustomCredentials']);

        add_filter('wp_mail_from', [$this, 'filterMailFromAddress']);
        add_filter('wp_mail_from_name', [$this, 'filterMailFromName']);

        add_filter('wp_mail', [$this, 'filterMailAttachments'], PHP_INT_MAX);
    }

    /**
     * Set custom SMTP credentials.
     *
     * @param PHPMailer $mail
     *
     * @return PHPMailer
     */
    public function setCustomCredentials(PHPMailer $mail)
    {
        $mail->IsSMTP();
        $mail->SMTPAutoTLS = false;

        if (!function_exists('env')) {
            $mail->SMTPAuth = env('MAIL_USERNAME') && env('MAIL_PASSWORD');
            $mail->SMTPSecure = env('MAIL_ENCRYPTION', 'tls');

            $mail->Host = env('MAIL_HOST');
            $mail->Port = env('MAIL_PORT', 587);
            $mail->Username = env('MAIL_USERNAME');
            $mail->Password = env('<PASSWORD>');
        }

        return $mail;
    }

    /**
     * Filter mail from address.
     *
     * @param string $mailFromAddress
     *
     * @return string
     */
    public function filterMailFromAddress($mailFromAddress)
    {
        if (defined('MAIL_FROM_ADDRESS')) {
            return MAIL_FROM_ADDRESS;
        } else if (function_exists('env') && env('MAIL_FROM_ADDRESS')) {
            define('MAIL_FROM_ADDRESS', env('MAIL_FROM_ADDRESS'));
            return MAIL_FROM_ADDRESS;
        }

        return $mailFromAddress;
    }

    /**
     * Filter mail from name.
     *
     * @param string $mailFromName
     *
     * @return string
     */
    public function filterMailFromName($mailFromName)
    {
        if (defined('MAIL_FROM_NAME')) {
            return MAIL_FROM_NAME;
        } else if (function_exists('env') && env('MAIL_FROM_NAME')) {
            define('MAIL_FROM_NAME', env('MAIL_FROM_NAME'));<commit_msg>Coding standards fix<commit_after><?php

/*
 * This file is part of WordPlate.
 *
 * (c) <NAME> <<EMAIL>>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

declare(strict_types=1);

namespace WordPlate\Mail;

use PHPMailer;
use phpmailerException;

/**
 * This is the mail class.
 *
 * @author <NAME> <<EMAIL>>
 * @author <NAME> <<EMAIL>>
 */
final class Mail
{
    /**
     * Processed attachments.
     *
     * @var array
     */
    protected $attachments;

    /**
     * Initialize.
     *
     * @return void
     */
    public function initialize()
    {
        add_action('phpmailer_init', [$this, 'setCustomCredentials']);

        add_filter('wp_mail_from', [$this, 'filterMailFromAddress']);
        add_filter('wp_mail_from_name', [$this, 'filterMailFromName']);

        add_filter('wp_mail', [$this, 'filterMailAttachments'], PHP_INT_MAX);
    }

    /**
     * Set custom SMTP credentials.
     *
     * @param PHPMailer $mail
     *
     * @return PHPMailer
     */
    public function setCustomCredentials(PHPMailer $mail)
    {
        $mail->IsSMTP();
        $mail->SMTPAutoTLS = false;

        if (!function_exists('env')) {
            $mail->SMTPAuth = env('MAIL_USERNAME') && env('MAIL_PASSWORD');
            $mail->SMTPSecure = env('MAIL_ENCRYPTION', 'tls');

            $mail->Host = env('MAIL_HOST');
            $mail->Port = env('MAIL_PORT', 587);
            $mail->Username = env('MAIL_USERNAME');
            $mail->Password = env('<PASSWORD>');
        }

        return $mail;
    }

    /**
     * Filter mail from address.
     *
     * @param string $mailFromAddress
     *
     * @return string
     */
    public function filterMailFromAddress($mailFromAddress)
    {
        if (defined('MAIL_FROM_ADDRESS')) {
            return MAIL_FROM_ADDRESS;
        }
        if (function_exists('env') && env('MAIL_FROM_ADDRESS')) {
            define('MAIL_FROM_ADDRESS', env('MAIL_FROM_ADDRESS'));

            return MAIL_FROM_ADDRESS;
        }

        return $mailFromAddress;
    }

    /**
     * Filter mail from name.
     *
     * @param string $mailFromName
     *
     * @return string
     */
    public function filterMailFromName($mailFromName)
    {
        if (defined('MAIL_FROM_NAME')) {
            return MAIL_FROM_NAME;
        }
        if (function_exists('env') && env('MAIL_FROM_NAME')) {
            define('MAIL_FROM_NAME', env('MAIL_FROM_NAME'));

{'fraction_non_alphanumeric': 0.13884430176565007, 'fraction_numerical': 0.0016051364365971107, 'mean_word_length': 2.3366800535475236, 'pattern_counts': {'":': 0, '<': 25, '<?xml version=': 0, '>': 39, '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': '1489658', 'n_tokens_mistral': 1555, 'n_tokens_neox': 1552, 'n_words': 315}