Class: ActionMailbox::PostfixRelayer

Inherits:
Object
  • Object
show all
Defined in:
lib/action_mailbox/postfix_relayer.rb

Defined Under Namespace

Classes: Result

Constant Summary collapse

CONTENT_TYPE =
"message/rfc822"
USER_AGENT =
"Action Mailbox Postfix relayer v#{ActionMailbox::VERSION}"

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(url:, username: "actionmailbox", password:) ⇒ PostfixRelayer

Returns a new instance of PostfixRelayer.



24
25
26
# File 'lib/action_mailbox/postfix_relayer.rb', line 24

def initialize(url:, username: "actionmailbox", password:)
  @uri, @username, @password = URI(url), username, password
end

Instance Attribute Details

#passwordObject (readonly)

Returns the value of attribute password.



22
23
24
# File 'lib/action_mailbox/postfix_relayer.rb', line 22

def password
  @password
end

#uriObject (readonly)

Returns the value of attribute uri.



22
23
24
# File 'lib/action_mailbox/postfix_relayer.rb', line 22

def uri
  @uri
end

#usernameObject (readonly)

Returns the value of attribute username.



22
23
24
# File 'lib/action_mailbox/postfix_relayer.rb', line 22

def username
  @username
end

Instance Method Details

#relay(source) ⇒ Object



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/action_mailbox/postfix_relayer.rb', line 28

def relay(source)
  case response = post(source)
  when Net::HTTPSuccess
    Result.new "2.0.0 Successfully relayed message to Postfix ingress"
  when Net::HTTPUnauthorized
    Result.new "4.7.0 Invalid credentials for Postfix ingress"
  else
    Result.new "4.0.0 HTTP #{response.code}"
  end
rescue IOError, SocketError, SystemCallError => error
  Result.new "4.4.2 Network error relaying to Postfix ingress: #{error.message}"
rescue Timeout::Error
  Result.new "4.4.2 Timed out relaying to Postfix ingress"
rescue => error
  Result.new "4.0.0 Error relaying to Postfix ingress: #{error.message}"
end