You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

mail_handler.rb 21KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613
  1. # frozen_string_literal: true
  2. # Redmine - project management software
  3. # Copyright (C) 2006-2019 Jean-Philippe Lang
  4. #
  5. # This program is free software; you can redistribute it and/or
  6. # modify it under the terms of the GNU General Public License
  7. # as published by the Free Software Foundation; either version 2
  8. # of the License, or (at your option) any later version.
  9. #
  10. # This program is distributed in the hope that it will be useful,
  11. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. # GNU General Public License for more details.
  14. #
  15. # You should have received a copy of the GNU General Public License
  16. # along with this program; if not, write to the Free Software
  17. # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  18. class MailHandler < ActionMailer::Base
  19. include ActionView::Helpers::SanitizeHelper
  20. include Redmine::I18n
  21. class UnauthorizedAction < StandardError; end
  22. class MissingInformation < StandardError; end
  23. attr_reader :email, :user, :handler_options
  24. def self.receive(raw_mail, options={})
  25. options = options.deep_dup
  26. options[:issue] ||= {}
  27. options[:allow_override] ||= []
  28. if options[:allow_override].is_a?(String)
  29. options[:allow_override] = options[:allow_override].split(',')
  30. end
  31. options[:allow_override].map! {|s| s.strip.downcase.gsub(/\s+/, '_')}
  32. # Project needs to be overridable if not specified
  33. options[:allow_override] << 'project' unless options[:issue].has_key?(:project)
  34. options[:no_account_notice] = (options[:no_account_notice].to_s == '1')
  35. options[:no_notification] = (options[:no_notification].to_s == '1')
  36. options[:no_permission_check] = (options[:no_permission_check].to_s == '1')
  37. ActiveSupport::Notifications.instrument("receive.action_mailer") do |payload|
  38. mail = Mail.new(raw_mail.b)
  39. set_payload_for_mail(payload, mail)
  40. new.receive(mail, options)
  41. end
  42. end
  43. # Receives an email and rescues any exception
  44. def self.safe_receive(*args)
  45. receive(*args)
  46. rescue => e
  47. Rails.logger.error "MailHandler: an unexpected error occurred when receiving email: #{e.message}"
  48. return false
  49. end
  50. # Extracts MailHandler options from environment variables
  51. # Use when receiving emails with rake tasks
  52. def self.extract_options_from_env(env)
  53. options = {:issue => {}}
  54. %w(project status tracker category priority assigned_to fixed_version).each do |option|
  55. options[:issue][option.to_sym] = env[option] if env[option]
  56. end
  57. %w(allow_override unknown_user no_permission_check no_account_notice no_notification default_group project_from_subaddress).each do |option|
  58. options[option.to_sym] = env[option] if env[option]
  59. end
  60. if env['private']
  61. options[:issue][:is_private] = '1'
  62. end
  63. options
  64. end
  65. def logger
  66. Rails.logger
  67. end
  68. cattr_accessor :ignored_emails_headers
  69. self.ignored_emails_headers = {
  70. 'Auto-Submitted' => /\Aauto-(replied|generated)/,
  71. 'X-Autoreply' => 'yes'
  72. }
  73. # Processes incoming emails
  74. # Returns the created object (eg. an issue, a message) or false
  75. def receive(email, options={})
  76. @email = email
  77. @handler_options = options
  78. sender_email = email.from.to_a.first.to_s.strip
  79. # Ignore emails received from the application emission address to avoid hell cycles
  80. emission_address = Setting.mail_from.to_s.gsub(/(?:.*<|>.*|\(.*\))/, '').strip
  81. if sender_email.casecmp(emission_address) == 0
  82. logger&.info "MailHandler: ignoring email from Redmine emission address [#{sender_email}]"
  83. return false
  84. end
  85. # Ignore auto generated emails
  86. self.class.ignored_emails_headers.each do |key, ignored_value|
  87. value = email.header[key]
  88. if value
  89. value = value.to_s.downcase
  90. if (ignored_value.is_a?(Regexp) && ignored_value.match?(value)) || value == ignored_value
  91. logger&.info "MailHandler: ignoring email with #{key}:#{value} header"
  92. return false
  93. end
  94. end
  95. end
  96. @user = User.find_by_mail(sender_email) if sender_email.present?
  97. if @user && !@user.active?
  98. logger&.info "MailHandler: ignoring email from non-active user [#{@user.login}]"
  99. return false
  100. end
  101. if @user.nil?
  102. # Email was submitted by an unknown user
  103. case handler_options[:unknown_user]
  104. when 'accept'
  105. @user = User.anonymous
  106. when 'create'
  107. @user = create_user_from_email
  108. if @user
  109. logger&.info "MailHandler: [#{@user.login}] account created"
  110. add_user_to_group(handler_options[:default_group])
  111. unless handler_options[:no_account_notice]
  112. ::Mailer.deliver_account_information(@user, @user.password)
  113. end
  114. else
  115. logger&.error "MailHandler: could not create account for [#{sender_email}]"
  116. return false
  117. end
  118. else
  119. # Default behaviour, emails from unknown users are ignored
  120. logger&.info "MailHandler: ignoring email from unknown user [#{sender_email}]"
  121. return false
  122. end
  123. end
  124. User.current = @user
  125. dispatch
  126. end
  127. private
  128. MESSAGE_ID_RE = %r{^<?redmine\.([a-z0-9_]+)\-(\d+)\.\d+(\.[a-f0-9]+)?@}
  129. ISSUE_REPLY_SUBJECT_RE = %r{\[(?:[^\]]*\s+)?#(\d+)\]}
  130. MESSAGE_REPLY_SUBJECT_RE = %r{\[[^\]]*msg(\d+)\]}
  131. def dispatch
  132. headers = [email.in_reply_to, email.references].flatten.compact
  133. subject = email.subject.to_s
  134. if headers.detect {|h| h.to_s =~ MESSAGE_ID_RE}
  135. klass, object_id = $1, $2.to_i
  136. method_name = "receive_#{klass}_reply"
  137. if self.class.private_instance_methods.collect(&:to_s).include?(method_name)
  138. send method_name, object_id
  139. else
  140. # ignoring it
  141. end
  142. elsif m = subject.match(ISSUE_REPLY_SUBJECT_RE)
  143. receive_issue_reply(m[1].to_i)
  144. elsif m = subject.match(MESSAGE_REPLY_SUBJECT_RE)
  145. receive_message_reply(m[1].to_i)
  146. else
  147. dispatch_to_default
  148. end
  149. rescue ActiveRecord::RecordInvalid => e
  150. # TODO: send a email to the user
  151. logger&.error "MailHandler: #{e.message}"
  152. false
  153. rescue MissingInformation => e
  154. logger&.error "MailHandler: missing information from #{user}: #{e.message}"
  155. false
  156. rescue UnauthorizedAction => e
  157. logger&.error "MailHandler: unauthorized attempt from #{user}"
  158. false
  159. end
  160. def dispatch_to_default
  161. receive_issue
  162. end
  163. # Creates a new issue
  164. def receive_issue
  165. project = target_project
  166. # check permission
  167. unless handler_options[:no_permission_check]
  168. raise UnauthorizedAction unless user.allowed_to?(:add_issues, project)
  169. end
  170. issue = Issue.new(:author => user, :project => project)
  171. attributes = issue_attributes_from_keywords(issue)
  172. if handler_options[:no_permission_check]
  173. issue.tracker_id = attributes['tracker_id']
  174. if project
  175. issue.tracker_id ||= project.trackers.first.try(:id)
  176. end
  177. end
  178. issue.safe_attributes = attributes
  179. issue.safe_attributes = {'custom_field_values' => custom_field_values_from_keywords(issue)}
  180. issue.subject = cleaned_up_subject
  181. if issue.subject.blank?
  182. issue.subject = '(no subject)'
  183. end
  184. issue.description = cleaned_up_text_body
  185. issue.start_date ||= User.current.today if Setting.default_issue_start_date_to_creation_date?
  186. if handler_options[:issue][:is_private] == '1'
  187. issue.is_private = true
  188. end
  189. # add To and Cc as watchers before saving so the watchers can reply to Redmine
  190. add_watchers(issue)
  191. issue.save!
  192. add_attachments(issue)
  193. logger&.info "MailHandler: issue ##{issue.id} created by #{user}"
  194. issue
  195. end
  196. # Adds a note to an existing issue
  197. def receive_issue_reply(issue_id, from_journal=nil)
  198. issue = Issue.find_by_id(issue_id)
  199. return unless issue
  200. # check permission
  201. unless handler_options[:no_permission_check]
  202. unless user.allowed_to?(:add_issue_notes, issue.project) ||
  203. user.allowed_to?(:edit_issues, issue.project)
  204. raise UnauthorizedAction
  205. end
  206. end
  207. # ignore CLI-supplied defaults for new issues
  208. handler_options[:issue] = {}
  209. journal = issue.init_journal(user)
  210. if from_journal && from_journal.private_notes?
  211. # If the received email was a reply to a private note, make the added note private
  212. issue.private_notes = true
  213. end
  214. issue.safe_attributes = issue_attributes_from_keywords(issue)
  215. issue.safe_attributes = {'custom_field_values' => custom_field_values_from_keywords(issue)}
  216. journal.notes = cleaned_up_text_body
  217. # add To and Cc as watchers before saving so the watchers can reply to Redmine
  218. add_watchers(issue)
  219. issue.save!
  220. add_attachments(issue)
  221. logger&.info "MailHandler: issue ##{issue.id} updated by #{user}"
  222. journal
  223. end
  224. # Reply will be added to the issue
  225. def receive_journal_reply(journal_id)
  226. journal = Journal.find_by_id(journal_id)
  227. if journal && journal.journalized_type == 'Issue'
  228. receive_issue_reply(journal.journalized_id, journal)
  229. end
  230. end
  231. # Receives a reply to a forum message
  232. def receive_message_reply(message_id)
  233. message = Message.find_by_id(message_id)
  234. if message
  235. message = message.root
  236. unless handler_options[:no_permission_check]
  237. raise UnauthorizedAction unless user.allowed_to?(:add_messages, message.project)
  238. end
  239. if !message.locked?
  240. reply = Message.new(:subject => cleaned_up_subject.gsub(%r{^.*msg\d+\]}, '').strip,
  241. :content => cleaned_up_text_body)
  242. reply.author = user
  243. reply.board = message.board
  244. message.children << reply
  245. add_attachments(reply)
  246. reply
  247. else
  248. logger&.info "MailHandler: ignoring reply from [#{sender_email}] to a locked topic"
  249. end
  250. end
  251. end
  252. def add_attachments(obj)
  253. if email.attachments && email.attachments.any?
  254. email.attachments.each do |attachment|
  255. next unless accept_attachment?(attachment)
  256. next unless attachment.body.decoded.size > 0
  257. obj.attachments << Attachment.create(:container => obj,
  258. :file => attachment.body.decoded,
  259. :filename => attachment.filename,
  260. :author => user,
  261. :content_type => attachment.mime_type)
  262. end
  263. end
  264. end
  265. # Returns false if the +attachment+ of the incoming email should be ignored
  266. def accept_attachment?(attachment)
  267. @excluded ||= Setting.mail_handler_excluded_filenames.to_s.split(',').map(&:strip).reject(&:blank?)
  268. @excluded.each do |pattern|
  269. if Setting.mail_handler_enable_regex_excluded_filenames?
  270. regexp = %r{\A#{pattern}\z}i
  271. else
  272. regexp = %r{\A#{Regexp.escape(pattern).gsub("\\*", ".*")}\z}i
  273. end
  274. if regexp.match?(attachment.filename.to_s)
  275. logger.info "MailHandler: ignoring attachment #{attachment.filename} matching #{pattern}"
  276. return false
  277. end
  278. end
  279. true
  280. end
  281. # Adds To and Cc as watchers of the given object if the sender has the
  282. # appropriate permission
  283. def add_watchers(obj)
  284. if handler_options[:no_permission_check] || user.allowed_to?("add_#{obj.class.name.underscore}_watchers".to_sym, obj.project)
  285. addresses = [email.to, email.cc].flatten.compact.uniq.collect {|a| a.strip.downcase}
  286. unless addresses.empty?
  287. users = User.active.having_mail(addresses).to_a
  288. users -= obj.watcher_users
  289. users.each do |u|
  290. obj.add_watcher(u)
  291. end
  292. end
  293. end
  294. end
  295. def get_keyword(attr, options={})
  296. @keywords ||= {}
  297. if @keywords.has_key?(attr)
  298. @keywords[attr]
  299. else
  300. @keywords[attr] = begin
  301. override = options.key?(:override) ?
  302. options[:override] :
  303. (handler_options[:allow_override] & [attr.to_s.downcase.gsub(/\s+/, '_'), 'all']).present?
  304. if override && (v = extract_keyword!(cleaned_up_text_body, attr, options[:format]))
  305. v
  306. elsif !handler_options[:issue][attr].blank?
  307. handler_options[:issue][attr]
  308. end
  309. end
  310. end
  311. end
  312. # Destructively extracts the value for +attr+ in +text+
  313. # Returns nil if no matching keyword found
  314. def extract_keyword!(text, attr, format=nil)
  315. keys = [attr.to_s.humanize]
  316. if attr.is_a?(Symbol)
  317. if user && user.language.present?
  318. keys << l("field_#{attr}", :default => '', :locale => user.language)
  319. end
  320. if Setting.default_language.present?
  321. keys << l("field_#{attr}", :default => '', :locale => Setting.default_language)
  322. end
  323. end
  324. keys.reject! {|k| k.blank?}
  325. keys.collect! {|k| Regexp.escape(k)}
  326. format ||= '.+'
  327. keyword = nil
  328. regexp = /^(#{keys.join('|')})[ \t]*:[ \t]*(#{format})\s*$/i
  329. if m = text.match(regexp)
  330. keyword = m[2].strip
  331. text.sub!(regexp, '')
  332. end
  333. keyword
  334. end
  335. def get_project_from_receiver_addresses
  336. local, domain = handler_options[:project_from_subaddress].to_s.split("@")
  337. return nil unless local && domain
  338. local = Regexp.escape(local)
  339. [:to, :cc, :bcc].each do |field|
  340. header = @email[field]
  341. next if header.blank? || header.field.blank? || !header.field.respond_to?(:addrs)
  342. header.field.addrs.each do |addr|
  343. if addr.domain.to_s.casecmp(domain)==0 && addr.local.to_s =~ /\A#{local}\+([^+]+)\z/
  344. if project = Project.find_by_identifier($1)
  345. return project
  346. end
  347. end
  348. end
  349. end
  350. nil
  351. end
  352. def target_project
  353. # TODO: other ways to specify project:
  354. # * parse the email To field
  355. # * specific project (eg. Setting.mail_handler_target_project)
  356. target = get_project_from_receiver_addresses
  357. target ||= Project.find_by_identifier(get_keyword(:project))
  358. if target.nil?
  359. # Invalid project keyword, use the project specified as the default one
  360. default_project = handler_options[:issue][:project]
  361. if default_project.present?
  362. target = Project.find_by_identifier(default_project)
  363. end
  364. end
  365. raise MissingInformation.new('Unable to determine target project') if target.nil?
  366. target
  367. end
  368. # Returns a Hash of issue attributes extracted from keywords in the email body
  369. def issue_attributes_from_keywords(issue)
  370. attrs = {
  371. 'tracker_id' => (k = get_keyword(:tracker)) && issue.project.trackers.named(k).first.try(:id),
  372. 'status_id' => (k = get_keyword(:status)) && IssueStatus.named(k).first.try(:id),
  373. 'priority_id' => (k = get_keyword(:priority)) && IssuePriority.named(k).first.try(:id),
  374. 'category_id' => (k = get_keyword(:category)) && issue.project.issue_categories.named(k).first.try(:id),
  375. 'assigned_to_id' => (k = get_keyword(:assigned_to)) && find_assignee_from_keyword(k, issue).try(:id),
  376. 'fixed_version_id' => (k = get_keyword(:fixed_version)) && issue.project.shared_versions.named(k).first.try(:id),
  377. 'start_date' => get_keyword(:start_date, :format => '\d{4}-\d{2}-\d{2}'),
  378. 'due_date' => get_keyword(:due_date, :format => '\d{4}-\d{2}-\d{2}'),
  379. 'estimated_hours' => get_keyword(:estimated_hours),
  380. 'done_ratio' => get_keyword(:done_ratio, :format => '(\d|10)?0'),
  381. 'is_private' => get_keyword_bool(:is_private),
  382. 'parent_issue_id' => get_keyword(:parent_issue)
  383. }.delete_if {|k, v| v.blank? }
  384. attrs
  385. end
  386. def get_keyword_bool(attr)
  387. true_values = ["1"]
  388. false_values = ["0"]
  389. locales = [Setting.default_language]
  390. if user
  391. locales << user.language
  392. end
  393. locales.select(&:present?).each do |locale|
  394. true_values << l("general_text_yes", :default => '', :locale => locale)
  395. true_values << l("general_text_Yes", :default => '', :locale => locale)
  396. false_values << l("general_text_no", :default => '', :locale => locale)
  397. false_values << l("general_text_No", :default => '', :locale => locale)
  398. end
  399. values = (true_values + false_values).select(&:present?)
  400. format = Regexp.union values
  401. if value = get_keyword(attr, :format => format)
  402. if true_values.include?(value)
  403. return true
  404. elsif false_values.include?(value)
  405. return false
  406. end
  407. end
  408. nil
  409. end
  410. # Returns a Hash of issue custom field values extracted from keywords in the email body
  411. def custom_field_values_from_keywords(customized)
  412. customized.custom_field_values.inject({}) do |h, v|
  413. if keyword = get_keyword(v.custom_field.name)
  414. h[v.custom_field.id.to_s] = v.custom_field.value_from_keyword(keyword, customized)
  415. end
  416. h
  417. end
  418. end
  419. # Returns the text content of the email.
  420. # If the value of Setting.mail_handler_preferred_body_part is 'html',
  421. # it returns text converted from the text/html part of the email.
  422. # Otherwise, it returns text/plain part.
  423. def plain_text_body
  424. return @plain_text_body unless @plain_text_body.nil?
  425. parse_order =
  426. if Setting.mail_handler_preferred_body_part == 'html'
  427. ['text/html', 'text/plain']
  428. else
  429. ['text/plain', 'text/html']
  430. end
  431. parse_order.each do |mime_type|
  432. @plain_text_body ||= email_parts_to_text(email.all_parts.select {|p| p.mime_type == mime_type}).presence
  433. return @plain_text_body unless @plain_text_body.nil?
  434. end
  435. # If there is still no body found, and there are no mime-parts defined,
  436. # we use the whole raw mail body
  437. @plain_text_body ||= email_parts_to_text([email]).presence if email.all_parts.empty?
  438. # As a fallback we return an empty plain text body (e.g. if we have only
  439. # empty text parts but a non-text attachment)
  440. @plain_text_body ||= ""
  441. end
  442. def email_parts_to_text(parts)
  443. parts.reject! do |part|
  444. part.attachment?
  445. end
  446. parts.map do |p|
  447. body_charset = Mail::RubyVer.respond_to?(:pick_encoding) ?
  448. Mail::RubyVer.pick_encoding(p.charset).to_s : p.charset
  449. body = Redmine::CodesetUtil.to_utf8(p.body.decoded, body_charset)
  450. # convert html parts to text
  451. p.mime_type == 'text/html' ? self.class.html_body_to_text(body) : self.class.plain_text_body_to_text(body)
  452. end.join("\r\n")
  453. end
  454. def cleaned_up_text_body
  455. @cleaned_up_text_body ||= cleanup_body(plain_text_body)
  456. end
  457. def cleaned_up_subject
  458. subject = email.subject.to_s
  459. subject.strip[0,255]
  460. end
  461. # Converts a HTML email body to text
  462. def self.html_body_to_text(html)
  463. Redmine::WikiFormatting.html_parser.to_text(html)
  464. end
  465. # Converts a plain/text email body to text
  466. def self.plain_text_body_to_text(text)
  467. # Removes leading spaces that would cause the line to be rendered as
  468. # preformatted text with textile
  469. text.gsub(/^ +(?![*#])/, '')
  470. end
  471. def self.assign_string_attribute_with_limit(object, attribute, value, limit=nil)
  472. limit ||= object.class.columns_hash[attribute.to_s].limit || 255
  473. value = value.to_s.slice(0, limit)
  474. object.send("#{attribute}=", value)
  475. end
  476. # Returns a User from an email address and a full name
  477. def self.new_user_from_attributes(email_address, fullname=nil)
  478. user = User.new
  479. # Truncating the email address would result in an invalid format
  480. user.mail = email_address
  481. assign_string_attribute_with_limit(user, 'login', email_address, User::LOGIN_LENGTH_LIMIT)
  482. names = fullname.blank? ? email_address.gsub(/@.*$/, '').split('.') : fullname.split
  483. assign_string_attribute_with_limit(user, 'firstname', names.shift, 30)
  484. assign_string_attribute_with_limit(user, 'lastname', names.join(' '), 30)
  485. user.lastname = '-' if user.lastname.blank?
  486. user.language = Setting.default_language
  487. user.generate_password = true
  488. user.mail_notification = 'only_my_events'
  489. unless user.valid?
  490. user.login = "user#{Redmine::Utils.random_hex(6)}" unless user.errors[:login].blank?
  491. user.firstname = "-" unless user.errors[:firstname].blank?
  492. (puts user.errors[:lastname];user.lastname = "-") unless user.errors[:lastname].blank?
  493. end
  494. user
  495. end
  496. # Creates a User for the +email+ sender
  497. # Returns the user or nil if it could not be created
  498. def create_user_from_email
  499. if from_addr = email.header['from'].try(:addrs).to_a.first
  500. addr = from_addr.address
  501. name = from_addr.display_name || from_addr.comments.to_a.first
  502. user = self.class.new_user_from_attributes(addr, name)
  503. if handler_options[:no_notification]
  504. user.mail_notification = 'none'
  505. end
  506. if user.save
  507. user
  508. else
  509. logger&.error "MailHandler: failed to create User: #{user.errors.full_messages}"
  510. nil
  511. end
  512. else
  513. logger&.error "MailHandler: failed to create User: no FROM address found"
  514. nil
  515. end
  516. end
  517. # Adds the newly created user to default group
  518. def add_user_to_group(default_group)
  519. if default_group.present?
  520. default_group.split(',').each do |group_name|
  521. if group = Group.named(group_name).first
  522. group.users << @user
  523. elsif logger
  524. logger.warn "MailHandler: could not add user to [#{group_name}], group not found"
  525. end
  526. end
  527. end
  528. end
  529. # Removes the email body of text after the truncation configurations.
  530. def cleanup_body(body)
  531. delimiters = Setting.mail_handler_body_delimiters.to_s.split(/[\r\n]+/).reject(&:blank?)
  532. if Setting.mail_handler_enable_regex_delimiters?
  533. begin
  534. delimiters = delimiters.map {|s| Regexp.new(s)}
  535. rescue RegexpError => e
  536. logger&.error "MailHandler: invalid regexp delimiter found in mail_handler_body_delimiters setting (#{e.message})"
  537. end
  538. end
  539. unless delimiters.empty?
  540. regex = Regexp.new("^[> ]*(#{ Regexp.union(delimiters) })[[:blank:]]*[\r\n].*", Regexp::MULTILINE)
  541. body = body.gsub(regex, '')
  542. end
  543. body.strip
  544. end
  545. def find_assignee_from_keyword(keyword, issue)
  546. Principal.detect_by_keyword(issue.assignable_users, keyword)
  547. end
  548. end