<commit_before># -*- coding: utf-8 -*-

require 'net/pop'

include MailProcessor

module MailProcessor

  class Pop3 < Base
    def initialize options = {}, &block
      @attributes = {
        :address => "pop.gmail.com",
        :port => 110, # 995,
        :username => nil,
        :password => <PASSWORD>,
        # Must have ruby 1.9 to use this
        :use_ssl => false, # true 
      }
      merge_to_attributes(options)

      instance_eval &block if block_given?
      self
    end


    def address v = nil
      if v
        @attributes[:address] = v
      else
        @attributes[:address]
      end
    end


    def port v = nil
      if v
        @attributes[:port] = v
      else
        @attributes[:port]
      end
    end


    def username v = nil
      if v
        @attributes[:username] = v
      else
        @attributes[:username]
      end
    end


    def password v = nil
      if v
        @attributes[:password] = v
      else
        @attributes[:password]
      end
    end


    def use_ssl?
      @attributes[:use_ssl]
    end


    def use_ssl v = nil
      if v
        @attributes[:use_ssl] = v
      else
        @attributes[:use_ssl]
      end
    end


    def process(options = {}, &block)
      a = @attributes.merge(options)

      didWork = false
      Net::POP3.enable_ssl(OpenSSL::SSL::VERIFY_NONE) if a[:use_ssl]
      pop = Net::POP3.new(a[:address], a[:port])
      pop.start(a[:username], a[:password])
      if pop.mails.empty?
        log.info 'No mail.'
      else
        pop.each_mail do |m|
          yield m.pop
          m.delete
        end
        log.info "Processed #{pop.mails.size} mails."
        pop.finish
        didWork = true
      end

      didWork
    end
  end
end<commit_msg>Got connection timeout exepction - should probably finish pop even if no mails<commit_after># -*- coding: utf-8 -*-

require 'net/pop'

include MailProcessor

module MailProcessor

  class Pop3 < Base
    def initialize options = {}, &block
      @attributes = {
        :address => "pop.gmail.com",
        :port => 110, # 995,
        :username => nil,
        :password => <PASSWORD>,
        # Must have ruby 1.9 to use this
        :use_ssl => false, # true 
      }
      merge_to_attributes(options)

      instance_eval &block if block_given?
      self
    end


    def address v = nil
      if v
        @attributes[:address] = v
      else
        @attributes[:address]
      end
    end


    def port v = nil
      if v
        @attributes[:port] = v
      else
        @attributes[:port]
      end
    end


    def username v = nil
      if v
        @attributes[:username] = v
      else
        @attributes[:username]
      end
    end


    def password v = nil
      if v
        @attributes[:password] = v
      else
        @attributes[:password]
      end
    end


    def use_ssl?
      @attributes[:use_ssl]
    end


    def use_ssl v = nil
      if v
        @attributes[:use_ssl] = v
      else
        @attributes[:use_ssl]
      end
    end


    def process(options = {}, &block)
      a = @attributes.merge(options)

      didWork = false
      Net::POP3.enable_ssl(OpenSSL::SSL::VERIFY_NONE) if a[:use_ssl]
      pop = Net::POP3.new(a[:address], a[:port])
      pop.start(a[:username], a[:password])
      if pop.mails.empty?
        log.info 'No mail.'
      else
        pop.each_mail do |m|
          yield m.pop
          m.delete
        end
        log.info "Processed #{pop.mails.size} mails."
        didWork = true
      end
      pop.finish

      didWork
    end
  end
end
{'fraction_non_alphanumeric': 0.1044525343041165, 'fraction_numerical': 0.006720806496779613, 'mean_word_length': 1.645925925925926, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4196787', 'n_tokens_mistral': 1145, 'n_tokens_neox': 1085, 'n_words': 304}