<commit_before><?php

use \PhpMimeMailParser\Parser as PHPMimeParser;

class EmailMessage extends DataObject implements PermissionProvider
{
    
    private static $db = array(
        "To" => "Varchar(255)",
        "From" => "Varchar(255)",
        "Subject" => "Varchar(255)",
        "MessageID" => "Varchar(255)",
        "Sent" => "SS_DateTime",
        "Source" => "Text"
    );

    private static $casting = array(
        "Title" => "Varchar",
        "Body" => "Text",
        "BodySummary" => "Text",
        "HTMLBody" => "HTMLText"
    );

    private static $summary_fields = array(
        "Subject" => "Subject",
        "From" => "From",
        "BodySummary" => "Summary",
        "Sent" => "Sent"
    );

    /**
     * Return an array of email addresses from a provided string
     * 
     * @param $string A string that contains email addresses
     * @return array
     */
    public static function get_emails_from_string($string)
    {
        $return = array();
        $re = "/([a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\\.[a-zA-Z]{2,6})/i";
        preg_match_all($re, $string, $matches);

        // Clean up the results intyo a simpler array
        foreach ($matches as $match) {
            $return[] = $match[0];
        }

        return array_unique($return);
    }

    public function getTitle()
    {
        return $this->Subject . "<{$this->From}>";
    }

    /**
     * Run email parser over message source and parse,
     * then return the parsed object
     *
     * @return \PhpMimeMailParser\Parser<commit_msg>Add check to ensure email matches return array<commit_after><?php

use \PhpMimeMailParser\Parser as PHPMimeParser;

class EmailMessage extends DataObject implements PermissionProvider
{
    
    private static $db = array(
        "To" => "Varchar(255)",
        "From" => "Varchar(255)",
        "Subject" => "Varchar(255)",
        "MessageID" => "Varchar(255)",
        "Sent" => "SS_DateTime",
        "Source" => "Text"
    );

    private static $casting = array(
        "Title" => "Varchar",
        "Body" => "Text",
        "BodySummary" => "Text",
        "HTMLBody" => "HTMLText"
    );

    private static $summary_fields = array(
        "Subject" => "Subject",
        "From" => "From",
        "BodySummary" => "Summary",
        "Sent" => "Sent"
    );

    /**
     * Return an array of email addresses from a provided string
     * 
     * @param $string A string that contains email addresses
     * @return array
     */
    public static function get_emails_from_string($string)
    {
        $return = array();
        $re = "/([a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\\.[a-zA-Z]{2,6})/i";
        preg_match_all($re, $string, $matches);

        // Clean up the results into a simpler array
        foreach ($matches as $match) {
            if (is_array($match)) {
                $return[] = $match[0];
            }
        }

        return array_unique($return);
    }

    public function getTitle()
    {
        return $this->Subject . "<{$this->From}>";
    }

    /**
     * Run email parser over message source and parse,
     * then return the parsed object
     *
     * @return \PhpMimeMailParser\Parser
{'fraction_non_alphanumeric': 0.15566037735849056, 'fraction_numerical': 0.011949685534591196, 'mean_word_length': 2.0943579766536966, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 37, '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': '1975749', 'n_tokens_mistral': 1016, 'n_tokens_neox': 980, 'n_words': 246}