Guest User

Untitled

a guest
Jun 3rd, 2018
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.57 KB | None | 0 0
  1. require 'net/pop'
  2.  
  3. module Mailman
  4. class Receiver
  5. # Receives messages using POP3, and passes them to a {MessageProcessor}.
  6. class POP3
  7.  
  8. # @return [Net::POP3] the POP3 connection
  9. attr_reader :connection
  10.  
  11. # @param [Hash] options the receiver options
  12. # @option options [MessageProcessor] :processor the processor to pass new
  13. # messages to
  14. # @option options [String] :server the server to connect to
  15. # @option options [Integer] :port the port to connect to
  16. # @option options [String] :username the username to authenticate with
  17. # @option options [String] :password the password to authenticate with
  18. def initialize(options)
  19. @processor = options[:processor]
  20. @username = options[:username]
  21. @password = options[:password]
  22. @connection = Net::POP3.new(options[:server], options[:port])
  23.  
  24.  
  25. @ssl = options[:ssl] ||= false
  26. @connection = Net::POP3.new(options[:server], options[:port])
  27. @connection.enable_ssl(OpenSSL::SSL::VERIFY_NONE) if @ssl
  28.  
  29. end
  30.  
  31. # Connects to the POP3 server.
  32. def connect
  33. @connection.start(@username, @password)
  34. end
  35.  
  36. # Disconnects from the POP3 server.
  37. def disconnect
  38. @connection.finish
  39. end
  40.  
  41. # Iterates through new messages, passing them to the processor, and
  42. # deleting them.
  43. def get_messages
  44. @connection.each_mail do |message|
  45. @processor.process(message.pop)
  46. message.delete
  47. end
  48. @connection.delete_all
  49. end
  50.  
  51. end
  52. end
  53. end
Add Comment
Please, Sign In to add comment