<commit_before>require 'drb'
#require File.expand_path("../gmail", __FILE__)
require 'yaml'
require 'mail'
require 'net/imap'
require 'time'


class String
  def col(width)
    self[0,width].ljust(width)
  end
end


class GmailServer
  def initialize(config)
    @username, @password = config['login'], config['password']
  end

  def open
    @imap = Net::IMAP.new('imap.gmail.com', 993, true, nil, false)
    @imap.login(@username, @password)
  end

  def close
    @imap.close rescue Net::IMAP::BadResponseError
    @imap.disconnect
  end

  def select_mailbox(mailbox)
    puts "selecting mailbox #{mailbox}"
    @imap.select(mailbox)
    return "OK"
  end

  def search(num_messages, query)
    all_uids = @imap.uid_search(query)
    uids = all_uids[-([num_messages.to_i, all_uids.size].min)..-1] || []

    lines = []
    threads = []
    uids.each do |uid|
<commit_msg>select mailbox only if necessary<commit_after>require 'drb'
#require File.expand_path("../gmail", __FILE__)
require 'yaml'
require 'mail'
require 'net/imap'
require 'time'


class String
  def col(width)
    self[0,width].ljust(width)
  end
end


class GmailServer
  def initialize(config)
    @username, @password = config['login'], config['password']
    @mailbox = nil
  end

  def open
    @imap = Net::IMAP.new('imap.gmail.com', 993, true, nil, false)
    @imap.login(@username, @password)
  end

  def close
    @imap.close rescue Net::IMAP::BadResponseError
    @imap.disconnect
  end

  def select_mailbox(mailbox)
    if mailbox == @mailbox 
      return
    end
    puts "selecting mailbox #{mailbox}"
    @imap.select(mailbox)
    @mailbox = mailbox
    return "OK"
  end

  def search(num_messages, query)
    all_uids = @imap.uid_search(query)
    uids = all_uids[-([num_messages.to_i, all_uids.size].min)..-1] || []

    lines = []
    threads = []
    uids.each do |uid|

{'fraction_non_alphanumeric': 0.13909774436090225, 'fraction_numerical': 0.0053705692803437165, 'mean_word_length': 3.4569377990430623, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 1, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5407696', 'n_tokens_mistral': 691, 'n_tokens_neox': 673, 'n_words': 153}