trabajo-afectivo/app/models/channel/pop3.rb

57 lines
1.3 KiB
Ruby
Raw Normal View History

2014-02-03 19:23:00 +00:00
# Copyright (C) 2012-2014 Zammad Foundation, http://zammad-foundation.org/
require 'net/pop'
2012-04-10 14:06:46 +00:00
class Channel::POP3 < Channel::EmailParser
2012-04-10 14:06:46 +00:00
def fetch (channel)
2013-01-04 23:14:08 +00:00
ssl = false
port = 110
if channel[:options][:ssl].to_s == 'true'
ssl = true
port = 995
end
puts "fetching pop3 (#{channel[:options][:host]}/#{channel[:options][:user]} port=#{port},ssl=#{ssl})"
2014-06-22 07:00:09 +00:00
@pop = Net::POP3.new( channel[:options][:host], port )
2013-01-04 23:14:08 +00:00
if ssl
2014-06-22 07:00:09 +00:00
@pop.enable_ssl
2013-01-04 23:14:08 +00:00
end
2014-06-22 07:00:09 +00:00
@pop.start( channel[:options][:user], channel[:options][:password] )
2012-04-13 17:06:09 +00:00
count = 0
2014-06-22 07:00:09 +00:00
count_all = @pop.mails.size
@pop.each_mail do |m|
2012-04-13 17:06:09 +00:00
count += 1
puts " - message #{count.to_s}/#{count_all.to_s}"
# delete email from server after article was created
if process(channel, m.pop)
m.delete
end
end
2014-06-22 07:00:09 +00:00
disconnect
2012-04-13 17:06:09 +00:00
if count == 0
puts " - no message"
end
puts "done"
end
2014-06-22 07:00:09 +00:00
def disconnect
if @pop
@pop.finish
end
end
def send(attr, notification = false)
channel = Channel.where( :area => 'Email::Outbound', :active => true ).first
begin
c = eval 'Channel::' + channel[:adapter] + '.new'
c.send(attr, channel, notification)
rescue Exception => e
puts "can't use " + 'Channel::' + channel[:adapter]
puts e.inspect
2012-04-10 14:06:46 +00:00
end
end
end