Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

breaking out bogus message handling to it's own method

  • Loading branch information...
commit 071a84e71635156122108a11f2f062db3b3f081b 1 parent e59c08c
@dweinand dweinand authored
Showing with 21 additions and 10 deletions.
  1. +10 −6 lib/fetcher/imap.rb
  2. +9 −4 lib/fetcher/pop.rb
  3. +2 −0  test/fetcher_test.rb
View
16 lib/fetcher/imap.rb
@@ -2,19 +2,19 @@
module Fetcher
class Imap < Base
-
+
protected
def assign_options(options={})
@authentication = options.delete(:authentication) || 'PLAIN'
super
end
-
+
def establish_connection
@connection = Net::IMAP.new(@server)
@connection.authenticate(@authentication, @username, @password)
end
-
+
def get_messages
@connection.select('INBOX')
@connection.search(['ALL']).each do |message_id|
@@ -24,19 +24,23 @@ def get_messages
@receiver.receive(msg)
rescue
# Store the message for inspection if the receiver errors
- @connection.append('bogus', msg)
+ handle_bogus_message(msg)
end
# Mark message as deleted
@connection.store(message_id, "+FLAGS", [:Deleted])
end
end
-
+
+ def handle_bogus_message(message)
+ @connection.append('bogus', message)
+ end
+
def close_connection
# expunge messages and log out.
@connection.expunge
@connection.logout
@connection.disconnect
end
-
+
end
end
View
13 lib/fetcher/pop.rb
@@ -9,13 +9,13 @@ def assign_options(options={})
@ssl = options.delete(:ssl)
super
end
-
+
def establish_connection
@connection = Net::POP3.new(@server)
@connection.enable_ssl(OpenSSL::SSL::VERIFY_NONE) if @ssl
@connection.start(@username, @password)
end
-
+
def get_messages
unless @connection.mails.empty?
@connection.each_mail do |msg|
@@ -24,16 +24,21 @@ def get_messages
@receiver.receive(msg.pop)
rescue
# Store the message for inspection if the receiver errors
+ handle_bogus_message(msg.pop)
end
# Delete message from server
msg.delete
end
end
end
-
+
+ def handle_bogus_message(message)
+
+ end
+
def close_connection
@connection.finish
end
-
+
end
end
View
2  test/fetcher_test.rb
@@ -25,3 +25,5 @@ def test_should_require_subclass
assert_raise(NotImplementedError) { @fetcher.fetch }
end
end
+
+# Write tests for sub-classes
Please sign in to comment.
Something went wrong with that request. Please try again.