Module: BIMI

Defined in:
lib/bimi.rb,
lib/bimi/version.rb

Defined Under Namespace

Classes: Error

Constant Summary collapse

SPINNER =
%w[         ].freeze
STEPS =
[
  "Looking up DMARC policy",
  "Resolving default._bimi TXT record",
  "Fetching SVG Tiny PS logo",
  "Validating VMC certificate chain",
  "Verifying mark ownership",
  "Polishing your brand indicator"
].freeze
RAINBOW =
[196, 208, 220, 190, 82, 51, 63, 129, 201].freeze
VERSION =
"0.1.0"

Class Method Summary collapse

Class Method Details

._banner(out) ⇒ Object



37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/bimi.rb', line 37

def self._banner(out)
  letters = %w[B I M I]
  8.times do |frame|
    out.print("\r")
    letters.each_with_index do |ch, i|
      color = RAINBOW[(frame + i * 2) % RAINBOW.length]
      out.print("\e[38;5;#{color};1m #{ch} ")
    end
    out.print("\e[0m")
    sleep(0.08)
  end
  out.puts("\e[0m  brand indicators for message identification\n\n")
end

._run_steps(domain, out) ⇒ Object



51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/bimi.rb', line 51

def self._run_steps(domain, out)
  STEPS.each_with_index do |step, idx|
    label = "#{step} for \e[1m#{domain}\e[0m"
    frames = 12 + rand(8)
    frames.times do |f|
      color = RAINBOW[(f + idx) % RAINBOW.length]
      out.print("\r\e[38;5;#{color}m#{SPINNER[f % SPINNER.length]}\e[0m  #{label}\e[K")
      sleep(0.05)
    end
    out.puts("\r\e[32m✓\e[0m  #{label}\e[K")
  end
  out.puts
end

._static(domain, out) ⇒ Object



82
83
84
85
86
# File 'lib/bimi.rb', line 82

def self._static(domain, out)
  out.puts("BIMI check for #{domain}")
  STEPS.each { |s| out.puts("  ok  #{s}") }
  out.puts("BIMI looks good for #{domain}!")
end

._victory(domain, out) ⇒ Object



65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
# File 'lib/bimi.rb', line 65

def self._victory(domain, out)
  msg = "  BIMI looks good for #{domain}!  "
  bar = "" * msg.length
  out.puts("\e[38;5;82m╔#{bar}╗\e[0m")
  8.times do |frame|
    tinted = msg.each_char.with_index.map do |ch, i|
      color = RAINBOW[(frame + i) % RAINBOW.length]
      "\e[38;5;#{color};1m#{ch}"
    end.join
    out.print("\e[38;5;82m║\e[0m#{tinted}\e[0m\e[38;5;82m║\e[0m\r")
    sleep(0.1)
  end
  out.puts
  out.puts("\e[38;5;82m╚#{bar}╝\e[0m")
  out.puts("\n  \e[2mpreview release — real record, SVG, and VMC checks land in a future version\e[0m\n\n")
end

.check(domain = "yourdomain.example") ⇒ Object



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/bimi.rb', line 21

def self.check(domain = "yourdomain.example")
  out = $stdout
  return _static(domain, out) unless out.tty?

  out.sync = true
  out.print("\e[?25l")
  begin
    _banner(out)
    _run_steps(domain, out)
    _victory(domain, out)
  ensure
    out.print("\e[?25h")
  end
  true
end