Added disconnect on exception.
This commit is contained in:
parent
3ea6ea6e10
commit
37bdde8272
5 changed files with 45 additions and 17 deletions
|
@ -13,6 +13,7 @@ class Channel < ApplicationModel
|
|||
puts "can't use " + 'Channel::' + channel[:adapter]
|
||||
puts e.inspect
|
||||
puts e.backtrace
|
||||
c.disconnect
|
||||
end
|
||||
}
|
||||
end
|
||||
|
|
|
@ -9,6 +9,12 @@ class Channel::Facebook
|
|||
|
||||
|
||||
end
|
||||
|
||||
def disconnect
|
||||
|
||||
|
||||
end
|
||||
|
||||
def send
|
||||
|
||||
logger.debug('face!!!!!!!!!!!!!!')
|
||||
|
|
|
@ -14,42 +14,49 @@ class Channel::IMAP < Channel::EmailParser
|
|||
|
||||
puts "fetching imap (#{channel[:options][:host]}/#{channel[:options][:user]} port=#{port},ssl=#{ssl})"
|
||||
|
||||
imap = Net::IMAP.new( channel[:options][:host], port, ssl, nil, false )
|
||||
@imap = Net::IMAP.new( channel[:options][:host], port, ssl, nil, false )
|
||||
|
||||
# try LOGIN, if not - try plain
|
||||
begin
|
||||
imap.authenticate( 'LOGIN', channel[:options][:user], channel[:options][:password] )
|
||||
@imap.authenticate( 'LOGIN', channel[:options][:user], channel[:options][:password] )
|
||||
rescue Exception => e
|
||||
if e.to_s !~ /unsupported\sauthentication\smechanism/i
|
||||
raise e
|
||||
end
|
||||
imap.login( channel[:options][:user], channel[:options][:password] )
|
||||
@imap.login( channel[:options][:user], channel[:options][:password] )
|
||||
end
|
||||
if !channel[:options][:folder] || channel[:options][:folder].empty?
|
||||
imap.select('INBOX')
|
||||
@imap.select('INBOX')
|
||||
else
|
||||
imap.select( channel[:options][:folder] )
|
||||
@imap.select( channel[:options][:folder] )
|
||||
end
|
||||
count = 0
|
||||
count_all = imap.search(['ALL']).count
|
||||
imap.search(['ALL']).each do |message_id|
|
||||
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']
|
||||
msg = @imap.fetch(message_id,'RFC822')[0].attr['RFC822']
|
||||
# puts msg.to_s
|
||||
|
||||
# delete email from server after article was created
|
||||
if process(channel, msg)
|
||||
imap.store(message_id, "+FLAGS", [:Deleted])
|
||||
@imap.store(message_id, "+FLAGS", [:Deleted])
|
||||
end
|
||||
end
|
||||
imap.expunge()
|
||||
imap.disconnect()
|
||||
@imap.expunge()
|
||||
disconnect
|
||||
if count == 0
|
||||
puts " - no message"
|
||||
end
|
||||
puts "done"
|
||||
end
|
||||
|
||||
def disconnect
|
||||
if @imap
|
||||
@imap.disconnect()
|
||||
end
|
||||
end
|
||||
|
||||
def send(attr, notification = false)
|
||||
channel = Channel.where( :area => 'Email::Outbound', :active => true ).first
|
||||
begin
|
||||
|
|
|
@ -14,14 +14,14 @@ class Channel::POP3 < Channel::EmailParser
|
|||
|
||||
puts "fetching pop3 (#{channel[:options][:host]}/#{channel[:options][:user]} port=#{port},ssl=#{ssl})"
|
||||
|
||||
pop = Net::POP3.new( channel[:options][:host], port )
|
||||
@pop = Net::POP3.new( channel[:options][:host], port )
|
||||
if ssl
|
||||
pop.enable_ssl
|
||||
@pop.enable_ssl
|
||||
end
|
||||
pop.start( channel[:options][:user], channel[:options][:password] )
|
||||
@pop.start( channel[:options][:user], channel[:options][:password] )
|
||||
count = 0
|
||||
count_all = pop.mails.size
|
||||
pop.each_mail do |m|
|
||||
count_all = @pop.mails.size
|
||||
@pop.each_mail do |m|
|
||||
count += 1
|
||||
puts " - message #{count.to_s}/#{count_all.to_s}"
|
||||
|
||||
|
@ -30,12 +30,19 @@ class Channel::POP3 < Channel::EmailParser
|
|||
m.delete
|
||||
end
|
||||
end
|
||||
pop.finish
|
||||
disconnect
|
||||
if count == 0
|
||||
puts " - no message"
|
||||
end
|
||||
puts "done"
|
||||
end
|
||||
|
||||
def disconnect
|
||||
if @pop
|
||||
@pop.finish
|
||||
end
|
||||
end
|
||||
|
||||
def send(attr, notification = false)
|
||||
channel = Channel.where( :area => 'Email::Outbound', :active => true ).first
|
||||
begin
|
||||
|
|
|
@ -12,6 +12,12 @@ class Channel::Twitter2
|
|||
end
|
||||
end
|
||||
|
||||
def disconnect
|
||||
if @client
|
||||
@client = nil
|
||||
end
|
||||
end
|
||||
|
||||
def fetch (channel)
|
||||
|
||||
puts "fetching tweets (oauth_token#{channel[:options][:oauth_token]})"
|
||||
|
@ -46,6 +52,7 @@ class Channel::Twitter2
|
|||
fetch_loop( tweets, channel, channel[:options][:direct_messages][:group] )
|
||||
end
|
||||
puts 'done'
|
||||
disconnect
|
||||
end
|
||||
|
||||
def fetch_loop( tweets, channel, group )
|
||||
|
|
Loading…
Reference in a new issue