module Sisimai::RFC1894
Sisimai::RFC1894
DSN field defined in RFC3464
(obsoletes RFC1894
)
Constants
- CapturesOn
- Correction
- FieldGroup
- FieldNames
Public Class Methods
FIELDTABLE()
click to toggle source
Table to be converted to key name defined in Sisimai::Lhost
class @param [Symbol] group RFC822 Header group name @return [Array,Hash] RFC822 Header list
# File lib/sisimai/rfc1894.rb, line 67 def FIELDTABLE return { 'action' => 'action', 'arrival-date' => 'date', 'diagnostic-code' => 'diagnosis', 'final-recipient' => 'recipient', 'last-attempt-date' => 'date', 'original-recipient' => 'alias', 'received-from-mta' => 'lhost', 'remote-mta' => 'rhost', 'reporting-mta' => 'rhost', 'status' => 'status', 'x-actual-recipient' => 'alias', } end
field(argv0 = '')
click to toggle source
Check the argument is including field defined in RFC3464
and return values @param [String] argv0 A line inlcuding field and value defined in RFC3464
@return [Array] ['field-name', 'value-type', 'Value', 'field-group'] @since v4.25.0
# File lib/sisimai/rfc1894.rb, line 98 def field(argv0 = '') return nil if argv0.empty? group = FieldGroup[argv0.split(':',2).shift.downcase] || '' return nil if group.empty? return nil unless CapturesOn[group] table = ['', '', '', ''] match = false while cv = argv0.match(CapturesOn[group]) # Try to match with each pattern of Per-Message field, Per-Recipient field # - 0: Field-Name # - 1: Sub Type: RFC822, DNS, X-Unix, and so on) # - 2: Value # - 3: Field Group(addr, code, date, host, stat, text) match = true table[0] = cv[1].downcase table[3] = group if group == 'addr' || group == 'code' || group == 'host' # - Final-Recipient: RFC822; kijitora@nyaan.jp # - Diagnostic-Code: SMTP; 550 5.1.1 <kijitora@example.jp>... User Unknown # - Remote-MTA: DNS; mx.example.jp table[1] = cv[2].upcase table[2] = group == 'host' ? cv[3].downcase : cv[3] table[2] = '' if table[2] =~ /\A\s+\z/ # Remote-MTA: dns; else # - Action: failed # - Status: 5.2.2 table[1] = '' table[2] = group == 'date' ? cv[2] : cv[2].downcase # Correct invalid value in Action field: break unless group == 'list' break unless Correction[:action][table[2]] table[2] = Correction[:action][table[2]] end break end return nil unless match return table end
match(argv0 = '')
click to toggle source
Check the argument matches with a field defined in RFC3464
@param [String] argv0 A line inlcuding field and value defined in RFC3464
@return [Integer] 0: did not matched, 1,2: matched @since v4.25.0
# File lib/sisimai/rfc1894.rb, line 87 def match(argv0 = '') return nil if argv0.empty? return 1 if FieldNames[0].any? { |a| argv0.start_with?(a) } return 2 if FieldNames[1].any? { |a| argv0.start_with?(a) } return nil end