blob: e02ae81dc98f152f0bb9bb1510084e8d7374b407 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
|
# frozen_string_literal: true
module SystemCheck
module IncomingEmail
class ImapAuthenticationCheck < SystemCheck::BaseCheck
set_name 'IMAP server credentials are correct?'
def check?
if config
try_connect_imap
else
@error = "#{mail_room_config_path} does not have mailboxes set up"
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
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
true
rescue StandardError => 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
def load_config
erb = ERB.new(File.read(mail_room_config_path))
erb.filename = mail_room_config_path
config_file = YAML.safe_load(erb.result, permitted_classes: [Symbol])
config_file[:mailboxes]
end
end
end
end
|