Sha256: 9b8ae0fa6f7c3864f96bd97a5fabd5bc8214cf089d19b4afac026645c2575367

Contents?: true

Size: 810 Bytes

Versions: 17

Compression:

Stored size: 810 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(text)
      # Hide password in Net::IMAP debug output
      text.gsub(
        /\A(C: RUBY\d+ LOGIN \S+) \S+/,
        "\\1 [PASSWORD REDACTED]"
      )
    end
  end
end

Version data entries

17 entries across 17 versions & 1 rubygems

Version Path
imap-backup-9.1.1 lib/imap/backup/sanitizer.rb
imap-backup-9.1.0 lib/imap/backup/sanitizer.rb
imap-backup-9.0.2 lib/imap/backup/sanitizer.rb
imap-backup-9.0.1.rc1 lib/imap/backup/sanitizer.rb
imap-backup-9.0.0 lib/imap/backup/sanitizer.rb
imap-backup-9.0.0.rc1 lib/imap/backup/sanitizer.rb
imap-backup-8.0.2 lib/imap/backup/sanitizer.rb
imap-backup-8.0.1 lib/imap/backup/sanitizer.rb
imap-backup-8.0.0 lib/imap/backup/sanitizer.rb
imap-backup-8.0.0.rc1 lib/imap/backup/sanitizer.rb
imap-backup-7.0.2 lib/imap/backup/sanitizer.rb
imap-backup-7.0.0.rc1 lib/imap/backup/sanitizer.rb
imap-backup-6.3.0 lib/imap/backup/sanitizer.rb
imap-backup-6.2.1 lib/imap/backup/sanitizer.rb
imap-backup-6.1.0 lib/imap/backup/sanitizer.rb
imap-backup-6.0.1 lib/imap/backup/sanitizer.rb
imap-backup-6.0.0 lib/imap/backup/sanitizer.rb