<commit_before>class ResqueMailer < ActionMailer::Base
  helper ProposalsHelper, EmailHelper, GroupsHelper, UsersHelper
  default from: ENV['DEFAULT_FROM']

  layout 'newsletters/default'

  def url_options
    options = {}
    if @user
      options.merge!(host: @user.locale.host, protocol: DEFAULT_EMAIL_PROTOCOL)
      options.merge!(subdomain: @user.subdomain) if @user.subdomain
      options.merge!(l: @user.locale.lang) unless @user.locale.lang.blank?
    end
    options
  end

  # don't send emails to user without an email address
  def mail(headers = {}, &block)
    super if headers[:to].present?
  end
  # specific templates for notification types
  TEMPLATES = {
      NotificationType::NEW_CONTRIBUTES => 'new_contribute',
      NotificationType::NEW_CONTRIBUTES_MINE => 'new_contribute',
      NotificationType::NEW_COMMENTS_MINE => 'new_contribute',
      NotificationType::NEW_COMMENTS => 'new_contribute',
      NotificationType::TEXT_UPDATE => 'text_update',
      NotificationType::NEW_PUBLIC_PROPOSALS => 'new_proposal',
      NotificationType::NEW_PROPOSALS => 'new_proposal',
      NotificationType::NEW_PUBLIC_EVENTS => 'notifications/new_event',
      NotificationType::NEW_EVENTS => 'notifications/new_event',
      NotificationType::AVAILABLE_AUTHOR => 'notifications/available_author',
      NotificationType::UNINTEGRATED_CONTRIBUTE => 'unintegrated_contribute',
      NotificationType::NEW_BLOG_COMMENT => 'new_blog_comment',
      NotificationType::CONTRIBUTE_UPDATE => 'notifications/update_contribute'
  }

  def notification(alert_id)
    @alert = Alert.find(alert_id)
    @user = @alert.user
    return if @alert.checked # do not send emails for already checked alerts
    I18n.locale = @user.locale.key || :'en-EU'
    @data = @alert.data
    to_id = @data[:to_id]
    subject_id = @data[:subject]
    subject = @alert.email_subject
    template_name = TEMPLATES[@alert.notification.notification_type_id] || 'notification'
    if to_id
      mail(to: "<EMAIL>", bcc: @user.email, subject: subject, template_name: template_name) #todo extract email
    else
      mail(to: @user.email, from: ENV['NOREPLY_EMAIL'], subject: subject, template_name: template_name)
    end
  end

  def admin_message(msg)
    @msg = msg
    mail(to: ENV['ADMIN_EMAIL'], subject: ENV['APP_SHORT_NAME'] + " - Messaggio di amministrazione")
  end

  def report_message(report_id)
    @report = ProposalCommentReport.find(report_id)

    mail(to: ENV['ADMIN_EMAIL'], subject: ENV['APP_SHORT_NAME'] + " - Segnalazione Contributo")
  end

  # send an invite to subscribe in the group
  def invite(group_invitation_email_id)
    @group_invitation_email = GroupInvitationEmail.find(group_invitation_email_id)
    @group_invitation = @group_invitation_email.group_invitation<commit_msg>modify email<commit_after>class ResqueMailer < ActionMailer::Base
  helper ProposalsHelper, EmailHelper, GroupsHelper, UsersHelper
  default from: ENV['DEFAULT_FROM']

  layout 'newsletters/default'

  def url_options
    options = {}
    if @user
      options.merge!(host: @user.locale.host, protocol: DEFAULT_EMAIL_PROTOCOL)
      options.merge!(subdomain: @user.subdomain) if @user.subdomain
      options.merge!(l: @user.locale.lang) unless @user.locale.lang.blank?
    end
    options
  end

  # don't send emails to user without an email address
  def mail(headers = {}, &block)
    super if headers[:to].present?
  end
  # specific templates for notification types
  TEMPLATES = {
      NotificationType::NEW_CONTRIBUTES => 'new_contribute',
      NotificationType::NEW_CONTRIBUTES_MINE => 'new_contribute',
      NotificationType::NEW_COMMENTS_MINE => 'new_contribute',
      NotificationType::NEW_COMMENTS => 'new_contribute',
      NotificationType::TEXT_UPDATE => 'text_update',
      NotificationType::NEW_PUBLIC_PROPOSALS => 'new_proposal',
      NotificationType::NEW_PROPOSALS => 'new_proposal',
      NotificationType::NEW_PUBLIC_EVENTS => 'notifications/new_event',
      NotificationType::NEW_EVENTS => 'notifications/new_event',
      NotificationType::AVAILABLE_AUTHOR => 'notifications/available_author',
      NotificationType::UNINTEGRATED_CONTRIBUTE => 'unintegrated_contribute',
      NotificationType::NEW_BLOG_COMMENT => 'new_blog_comment',
      NotificationType::CONTRIBUTE_UPDATE => 'notifications/update_contribute'
  }

  def notification(alert_id)
    @alert = Alert.find(alert_id)
    @user = @alert.user
    return if @alert.checked # do not send emails for already checked alerts
    I18n.locale = @user.locale.key || :'en-EU'
    @data = @alert.data
    to_id = @data[:to_id]
    subject_id = @data[:subject]
    subject = @alert.email_subject
    template_name = TEMPL<EMAIL>[@<EMAIL>] || 'notification'
    if to_id
      mail(to: "<EMAIL>", bcc: @user.email, subject: subject, template_name: template_name) #todo extract email
    else
      mail(to: @user.email, from: ENV['NOREPLY_EMAIL'], subject: subject, template_name: template_name)
    end
  end

  def admin_message(msg)
    @msg = msg
    mail(to: ENV['ADMIN_EMAIL'], subject: ENV['APP_SHORT_NAME'] + " - Messaggio di amministrazione")
  end

  def report_message(report_id)
    @report = ProposalCommentReport.find(report_id)

    mail(to: ENV['ADMIN_EMAIL'], subject: ENV['APP_SHORT_NAME'] + " - Segnalazione Contributo")
  end

  # send an invite to subscribe in the group
  def invite(group_invitation_email_id)
    @group_invitation_email = GroupInvitationEmail.find(group_invitation_email_id)
    @group_invitation = @group_invitation_email.group_invitation
{'fraction_non_alphanumeric': 0.11011155091759625, 'fraction_numerical': 0.0007196833393306944, 'mean_word_length': 4.570140280561122, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 33, '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': '3192963', 'n_tokens_mistral': 1818, 'n_tokens_neox': 1731, 'n_words': 346}