<commit_before>module RedmineHelpdesk
  module MailHandlerPatch
    def self.included(base) # :nodoc:
      base.send(:include, InstanceMethods)
      
      base.class_eval do
        alias_method_chain :dispatch_to_default, :helpdesk
      end
    end
    
    module InstanceMethods
      private
      # Overrides the dispatch_to_default method
      def dispatch_to_default_with_helpdesk
        issue = receive_issue
        begin
          # add owner-email only if the email is comming from an AnonymousUser
          if issue.author.class == AnonymousUser
            sender_email = @email.from.to_a.first.to_s.strip
            custom_field = CustomField.find_by_name('owner-email')
            custom_value = CustomValue.find(
              :first,
              :conditions => ["customized_id = ? AND custom_field_id = ?", issue.id, custom_field.id]
            )
            custom_value.value = sender_email
            custom_value.save(false) # skip validation!
            # regular email sending to known users is done
            # on the first issue.save. So we need to send
            # the notification email to the supportclient
            # on our own.
            Mailer.deliver_email_to_supportclient(issue, sender_email)
          end
        rescue Exception => e
          msg = ("The following error occured while sending email notification: Failed to set owner-email \"#{e.message}\". Hint: is the owner-email part of the project?")
          if logger && logger.error
            logger.error(msg)
          else
            $stderr.puts(msg)
          end
        end
        issue
      end
      
    end # module InstanceMethods
  end # module MailHandlerPatch
end # module RedmineHelpdesk

# Add module to MailHandler class
MailHandler.send(:include, RedmineHelpdesk::MailHandlerPatch)
<commit_msg>let method_missing do its work<commit_after>module RedmineHelpdesk
  module MailHandlerPatch
    def self.included(base) # :nodoc:
      base.send(:include, InstanceMethods)
      
      base.class_eval do
        alias_method_chain :dispatch_to_default, :helpdesk
      end
    end
    
    module InstanceMethods
      private
      # Overrides the dispatch_to_default method
      def dispatch_to_default_with_helpdesk
        issue = receive_issue
        # add owner-email only if the email is comming from an AnonymousUser
        if issue.author.class == AnonymousUser
          sender_email = @email.from.to_a.first.to_s.strip
          custom_field = CustomField.find_by_name('owner-email')
          custom_value = CustomValue.find(
            :first,
            :conditions => ["customized_id = ? AND custom_field_id = ?", issue.id, custom_field.id]
          )
          custom_value.value = sender_email
          custom_value.save(false) # skip validation!
          # regular email sending to known users is done
          # on the first issue.save. So we need to send
          # the notification email to the supportclient
          # on our own.
          Mailer.deliver_email_to_supportclient(issue, sender_email)
        end
        issue
      end
      
    end # module InstanceMethods
  end # module MailHandlerPatch
end # module RedmineHelpdesk

# Add module to MailHandler class
MailHandler.send(:include, RedmineHelpdesk::MailHandlerPatch)

{'fraction_non_alphanumeric': 0.06382335148215366, 'fraction_numerical': 0.0, 'mean_word_length': 2.2905472636815922, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 6, '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': '6507238', 'n_tokens_mistral': 888, 'n_tokens_neox': 890, 'n_words': 250}