pop3.rb 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. # Copyright (C) 2012-2014 Zammad Foundation, http://zammad-foundation.org/
  2. require 'net/pop'
  3. class Channel::POP3 < Channel::EmailParser
  4. def fetch (channel, check_type = '')
  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. if check_type == 'check'
  18. puts "check only mode, fetch no emails"
  19. disconnect
  20. return
  21. elsif check_type == 'verify'
  22. puts "verify mode, fetch no emails"
  23. end
  24. count = 0
  25. count_all = @pop.mails.size
  26. @pop.each_mail do |m|
  27. count += 1
  28. puts " - message #{count.to_s}/#{count_all.to_s}"
  29. # check for verify message
  30. if check_type == 'verify'
  31. mail = m.pop
  32. if mail && mail =~ /#{verify_string}/
  33. puts " - verify email #{verify_string} found"
  34. m.delete
  35. disconnect
  36. return 'verify ok'
  37. end
  38. else
  39. # delete email from server after article was created
  40. if process(channel, m.pop)
  41. m.delete
  42. end
  43. end
  44. end
  45. disconnect
  46. if count == 0
  47. puts " - no message"
  48. end
  49. puts "done"
  50. end
  51. def disconnect
  52. if @pop
  53. @pop.finish
  54. end
  55. end
  56. end