summaryrefslogtreecommitdiff
path: root/lib/gitlab/email
diff options
context:
space:
mode:
authorBrett Walker <bwalker@gitlab.com>2018-12-14 12:37:03 -0600
committerBrett Walker <bwalker@gitlab.com>2019-01-03 14:37:35 -0600
commit2e514314031f1722db45e2440eb1c7df105218dd (patch)
tree95f47e8c3233d1680543958e90e2629b32f62b9d /lib/gitlab/email
parent34dd6196e31b248dc614edd531105ee6b6551060 (diff)
downloadgitlab-ce-2e514314031f1722db45e2440eb1c7df105218dd.tar.gz
Use new issue email address format
We now use `-issue` in order to support catch all email addresses
Diffstat (limited to 'lib/gitlab/email')
-rw-r--r--lib/gitlab/email/handler/create_issue_handler.rb29
-rw-r--r--lib/gitlab/email/handler/create_merge_request_handler.rb2
-rw-r--r--lib/gitlab/email/handler/create_note_handler.rb2
-rw-r--r--lib/gitlab/email/handler/unsubscribe_handler.rb8
4 files changed, 31 insertions, 10 deletions
diff --git a/lib/gitlab/email/handler/create_issue_handler.rb b/lib/gitlab/email/handler/create_issue_handler.rb
index 69982efbbe6..7e5fa5f5cd2 100644
--- a/lib/gitlab/email/handler/create_issue_handler.rb
+++ b/lib/gitlab/email/handler/create_issue_handler.rb
@@ -2,21 +2,30 @@
require 'gitlab/email/handler/base_handler'
+# handles issue creation emails with these formats:
+# incoming+gitlab-org-gitlab-ce-20-Author_Token12345678-issue@incoming.gitlab.com
+# incoming+gitlab-org/gitlab-ce+Author_Token12345678@incoming.gitlab.com (legacy)
module Gitlab
module Email
module Handler
class CreateIssueHandler < BaseHandler
include ReplyProcessing
- attr_reader :project_path, :incoming_email_token
+
+ HANDLER_REGEX = /\A.+-(?<project_id>.+)-(?<incoming_email_token>.+)-issue\z/.freeze
+ HANDLER_REGEX_LEGACY = /\A(?<project_path>[^\+]*)\+(?<incoming_email_token>.*)\z/.freeze
def initialize(mail, mail_key)
super(mail, mail_key)
- @project_path, @incoming_email_token =
- mail_key && mail_key.split('+', 2)
+
+ if matched = HANDLER_REGEX.match(mail_key.to_s)
+ @project_id, @incoming_email_token = matched.captures
+ elsif matched = HANDLER_REGEX_LEGACY.match(mail_key.to_s)
+ @project_path, @incoming_email_token = matched.captures
+ end
end
def can_handle?
- !incoming_email_token.nil? && !incoming_email_token.include?("+") && !mail_key.include?(Gitlab::IncomingEmail::UNSUBSCRIBE_SUFFIX)
+ incoming_email_token && (project_id || can_handle_legacy_format?)
end
def execute
@@ -37,11 +46,17 @@ module Gitlab
# rubocop: enable CodeReuse/ActiveRecord
def project
- @project ||= Project.find_by_full_path(project_path)
+ @project ||= if project_id
+ Project.find_by_id(project_id)
+ else
+ Project.find_by_full_path(project_path)
+ end
end
private
+ attr_reader :project_id, :project_path, :incoming_email_token
+
def create_issue
Issues::CreateService.new(
project,
@@ -50,6 +65,10 @@ module Gitlab
description: message_including_reply
).execute
end
+
+ def can_handle_legacy_format?
+ project_path && !incoming_email_token.include?('+') && !mail_key.include?(Gitlab::IncomingEmail::UNSUBSCRIBE_SUFFIX_LEGACY)
+ end
end
end
end
diff --git a/lib/gitlab/email/handler/create_merge_request_handler.rb b/lib/gitlab/email/handler/create_merge_request_handler.rb
index bb62d76a091..d065da70931 100644
--- a/lib/gitlab/email/handler/create_merge_request_handler.rb
+++ b/lib/gitlab/email/handler/create_merge_request_handler.rb
@@ -3,7 +3,7 @@
require 'gitlab/email/handler/base_handler'
require 'gitlab/email/handler/reply_processing'
-# handles merge request creation emails with these forms:
+# handles merge request creation emails with these formats:
# incoming+gitlab-org-gitlab-ce-20-Author_Token12345678-merge-request@incoming.gitlab.com
# incoming+gitlab-org/gitlab-ce+merge-request+Author_Token12345678@incoming.gitlab.com (legacy)
module Gitlab
diff --git a/lib/gitlab/email/handler/create_note_handler.rb b/lib/gitlab/email/handler/create_note_handler.rb
index c7c573595fa..b00af15364d 100644
--- a/lib/gitlab/email/handler/create_note_handler.rb
+++ b/lib/gitlab/email/handler/create_note_handler.rb
@@ -3,6 +3,8 @@
require 'gitlab/email/handler/base_handler'
require 'gitlab/email/handler/reply_processing'
+# handles note/reply creation emails with these formats:
+# incoming+1234567890abcdef1234567890abcdef@incoming.gitlab.com
module Gitlab
module Email
module Handler
diff --git a/lib/gitlab/email/handler/unsubscribe_handler.rb b/lib/gitlab/email/handler/unsubscribe_handler.rb
index 2d679c676a5..0155d7bd113 100644
--- a/lib/gitlab/email/handler/unsubscribe_handler.rb
+++ b/lib/gitlab/email/handler/unsubscribe_handler.rb
@@ -2,7 +2,7 @@
require 'gitlab/email/handler/base_handler'
-# handles unsubscribe emails with these forms:
+# handles unsubscribe emails with these formats:
# incoming+1234567890abcdef1234567890abcdef-unsubscribe@incoming.gitlab.com
# incoming+1234567890abcdef1234567890abcdef+unsubscribe@incoming.gitlab.com (legacy)
module Gitlab
@@ -11,14 +11,14 @@ module Gitlab
class UnsubscribeHandler < BaseHandler
delegate :project, to: :sent_notification, allow_nil: true
- HANDLER_REGEX = /\A(?<replytoken>\w+)#{Gitlab::IncomingEmail::UNSUBSCRIBE_SUFFIX}\z/.freeze
- HANDLER_REGEX_LEGACY = /\A(?<replytoken>\w+)#{Regexp.escape(Gitlab::IncomingEmail::UNSUBSCRIBE_SUFFIX_OLD)}\z/.freeze
+ HANDLER_REGEX = /\A(?<reply_token>\w+)#{Gitlab::IncomingEmail::UNSUBSCRIBE_SUFFIX}\z/.freeze
+ HANDLER_REGEX_LEGACY = /\A(?<reply_token>\w+)#{Regexp.escape(Gitlab::IncomingEmail::UNSUBSCRIBE_SUFFIX_LEGACY)}\z/.freeze
def initialize(mail, mail_key)
super(mail, mail_key)
matched = HANDLER_REGEX.match(mail_key.to_s) || HANDLER_REGEX_LEGACY.match(mail_key.to_s)
- @reply_token = matched[:replytoken] if matched
+ @reply_token = matched[:reply_token] if matched
end
def can_handle?