Sha256: cb03ebb2308b561d2088adc3acd035b3947617b4feb03bd682ff79ffab26a147

Contents?: true

Size: 891 Bytes

Versions: 4

Compression:

Stored size: 891 Bytes

Contents

module Luggage
  class MailboxArray
    attr_reader :connection

    def initialize(connection)
      @connection = connection
    end

    def [](*args, &block)
      mailbox_name = Luggage::Mailbox.convert_mailbox_name(args.first)

      if mailbox_name
        mailbox(mailbox_name, &block)
      else
        super
      end
    end

    def method_missing(meth, *args, &block)
      mailboxes.send(meth, *args, &block)
    end

    def inspect
      mailboxes.inspect
    end

    def host
      connection.instance_variable_get(:@host)
    end

    private

    # Cosntructs a Mailbox
    #
    # `name` should be a string describing the Imap mailbox's name
    #
    def mailbox(name, &block)
      Mailbox.new(connection, name, &block)
    end

    def mailboxes
      connection.list("", "*").map do |result|
        Mailbox.new(connection, result.name)
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
luggage-1.2.3 lib/luggage/mailbox_array.rb
luggage-1.2.2 lib/luggage/mailbox_array.rb
luggage-1.2.1 lib/luggage/mailbox_array.rb
luggage-1.2.0 lib/luggage/mailbox_array.rb