<commit_before><?php
class SimpleEmailService {
  const SERVICE = 'email';
  const DOMAIN = 'amazonaws.com';
  const ALGORITHM = 'AWS4-HMAC-SHA256';
  const ERROR = "Please check your aws_access_key_id and aws_secret_access_key.\nAnd set correct permissions to your user or group.";

  private $aws_key;
  private $aws_secret;
  private $region;

  private $host;
  private $endpoint;

  private $amz_date;
  private $date;

  private $action;
  private $method;

  private $headers;
  private $query_parameters;

  public function __construct($credentials = array(), $enabled_ssl_verify_peer = true) {
    $this -> aws_key = $credentials['aws_access_key_id'];
    $this -> aws_secret = $credentials['aws_secret_access_key'];
    // default is us-east-1
    $this -> region = $credentials['region'] ? $credentials['region'] : 'us-east-1';

    $this -> host = self::SERVICE . '.' . $this -> region . '.' . self::DOMAIN;
    $this -> endpoint = 'https://' . self::SERVICE . '.' . $this -> region . '.' . self::DOMAIN;

    $this -> amz_date = gmdate('Ymd\THis\Z');
    $this -> date = gmdate('Ymd');

    $this -> ssl_verify = $enabled_ssl_verify_peer;
  }

  public function list_identities($identity_type = 'EmailAddress') {
    $this -> action = 'ListIdentities';
    $this -> method = 'GET';

    $parameters = array(
      'IdentityType' => $identity_type
    );

    $this -> generate_signature($parameters);
    $context = $this -> create_stream_context();
    if ($res = @file_get_contents($this -> endpoint . '?' . $this -> query_parameters, false, $context)) {
      $identities = new SimpleXMLElement($res);
      return $identities -> ListIdentitiesResult -> Identities -> member;
    } else {
      error_log(self::ERROR);
      return array();
    }
  }

  public function send_email($assets = array()) {
    $this -> action = 'SendEmail';
    $this -> method = 'POST';

    $parameters = array(
      'Message.Body.Text.Data' => $assets['body'],
      'Message.Subject.Data' => $assets['subject'],
      'Source' => $assets['from']
    );

    $address_index = 1;
    if (isset($assets['to']) && is_array($assets['to'])) {
      foreach ($assets['to'] as $address) {
        $parameters['Destination.ToAddresses.member.' . $address_index] = $address;
        $address_index++;
      }
    }

    if (isset($assets['cc']) && is_array($assets['cc'])) {
      $address_index = 1;
      foreach ($assets['cc'] as $address) {
        $parameters['Destination.CcAddresses.member.' . $address_index] = $address;
        $address_index++;
      }
    }<commit_msg>Improve check identity type in list_identities<commit_after><?php
class SimpleEmailService {
  const SERVICE = 'email';
  const DOMAIN = 'amazonaws.com';
  const ALGORITHM = 'AWS4-HMAC-SHA256';
  const ERROR = "Please check your aws_access_key_id and aws_secret_access_key.\nAnd set correct permissions to your user or group.";

  private $aws_key;
  private $aws_secret;
  private $region;

  private $host;
  private $endpoint;

  private $amz_date;
  private $date;

  private $action;
  private $method;

  private $headers;
  private $query_parameters;

  public function __construct($credentials = array(), $enabled_ssl_verify_peer = true) {
    $this -> aws_key = $credentials['aws_access_key_id'];
    $this -> aws_secret = $credentials['aws_secret_access_key'];
    // default is us-east-1
    $this -> region = $credentials['region'] ? $credentials['region'] : 'us-east-1';

    $this -> host = self::SERVICE . '.' . $this -> region . '.' . self::DOMAIN;
    $this -> endpoint = 'https://' . self::SERVICE . '.' . $this -> region . '.' . self::DOMAIN;

    $this -> amz_date = gmdate('Ymd\THis\Z');
    $this -> date = gmdate('Ymd');

    $this -> ssl_verify = $enabled_ssl_verify_peer;
  }

  public function list_identities($identity_type = 'EmailAddress') {
    $this -> action = 'ListIdentities';
    $this -> method = 'GET';

    if (!preg_match('/EmailAddress|Domain/', $identity_type)) {
      error_log('IdentityType must EmailAddress or Domain');
      return;
    }

    $parameters = array(
      'IdentityType' => $identity_type
    );

    $this -> generate_signature($parameters);
    $context = $this -> create_stream_context();
    if ($res = @file_get_contents($this -> endpoint . '?' . $this -> query_parameters, false, $context)) {
      $identities = new SimpleXMLElement($res);
      return $identities -> ListIdentitiesResult -> Identities -> member;
    } else {
      error_log(self::ERROR);
      return;
    }
  }

  public function send_email($assets = array()) {
    $this -> action = 'SendEmail';
    $this -> method = 'POST';

    $parameters = array(
      'Message.Body.Text.Data' => $assets['body'],
      'Message.Subject.Data' => $assets['subject'],
      'Source' => $assets['from']
    );

    $address_index = 1;
    if (isset($assets['to']) && is_array($assets['to'])) {
      foreach ($assets['to'] as $address) {
        $parameters['Destination.ToAddresses.member.' . $address_index] = $address;
        $address_index++;
      }
    }

    if (isset($assets['cc']) && is_array($assets['cc'])) {
      $address_index = 1;
      foreach ($assets['cc'] as $address) {
        $parameters['Destination.CcAddresses.member.' . $address_index] = $address;
        $address_index++;
      }
    }
{'fraction_non_alphanumeric': 0.16757672754660138, 'fraction_numerical': 0.0030126153266804745, 'mean_word_length': 3.2192216044479744, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 53, 'https://': 2, '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': '1396176', 'n_tokens_mistral': 1708, 'n_tokens_neox': 1683, 'n_words': 363}