<commit_before><?php
/**
 * Tatoeba Project, free collaborative creation of multilingual corpuses project
 * Copyright (C) 2009  <NAME> <<EMAIL>>
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Affero General Public License for more details.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *
 * PHP version 5
 *
 * @category PHP
 * @package  Tatoeba
 * @author   <NAME> <<EMAIL>>
 * @license  Affero General Public License
 * @link     http://tatoeba.org
 */

/**
 * Component for mails.
 *
 * @category Default
 * @package  Components
 * @author   <NAME> <<EMAIL>>
 * @license  Affero General Public License
 * @link     http://tatoeba.org
 */
class MailerComponent extends Object
{
    public $from     = '<EMAIL>';
    public $fromName = 'Tatoeba (no-reply)';
    public $to       = null;
    public $toName   = null;
    public $subject  = null;
    public $message  = null;

    /**
     * Send email.
     *
     * @return void
     */
    public function send()
    {
        /* email notification */
        $this->_authgMail(
            $this->from,
            $this->fromName,
            $this->to,
            $this->toName,
            $this->subject,
            $this->message
        );
    }

    /**
     * Send via Gmail.
     *
     * @param string $from     Email of sender.
     * @param string $namefrom Name of sender.
     * @param string $to       Email of recipient.
     * @param string $nameto   Name of recipient.
     * @param string $subject  Subject.
     * @param string $message  Message.
     *
     * @return array
     */
    private function _authgMail($from, $namefrom, $to, $nameto, $subject, $message)
    {
        if (Configure::read('Mailer.enabled') == false) {
            return;
        }

        /*  your configuration here  */

        $smtpServer = "tls://smtp.gmail.com"; //does not accept STARTTLS
        $port = "465"; // try 587 if this fails
        $timeout = "45"; //typical timeout. try 45 for slow servers
        $username = Configure::read('Mailer.username'); //your gmail account
        $password = Configure::read('Mailer.password'); //the pass for your gmail
        $localhost = $_SERVER['REMOTE_ADDR']; //requires a real ip
        $newLine = "\r\n"; //var just for newlines

        /*  you shouldn't need to mod anything else */

        //connect to the host and port
        $smtpConnect = fsockopen($smtpServer, $port, $errno, $errstr, $timeout);
        //echo $errstr." - ".$errno;
        $smtpResponse = fgets($smtpConnect, 4096);
        if (empty($smtpConnect)) {
            $output = "Failed to connect: $smtpResponse";
            //echo $output;
            return $output;
        } else {
            $logArray['connection'] = "Connected to: $smtpResponse";
            //echo "connection accepted<br>".$smtpResponse."<p />Continuing<p />";
        }

        //you have to say HELO again after TLS is started
        fputs($smtpConnect, "HELO $localhost". $newLine);
        $smtpResponse = fgets($smtpConnect, 4096);
        $logArray['heloresponse2'] = "$smtpResponse";

        //request for auth login
        fputs($smtpConnect, "AUTH LOGIN" . $newLine);
        $smtpResponse = fgets($smtpConnect, 4096);
        $logArray['authrequest'] = "$smtpResponse";

        //send the username
        fputs($smtpConnect, base64_encode($username) . $newLine);
        $smtpResponse = fgets($smtpConnect, 4096);
        $logArray['authusername'] = "$smtpResponse";

        //send the password
        fputs($smtpConnect, base64_encode($password) . $newLine);
        $smtpResponse = fgets($smtpConnect, 4096);
        $logArray['authpassword'] = "$smtpResponse";

        //email from
        fputs($smtpConnect, "MAIL FROM: <$from>" . $newLine);
        $smtpResponse = fgets($smtpConnect, 4096);
        $logArray['mailfromresponse'] = "$smtpResponse";

        //email to
        fputs($smtpConnect, "RCPT TO: <$to>" . $newLine);
        $smtpResponse = fgets($smtpConnect, 4096);
        $logArray['mailtoresponse'] = "$smtpResponse";

        //the email
        fputs($smtpConnect, "DATA" . $newLine);
        $smtpResponse = fgets($smtpConnect, 4096);
        $logArray['data1response'] = "$smtpResponse";

        //construct headers<commit_msg>MIME-encode mail headers. Closes #531.<commit_after><?php
/**
 * Tatoeba Project, free collaborative creation of multilingual corpuses project
 * Copyright (C) 2009  <NAME> <<EMAIL>>
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Affero General Public License for more details.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *
 * PHP version 5
 *
 * @category PHP
 * @package  Tatoeba
 * @author   <NAME> <<EMAIL>>
 * @license  Affero General Public License
 * @link     http://tatoeba.org
 */

/**
 * Component for mails.
 *
 * @category Default
 * @package  Components
 * @author   <NAME> <<EMAIL>>
 * @license  Affero General Public License
 * @link     http://tatoeba.org
 */
class MailerComponent extends Object
{
    public $from     = '<EMAIL>';
    public $fromName = 'Tatoeba (no-reply)';
    public $to       = null;
    public $toName   = null;
    public $subject  = null;
    public $message  = null;

    /**
     * Send email.
     *
     * @return void
     */
    public function send()
    {
        /* email notification */
        $this->_authgMail(
            $this->from,
            $this->fromName,
            $this->to,
            $this->toName,
            $this->subject,
            $this->message
        );
    }

    /**
     * Send via Gmail.
     *
     * @param string $from     Email of sender.
     * @param string $namefrom Name of sender.
     * @param string $to       Email of recipient.
     * @param string $nameto   Name of recipient.
     * @param string $subject  Subject.
     * @param string $message  Message.
     *
     * @return array
     */
    private function _authgMail($from, $namefrom, $to, $nameto, $subject, $message)
    {
        if (Configure::read('Mailer.enabled') == false) {
            return;
        }

        /*  your configuration here  */

        $smtpServer = "tls://smtp.gmail.com"; //does not accept STARTTLS
        $port = "465"; // try 587 if this fails
        $timeout = "45"; //typical timeout. try 45 for slow servers
        $username = Configure::read('Mailer.username'); //your gmail account
        $password = Configure::read('Mailer.password'); //the pass for your gmail
        $localhost = $_SERVER['REMOTE_ADDR']; //requires a real ip
        $newLine = "\r\n"; //var just for newlines

        /*  you shouldn't need to mod anything else */

        //connect to the host and port
        $smtpConnect = fsockopen($smtpServer, $port, $errno, $errstr, $timeout);
        //echo $errstr." - ".$errno;
        $smtpResponse = fgets($smtpConnect, 4096);
        if (empty($smtpConnect)) {
            $output = "Failed to connect: $smtpResponse";
            //echo $output;
            return $output;
        } else {
            $logArray['connection'] = "Connected to: $smtpResponse";
            //echo "connection accepted<br>".$smtpResponse."<p />Continuing<p />";
        }

        //you have to say HELO again after TLS is started
        fputs($smtpConnect, "HELO $localhost". $newLine);
        $smtpResponse = fgets($smtpConnect, 4096);
        $logArray['heloresponse2'] = "$smtpResponse";

        //request for auth login
        fputs($smtpConnect, "AUTH LOGIN" . $newLine);
        $smtpResponse = fgets($smtpConnect, 4096);
        $logArray['authrequest'] = "$smtpResponse";

        //send the username
        fputs($smtpConnect, base64_encode($username) . $newLine);
        $smtpResponse = fgets($smtpConnect, 4096);
        $logArray['authusername'] = "$smtpResponse";

        //send the password
        fputs($smtpConnect, base64_encode($password) . $newLine);
        $smtpResponse = fgets($smtpConnect, 4096);
        $logArray['authpassword'] = "$smtpResponse";

        //email from
        fputs($smtpConnect, "MAIL FROM: <$from>" . $newLine);
        $smtpResponse = fgets($smtpConnect, 4096);
        $logArray['mailfromresponse'] = "$smtpResponse";

        //email to
        fputs($smtpConnect, "RCPT TO: <$to>" . $newLine);
        $smtpResponse = fgets($smtpConnect, 4096);
        $logArray['mailtoresponse'] = "$smtpResponse";

        //the email
        fputs($smtpConnect, "DATA" . $newLine);
        $smtpResponse = fgets($smtpConnect, 4096);
        $logArray['data1response'] = "$smtpResponse";

        //construct headers
        $subject  = mb_encode_mimeheader($subject);
        $nameto   = mb_encode_mimeheader($nameto);
        $namefrom = mb_encode_mimeheader($namefrom);
{'fraction_non_alphanumeric': 0.12943718489556538, 'fraction_numerical': 0.011420928079020475, 'mean_word_length': 2.393854748603352, 'pattern_counts': {'":': 0, '<': 37, '<?xml version=': 0, '>': 49, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '1671868', 'n_tokens_mistral': 3048, 'n_tokens_neox': 2837, 'n_words': 855}