Sha256: 67b796fcb1a86a69814656eaea5c9f739b350d994ef95f04b2ca8d3ba6312ff2

Contents?: true

Size: 1.14 KB

Versions: 4

Compression:

Stored size: 1.14 KB

Contents

module Gmail
  class Labels
    include Enumerable
    attr_reader :connection
    alias :conn :connection
     
    def initialize(connection)
      @connection = connection
    end
    
    # Get list of all defined labels.
    def all
      (conn.list("", "%")+conn.list("[Gmail]/", "%")).inject([]) do |labels,label|
        label[:name].each_line {|l| labels << Net::IMAP.decode_utf7(l) }
        labels 
      end
    end
    alias :list :all
    alias :to_a :all

    def each(*args, &block)
      all.each(*args, &block)
    end
    
    # Returns +true+ when given label defined. 
    def exists?(label)
      all.include?(Net::IMAP.encode_utf7(label))
    end
    alias :exist? :exists?
    
    # Creates given label in your account.
    def create(label)
      !!conn.create(Net::IMAP.encode_utf7(label)) rescue false
    end
    alias :new :create
    alias :add :create
    
    # Deletes given label from your account. 
    def delete(label)
      !!conn.delete(Net::IMAP.encode_utf7(label)) rescue false
    end
    alias :remove :delete
    
    def inspect
      "#<Gmail::Labels#{'0x%04x' % (object_id << 1)}>"
    end
  end # Labels
end # Gmail

Version data entries

4 entries across 4 versions & 2 rubygems

Version Path
gmail-0.4.0 lib/gmail/labels.rb
gmail_oauth-0.1.3 lib/gmail/labels.rb
gmail_oauth-0.1.2 lib/gmail/labels.rb
gmail_oauth-0.1.1 lib/gmail/labels.rb