Skip to content
This repository has been archived by the owner on Nov 27, 2018. It is now read-only.

Graceful Handling of POP3 connection errors #23

Merged
merged 1 commit into from
May 3, 2011
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions lib/mailman/application.rb
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,14 @@ def run

connection = Receiver::POP3.new(options)
loop do
Mailman.logger.debug "Checking POP3 server for messages..."
connection.connect
connection.get_messages
connection.disconnect
begin
connection.connect
connection.get_messages
connection.disconnect
rescue SystemCallError => e
Mailman.logger.error e.message
end

break if !polling
sleep Mailman.config.poll_interval
end
Expand Down
3 changes: 2 additions & 1 deletion mailman.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ Gem::Specification.new do |s|
s.add_dependency 'maildir', '>= 0.5.0'
s.add_dependency 'i18n', '>= 0.4.1' # fix for mail/activesupport-3 dependency issue

s.add_development_dependency 'rspec'
s.add_development_dependency 'rspec', '1.3.2'
s.add_development_dependency 'mocha'

s.files = Dir.glob('{bin,lib,examples}/**/*') + %w(LICENSE README.md USER_GUIDE.md)
s.require_path = 'lib'
Expand Down
26 changes: 26 additions & 0 deletions spec/functional/application_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,32 @@ def send_example
@app.router.instance_variable_get('@count').should == 2
end

it 'should handle connection errors and log them to logger.error' do
config.pop3 = { :server => 'example.com',
:username => 'chunky',
:password => 'bacon' }
config.poll_interval = 0 # just poll once

MockPOP3.any_instance.stubs(:start).raises(SystemCallError, "Generic Connection Error")
Mailman.logger.expects(:error).with("unknown error - Generic Connection Error")

mailman_app {
from 'chunky@bacon.com' do
@count ||= 0
@count += 1
end
}
@app.run
@app.router.instance_variable_get('@count').should == nil

MockPOP3.any_instance.unstub(:start)
end






it 'should watch a maildir folder for messages' do
setup_maildir # creates the maildir with a queued message

Expand Down
2 changes: 1 addition & 1 deletion spec/mailman/receiver/pop3_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
it 'should connect to a POP3 server' do
@receiver.connect.should be_true
end

it 'should disconnect from a POP3 server' do
@receiver.connect
@receiver.disconnect.should be_true
Expand Down
2 changes: 2 additions & 0 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
require 'spec'
require 'spec/autorun'
require 'pop3_mock'
require 'mocha'

unless defined?(SPEC_ROOT)
SPEC_ROOT = File.join(File.dirname(__FILE__))
Expand Down Expand Up @@ -53,6 +54,7 @@ def setup_maildir

Spec::Runner.configure do |config|
config.include Mailman::SpecHelpers
config.mock_with :mocha
end


Expand Down