Commit db0ffef8 authored by http://jneen.net/'s avatar http://jneen.net/ Committed by Felipe Artur

add an incoming email handler for service desk

parent 15464516
......@@ -2,10 +2,13 @@ require 'gitlab/email/handler/create_note_handler'
require 'gitlab/email/handler/create_issue_handler'
require 'gitlab/email/handler/unsubscribe_handler'
require 'gitlab/email/handler/ee/service_desk_handler'
module Gitlab
module Email
module Handler
HANDLERS = [
EE::ServiceDeskHandler,
UnsubscribeHandler,
CreateNoteHandler,
CreateIssueHandler,
......
module Gitlab
module Email
module Handler
module EE
class ServiceDeskHandler < BaseHandler
include ReplyProcessing
def can_handle?
Gitlab::EE::ServiceDesk.enabled? && service_desk_key.present?
end
def execute
raise EmailUnparsableError if from_address.blank?
create_issue!
send_thank_you_email!
end
private
def service_desk_key
@service_desk_key ||= (mail_key =~ /\Aservice-desk[+](\w+)\z/ and $1)
end
def project
return @project if instance_variable_defined?(:@project)
@project = Project.where(
service_desk_enabled: true,
service_desk_mail_key: service_desk_key
).first
end
def create_issue!
# NB: the support bot is specifically forbidden
# from mentioning any entities, or from using
# slash commands.
@issue = Issues::CreateService.new(
project,
User.support_bot,
title: mail.subject,
description: message,
confidential: true,
).execute
@issue.update_attributes(
service_desk_reply_to: from_address
)
end
def send_thank_you_email!
Notify.thank_you_email(@issue.id)
end
def from_address
(mail.reply_to || []).first || mail.sender || mail.from.first
end
end
end
end
end
end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment