source: valtobtest/subversion-1.6.2/tools/hook-scripts/commit-email.rb @ 3

Last change on this file since 3 was 3, checked in by valtob, 15 years ago

subversion source 1.6.2 as test

  • Property svn:executable set to *
File size: 2.1 KB
Line 
1#!/usr/bin/env ruby
2
3require 'English'
4
5original_argv = ARGV.dup
6argv = []
7
8found_include_option = false
9while (arg = original_argv.shift)
10  if found_include_option
11    $LOAD_PATH.unshift(arg)
12    found_include_option = false
13  else
14    case arg
15    when "-I", "--include"
16      found_include_option = true
17    when /\A-I/, /\A--include=?/
18      path = $POSTMATCH
19      $LOAD_PATH.unshift(path) unless path.empty?
20    else
21      argv << arg
22    end
23  end
24end
25
26def extract_email_address(address)
27  if /<(.+?)>/ =~ address
28    $1
29  else
30    address
31  end
32end
33
34def sendmail(to, from, mail, server=nil, port=nil)
35  server ||= "localhost"
36  from = extract_email_address(from)
37  to = to.collect {|address| extract_email_address(address)}
38  Net::SMTP.start(server, port) do |smtp|
39    smtp.open_message_stream(from, to) do |f|
40      f.print(mail)
41    end
42  end
43end
44
45begin
46  require 'svn/commit-mailer'
47  Svn::Locale.set
48  Svn::CommitMailer.run(argv)
49rescue Exception => error
50  require 'net/smtp'
51  require 'socket'
52
53  to = []
54  subject = "Error"
55  from = "#{ENV['USER']}@#{Socket.gethostname}"
56  server = nil
57  port = nil
58  begin
59    begin
60      Svn::CommitMailer
61    rescue NameError
62      raise OptionParser::ParseError
63    end
64    _, _, _to, options = Svn::CommitMailer.parse(argv)
65    to = [_to]
66    to = options.error_to unless options.error_to.empty?
67    from = options.from || from
68    subject = "#{options.name}: #{subject}" if options.name
69    server = options.server
70    port = options.port
71  rescue OptionParser::MissingArgument
72    argv.delete_if {|arg| $!.args.include?(arg)}
73    retry
74  rescue OptionParser::ParseError
75    if to.empty?
76      _, _, _to, *_ = ARGV.reject {|arg| /^-/.match(arg)}
77      to = [_to]
78    end
79  end
80
81  detail = <<-EOM
82#{error.class}: #{error.message}
83#{error.backtrace.join("\n")}
84EOM
85  to = to.compact
86  if to.empty?
87    STDERR.puts detail
88  else
89    sendmail(to, from, <<-MAIL, server, port)
90MIME-Version: 1.0
91Content-Type: text/plain; charset=us-ascii
92Content-Transfer-Encoding: 7bit
93From: #{from}
94To: #{to.join(', ')}
95Subject: #{subject}
96Date: #{Time.now.rfc2822}
97
98#{detail}
99MAIL
100  end
101end
Note: See TracBrowser for help on using the repository browser.