Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Graceful Handling of POP3 connection errors #23

Merged
merged 1 commit into from

2 participants

@dnch

I've noticed that long-running Mailman instances crash if Net::POP3 raises connection errors (ie, no route to host, timeout, etc). Rather than letting it crash, I've added a simple handler for those instances.

I've also quietened the POP3 handler down somewhat.

Note: I've added Mocha as a development dependency.

@titanous titanous merged commit 8b4373a into from
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on May 3, 2011
  1. @dnch
This page is out of date. Refresh to see the latest.
View
12 lib/mailman/application.rb
@@ -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
View
3  mailman.gemspec
@@ -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'
View
26 spec/functional/application_spec.rb
@@ -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
View
2  spec/mailman/receiver/pop3_spec.rb
@@ -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
View
2  spec/spec_helper.rb
@@ -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__))
@@ -53,6 +54,7 @@ def setup_maildir
Spec::Runner.configure do |config|
config.include Mailman::SpecHelpers
+ config.mock_with :mocha
end
Something went wrong with that request. Please try again.