Class Larch::IMAP
In: lib/larch/errors.rb
lib/larch/imap/mailbox.rb
lib/larch/imap.rb
Parent: Object

Manages a connection to an IMAP server and all the glorious fun that entails.

This class borrows heavily from Sup, the source code of which should be required reading if you‘re doing anything with IMAP in Ruby: sup.rubyforge.org

Methods

connect   delim   disconnect   each_mailbox   host   mailbox   new   noop   password   port   safely   ssl?   uri   uri_mailbox   username  

Classes and Modules

Class Larch::IMAP::Error
Class Larch::IMAP::FatalError
Class Larch::IMAP::Mailbox
Class Larch::IMAP::MailboxNotFoundError
Class Larch::IMAP::MessageNotFoundError

Constants

REGEX_URI = URI.regexp(['imap', 'imaps'])   URI format validation regex.
Message = Struct.new(:guid, :envelope, :rfc822, :flags, :internaldate)   Larch::IMAP::Message represents a transferable IMAP message which can be passed between Larch::IMAP instances.

Attributes

conn  [R] 
db_account  [R] 
mailboxes  [R] 
options  [R] 
quirks  [R] 

Public Class methods

Initializes a new Larch::IMAP instance that will connect to the specified IMAP URI.

In addition to the URI, the following options may be specified:

:create_mailbox
If true, mailboxes that don‘t already exist will be created if necessary.
:dry_run
If true, read-only operations will be performed as usual and all change operations will be simulated, but no changes will actually be made. Note that it‘s not actually possible to simulate mailbox creation, so +:dry_run+ mode always behaves as if +:create_mailbox+ is false.
:log_label
Label to use for this connection in log output. If not specified, the default label is "[username@host]".
:max_retries
After a recoverable error occurs, retry the operation up to this many times. Default is 3.
:ssl_certs
Path to a trusted certificate bundle to use to verify server SSL certificates. You can download a bundle of certificate authority root certs at curl.haxx.se/ca/cacert.pem (it‘s up to you to verify that this bundle hasn‘t been tampered with, however; don‘t trust it blindly).
:ssl_verify
If true, server SSL certificates will be verified against the trusted certificate bundle specified in ssl_certs. By default, server SSL certificates are not verified.

Public Instance methods

Connects to the IMAP server and logs in if a connection hasn‘t already been established.

Gets the server‘s mailbox hierarchy delimiter.

Closes the IMAP connection if one is currently open.

Iterates through all mailboxes in the account, yielding each one as a Larch::IMAP::Mailbox instance to the given block.

Gets the IMAP hostname.

Gets a Larch::IMAP::Mailbox instance representing the specified mailbox. If the mailbox doesn‘t exist and the :create_mailbox option is false, or if :create_mailbox is true and mailbox creation fails, a Larch::IMAP::MailboxNotFoundError will be raised.

Sends an IMAP NOOP command.

Gets the IMAP port number.

Connect if necessary, execute the given block, retry if a recoverable error occurs, die if an unrecoverable error occurs.

Gets the SSL status.

Gets the IMAP URI.

Gets the IMAP mailbox specified in the URI, or nil if none.

[Validate]