class Luggage::Mailbox

Attributes

connection[R]
name[R]

Public Class Methods

convert_mailbox_name(mailbox_name) click to toggle source
# File lib/luggage/mailbox.rb, line 7
def self.convert_mailbox_name(mailbox_name)
  case mailbox_name
  when :g_all
    "[Gmail]/All Mail"
  when :g_sent
    "[Gmail]/Sent"
  when :g_trash
    "[Gmail]/Trash"
  when :inbox, :spam, :sent, :trash
    mailbox_name.to_s.upcase
  when Symbol
    mailbox_name.to_s
  when String
    mailbox_name
  else
    nil
  end
end
new(connection, name, &block) click to toggle source

This provides an interface to a remote Imap mailbox

`connection` should be an authenticated Net::IMAP

`name` is the name of the remote mailbox

# File lib/luggage/mailbox.rb, line 32
def initialize(connection, name, &block)
  @connection = connection
  @name = name

  instance_eval &block if block_given?
end

Public Instance Methods

all() click to toggle source

Returns an array of Message instances describing all emails in the remote mailbox

# File lib/luggage/mailbox.rb, line 87
def all
  MailboxQueryBuilder.new(self)
end
delete!() click to toggle source

Deletes this mailbox on the remote server

# File lib/luggage/mailbox.rb, line 57
def delete!
  connection.delete(name)
  @exists = false
end
each(&block) click to toggle source

Iterates over Mailbox#each

# File lib/luggage/mailbox.rb, line 99
def each(&block)
  all.each(&block)
end
exists?() click to toggle source

Returns true if this mailbox exists on the remote server, false otherwise

# File lib/luggage/mailbox.rb, line 49
def exists?
  return @exists if instance_variable_defined?(:@exists)

  @exists = !connection.list("", name).nil?
end
expunge!() click to toggle source

Removes 'deleted' messages on the remote server. Message#delete! marks messages with the 'Deleted' flag, but leaves them on the server. This removes them entirely

# File lib/luggage/mailbox.rb, line 80
def expunge!
  select!
  connection.expunge()
end
first() click to toggle source

Returns a Message instance describing the first email on the remote mailbox

# File lib/luggage/mailbox.rb, line 93
def first
  all.first
end
host() click to toggle source
# File lib/luggage/mailbox.rb, line 115
def host
  connection.instance_variable_get(:@host)
end
inspect() click to toggle source
# File lib/luggage/mailbox.rb, line 111
def inspect
  "#<Luggage::Mailbox server: \"#{host}\", name: \"#{name}\">"
end
message(args = {}, &block) click to toggle source

Constructs an Message whose mailbox will be set to this instance

`args` will be passed to ImapFactorY::Message#new_local - see that method for details

# File lib/luggage/mailbox.rb, line 43
def message(args = {}, &block)
  Message.new_local(connection, self, args, &block)
end
save!() click to toggle source

Creates the mailbox on the remote server if it doesn't exist already

# File lib/luggage/mailbox.rb, line 70
def save!
  unless exists?
    connection.create(name)
  end
end
select!() click to toggle source

Selects this mailbox for future Imap commands.

# File lib/luggage/mailbox.rb, line 64
def select!
   connection.select(name)
end
where(*args) click to toggle source

Filters emails on the remote server

Returns a MailboxQueryBuilder - see MailboxQueryBuilder#where for usage details

# File lib/luggage/mailbox.rb, line 107
def where(*args)
  all.where(*args)
end