Sha256: 069ef14a8edbf508bff4cf7814936a904d6b1943246ca1dca7e7c4a2f653021e

Contents?: true

Size: 1.1 KB

Versions: 2

Compression:

Stored size: 1.1 KB

Contents

require 'net/imap'


module Ryespy
  module Listener
    class IMAP
      
      def initialize
        begin
          @imap = Net::IMAP.new(Ryespy.config.imap_host, {
            :port => Ryespy.config.imap_port,
            :ssl  => Ryespy.config.imap_ssl,
          })
          
          @imap.login(Ryespy.config.imap_username, Ryespy.config.imap_password)
        rescue Errno::ECONNREFUSED, Net::IMAP::Error => e
          Ryespy.logger.error { e.to_s }
          
          return
        end
        
        if block_given?
          yield self
          
          close
        end
      end
      
      def close
        @imap.logout
        
        @imap.disconnect
      end
      
      def check(params)
        begin
          @imap.select(params[:mailbox])
          
          uids = @imap.uid_search("#{params[:last_seen_uid] + 1}:*")
          
          uids.find_all { |uid| uid > params[:last_seen_uid] } # IMAP search gets fun with edge cases
        rescue Net::IMAP::Error => e
          Ryespy.logger.error { e.to_s }
          
          return
        end
      end
      
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
ryespy-0.6.1 lib/ryespy/listeners/imap.rb
ryespy-0.6.0 lib/ryespy/listeners/imap.rb