From 9b431deea3cc9458ac077870307df90dce3540df Mon Sep 17 00:00:00 2001 From: Martin Edenhofer Date: Fri, 13 Apr 2012 19:06:09 +0200 Subject: [PATCH] Improved debug output. --- app/models/channel/imap.rb | 13 +++++++++---- app/models/channel/pop3.rb | 15 ++++++++++----- 2 files changed, 19 insertions(+), 9 deletions(-) diff --git a/app/models/channel/imap.rb b/app/models/channel/imap.rb index c679a0aa5..408de5881 100644 --- a/app/models/channel/imap.rb +++ b/app/models/channel/imap.rb @@ -4,13 +4,16 @@ class Channel::IMAP < Channel::EmailParser include UserInfo def fetch (channel) - puts 'fetching imap' + puts "fetching imap (#{channel[:options][:host]}/#{channel[:options][:user]})" imap = Net::IMAP.new(channel[:options][:host], 993, true ) imap.authenticate('LOGIN', channel[:options][:user], channel[:options][:password]) imap.select('INBOX') - count = 0 + count = 0 + count_all = imap.search(['ALL']).count imap.search(['ALL']).each do |message_id| + count += 1 + puts " - message #{count.to_s}/#{count_all.to_s}" msg = imap.fetch(message_id,'RFC822')[0].attr['RFC822'] # puts msg.to_s @@ -18,11 +21,13 @@ class Channel::IMAP < Channel::EmailParser if parse(channel, msg) imap.store(message_id, "+FLAGS", [:Deleted]) end - count += 1 end imap.expunge() imap.disconnect() - puts "#{count.to_s} mails fetched. done." + if count == 0 + puts " - no message" + end + puts "done" end def send(attr, notification = false) channel = Channel.where( :area => 'Email::Outbound', :active => true ).first diff --git a/app/models/channel/pop3.rb b/app/models/channel/pop3.rb index 36f84038a..86dfc3f30 100644 --- a/app/models/channel/pop3.rb +++ b/app/models/channel/pop3.rb @@ -4,22 +4,27 @@ class Channel::POP3 < Channel::EmailParser include UserInfo def fetch (channel) - puts 'fetching pop3' + puts "fetching pop3 (#{channel[:options][:host]}/#{channel[:options][:user]})" pop = Net::POP3.new( channel[:options][:host], 995 ) pop.enable_ssl pop.start( channel[:options][:user], channel[:options][:password] ) - count = 0 + count = 0 + count_all = pop.mails.size pop.each_mail do |m| - + count += 1 + puts " - message #{count.to_s}/#{count_all.to_s}" + # delete email from server after article was created if parse(channel, m.pop) m.delete end - count += 1 end pop.finish - puts "#{count.to_s} mails popped. done." + if count == 0 + puts " - no message" + end + puts "done" end def send(attr, notification = false) channel = Channel.where( :area => 'Email::Outbound', :active => true ).first