Class: Mailman::Receiver::POP3
- Inherits:
-
Object
- Object
- Mailman::Receiver::POP3
- Defined in:
- lib/mailman/receiver/pop3.rb
Overview
Receives messages using POP3, and passes them to a MessageProcessor.
Instance Attribute Summary collapse
-
#connection ⇒ Net::POP3
readonly
The POP3 connection.
Instance Method Summary collapse
-
#connect ⇒ Object
Connects to the POP3 server.
-
#disconnect ⇒ Object
Disconnects from the POP3 server.
-
#get_messages ⇒ Object
Iterates through new messages, passing them to the processor, and deleting them.
-
#initialize(options) ⇒ POP3
constructor
A new instance of POP3.
- #started? ⇒ Boolean
Constructor Details
#initialize(options) ⇒ POP3
Returns a new instance of POP3.
19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/mailman/receiver/pop3.rb', line 19 def initialize() @processor = [:processor] @username = [:username] @password = [:password] port = [:port] || ([:ssl] ? 995 : 110) @connection = Net::POP3.new([:server], port) if [:ssl].is_a? Hash @connection.enable_ssl([:ssl]) elsif [:ssl] @connection.enable_ssl end @connection.open_timeout = [:open_timeout] if [:open_timeout] @connection.read_timeout = [:read_timeout] if [:read_timeout] end |
Instance Attribute Details
#connection ⇒ Net::POP3 (readonly)
Returns the POP3 connection.
9 10 11 |
# File 'lib/mailman/receiver/pop3.rb', line 9 def connection @connection end |
Instance Method Details
#connect ⇒ Object
Connects to the POP3 server.
35 36 37 |
# File 'lib/mailman/receiver/pop3.rb', line 35 def connect @connection.start(@username, @password) end |
#disconnect ⇒ Object
Disconnects from the POP3 server.
40 41 42 |
# File 'lib/mailman/receiver/pop3.rb', line 40 def disconnect @connection.finish end |
#get_messages ⇒ Object
Iterates through new messages, passing them to the processor, and deleting them.
46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/mailman/receiver/pop3.rb', line 46 def @connection.each_mail do || begin @processor.process(.pop) rescue StandardError => error Mailman.logger.error "Error encountered processing message: #{.inspect}\n #{error.class.to_s}: #{error.}\n #{error.backtrace.join("\n")}" next end end @connection.delete_all end |
#started? ⇒ Boolean
58 59 60 |
# File 'lib/mailman/receiver/pop3.rb', line 58 def started? @connection.started? end |