<commit_before>class Spree::EmailSenderController < Spree::BaseController
  before_filter :find_object

  def send_mail
    if request.get?
      @mail_to_friend = Spree::MailToFriend.new(:sender_email => current_user.try(:email))
    else
      mail_to_friend
    end
  end

  private
    def mail_to_friend
      @mail_to_friend = Spree::MailToFriend.new(params[:mail_to_friend])
      @mail_to_friend.host = request.env['HTTP_HOST']
      respond_to do |format|
        format.html do
          captcha_passed = !Spree::Captcha::Config[:use_captcha] || verify_recaptcha(:private_key => Spree::Captcha::Config[:private_key])
          if @mail_to_friend.valid? && captcha_passed
            flash[:notice] = I18n.t('email_to_friend.mail_sent_to', :email => @mail_to_friend.recipient_email).html_safe
            flash[:notice] << ActionController::Base.helpers.link_to(I18n.t('email_to_friend.send_to_other'), email_to_friend_path(@object.class.name.split("::").last.downcase, @object)).html_safe

            send_message(@object, @mail_to_friend)

            method_name = "after_delivering_#{@object.class.name.downcase}_mail"<commit_msg>Fix view error when google bot visits<commit_after>class Spree::EmailSenderController < Spree::BaseController
  before_filter :find_object

  def send_mail
    if request.get?
      # google bot seems to get into this error
      # if we are called for a non existing product, @object is nil and it will raise an 
      # error trying to render the view. 
      render :nothing => true, :status => 200, :content_type => 'text/html' and return if @object.nil?
      @mail_to_friend = Spree::MailToFriend.new(:sender_email => current_user.try(:email))
    else
      mail_to_friend
    end
  end

  private
    def mail_to_friend
      @mail_to_friend = Spree::MailToFriend.new(params[:mail_to_friend])
      @mail_to_friend.host = request.env['HTTP_HOST']
      respond_to do |format|
        format.html do
          captcha_passed = !Spree::Captcha::Config[:use_captcha] || verify_recaptcha(:private_key => Spree::Captcha::Config[:private_key])
          if @mail_to_friend.valid? && captcha_passed
            flash[:notice] = I18n.t('email_to_friend.mail_sent_to', :email => @mail_to_friend.recipient_email).html_safe
            flash[:notice] << ActionController::Base.helpers.link_to(I18n.t('email_to_friend.send_to_other'), email_to_friend_path(@object.class.name.split("::").last.downcase, @object)).html_safe

            send_message(@object, @mail_to_friend)

            method_name = "after_delivering_#{@object.class.name.downcase}_mail"
{'fraction_non_alphanumeric': 0.11753371868978806, 'fraction_numerical': 0.004238921001926782, 'mean_word_length': 3.9923076923076923, 'pattern_counts': {'":': 2, '<': 9, '<?xml version=': 0, '>': 12, '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': '971232', 'n_tokens_mistral': 847, 'n_tokens_neox': 824, 'n_words': 141}