2018-10-08 14:50:39 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2017-09-04 02:25:58 +00:00
|
|
|
module SystemCheck
|
|
|
|
module IncomingEmail
|
|
|
|
class ImapAuthenticationCheck < SystemCheck::BaseCheck
|
|
|
|
set_name 'IMAP server credentials are correct?'
|
|
|
|
|
|
|
|
def check?
|
2017-09-21 18:03:57 +00:00
|
|
|
if config
|
|
|
|
try_connect_imap
|
|
|
|
else
|
2018-09-17 09:17:33 +00:00
|
|
|
@error = "#{mail_room_config_path} does not have mailboxes set up"
|
2017-09-21 18:03:57 +00:00
|
|
|
false
|
2017-09-04 02:25:58 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def show_error
|
|
|
|
try_fixing_it(
|
2017-09-21 18:03:57 +00:00
|
|
|
"An error occurred: #{@error.class}: #{@error.message}",
|
2017-09-04 02:25:58 +00:00
|
|
|
'Check that the information in config/gitlab.yml is correct'
|
|
|
|
)
|
|
|
|
for_more_information(
|
|
|
|
'doc/administration/reply_by_email.md'
|
|
|
|
)
|
|
|
|
fix_and_rerun
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
2017-09-21 18:03:57 +00:00
|
|
|
def try_connect_imap
|
2020-07-10 12:09:15 +00:00
|
|
|
config.each do |mailbox|
|
|
|
|
$stdout.puts "Checking #{mailbox[:email]}"
|
|
|
|
imap = Net::IMAP.new(mailbox[:host], port: mailbox[:port], ssl: mailbox[:ssl])
|
|
|
|
imap.starttls if mailbox[:start_tls]
|
|
|
|
imap.login(mailbox[:email], mailbox[:password])
|
|
|
|
end
|
2017-09-21 18:03:57 +00:00
|
|
|
true
|
|
|
|
rescue => error
|
|
|
|
@error = error
|
|
|
|
false
|
|
|
|
end
|
|
|
|
|
|
|
|
def config
|
|
|
|
@config ||= load_config
|
|
|
|
end
|
|
|
|
|
|
|
|
def mail_room_config_path
|
|
|
|
@mail_room_config_path ||=
|
|
|
|
Rails.root.join('config', 'mail_room.yml').to_s
|
|
|
|
end
|
2017-09-04 02:25:58 +00:00
|
|
|
|
2017-09-21 18:03:57 +00:00
|
|
|
def load_config
|
|
|
|
erb = ERB.new(File.read(mail_room_config_path))
|
|
|
|
erb.filename = mail_room_config_path
|
2017-09-04 02:25:58 +00:00
|
|
|
config_file = YAML.load(erb.result)
|
|
|
|
|
2020-07-10 12:09:15 +00:00
|
|
|
config_file[:mailboxes]
|
2017-09-04 02:25:58 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|