Only set @raw for receiver, and handle the rest in execute
This commit is contained in:
parent
32eae15f2f
commit
ee548b6ed0
|
@ -19,15 +19,16 @@ module Gitlab
|
||||||
class InvalidIssueError < ProcessingError; end
|
class InvalidIssueError < ProcessingError; end
|
||||||
|
|
||||||
class Receiver
|
class Receiver
|
||||||
attr_reader :mail
|
|
||||||
|
|
||||||
def initialize(raw)
|
def initialize(raw)
|
||||||
raise EmptyEmailError if raw.blank?
|
@raw = raw
|
||||||
@mail = build_mail(raw)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def execute
|
def execute
|
||||||
mail_key = extract_mail_key
|
raise EmptyEmailError if @raw.blank?
|
||||||
|
|
||||||
|
mail = build_mail
|
||||||
|
mail_key = extract_mail_key(mail)
|
||||||
|
|
||||||
raise SentNotificationNotFoundError unless mail_key
|
raise SentNotificationNotFoundError unless mail_key
|
||||||
|
|
||||||
if handler = find_handler(mail, mail_key)
|
if handler = find_handler(mail, mail_key)
|
||||||
|
@ -40,25 +41,25 @@ module Gitlab
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def build_mail(raw)
|
def build_mail
|
||||||
Mail::Message.new(raw)
|
Mail::Message.new(@raw)
|
||||||
rescue Encoding::UndefinedConversionError,
|
rescue Encoding::UndefinedConversionError,
|
||||||
Encoding::InvalidByteSequenceError => e
|
Encoding::InvalidByteSequenceError => e
|
||||||
raise EmailUnparsableError, e
|
raise EmailUnparsableError, e
|
||||||
end
|
end
|
||||||
|
|
||||||
def extract_mail_key
|
def extract_mail_key(mail)
|
||||||
key_from_to_header || key_from_additional_headers
|
key_from_to_header(mail) || key_from_additional_headers(mail)
|
||||||
end
|
end
|
||||||
|
|
||||||
def key_from_to_header
|
def key_from_to_header(mail)
|
||||||
mail.to.find do |address|
|
mail.to.find do |address|
|
||||||
key = Gitlab::IncomingEmail.key_from_address(address)
|
key = Gitlab::IncomingEmail.key_from_address(address)
|
||||||
break key if key
|
break key if key
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def key_from_additional_headers
|
def key_from_additional_headers(mail)
|
||||||
Array(mail.references).find do |mail_id|
|
Array(mail.references).find do |mail_id|
|
||||||
key = Gitlab::IncomingEmail.key_from_fallback_message_id(mail_id)
|
key = Gitlab::IncomingEmail.key_from_fallback_message_id(mail_id)
|
||||||
break key if key
|
break key if key
|
||||||
|
|
Loading…
Reference in New Issue