Class: Mail::IMAP
- Inherits:
-
Object
- Object
- Mail::IMAP
- Defined in:
- lib/mail/network/retriever_methods/imap.rb
Instance Attribute Summary collapse
-
#settings ⇒ Object
Returns the value of attribute settings.
Instance Method Summary collapse
- #first(options = {}, &block) ⇒ Object
-
#initialize(values) ⇒ IMAP
constructor
A new instance of IMAP.
Constructor Details
#initialize(values) ⇒ IMAP
Returns a new instance of IMAP.
7 8 9 10 11 12 13 14 |
# File 'lib/mail/network/retriever_methods/imap.rb', line 7 def initialize(values) self.settings = { :address => "localhost", :port => 110, :user_name => nil, :password => nil, :authentication => nil, :enable_ssl => false }.merge!(values) end |
Instance Attribute Details
#settings ⇒ Object
Returns the value of attribute settings.
16 17 18 |
# File 'lib/mail/network/retriever_methods/imap.rb', line 16 def settings @settings end |
Instance Method Details
#first(options = {}, &block) ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/mail/network/retriever_methods/imap.rb', line 18 def first( = {}, &block) imap = Net::IMAP.new(settings[:address], settings[:port], settings[:enable_ssl]) imap.login(settings[:user_name], settings[:password]) imap.examine('INBOX') uids = imap.uid_search('ALL') uids = uids[0,[:count]] if [:count] uids.each do || fetch_data = imap.uid_fetch(, ['BODY.PEEK[HEADER]']) fetch_data.each{|fd| yield Mail.new(fd.attr['BODY[HEADER]'])} end end |