#!/usr/bin/env ruby require 'net/smtp' def send(mail) unless(mail == '') mail.chomp! print '#' * 80 + ($c += 1).to_s + $/ + mail[0, 128], $/ + mail[-128, 128], $/ if(mail != '' and ARGV[4]) Net::SMTP.start(ARGV[1], 25) {|smtp| smtp.send_mail mail, ARGV[3], ARGV[2] sleep 1 } end end end raise 'Usage: import2gmail file host to_adr from_adr [exec]' unless(ARGV.length >= 4) $c = 0; ll = 1; mail = '' open(ARGV[0]) {|mails| mails.each_line {|line| if(ll and line =~ /^From\s/) send(mail) mail = '' elsif(line =~ /^$/) ll = 1 mail += line else ll = nil mail += line end } send(mail) }