class Luggage::Mailbox
Attributes
Public Class Methods
# 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
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
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
Deletes this mailbox on the remote server
# File lib/luggage/mailbox.rb, line 57 def delete! connection.delete(name) @exists = false end
Iterates over Mailbox#each
# File lib/luggage/mailbox.rb, line 99 def each(&block) all.each(&block) end
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
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
Returns a Message
instance describing the first email on the remote mailbox
# File lib/luggage/mailbox.rb, line 93 def first all.first end
# File lib/luggage/mailbox.rb, line 115 def host connection.instance_variable_get(:@host) end
# File lib/luggage/mailbox.rb, line 111 def inspect "#<Luggage::Mailbox server: \"#{host}\", name: \"#{name}\">" end
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
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
Selects this mailbox for future Imap commands.
# File lib/luggage/mailbox.rb, line 64 def select! connection.select(name) end
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