Sha256: 54102d3d1b6f654c8cdb50da0f41a7493128f160ac184aee22aa967d928dfa46

Contents?: true

Size: 766 Bytes

Versions: 1

Compression:

Stored size: 766 Bytes

Contents

module Imap::Backup
  class Serializer; end

  class Serializer::MboxEnumerator
    attr_reader :mbox_pathname

    def initialize(mbox_pathname)
      @mbox_pathname = mbox_pathname
    end

    def each(&block)
      return enum_for(:each) if !block

      File.open(mbox_pathname, "rb") do |f|
        lines = []

        loop do
          line = f.gets
          break if !line

          if line.start_with?("From ")
            yield lines.join if lines.count.positive?
            lines = [line]
          else
            lines << line
          end
        end

        block.call(lines.join) if lines.count.positive?
      end
    end

    def map(&block)
      return enum_for(:map) if !block

      each.map { |line| block.call(line) }
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
imap-backup-7.0.0.rc1 lib/imap/backup/serializer/mbox_enumerator.rb