Class: Coppertone::Request

Inherits:
Object
  • Object
show all
Defined in:
lib/coppertone/request.rb

Overview

Represents an SPF request.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(ip_as_s, sender, helo_domain, options = {}) ⇒ Request

Returns a new instance of Request.



6
7
8
9
10
11
# File 'lib/coppertone/request.rb', line 6

def initialize(ip_as_s, sender, helo_domain, options = {})
  @ip_as_s = ip_as_s
  @sender = sender
  @helo_domain = helo_domain
  @options = options
end

Instance Attribute Details

#helo_domainObject (readonly)

Returns the value of attribute helo_domain.



4
5
6
# File 'lib/coppertone/request.rb', line 4

def helo_domain
  @helo_domain
end

#helo_resultObject (readonly)

Returns the value of attribute helo_result.



4
5
6
# File 'lib/coppertone/request.rb', line 4

def helo_result
  @helo_result
end

#ip_as_sObject (readonly)

Returns the value of attribute ip_as_s.



4
5
6
# File 'lib/coppertone/request.rb', line 4

def ip_as_s
  @ip_as_s
end

#mailfrom_resultObject (readonly)

Returns the value of attribute mailfrom_result.



4
5
6
# File 'lib/coppertone/request.rb', line 4

def mailfrom_result
  @mailfrom_result
end

#optionsObject (readonly)

Returns the value of attribute options.



4
5
6
# File 'lib/coppertone/request.rb', line 4

def options
  @options
end

#resultObject (readonly)

Returns the value of attribute result.



4
5
6
# File 'lib/coppertone/request.rb', line 4

def result
  @result
end

#senderObject (readonly)

Returns the value of attribute sender.



4
5
6
# File 'lib/coppertone/request.rb', line 4

def sender
  @sender
end

Instance Method Details

#authenticateObject



13
14
15
# File 'lib/coppertone/request.rb', line 13

def authenticate
  process_helo || process_mailfrom || default_value
end

#default_valueObject



31
32
33
# File 'lib/coppertone/request.rb', line 31

def default_value
  no_matching_record? ? Result.none : Result.neutral
end

#helo_contextObject



43
44
45
# File 'lib/coppertone/request.rb', line 43

def helo_context
  MacroContext.new(helo_domain, ip_as_s, sender, helo_domain, options)
end

#mailfrom_contextObject



47
48
49
# File 'lib/coppertone/request.rb', line 47

def mailfrom_context
  MacroContext.new(nil, ip_as_s, sender, helo_domain, options)
end

#no_matching_record?Boolean

Returns:

  • (Boolean)


35
36
37
# File 'lib/coppertone/request.rb', line 35

def no_matching_record?
  helo_result.nil? && mailfrom_result.nil?
end

#process_heloObject



17
18
19
20
21
22
# File 'lib/coppertone/request.rb', line 17

def process_helo
  check_spf_for_helo
  return nil if helo_result&.none?

  helo_result
end

#process_mailfromObject



24
25
26
27
28
29
# File 'lib/coppertone/request.rb', line 24

def process_mailfrom
  check_spf_for_mailfrom
  return nil if mailfrom_result&.none?

  mailfrom_result
end

#request_contextObject



39
40
41
# File 'lib/coppertone/request.rb', line 39

def request_context
  @request_context ||= RequestContext.new(options)
end

#spf_record(macro_context) ⇒ Object



51
52
53
54
# File 'lib/coppertone/request.rb', line 51

def spf_record(macro_context)
  RecordFinder.new(request_context.dns_client,
                   macro_context.domain).record
end

#spf_request(macro_context, record, identity) ⇒ Object



56
57
58
59
60
61
62
# File 'lib/coppertone/request.rb', line 56

def spf_request(macro_context, record, identity)
  return Result.new(:none) if record.nil?

  r = RecordEvaluator.new(record).evaluate(macro_context, request_context)
  r.identity = identity
  r
end