Created
October 16, 2009 12:21
-
-
Save naoto/211782 to your computer and use it in GitHub Desktop.
tiarraのLogをgmail経由で転送
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
require 'sendgmail.rb' | |
require 'yaml' | |
@log_dir = "/path/to/log" | |
@channels = %w{#xxxxx@freenode #xxxxx@twitter} | |
@file_name = Time.now.strftime("%Y.%m.%d.txt") | |
@keywords = "key1|key2|key3" | |
@send_mail_address = "xxxxxx@gmail.com" | |
@to_mail_address = "xxxx@xxxx.ne.jp" | |
@mail_title = "IRC REPLY" | |
@user = "user" | |
@pass = "pass" | |
@save_file = "readLabel.yaml" | |
replys = [] | |
readLabel = YAML.load_file(@save_file) | |
@channels.each do |channel| | |
line_number = 0 | |
open("#{@log_dir}/#{channel}/#{@file_name}").each_line { |line| | |
line_number += 1 | |
next if !readLabel[channel].nil? && line_number <= readLabel[channel] | |
replys << line if line =~ /^[\d]{2}:[\d]{2}:[\d]{2}[\s]+[<].+?[>].+?(#{@keywords})/ | |
} | |
readLabel[channel] = line_number | |
end | |
fw = File.open(@save_file,'w+') | |
fw.puts readLabel.to_yaml | |
fw.close | |
if !replys.empty?s | |
sendgmail(@send_mail_address, [@to_mail_address], @mail_title, replys.join, @user, @pass) | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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