Class: Postman::Fetcher
- Inherits:
-
Object
- Object
- Postman::Fetcher
- Defined in:
- lib/postman/fetcher.rb
Instance Attribute Summary collapse
-
#process_count ⇒ Object
Returns the value of attribute process_count.
Instance Method Summary collapse
- #fetch ⇒ Object
- #inbox_size ⇒ Object
-
#initialize(config) ⇒ Fetcher
constructor
A new instance of Fetcher.
Constructor Details
#initialize(config) ⇒ Fetcher
Returns a new instance of Fetcher.
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/postman/fetcher.rb', line 6 def initialize(config) @username = config['username'] @password = config['password'] @pop_host = config['pop_host'] @pop_port = config['pop_port'] @pop_ssl = config['pop_ssl'] @working_dir = config['working_dir'] @logger = Logger.new(config['log']) @process_count = 0 @inbox_dir = "#{@working_dir}/inbox" FileUtils.mkdir_p("#{@inbox_dir}") @logger.info "Fetcher starting: [username: #{@username}] [pop_host: #{@pop_host}] [working_dir: #{@working_dir}]" end |
Instance Attribute Details
#process_count ⇒ Object
Returns the value of attribute process_count.
4 5 6 |
# File 'lib/postman/fetcher.rb', line 4 def process_count @process_count end |
Instance Method Details
#fetch ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/postman/fetcher.rb', line 27 def fetch download_count = 0 Net::POP3.enable_ssl(OpenSSL::SSL::VERIFY_NONE) if @pop_ssl Net::POP3.start(@pop_host, @pop_port, @username, @password) do |pop| unless pop.mails.empty? pop.each_mail do |mail| File.open("#{inbox_dir}/#{mail.unique_id}", 'w') do |f| f.write mail.pop end download_count += 1 @process_count += 1 end end end download_count end |
#inbox_size ⇒ Object
23 24 25 |
# File 'lib/postman/fetcher.rb', line 23 def inbox_size Dir.glob("#{@inbox_dir}/*").size end |