From 4970550677638db12cf5109d644035e061da8b1d Mon Sep 17 00:00:00 2001 From: Vladislav Moskovets Date: Wed, 17 Nov 2010 10:29:05 +0200 Subject: [PATCH 1/6] keep option added --- lib/fetcher/base.rb | 1 + lib/fetcher/imap.rb | 4 ++-- lib/fetcher/pop.rb | 2 +- 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/lib/fetcher/base.rb b/lib/fetcher/base.rb index 5b7ea3e..95c5b2d 100644 --- a/lib/fetcher/base.rb +++ b/lib/fetcher/base.rb @@ -5,6 +5,7 @@ class Base # * :username - Username to use when connecting to server. # * :password - Password to use when connecting to server. # * :receiver - Receiver object to pass messages to. Assumes the + # * :keep - 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 diff --git a/lib/fetcher/imap.rb b/lib/fetcher/imap.rb index c0d0c72..122fe6a 100644 --- a/lib/fetcher/imap.rb +++ b/lib/fetcher/imap.rb @@ -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 @@ -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? diff --git a/lib/fetcher/pop.rb b/lib/fetcher/pop.rb index e165799..ae3333c 100644 --- a/lib/fetcher/pop.rb +++ b/lib/fetcher/pop.rb @@ -31,7 +31,7 @@ def get_messages handle_bogus_message(msg.pop) end # Delete message from server - msg.delete + msg.delete unless @keep end end end From e47336fc1189555e68085ce864c2573f962eb95c Mon Sep 17 00:00:00 2001 From: Vladislav Moskovets Date: Wed, 17 Nov 2010 10:41:24 +0200 Subject: [PATCH 2/6] update README --- README.rdoc | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.rdoc b/README.rdoc index e1878de..f114623 100644 --- a/README.rdoc +++ b/README.rdoc @@ -43,6 +43,7 @@ The following options can be passed to the Fetcher.create factory metho [type] POP or IMAP [server] The IP address or domain name of the server [port] The port to connect to (defaults to the standard port for the type of server) +[keep] Set to any value to dont delete messages after retriving [ssl] Set to any value to use SSL encryption [username] The username used to connect to the server [password] The password used to connect to the server @@ -98,4 +99,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. \ No newline at end of file +Licensed under the terms of the MIT License. Be excellent to each other. From 7c05c89cef8b130fd7b17319db5f23807bec6ff0 Mon Sep 17 00:00:00 2001 From: Vladislav Moskovets Date: Wed, 17 Nov 2010 20:11:19 +0200 Subject: [PATCH 3/6] return msg --- lib/fetcher/pop.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/fetcher/pop.rb b/lib/fetcher/pop.rb index ae3333c..b600859 100644 --- a/lib/fetcher/pop.rb +++ b/lib/fetcher/pop.rb @@ -26,9 +26,9 @@ def get_messages unless @connection.mails.empty? @connection.each_mail do |msg| begin - process_message(msg.pop) + process_message(msg) rescue - handle_bogus_message(msg.pop) + handle_bogus_message(msg) end # Delete message from server msg.delete unless @keep From 43b196d0a6096c4f38f1c15e8b09aa3e7fae4381 Mon Sep 17 00:00:00 2001 From: Vladislav Moskovets Date: Thu, 18 Nov 2010 16:02:56 +0200 Subject: [PATCH 4/6] back to string body --- .gitignore | 1 + lib/fetcher/pop.rb | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index e43b0f9..f31b3e2 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ .DS_Store +*.swp diff --git a/lib/fetcher/pop.rb b/lib/fetcher/pop.rb index b600859..307b22d 100644 --- a/lib/fetcher/pop.rb +++ b/lib/fetcher/pop.rb @@ -26,7 +26,7 @@ def get_messages unless @connection.mails.empty? @connection.each_mail do |msg| begin - process_message(msg) + process_message(msg.pop) rescue handle_bogus_message(msg) end From fe9a17582f119d1349359e52b8077e64887e0bf1 Mon Sep 17 00:00:00 2001 From: Vladislav Moskovets Date: Thu, 18 Nov 2010 20:21:02 +0200 Subject: [PATCH 5/6] reciver can be Proc --- README.rdoc | 6 ++++++ lib/fetcher/base.rb | 10 +++++++--- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/README.rdoc b/README.rdoc index f114623..04d13cf 100644 --- a/README.rdoc +++ b/README.rdoc @@ -35,6 +35,12 @@ The receiver object is expected to have a receive method that takes a message as Call fetch to download messages and process them. @fetcher.fetch + +or + + @fetcher.fetch do |message| + ... + end == Configuration diff --git a/lib/fetcher/base.rb b/lib/fetcher/base.rb index 95c5b2d..51d6019 100644 --- a/lib/fetcher/base.rb +++ b/lib/fetcher/base.rb @@ -17,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]) @@ -28,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 @@ -53,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. From 784510ab4f428663b0ec066f1b04ee769639fb6d Mon Sep 17 00:00:00 2001 From: Vladislav Moskovets Date: Tue, 23 Nov 2010 00:46:31 +0200 Subject: [PATCH 6/6] remove deprecated task file --- tasks/fetcher_tasks.rake | 4 ---- 1 file changed, 4 deletions(-) delete mode 100644 tasks/fetcher_tasks.rake diff --git a/tasks/fetcher_tasks.rake b/tasks/fetcher_tasks.rake deleted file mode 100644 index d952ae4..0000000 --- a/tasks/fetcher_tasks.rake +++ /dev/null @@ -1,4 +0,0 @@ -# desc "Explaining what the task does" -# task :fetcher do -# # Task goes here -# end \ No newline at end of file