Class: EasyIMAP::Server
- Inherits:
-
Object
- Object
- EasyIMAP::Server
- Defined in:
- lib/easy_imap/server.rb
Overview
A connection to an IMAP server.
Class Method Summary collapse
-
.connect(host, options = nil) ⇒ Object
Makes a connection to
host
and returns an instance of Server.
Instance Method Summary collapse
-
#close ⇒ Object
Closes the connection to the IMAP server.
-
#folders ⇒ Object
Returns an array of Folder instances, one for each root level folder on the server.
-
#initialize(host, options = nil) ⇒ Server
constructor
A new instance of Server.
Constructor Details
#initialize(host, options = nil) ⇒ Server
Returns a new instance of Server.
36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/easy_imap/server.rb', line 36 def initialize(host, = nil) ||= {} @host = host @conn = Net::IMAP.new(host, [:port] || 143, [:use_ssl] || false) if [:auth_type].to_s.downcase == "plain" @conn.login([:username], [:password]) else @conn.authenticate([:auth_type] || "LOGIN", [:username], [:password]) end end |
Class Method Details
.connect(host, options = nil) ⇒ Object
Makes a connection to host
and returns an instance of Server.
It is recommended that you use this method to connect instead of Server#new, because at some time in the future there may be multiple server classes to smooth over “quirks” in IMAP implementations. This method should automatically select the right server class for you.
If given a block it will yield the Server instance to the block, and then close the connection to the IMAP server after the block has finished. Otherwise you must close the connection yourself.
Valid options are:
- port
-
the server port on which to connect (defaults to 143)
- username
-
the username with which to connect
- password
-
the password with which to connect
- auth_type
-
the authentication type with which to connect (defaults to LOGIN)
- use_ssl
-
if true, then use SSL to connect (defaults to false).
25 26 27 28 29 30 31 32 33 34 |
# File 'lib/easy_imap/server.rb', line 25 def self.connect(host, = nil) conn = Server.new(host, ) if block_given? begin yield conn ensure conn.close end end end |
Instance Method Details
#close ⇒ Object
Closes the connection to the IMAP server.
57 58 59 |
# File 'lib/easy_imap/server.rb', line 57 def close @conn.disconnect end |