diff options
author | Lin Jen-Shin <godfat@godfat.org> | 2017-01-17 14:50:49 -0500 |
---|---|---|
committer | Lin Jen-Shin <godfat@godfat.org> | 2017-01-20 20:19:22 +0800 |
commit | d15b7db1216f220b9f5af7e777cf04712483cbdf (patch) | |
tree | 697452bdb1490c95596a9b2419e62e2e2af7d28e /lib | |
parent | 491f1375fc055805c623a3079a383de988689f3d (diff) | |
download | gitlab-ce-d15b7db1216f220b9f5af7e777cf04712483cbdf.tar.gz |
Fix References header parser for Microsoft Exchange
Microsoft Exchange would append a comma and another
message id into the References header, therefore we'll
need to fallback and parse the header by ourselves.
Closes #26567
Diffstat (limited to 'lib')
-rw-r--r-- | lib/gitlab/email/receiver.rb | 17 | ||||
-rw-r--r-- | lib/gitlab/incoming_email.rb | 9 |
2 files changed, 20 insertions, 6 deletions
diff --git a/lib/gitlab/email/receiver.rb b/lib/gitlab/email/receiver.rb index a40c44eb1bc..df9d1cae8da 100644 --- a/lib/gitlab/email/receiver.rb +++ b/lib/gitlab/email/receiver.rb @@ -35,6 +35,8 @@ module Gitlab handler.execute end + private + def build_mail Mail::Message.new(@raw) rescue Encoding::UndefinedConversionError, @@ -54,7 +56,20 @@ module Gitlab end def key_from_additional_headers(mail) - Array(mail.references).find do |mail_id| + find_key_from_references(ensure_references_array(mail.references)) + end + + def ensure_references_array(references) + case references + when Array + references + when String # Handle emails from Microsoft exchange which uses commas + Gitlab::IncomingEmail.scan_fallback_references(references) + end + end + + def find_key_from_references(references) + references.find do |mail_id| key = Gitlab::IncomingEmail.key_from_fallback_message_id(mail_id) break key if key end diff --git a/lib/gitlab/incoming_email.rb b/lib/gitlab/incoming_email.rb index 801dfde9a36..9ae3a2c1214 100644 --- a/lib/gitlab/incoming_email.rb +++ b/lib/gitlab/incoming_email.rb @@ -3,8 +3,6 @@ module Gitlab WILDCARD_PLACEHOLDER = '%{key}'.freeze class << self - FALLBACK_MESSAGE_ID_REGEX = /\Areply\-(.+)@#{Gitlab.config.gitlab.host}\Z/.freeze - def enabled? config.enabled && config.address end @@ -32,10 +30,11 @@ module Gitlab end def key_from_fallback_message_id(mail_id) - match = mail_id.match(FALLBACK_MESSAGE_ID_REGEX) - return unless match + mail_id[/\Areply\-(.+)@#{Gitlab.config.gitlab.host}\z/, 1] + end - match[1] + def scan_fallback_references(references) + references.scan(/(?!<)[^<>]+(?=>)/.freeze) end def config |