summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xnsa63
1 files changed, 19 insertions, 44 deletions
diff --git a/nsa b/nsa
index 99789bc..cebe329 100755
--- a/nsa
+++ b/nsa
@@ -24,6 +24,7 @@
require 'socket'
require 'openssl'
require 'yaml'
+require 'mail'
require 'monitor'
if RUBY_VERSION =~ /1.9/
@@ -420,60 +421,34 @@ while (1) do
next if filename == ".."
in_headers = true
- fh = File.open(filename, "r")
- project = nil
- lines = []
- commitmsg = ""
- transfer_encoding = "plain"
- fh.readlines.each { |line|
- line.chomp!
- in_headers = false if line == ""
- if (in_headers and not line =~ /^\s/)
- (header, content) = line.split(':', 2);
- content.strip!
- if header.upcase == "SUBJECT"
- m = /Announce\s+([A-Za-z0-9_-]+)/.match(content)
- if m
- project = m[1];
- end
- elsif header.upcase == "CONTENT-TRANSFER-ENCODING"
- transfer_encoding = content
- end
- elsif (not in_headers)
- lines.push line
- commitmsg = commitmsg + line
- end
- }
- fh.close
+ mail = Mail.read(filename)
File.unlink(filename)
- if transfer_encoding == "base64"
- require 'base64'
- lines = Base64.decode64(lines.join()).split("\n")
- end
-
- if project.nil?
+ if (m = /Announce\s+([A-Za-z0-9_-]+)/.match(mail.subject))
+ project = m[1]
+ else
puts "Ignoring invalid mail without project"
next
end
+ commitmsg = mail.body.decoded
+
puts "Project "+project
puts "commitmsg "+commitmsg
- if project and commitmsg != oldcommitmsg
+ if commitmsg != oldcommitmsg
pr = "%c"%(002) + project + "%c: "%(002)
- lines.each{ |line|
- if (line != '')
- line = pr + line
- channellist = CONFIG['projects'].has_key?(project) ? CONFIG['projects'][project] : CONFIG['projects']['*']
- channellist.each do |c|
- counter.pop
- m = /^NOTICE:(.*)/.match c
- if m
- bot.print "NOTICE #{m[1]} :#{line}"
- else
- bot.print "PRIVMSG #{c} :#{line}"
- end
+ commitmsg.split("\n").each{ |line|
+ if (line == '') then next; end
+ line = pr + line
+ channellist = CONFIG['projects'].has_key?(project) ? CONFIG['projects'][project] : CONFIG['projects']['*']
+ channellist.each do |c|
+ counter.pop
+ m = /^NOTICE:(.*)/.match c
+ if m
+ bot.print "NOTICE #{m[1]} :#{line}"
+ else
+ bot.print "PRIVMSG #{c} :#{line}"
end
end
}