Class: UnfuddleMyEmail::Fetcher
- Inherits:
-
Object
- Object
- UnfuddleMyEmail::Fetcher
- Includes:
- Enumerable
- Defined in:
- lib/unfuddle_my_email/fetcher.rb
Overview
Fetcher iterates through all emails in the given POP3 mailbox and yields each one, optionally deleting the message after yield. The message yielded is an instance of TmailAdapter.
Example:
fetch = Fetcher.new('pop.example.com',995,true,'username','password',false)
fetcher.each do ||
puts .subject
end
# Enumerable is included so you can use those features (except for sort,min,max) as well:
fetcher.to_a # => [#<TmailAdapter instance>]
Instance Method Summary collapse
- #each ⇒ Object
-
#initialize(server, port, ssl, username, password, delete = false) ⇒ Fetcher
constructor
A new instance of Fetcher.
Constructor Details
#initialize(server, port, ssl, username, password, delete = false) ⇒ Fetcher
18 19 20 21 22 23 24 25 |
# File 'lib/unfuddle_my_email/fetcher.rb', line 18 def initialize(server, port, ssl, username, password, delete=false) @pop3_server = server @pop3_port = port @pop3_ssl = ssl @pop3_username = username @pop3_password = password @pop3_delete = delete end |
Instance Method Details
#each ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/unfuddle_my_email/fetcher.rb', line 27 def each if @pop3_ssl Net::POP3.enable_ssl(OpenSSL::SSL::VERIFY_NONE) end Net::POP3.start(@pop3_server, @pop3_port, @pop3_username, @pop3_password) do |pop| pop.each_mail { || mail_item = TmailAdapter.new(.pop) yield mail_item .delete if @pop3_delete } end end |