class Luggage::Factory
Attributes
Public Class Methods
Factories require an instance of Net::IMAP. Serveral methods are supported:
Factory.new
(:connection => connection) In this case, `connection` should be an authorized Net::IMAP instance.
Factory.new
(:server => “imap.gmail.com”, :xoauth => [token, string]) In this case we'll build a Net::IMAP instance and attempt to send a raw XOAUTH authentication request using the supplied token.
Factory.new
(:server => 'imap.example.com', :login => [username, password]) In this case, we'll build a Net::IMAP instance and use the `#login` method to authenticate. This isn't the same as using 'LOGIN' as the auth method in the next example.
Factory.new
(:server => “imap.example.com”, :authentication => [some_auth_method, appropriate, arguments]) In this case, we'll build a Net::IMAP instance and attempt to authenticate with the value of `:authentication` by calling `Net::IMAP#authenticate`.
# File lib/luggage/factory.rb, line 24 def initialize(args = {}, &block) if args.has_key?(:connection) @connection = args[:connection] elsif args.has_key?(:server) && args.has_key?(:xoauth) @connection = Net::IMAP.new(*Array(args[:server])) @connection.send(:send_command, "AUTHENTICATE XOAUTH #{Array(args[:xoauth]).join(' ')}") elsif args.has_key?(:server) && args.has_key?(:login) @connection = Net::IMAP.new(*Array(args[:server])) @connection.login(*Array(args[:login])) elsif args.has_key?(:server) && args.has_key?(:authenticate) @connection = Net::IMAP.new(*Array(args[:server])) @connection.authenticate(*Array(args[:authenticate])) else raise ArgumentError, 'Imap Connection required.' end instance_eval &block if block_given? end
Public Instance Methods
# File lib/luggage/factory.rb, line 69 def host connection.instance_variable_get(:@host) end
# File lib/luggage/factory.rb, line 65 def inspect "#<Luggage::Factory server: \"#{host}\">" end
# File lib/luggage/factory.rb, line 60 def mailboxes(*args, &block) array = MailboxArray.new(connection) args.empty? ? array : array[*args, &block] end
Constructs an Message
`mailbox` can be either a string describing the Imap mailbox the message belongs to or an instance of Mailbox
.
`args` will be passed to ImapFactorY::Message#new_local - see that method for details
# File lib/luggage/factory.rb, line 56 def message(mailbox, args = {}, &block) Message.new_local(connection, mailbox, args, &block) end