Fix pop3 SSL state leaking over multisite

This commit is contained in:
riking 2014-08-26 17:00:27 -07:00
parent 6d357c9c23
commit e28ef099a4
3 changed files with 21 additions and 5 deletions

View file

@ -73,10 +73,10 @@ module Jobs
end
def poll_pop3
Net::POP3.start(SiteSetting.pop3_polling_host,
SiteSetting.pop3_polling_port,
SiteSetting.pop3_polling_username,
SiteSetting.pop3_polling_password) do |pop|
connection = Net::POP3.new(SiteSetting.pop3_polling_host, SiteSetting.pop3_polling_port)
connection.enable_ssl if SiteSetting.pop3_polling_ssl
connection.start(SiteSetting.pop3_polling_username, SiteSetting.pop3_polling_password) do |pop|
unless pop.mails.empty?
pop.each do |mail|
handle_mail(mail)

View file

@ -386,6 +386,7 @@ email:
reply_by_email_enabled: false
reply_by_email_address: ''
pop3_polling_enabled: false
pop3_polling_ssl: true
pop3_polling_period_mins: 5
pop3_polling_host: ''
pop3_polling_port: 995

View file

@ -32,13 +32,28 @@ describe Jobs::PollMailbox do
error = Net::POPAuthenticationError.new
data = { limit_once_per: 1.hour, message_params: { error: error }}
Net::POP3.expects(:start).raises(error)
Net::POP3.any_instance.expects(:start).raises(error)
Discourse.expects(:handle_exception)
poller.poll_pop3
end
it "calls enable_ssl when the setting is enabled" do
SiteSetting.pop3_polling_ssl = true
Net::POP3.any_instance.stubs(:start)
Net::POP3.any_instance.expects(:enable_ssl)
poller.poll_pop3
end
it "does not call enable_ssl when the setting is off" do
SiteSetting.pop3_polling_ssl = false
Net::POP3.any_instance.stubs(:start)
Net::POP3.any_instance.expects(:enable_ssl).never
poller.poll_pop3
end
end
# Testing mock for the email objects that you get