2017-09-03 22:25:58 -04:00
|
|
|
module SystemCheck
|
|
|
|
module IncomingEmail
|
|
|
|
class ImapAuthenticationCheck < SystemCheck::BaseCheck
|
|
|
|
set_name 'IMAP server credentials are correct?'
|
|
|
|
|
|
|
|
def check?
|
2017-09-21 14:03:57 -04:00
|
|
|
if config
|
|
|
|
try_connect_imap
|
|
|
|
else
|
|
|
|
@error = "#{mail_room_config_path} does not have mailboxes setup"
|
|
|
|
false
|
2017-09-03 22:25:58 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def show_error
|
|
|
|
try_fixing_it(
|
2017-09-21 14:03:57 -04:00
|
|
|
"An error occurred: #{@error.class}: #{@error.message}",
|
2017-09-03 22:25:58 -04: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 14:03:57 -04:00
|
|
|
def try_connect_imap
|
|
|
|
imap = Net::IMAP.new(config[:host], port: config[:port], ssl: config[:ssl])
|
|
|
|
imap.starttls if config[:start_tls]
|
|
|
|
imap.login(config[:email], config[:password])
|
|
|
|
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-03 22:25:58 -04:00
|
|
|
|
2017-09-21 14:03:57 -04:00
|
|
|
def load_config
|
|
|
|
erb = ERB.new(File.read(mail_room_config_path))
|
|
|
|
erb.filename = mail_room_config_path
|
2017-09-03 22:25:58 -04:00
|
|
|
config_file = YAML.load(erb.result)
|
|
|
|
|
2017-09-21 14:03:57 -04:00
|
|
|
config_file.dig(:mailboxes, 0)
|
2017-09-03 22:25:58 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|