2018-12-13 13:39:08 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
module SystemCheck
|
|
|
|
module IncomingEmail
|
|
|
|
class ImapAuthenticationCheck < SystemCheck::BaseCheck
|
|
|
|
set_name 'IMAP server credentials are correct?'
|
|
|
|
|
|
|
|
def check?
|
|
|
|
if config
|
|
|
|
try_connect_imap
|
|
|
|
else
|
2018-12-05 23:21:45 +05:30
|
|
|
@error = "#{mail_room_config_path} does not have mailboxes set up"
|
2018-03-17 18:26:18 +05:30
|
|
|
false
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def show_error
|
|
|
|
try_fixing_it(
|
|
|
|
"An error occurred: #{@error.class}: #{@error.message}",
|
|
|
|
'Check that the information in config/gitlab.yml is correct'
|
|
|
|
)
|
|
|
|
for_more_information(
|
|
|
|
'doc/administration/reply_by_email.md'
|
|
|
|
)
|
|
|
|
fix_and_rerun
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def try_connect_imap
|
2020-07-28 23:09:34 +05:30
|
|
|
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
|
2018-03-17 18:26:18 +05:30
|
|
|
true
|
2021-06-08 01:23:25 +05:30
|
|
|
rescue StandardError => error
|
2018-03-17 18:26:18 +05:30
|
|
|
@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
|
|
|
|
|
|
|
|
def load_config
|
|
|
|
erb = ERB.new(File.read(mail_room_config_path))
|
|
|
|
erb.filename = mail_room_config_path
|
2021-09-04 01:27:46 +05:30
|
|
|
config_file = YAML.safe_load(erb.result, permitted_classes: [Symbol])
|
2018-03-17 18:26:18 +05:30
|
|
|
|
2020-07-28 23:09:34 +05:30
|
|
|
config_file[:mailboxes]
|
2018-03-17 18:26:18 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|