Permalink
Browse files

print stack trace to stderr when receiving mail fails. And added imap…

… copy bogus messages back to inbox method
  • Loading branch information...
1 parent d1a1363 commit f44ae8a6642a8b0487855f9fb5eae21aef9b0b11 Edgars Beigarts committed Aug 20, 2009
Showing with 16 additions and 2 deletions.
  1. +13 −1 lib/fetcher/imap.rb
  2. +3 −1 lib/fetcher/pop.rb
View
@@ -42,14 +42,24 @@ def get_messages
begin
process_message(msg)
add_to_processed_folder(uid) if @processed_folder
- rescue
+ rescue => e
+ $stderr.puts e.inspect
+ $stderr.puts e.backtrace
handle_bogus_message(msg)
end
# Mark message as deleted
@connection.uid_store(uid, "+FLAGS", [:Seen, :Deleted])
end
end
+ def copy_bogus_messages_back_to_inbox
+ @connection.select(@error_folder)
+ @connection.uid_search(['ALL']).each do |uid|
+ msg = @connection.uid_fetch(uid,'RFC822').first.attr['RFC822']
+ @connection.append("INBOX", msg)
+ end
+ end
+
# Store the message for inspection if the receiver errors
def handle_bogus_message(message)
create_mailbox(@error_folder)
@@ -61,6 +71,8 @@ def close_connection
@connection.expunge
@connection.logout
@connection.disconnect
+ rescue Errno::ENOTCONN
+ true
end
def add_to_processed_folder(uid)
View
@@ -27,7 +27,9 @@ def get_messages
@connection.each_mail do |msg|
begin
process_message(msg.pop)
- rescue
+ rescue => e
+ $stderr.puts e.inspect
+ $stderr.puts e.backtrace
handle_bogus_message(msg.pop)
end
# Delete message from server

0 comments on commit f44ae8a

Please sign in to comment.