Sha256: 216fef9ebeefc7604e2023805f449fb8a9e7388a8d8b0ac9254a6261e1b63ca1

Contents?: true

Size: 771 Bytes

Versions: 5

Compression:

Stored size: 771 Bytes

Contents

module Imap::Backup
  class Downloader
    attr_reader :folder
    attr_reader :serializer

    def initialize(folder, serializer)
      @folder = folder
      @serializer = serializer
    end

    def run
      uids = folder.uids - serializer.uids
      count = uids.count
      Imap::Backup.logger.debug "[#{folder.name}] #{count} new messages"
      uids.each.with_index do |uid, i|
        body = folder.fetch(uid)
        log_prefix = "[#{folder.name}] uid: #{uid} (#{i + 1}/#{count}) -"
        if body.nil?
          Imap::Backup.logger.debug("#{log_prefix} not available - skipped")
          next
        end
        Imap::Backup.logger.debug(
          "#{log_prefix} #{body.size} bytes"
        )
        serializer.save(uid, body)
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
imap-backup-4.0.7 lib/imap/backup/downloader.rb
imap-backup-4.0.6 lib/imap/backup/downloader.rb
imap-backup-4.0.5 lib/imap/backup/downloader.rb
imap-backup-4.0.4 lib/imap/backup/downloader.rb
imap-backup-4.0.3 lib/imap/backup/downloader.rb