Class Mail::IMAP
In: lib/mail/network/retriever_methods/imap.rb
Parent: Object

The IMAP retriever allows to get the last, first or all emails from a POP3 server. Each email retrieved (RFC2822) is given as an instance of Message.

While being retrieved, emails can be yielded if a block is given.

Example of retrieving Emails from GMail:

  Mail.defaults do
    retriever_method :imap, { :address             => "imap.googlemail.com",
                              :port                => 993,
                              :user_name           => '<username>',
                              :password            => '<password>',
                              :enable_ssl          => true }
  end

  Mail.all    #=> Returns an array of all emails
  Mail.first  #=> Returns the first unread email
  Mail.last   #=> Returns the first unread email

You can also pass options into Mail.find to locate an email in your imap mailbox with the following options:

  mailbox: name of the mailbox used for email retrieval. The default is 'INBOX'.
  what:    last or first emails. The default is :first.
  order:   order of emails returned. Possible values are :asc or :desc. Default value is :asc.
  count:   number of emails to retrieve. The default value is 10. A value of 1 returns an
           instance of Message, not an array of Message instances.

  Mail.find(:what => :first, :count => 10, :order => :asc)
  #=> Returns the first 10 emails in ascending order

Methods

all   connection   delete_all   find   first   last   new  

Attributes

settings  [RW] 

Public Class methods

Public Instance methods

Get all emails.

Possible options:

  mailbox: mailbox to retrieve all email(s) from. The default is 'INBOX'.
  count:   number of emails to retrieve. The default value is 1.
  order:   order of emails returned. Possible values are :asc or :desc. Default value is :asc.
  keys:    keywords for the imap SEARCH command. Can be either a string holding the entire
           search string or a single-dimension array of search keywords and arguments.

Returns the connection object of the retrievable (IMAP or POP3)

Delete all emails from a IMAP mailbox

Find emails in a POP3 mailbox. Without any options, the 10 last received emails are returned.

Possible options:

  mailbox: mailbox to search the email(s) in. The default is 'INBOX'.
  what:    last or first emails. The default is :first.
  order:   order of emails returned. Possible values are :asc or :desc. Default value is :asc.
  count:   number of emails to retrieve. The default value is 10. A value of 1 returns an
           instance of Message, not an array of Message instances.

Get the oldest received email(s)

Possible options:

  mailbox: mailbox to retrieve the oldest received email(s) from. The default is 'INBOX'.
  count:   number of emails to retrieve. The default value is 1.
  order:   order of emails returned. Possible values are :asc or :desc. Default value is :asc.
  keys:    keywords for the imap SEARCH command. Can be either a string holding the entire
           search string or a single-dimension array of search keywords and arguments.

Get the most recent received email(s)

Possible options:

  mailbox: mailbox to retrieve the most recent received email(s) from. The default is 'INBOX'.
  count:   number of emails to retrieve. The default value is 1.
  order:   order of emails returned. Possible values are :asc or :desc. Default value is :asc.
  keys:    keywords for the imap SEARCH command. Can be either a string holding the entire
           search string or a single-dimension array of search keywords and arguments.

[Validate]