Class: Mailman::Receiver::POP3

Inherits:
Object
  • Object
show all
Defined in:
lib/mailman/receiver/pop3.rb

Overview

Receives messages using POP3, and passes them to a MessageProcessor.

Instance Attribute Summary (collapse)

Instance Method Summary (collapse)

Constructor Details

- (POP3) initialize(options)

A new instance of POP3

Parameters:

  • options (Hash)

    the receiver options

Options Hash (options):

  • :processor (MessageProcessor)

    the processor to pass new messages to

  • :server (String)

    the server to connect to

  • :port (Integer)

    the port to connect to

  • :username (String)

    the username to authenticate with

  • :password (String)

    the password to authenticate with

  • :ssl (true, false)

    enable SSL



19
20
21
22
23
24
25
# File 'lib/mailman/receiver/pop3.rb', line 19

def initialize(options)
  @processor = options[:processor]
  @username = options[:username]
  @password = options[:password]
  @connection = Net::POP3.new(options[:server], options[:port])
  @connection.enable_ssl(OpenSSL::SSL::VERIFY_NONE) if options[:ssl]
end

Instance Attribute Details

- (Net::POP3) connection (readonly)

The POP3 connection

Returns:

  • (Net::POP3)

    the POP3 connection



9
10
11
# File 'lib/mailman/receiver/pop3.rb', line 9

def connection
  @connection
end

Instance Method Details

- (Object) connect

Connects to the POP3 server.



28
29
30
# File 'lib/mailman/receiver/pop3.rb', line 28

def connect
  @connection.start(@username, @password)
end

- (Object) disconnect

Disconnects from the POP3 server.



33
34
35
# File 'lib/mailman/receiver/pop3.rb', line 33

def disconnect
  @connection.finish
end

- (Object) get_messages

Iterates through new messages, passing them to the processor, and deleting them.



39
40
41
42
43
44
# File 'lib/mailman/receiver/pop3.rb', line 39

def get_messages
  @connection.each_mail do |message|
    @processor.process(message.pop)
  end
  @connection.delete_all
end