Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'lib/gitlab/email/handler/unsubscribe_handler.rb')
-rw-r--r--lib/gitlab/email/handler/unsubscribe_handler.rb29
1 files changed, 15 insertions, 14 deletions
diff --git a/lib/gitlab/email/handler/unsubscribe_handler.rb b/lib/gitlab/email/handler/unsubscribe_handler.rb
index 77b6c9177de..2d679c676a5 100644
--- a/lib/gitlab/email/handler/unsubscribe_handler.rb
+++ b/lib/gitlab/email/handler/unsubscribe_handler.rb
@@ -2,14 +2,27 @@
require 'gitlab/email/handler/base_handler'
+# handles unsubscribe emails with these forms:
+# incoming+1234567890abcdef1234567890abcdef-unsubscribe@incoming.gitlab.com
+# incoming+1234567890abcdef1234567890abcdef+unsubscribe@incoming.gitlab.com (legacy)
module Gitlab
module Email
module Handler
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
+
+ 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
+ end
+
def can_handle?
- mail_key =~ /\A\w+#{Regexp.escape(suffix)}\z/
+ @reply_token.present?
end
def execute
@@ -25,19 +38,7 @@ module Gitlab
private
def sent_notification
- @sent_notification ||= SentNotification.for(reply_key)
- end
-
- def suffix
- @suffix ||= if mail_key&.end_with?(Gitlab::IncomingEmail::UNSUBSCRIBE_SUFFIX)
- Gitlab::IncomingEmail::UNSUBSCRIBE_SUFFIX
- else
- Gitlab::IncomingEmail::UNSUBSCRIBE_SUFFIX_OLD
- end
- end
-
- def reply_key
- mail_key.sub(suffix, '')
+ @sent_notification ||= SentNotification.for(@reply_token)
end
end
end