#!/usr/bin/ruby # # outlook2qconfirm # This script is designed to take the exported address book from Outlook express # and create the files used by qconfirm in the "ok/" or "bad/" directories. The # contents of the exported Outlook address book is read on stdin, and the files # are created in the directory identified by the parameter. # # I use this to quickly import a list of good addresses into the qconfirm system # for a particular user. # # Usage: # outlook2qconfirm dir < INPUT_FILE # # Written by Sam Storie, 2007/05/02 # if ARGV[0].nil? then puts "Usage: #{$0} dir < input" exit(1) end target_dir = ARGV[0] if !File.stat(target_dir).directory? || !File.stat(target_dir).writable? then puts "Argument must be a writeable directory" exit(1) end ## For each line on stdin convert it to the format that qconfirm expects, and collect # all of them into an array, while removing the nil entries (which result from empty # lines) # files = $stdin.collect { |email| email.chomp! next unless email.length > 0 email.downcase! email.gsub!(/\.|\/|'/, ":") (name, domain) = email.split("@") file = "#{domain}=-#{name}" }.compact ## Now touch a file corresponding to each address we've processed # files.each { |file| File.new("#{target_dir}/#{file}", "w") }