From 176fa21cb75f404b401e021f0cdcc6a138c207eb Mon Sep 17 00:00:00 2001
From: Lin Jen-Shin <godfat@godfat.org>
Date: Mon, 20 Jun 2016 19:15:54 +0800
Subject: [PATCH] raise UnknownIncomingEmail when there's no mail_key:

So that we don't have to pretend that CreateNoteHandler
could handle a nil mail_key. Also, since NilClass#=~ would
just return nil for any regular expression, we could just
match it without checking nilness.

Feedback:
https://gitlab.com/gitlab-org/gitlab-ce/merge_requests/3363#note_12566407
---
 lib/gitlab/email/handler/create_note_handler.rb           | 3 +--
 spec/lib/gitlab/email/handler/create_note_handler_spec.rb | 4 ++--
 2 files changed, 3 insertions(+), 4 deletions(-)

diff --git a/lib/gitlab/email/handler/create_note_handler.rb b/lib/gitlab/email/handler/create_note_handler.rb
index 69646651223..06dae31cc27 100644
--- a/lib/gitlab/email/handler/create_note_handler.rb
+++ b/lib/gitlab/email/handler/create_note_handler.rb
@@ -6,8 +6,7 @@ module Gitlab
     module Handler
       class CreateNoteHandler < BaseHandler
         def can_handle?
-          # We want to raise SentNotificationNotFoundError for missing key
-          !!(mail_key.nil? || mail_key =~ /\A\w+\z/)
+          mail_key =~ /\A\w+\z/
         end
 
         def execute
diff --git a/spec/lib/gitlab/email/handler/create_note_handler_spec.rb b/spec/lib/gitlab/email/handler/create_note_handler_spec.rb
index 9b7fb6a1a4b..a2119b0dadf 100644
--- a/spec/lib/gitlab/email/handler/create_note_handler_spec.rb
+++ b/spec/lib/gitlab/email/handler/create_note_handler_spec.rb
@@ -20,8 +20,8 @@ describe Gitlab::Email::Handler::CreateNoteHandler, lib: true do
   context "when the recipient address doesn't include a mail key" do
     let(:email_raw) { fixture_file('emails/valid_reply.eml').gsub(mail_key, "") }
 
-    it "raises a SentNotificationNotFoundError" do
-      expect { receiver.execute }.to raise_error(Gitlab::Email::SentNotificationNotFoundError)
+    it "raises a UnknownIncomingEmail" do
+      expect { receiver.execute }.to raise_error(Gitlab::Email::UnknownIncomingEmail)
     end
   end
 
-- 
GitLab