Project

General

Profile

Patch #38614 » email-handler.patch

Aisha Tammy, 2023-05-26 16:55

View differences:

app/models/mail_handler.rb
44 44
    options[:no_account_notice] = (options[:no_account_notice].to_s == '1')
45 45
    options[:no_notification] = (options[:no_notification].to_s == '1')
46 46
    options[:no_permission_check] = (options[:no_permission_check].to_s == '1')
47
    options[:find_by_subject] = (options[:find_by_subject].to_s == '1')
47 48

  
48 49
    ActiveSupport::Notifications.instrument("receive.action_mailer") do |payload|
49 50
      mail = Mail.new(raw_mail.b)
......
67 68
    %w(project status tracker category priority assigned_to fixed_version).each do |option|
68 69
      options[:issue][option.to_sym] = env[option] if env[option]
69 70
    end
70
    %w(allow_override unknown_user no_permission_check no_account_notice no_notification default_group project_from_subaddress).each do |option|
71
    %w(allow_override unknown_user no_permission_check no_account_notice no_notification default_group project_from_subaddress find_by_subject).each do |option|
71 72
      options[option.to_sym] = env[option] if env[option]
72 73
    end
73 74
    if env['private']
......
145 146

  
146 147
  MESSAGE_ID_RE = %r{^<?redmine\.([a-z0-9_]+)\-(\d+)\.\d+(\.[a-f0-9]+)?@}
147 148
  ISSUE_REPLY_SUBJECT_RE = %r{\[(?:[^\]]*\s+)?#(\d+)\]}
149
  ISSUE_REPLY_SUBJECT_RE2 = %r{^(?:Re:\s*)*(.*)$}i
148 150
  MESSAGE_REPLY_SUBJECT_RE = %r{\[[^\]]*msg(\d+)\]}
149 151

  
150 152
  def dispatch
......
162 164
      receive_issue_reply(m[1].to_i)
163 165
    elsif m = subject.match(MESSAGE_REPLY_SUBJECT_RE)
164 166
      receive_message_reply(m[1].to_i)
167
    elsif handler_options[:find_by_subject]
168
      logger&.info("MailHandler: trying to find issue by subject")
169
      if issue = Issue.find_by(:subject => subject)
170
        logger&.info("MailHandler: found issue #{issue.id} using the full subject")
171
        receive_issue_reply(issue.id)
172
      elsif m = subject.match(ISSUE_REPLY_SUBJECT_RE2)
173
        if issue = Issue.find_by(:subject => m[1])
174
          logger&.info("MailHandler: found issue #{issue.id} using the subject regex")
175
          receive_issue_reply(issue.id)
176
        end
177
      end
165 178
    else
166 179
      dispatch_to_default
167 180
    end
(1-1/3)