pop3.rb 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. # Copyright (C) 2012-2013 Zammad Foundation, http://zammad-foundation.org/
  2. require 'net/pop'
  3. class Channel::POP3 < Channel::EmailParser
  4. def fetch (channel)
  5. ssl = false
  6. port = 110
  7. if channel[:options][:ssl].to_s == 'true'
  8. ssl = true
  9. port = 995
  10. end
  11. puts "fetching pop3 (#{channel[:options][:host]}/#{channel[:options][:user]} port=#{port},ssl=#{ssl})"
  12. pop = Net::POP3.new( channel[:options][:host], port )
  13. if ssl
  14. pop.enable_ssl
  15. end
  16. pop.start( channel[:options][:user], channel[:options][:password] )
  17. count = 0
  18. count_all = pop.mails.size
  19. pop.each_mail do |m|
  20. count += 1
  21. puts " - message #{count.to_s}/#{count_all.to_s}"
  22. # delete email from server after article was created
  23. if process(channel, m.pop)
  24. m.delete
  25. end
  26. end
  27. pop.finish
  28. if count == 0
  29. puts " - no message"
  30. end
  31. puts "done"
  32. end
  33. def send(attr, notification = false)
  34. channel = Channel.where( :area => 'Email::Outbound', :active => true ).first
  35. begin
  36. c = eval 'Channel::' + channel[:adapter] + '.new'
  37. c.send(attr, channel, notification)
  38. rescue Exception => e
  39. puts "can't use " + 'Channel::' + channel[:adapter]
  40. puts e.inspect
  41. end
  42. end
  43. end