Sha256: a342d3899f0bf5742df46b02d3cc05aef667f2d789e602c867f337647ad674f0

Contents?: true

Size: 1.35 KB

Versions: 2

Compression:

Stored size: 1.35 KB

Contents

require 'logger'


module Redimap
  
  def self.config
    @config ||= Redimap::Config.new
  end
  
  def self.configure
    yield self.config
    
    Redimap.logger.debug { "Configured #{Redimap.config.to_s}" }
  end
  
  def self.logger
    unless @logger
      @logger = Logger.new($stdout)
      
      @logger.level    = Logger.const_get(Redimap.config.log_level)
      @logger.progname = :Redimap
    end
    
    @logger
  end
  
  def self.queue_new_mailboxes_uids
    @logger = Redimap.logger
    
    @logger.info { "Queueing new mailboxes UIDs" }
    
    Redimap::ImapConn.new do |imap|
      Redimap::RedisConn.new do |redis|
        begin
          Redimap.config.imap_mailboxes.each do |mailbox|
            last_seen_uid = redis.get_mailbox_uid(mailbox)
            
            @logger.debug { "Last saw #{mailbox}##{last_seen_uid}" }
            
            unseen_uids = imap.read_mailbox(mailbox, last_seen_uid)
            
            unseen_uids.each do |uid|
              redis.queue_mailbox_uid(mailbox, uid)
              
              redis.set_mailbox_uid(mailbox, uid)
            end
            
            @logger.info { "Queued #{unseen_uids.count} UIDs from #{mailbox}" }
          end
        rescue Net::IMAP::Error, Redis::BaseError => e
          @logger.error { e.to_s }
          
          return
        end
      end
    end
  end
  
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
redimap-0.5.0 lib/redimap/base.rb
redimap-0.4.0 lib/redimap/base.rb