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