Skip to content

Instantly share code, notes, and snippets.

@yosshi
Forked from naoto/irc2mail.rb
Created January 26, 2010 05:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yosshi/286582 to your computer and use it in GitHub Desktop.
Save yosshi/286582 to your computer and use it in GitHub Desktop.
#!/usr/local/bin/ruby
#
require 'sendgmail.rb'
require 'yaml'
@LOG_DIR = "/path/to/log"
@CHANNEL = %w{#xxxxx@freenode #xxxxx@twitter}
@FILE_NAME = Time.now.strftime("%Y.%m.%d.txt")
@KEYWORDS = "key1|key2|key3"
replys = Array.new
readLabel = YAML.load_file("readLabel.yaml")
@CHANNEL.each { |channel|
i = 0
open("#{@LOG_DIR}/#{channel}/#{@FILE_NAME}"){ |file|
while line = file.gets
i = i + 1
next if !readLabel[channel].nil? && i <= readLabel[channel]
replys << line if line =~ /^[\d]{2}:[\d]{2}:[\d]{2}[\s]+[<].+?[>].+?(#{@KEYWORDS})/
end
}
readLabel[channel] = i
}
fw = File.open("readLabel.yaml",'w+')
fw.puts readLabel.to_yaml
fw.close
if !replys.empty?s
sendgmail("xxxxx@gmail.com",["xxxx@xxxx.ne.jp"],"IRC REPLY",replys.join,"user","pass")
end
# Send Japanese mail using Gmail SMTP server. You need tlsmail.
# $ sudo gem install tlsmail
require "rubygems"
require "tlsmail"
require "nkf"
require "net/smtp"
def sendgmail(from, to, subject, body, user, pass, host = "smtp.gmail.com", port = 587)
body = <<EOT
From: #{from}
To: #{to.to_a.join(",\n ")}
Subject: #{NKF.nkf("-WMm0", subject)}
Date: #{Time::now.strftime("%a, %d %b %Y %X %z")}
Mime-Version: 1.0
Content-Type: text/plain; charset=ISO-2022-JP
Content-Transfer-Encoding: 7bit
#{NKF.nkf("-Wjm0", body)}
EOT
Net::SMTP.enable_tls(OpenSSL::SSL::VERIFY_NONE)
Net::SMTP.start(host, port, "localhost.localdomain", user, pass, "plain") do |smtp|
smtp.send_mail body, from, to
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment