Skip to content
This repository was archived by the owner on Dec 2, 2017. It is now read-only.
Open

Hi #10

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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
.DS_Store
*.swp
9 changes: 8 additions & 1 deletion README.rdoc
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,12 @@ The receiver object is expected to have a receive method that takes a message as
Call <tt>fetch</tt> to download messages and process them.

@fetcher.fetch

or

@fetcher.fetch do |message|
...
end

== Configuration

Expand All @@ -43,6 +49,7 @@ The following options can be passed to the <tt>Fetcher.create</tt> factory metho
[<tt>type</tt>] POP or IMAP
[<tt>server</tt>] The IP address or domain name of the server
[<tt>port</tt>] The port to connect to (defaults to the standard port for the type of server)
[<tt>keep</tt>] Set to any value to dont delete messages after retriving
[<tt>ssl</tt>] Set to any value to use SSL encryption
[<tt>username</tt>] The username used to connect to the server
[<tt>password</tt>] The password used to connect to the server
Expand Down Expand Up @@ -98,4 +105,4 @@ Created by Dan Weinand and Luke Francl. Development supported by {Slantwise Desi

Generators for Rails 3 compatibility added by Amol Hatwár, Exceed Consulting.

Licensed under the terms of the MIT License. Be excellent to each other.
Licensed under the terms of the MIT License. Be excellent to each other.
11 changes: 8 additions & 3 deletions lib/fetcher/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ class Base
# * <tt>:username</tt> - Username to use when connecting to server.
# * <tt>:password</tt> - Password to use when connecting to server.
# * <tt>:receiver</tt> - Receiver object to pass messages to. Assumes the
# * <tt>:keep</tt> - Do not remove messages from server
# receiver object has a receive method that takes a message as it's argument
#
# Additional protocol-specific options implimented by sub-classes
Expand All @@ -16,7 +17,6 @@ class Base
# :receiver => IncomingMailHandler)
def initialize(options={})
%w(server username password receiver).each do |opt|
raise ArgumentError, "#{opt} is required" unless options[opt.to_sym]
# convert receiver to a Class if it isn't already.
if opt == "receiver" && options[:receiver].is_a?(String)
options[:receiver] = Kernel.const_get(options[:receiver])
Expand All @@ -27,7 +27,8 @@ def initialize(options={})
end

# Run the fetching process
def fetch
def fetch &block
@receiver = block if block_given?
establish_connection
get_messages
close_connection
Expand All @@ -52,7 +53,11 @@ def close_connection #:nodoc:

# Send message to receiver object
def process_message(message)
@receiver.receive(message)
if @receiver.is_a? Proc
@receiver.call message
else
@receiver.receive(message)
end
end

# Stub. Should be overridden by subclass.
Expand Down
4 changes: 2 additions & 2 deletions lib/fetcher/imap.rb
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ def get_messages
handle_bogus_message(msg)
end
# Mark message as deleted
@connection.uid_store(uid, "+FLAGS", [:Seen, :Deleted])
@connection.uid_store(uid, "+FLAGS", [:Seen, :Deleted]) unless @keep
end
end

Expand All @@ -64,7 +64,7 @@ def handle_bogus_message(message)

# Delete messages and log out
def close_connection
@connection.expunge
@connection.expunge unless @keep
@connection.logout
begin
@connection.disconnect unless @connection.disconnected?
Expand Down
4 changes: 2 additions & 2 deletions lib/fetcher/pop.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,10 @@ def get_messages
begin
process_message(msg.pop)
rescue
handle_bogus_message(msg.pop)
handle_bogus_message(msg)
end
# Delete message from server
msg.delete
msg.delete unless @keep
end
end
end
Expand Down
4 changes: 0 additions & 4 deletions tasks/fetcher_tasks.rake

This file was deleted.