Sha256: 7111b086fb3ea205aea83c5c00c7a018efe4797b6d23fe5b1408ba6387b47eb5

Contents?: true

Size: 803 Bytes

Versions: 4

Compression:

Stored size: 803 Bytes

Contents

require "forwardable"

module Imap::Backup
  class Sanitizer
    extend Forwardable

    attr_reader :output

    delegate puts: :output
    delegate write: :output

    def initialize(output)
      @output = output
      @current = ""
    end

    def print(*args)
      @current << args.join
      loop do
        line, newline, rest = @current.partition("\n")
        break if newline != "\n"
        clean = sanitize(line)
        output.puts clean
        @current = rest
      end
    end

    def flush
      return if @current == ""

      clean = sanitize(@current)
      output.puts clean
    end

    private

    def sanitize(t)
      # Hide password in Net::IMAP debug output
      t.gsub(
        /\A(C: RUBY\d+ LOGIN \S+) \S+/,
        "\\1 [PASSWORD REDACTED]"
      )
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
imap-backup-6.0.0.rc2 lib/imap/backup/sanitizer.rb
imap-backup-5.2.0 lib/imap/backup/sanitizer.rb
imap-backup-5.1.0 lib/imap/backup/sanitizer.rb
imap-backup-5.0.0 lib/imap/backup/sanitizer.rb