<commit_before><commit_msg>Add Pear namespace with PEAR::Mail implementation<commit_after><?php
/**
 * DronePHP (http://www.dronephp.com)
 *
 * @link      http://github.com/Pleets/DronePHP
 * @copyright Copyright (c) 2016-2018 Pleets. (http://www.pleets.org)
 * @license   http://www.dronephp.com/license
 * @author    <NAME> <<EMAIL>>
 */

namespace Drone\Pear;

/**
 * Mail class
 *
 * Helper class to send emails
 */
class Mail
{
    /**
     * @var string
     */
    protected $host;

    /**
     * Failure messages
     *
     * @var array
     */
    protected $errors = [];

    /**
     * Returns the host attribute
     *
     * @return string
     */
    public function getHost()
    {
        return $this->host;
    }

    /**
     * Returns an array with all failure messages
     *
     * @return array
     */
    public function getErrors()
    {
        return $this->errors;
    }

    /**
     * Sets host attribute
     *
     * @param string $value
     *
     * @return null
     */
    public function setHost($value)
    {
        return $this->host = $value;
    }

    /**
     * Constructor
     *
     * @throws RuntimeException
     *
     * @param array $options
     */
    public function __construct()
    {
        @include_once 'System.php';

        if (!class_exists('System', false))
            throw new \RuntimeException("PEAR is not installed in your system!");

        include_once 'Net/SMTP.php';

        if (!class_exists('\Net_SMTP', false))
            throw new \RuntimeException("PEAR::Net_SMTP is not installed!");

        @include_once 'Mail.php';

        if (!class_exists('\Mail', false))
            throw new \RuntimeException("PEAR::Mail is not installed!");
    }

    /**
     * Adds an error
     *
     * @param string $code
     * @param string $message
     *
     * @return null
     */
    protected function error($code, $message = null)
    {
        if (!array_key_exists($code, $this->errors))
            $this->errors[$message] = (is_null($message) && array_key_exists($code, $this->messagesTemplates)) ? $this->messagesTemplates[$code] : $message;
    }

    /**
     * Sends an email
     *
     * @param string $from
     * @param string $to
     * @param string $subject
     * @param string $body
     *
     * @return boolean
     */
    public function send($from, $to, $subject, $body)
    {
        $headers = array (
            'From'         => $from,
            'To'           => $to,
            'Subject'      => $subject,
            'Content-type' => 'text/html;charset=iso-8859-1'
        );

        $smtp = \Mail::factory(
            'smtp',
            array ('host' => $this->host, 'auth' => false)
        );

        $mail = $smtp->send($to, $headers, $body);

        if (\PEAR::isError($mail))
        {
            $this->error(
            	$mail->getCode(), $mail->getMessage()
            );

            return false;
        }

        return true;
    }
}
{'fraction_non_alphanumeric': 0.14728682170542637, 'fraction_numerical': 0.004381530165149983, 'mean_word_length': 1.7506950880444856, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 24, 'https://': 0, 'lorem ipsum': 0, 'www.': 3, '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': '1631020', 'n_tokens_mistral': 921, 'n_tokens_neox': 891, 'n_words': 205}