<commit_before># -*- encoding : utf-8 -*-
class Emailer < ActionMailer::Base
  include ActionView::Helpers::TextHelper
  include Emailer::Incoming

  helper :application

  ANSWER_LINE = '-----------------------------==-----------------------------'

  class << self

    def emailer_defaults
      {
      :content_type => 'text/html',
      # :sent_on => Time.now,
      :from => from_address
      }
    end

    def send_email(template, *args)
      send_with_language(template, :en, *args)
    end

    def send_with_language(template, language, *args)
      old_locale = I18n.locale
      I18n.locale = language
      begin
        send(template, *args).deliver
      ensure
        I18n.locale = old_locale
      end
    end

    # can't use regular `receive` class method since it deals with Mail objects
    def receive_params(params)
      new.receive(params)
    end

    def from_user(reply_identifier, user)
      unless Teambox.config.allow_incoming_email and reply_identifier
        reply_identifier = "no-reply"
      end

      from_address(reply_identifier, user.try(:name))
    end

    def from_address(recipient = "no-reply", name = Teambox.config.application_name)
      domain = Teambox.config.smtp_settings[:domain]
      address = "#{recipient}@#{domain}"

      if name.blank? or Teambox.config.smtp_settings[:safe_from]
        address
      else
        %("#{name}" <#{address}>)
      end
    end
  end

  default emailer_defaults


  def confirm_email(user_id)
    @user = User.find(user_id)
    @login_link = confirm_email_user_url(@user, :token => @user.login_token)

    mail(
      :to         => @user.email,
      :subject => I18n.t("emailer.confirm.subject")
    )
  end

  def reset_password(user_id)
    @user = User.find(user_id)
    mail(
      :to         => @user.email,
      :subject    => I18n.t("emailer.reset_password.subject")
    )
  end

  def forgot_password(reset_password_id)
    reset_password = ResetPassword.find(reset_password_id)
    @user = reset_password.user
    @url  = reset_password_url(reset_password.reset_code)
    mail(
      :to         =>   reset_password.user.email,
      :subject    =>   I18n.t("emailer.forgot_password.subject")
    )
  end

  def project_invitation(invitation_id)
    @invitation = Invitation.find(invitation_id)
    @referral   = @invitation.user
    @project    = @invitation.project
    @recipient  = @invitation.invited_user<commit_msg>fix: get organisation when sending project invitation email<commit_after># -*- encoding : utf-8 -*-
class Emailer < ActionMailer::Base
  include ActionView::Helpers::TextHelper
  include Emailer::Incoming

  helper :application

  ANSWER_LINE = '-----------------------------==-----------------------------'

  class << self

    def emailer_defaults
      {
      :content_type => 'text/html',
      # :sent_on => Time.now,
      :from => from_address
      }
    end

    def send_email(template, *args)
      send_with_language(template, :en, *args)
    end

    def send_with_language(template, language, *args)
      old_locale = I18n.locale
      I18n.locale = language
      begin
        send(template, *args).deliver
      ensure
        I18n.locale = old_locale
      end
    end

    # can't use regular `receive` class method since it deals with Mail objects
    def receive_params(params)
      new.receive(params)
    end

    def from_user(reply_identifier, user)
      unless Teambox.config.allow_incoming_email and reply_identifier
        reply_identifier = "no-reply"
      end

      from_address(reply_identifier, user.try(:name))
    end

    def from_address(recipient = "no-reply", name = Teambox.config.application_name)
      domain = Teambox.config.smtp_settings[:domain]
      address = "#{recipient}@#{domain}"

      if name.blank? or Teambox.config.smtp_settings[:safe_from]
        address
      else
        %("#{name}" <#{address}>)
      end
    end
  end

  default emailer_defaults


  def confirm_email(user_id)
    @user = User.find(user_id)
    @login_link = confirm_email_user_url(@user, :token => @user.login_token)

    mail(
      :to         => @user.email,
      :subject => I18n.t("emailer.confirm.subject")
    )
  end

  def reset_password(user_id)
    @user = User.find(user_id)
    mail(
      :to         => @user.email,
      :subject    => I18n.t("emailer.reset_password.subject")
    )
  end

  def forgot_password(reset_password_id)
    reset_password = <PASSWORD>Password.<PASSWORD>(reset_password_id)
    @user = reset_password.user
    @url  = reset_password_url(reset_password.reset_code)
    mail(
      :to         =>   reset_password.user.email,
      :subject    =>   I18n.t("emailer.forgot_password.subject")
    )
  end

  def project_invitation(invitation_id)
    @invitation = Invitation.find(invitation_id)
    @referral   = @invitation.user
    @project    = @invitation.project
    @recipient  = @invitation.invited_user
    @organization = @project.organization
{'fraction_non_alphanumeric': 0.12824642641433462, 'fraction_numerical': 0.0052345480169116165, 'mean_word_length': 2.5536480686695278, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 27, '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': '7110212', 'n_tokens_mistral': 1614, 'n_tokens_neox': 1551, 'n_words': 300}