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

#initialize(options) ⇒ POP3

Returns 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
26
27
# 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 if options[:ssl]
  @connection.open_timeout = options[:open_timeout] if options[:open_timeout]
  @connection.read_timeout = options[:read_timeout] if options[:read_timeout]
end

Instance Attribute Details

#connectionNet::POP3 (readonly)

Returns 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

#connectObject

Connects to the POP3 server.


30
31
32
# File 'lib/mailman/receiver/pop3.rb', line 30

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

#disconnectObject

Disconnects from the POP3 server.


35
36
37
# File 'lib/mailman/receiver/pop3.rb', line 35

def disconnect
  @connection.finish
end

#get_messagesObject

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


41
42
43
44
45
46
47
48
49
50
51
# File 'lib/mailman/receiver/pop3.rb', line 41

def get_messages
  @connection.each_mail do |message|
    begin
      @processor.process(message.pop)
    rescue StandardError => error
      Mailman.logger.error "Error encountered processing message: #{message.inspect}\n #{error.class.to_s}: #{error.message}\n #{error.backtrace.join("\n")}"
      next
    end
  end
  @connection.delete_all
end

#started?Boolean

Returns:

  • (Boolean)

53
54
55
# File 'lib/mailman/receiver/pop3.rb', line 53

def started?
  @connection.started?
end