clutil 2010.127.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/cl/util/clqsend.rb +86 -0
- data/cl/util/console.rb +60 -0
- data/cl/util/cvs.maint.rb +41 -0
- data/cl/util/decide.rb +69 -0
- data/cl/util/dirsize.rb +144 -0
- data/cl/util/doc/License +14 -0
- data/cl/util/doc/Readme +22 -0
- data/cl/util/file.rb +210 -0
- data/cl/util/install.rb +107 -0
- data/cl/util/install.util.rb +67 -0
- data/cl/util/net.rb +15 -0
- data/cl/util/progress.rb +104 -0
- data/cl/util/smtp.rb +131 -0
- data/cl/util/string.rb +65 -0
- data/cl/util/test.rb +92 -0
- data/cl/util/test/dirsizetest.rb +138 -0
- data/cl/util/test/filetest.rb +178 -0
- data/cl/util/test/installtest.rb +12 -0
- data/cl/util/test/progresstest.rb +43 -0
- data/cl/util/test/stringtest.rb +50 -0
- data/cl/util/test/versiontest.rb +72 -0
- data/cl/util/test/wintest.rb +106 -0
- data/cl/util/time.rb +35 -0
- data/cl/util/util.rb +10 -0
- data/cl/util/version.rb +115 -0
- data/cl/util/win.rb +351 -0
- metadata +81 -0
data/cl/util/install.rb
ADDED
@@ -0,0 +1,107 @@
|
|
1
|
+
# $Id: install.rb,v 1.7 2002/09/09 03:04:38 chrismo Exp $
|
2
|
+
=begin
|
3
|
+
--------------------------------------------------------------------------
|
4
|
+
Copyright (c) 2002, Chris Morris
|
5
|
+
All rights reserved.
|
6
|
+
|
7
|
+
Redistribution and use in source and binary forms, with or without modification,
|
8
|
+
are permitted provided that the following conditions are met:
|
9
|
+
|
10
|
+
1. Redistributions of source code must retain the above copyright notice, this
|
11
|
+
list of conditions and the following disclaimer.
|
12
|
+
|
13
|
+
2. Redistributions in binary form must reproduce the above copyright notice,
|
14
|
+
this list of conditions and the following disclaimer in the documentation and/or
|
15
|
+
other materials provided with the distribution.
|
16
|
+
|
17
|
+
3. Neither the names Chris Morris, cLabs nor the names of contributors to this
|
18
|
+
software may be used to endorse or promote products derived from this software
|
19
|
+
without specific prior written permission.
|
20
|
+
|
21
|
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS''
|
22
|
+
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
23
|
+
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
24
|
+
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE
|
25
|
+
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
26
|
+
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
27
|
+
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
28
|
+
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
|
29
|
+
TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
30
|
+
THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
31
|
+
--------------------------------------------------------------------------------
|
32
|
+
=end
|
33
|
+
|
34
|
+
require 'rbconfig'
|
35
|
+
require 'find'
|
36
|
+
require 'ftools'
|
37
|
+
require "#{File.dirname(__FILE__)}/console"
|
38
|
+
|
39
|
+
include Config
|
40
|
+
|
41
|
+
# altered copy of rbconfig.rb -> Config::expand
|
42
|
+
def custom_expand(val, conf)
|
43
|
+
val.gsub!(/\$\(([^()]+)\)/) do |var|
|
44
|
+
key = $1
|
45
|
+
if CONFIG.key? key
|
46
|
+
custom_expand(conf[key], conf)
|
47
|
+
else
|
48
|
+
var
|
49
|
+
end
|
50
|
+
end
|
51
|
+
val
|
52
|
+
end
|
53
|
+
|
54
|
+
def get_conf(customizations)
|
55
|
+
conf = {}
|
56
|
+
MAKEFILE_CONFIG.each{|k,v| conf[k] = v.dup}
|
57
|
+
customizations.each do |k, v|
|
58
|
+
conf[k] = v
|
59
|
+
end
|
60
|
+
conf.each_value do |val| custom_expand(val, conf) end
|
61
|
+
conf
|
62
|
+
end
|
63
|
+
|
64
|
+
def init
|
65
|
+
prefixdir = get_switch('-p')
|
66
|
+
customizations = {}
|
67
|
+
customizations['prefix'] = prefixdir if prefixdir
|
68
|
+
conf = get_conf(customizations)
|
69
|
+
|
70
|
+
$version = conf["MAJOR"]+"."+conf["MINOR"]
|
71
|
+
$libdir = File.join(conf["libdir"], "ruby", $version)
|
72
|
+
|
73
|
+
$bindir = conf["bindir"]
|
74
|
+
$sitedir = conf["sitedir"] || File.join($libdir, "site_ruby")
|
75
|
+
$siteverdir = File.join($sitedir, $version)
|
76
|
+
$archdir = File.join($libdir, "i586-mswin32")
|
77
|
+
end
|
78
|
+
|
79
|
+
def install_executables(files)
|
80
|
+
tmpfn = "cl_tmp"
|
81
|
+
files.each do |aFile, dest|
|
82
|
+
File.open(aFile) do |ip|
|
83
|
+
File.open(tmpfn, "w") do |op|
|
84
|
+
ruby = File.join($bindir, "ruby")
|
85
|
+
op.puts "#!#{ruby}"
|
86
|
+
op.write ip.read
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
File::makedirs(dest)
|
91
|
+
# 0755 I assume means read/write/execute, not needed for Windows
|
92
|
+
File::chmod(0755, dest, true)
|
93
|
+
File::install(tmpfn, File.join(dest, File.basename(aFile)), 0755, true)
|
94
|
+
File::unlink(tmpfn)
|
95
|
+
end
|
96
|
+
end
|
97
|
+
|
98
|
+
def install_lib(files)
|
99
|
+
files.each do |aFile, dest|
|
100
|
+
File::makedirs(dest)
|
101
|
+
File::install(aFile, File.join(dest, File.basename(aFile)), 0644, true)
|
102
|
+
end
|
103
|
+
end
|
104
|
+
|
105
|
+
if __FILE__ == $0
|
106
|
+
init
|
107
|
+
end
|
@@ -0,0 +1,67 @@
|
|
1
|
+
# $Id: install.util.rb,v 1.8 2003/06/27 17:46:03 chrismo Exp $
|
2
|
+
=begin
|
3
|
+
--------------------------------------------------------------------------
|
4
|
+
Copyright (c) 2002, Chris Morris
|
5
|
+
All rights reserved.
|
6
|
+
|
7
|
+
Redistribution and use in source and binary forms, with or without modification,
|
8
|
+
are permitted provided that the following conditions are met:
|
9
|
+
|
10
|
+
1. Redistributions of source code must retain the above copyright notice, this
|
11
|
+
list of conditions and the following disclaimer.
|
12
|
+
|
13
|
+
2. Redistributions in binary form must reproduce the above copyright notice,
|
14
|
+
this list of conditions and the following disclaimer in the documentation and/or
|
15
|
+
other materials provided with the distribution.
|
16
|
+
|
17
|
+
3. Neither the names Chris Morris, cLabs nor the names of contributors to this
|
18
|
+
software may be used to endorse or promote products derived from this software
|
19
|
+
without specific prior written permission.
|
20
|
+
|
21
|
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS''
|
22
|
+
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
23
|
+
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
24
|
+
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE
|
25
|
+
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
26
|
+
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
27
|
+
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
28
|
+
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
|
29
|
+
TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
30
|
+
THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
31
|
+
--------------------------------------------------------------------------------
|
32
|
+
=end
|
33
|
+
|
34
|
+
require "#{File.dirname(__FILE__)}/install"
|
35
|
+
init
|
36
|
+
|
37
|
+
$cldir = File.join($siteverdir, "cl")
|
38
|
+
$clutildir = File.join($cldir, "util")
|
39
|
+
$clutiltestdir = File.join($clutildir, "test")
|
40
|
+
|
41
|
+
$libfiles = { 'util.rb' => $cldir ,
|
42
|
+
|
43
|
+
"file.rb" => $clutildir ,
|
44
|
+
"win.rb" => $clutildir ,
|
45
|
+
"dirsize.rb" => $clutildir ,
|
46
|
+
"test.rb" => $clutildir ,
|
47
|
+
"time.rb" => $clutildir ,
|
48
|
+
"console.rb" => $clutildir ,
|
49
|
+
"progress.rb" => $clutildir ,
|
50
|
+
"install.rb" => $clutildir ,
|
51
|
+
"smtp.rb" => $clutildir ,
|
52
|
+
"string.rb" => $clutildir ,
|
53
|
+
"version.rb" => $clutildir ,
|
54
|
+
"clqsend.rb" => $bindir ,
|
55
|
+
|
56
|
+
"./test/dirsizetest.rb" => $clutiltestdir,
|
57
|
+
"./test/filetest.rb" => $clutiltestdir ,
|
58
|
+
"./test/installtest.rb" => $clutiltestdir ,
|
59
|
+
"./test/progresstest.rb" => $clutiltestdir,
|
60
|
+
"./test/stringtest.rb" => $clutiltestdir,
|
61
|
+
"./test/versiontest.rb" => $clutiltestdir,
|
62
|
+
"./test/wintest.rb" => $clutiltestdir
|
63
|
+
}
|
64
|
+
|
65
|
+
if __FILE__ == $0
|
66
|
+
install_lib($libfiles)
|
67
|
+
end
|
data/cl/util/net.rb
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
module ClUtilNet
|
2
|
+
def ping(host)
|
3
|
+
(`ping -n 1 #{host}` =~ "Request timed out") == nil
|
4
|
+
end
|
5
|
+
end
|
6
|
+
|
7
|
+
if __FILE__ == $0
|
8
|
+
include ClUtilNet
|
9
|
+
|
10
|
+
puts "Pinging 66.169.210.208"
|
11
|
+
puts ping("66.169.210.208")
|
12
|
+
|
13
|
+
puts "Pinging localhost"
|
14
|
+
puts ping("localhost")
|
15
|
+
end
|
data/cl/util/progress.rb
ADDED
@@ -0,0 +1,104 @@
|
|
1
|
+
# $Id: progress.rb,v 1.2 2003/09/12 14:53:50 chrismo Exp $
|
2
|
+
=begin
|
3
|
+
--------------------------------------------------------------------------
|
4
|
+
Copyright (c) 2002, Chris Morris
|
5
|
+
All rights reserved.
|
6
|
+
|
7
|
+
Redistribution and use in source and binary forms, with or without modification,
|
8
|
+
are permitted provided that the following conditions are met:
|
9
|
+
|
10
|
+
1. Redistributions of source code must retain the above copyright notice, this
|
11
|
+
list of conditions and the following disclaimer.
|
12
|
+
|
13
|
+
2. Redistributions in binary form must reproduce the above copyright notice,
|
14
|
+
this list of conditions and the following disclaimer in the documentation and/or
|
15
|
+
other materials provided with the distribution.
|
16
|
+
|
17
|
+
3. Neither the names Chris Morris, cLabs nor the names of contributors to this
|
18
|
+
software may be used to endorse or promote products derived from this software
|
19
|
+
without specific prior written permission.
|
20
|
+
|
21
|
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS''
|
22
|
+
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
23
|
+
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
24
|
+
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE
|
25
|
+
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
26
|
+
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
27
|
+
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
28
|
+
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
|
29
|
+
TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
30
|
+
THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
31
|
+
--------------------------------------------------------------------------------
|
32
|
+
=end
|
33
|
+
|
34
|
+
class Progress
|
35
|
+
def initialize(total)
|
36
|
+
@total = total
|
37
|
+
@current = 0
|
38
|
+
end
|
39
|
+
|
40
|
+
def start
|
41
|
+
@start = Time.now
|
42
|
+
@in_place_called_already = false
|
43
|
+
end
|
44
|
+
|
45
|
+
def step
|
46
|
+
@current += 1
|
47
|
+
end
|
48
|
+
|
49
|
+
def elapsed
|
50
|
+
(Time.now - @start)
|
51
|
+
end
|
52
|
+
|
53
|
+
def format_seconds(seconds)
|
54
|
+
minutes, seconds = seconds.divmod 60
|
55
|
+
hours, minutes = minutes.divmod 60
|
56
|
+
sprintf("%02d:%02d:%02d", hours, minutes, seconds)
|
57
|
+
end
|
58
|
+
|
59
|
+
def elapsedf
|
60
|
+
format_seconds(elapsed)
|
61
|
+
end
|
62
|
+
|
63
|
+
def done
|
64
|
+
@current
|
65
|
+
end
|
66
|
+
|
67
|
+
def remaining
|
68
|
+
@total - @current
|
69
|
+
end
|
70
|
+
|
71
|
+
def est_remaining_time
|
72
|
+
((elapsed / done) * remaining)
|
73
|
+
end
|
74
|
+
|
75
|
+
def est_remaining_timef
|
76
|
+
format_seconds(est_remaining_time)
|
77
|
+
end
|
78
|
+
|
79
|
+
def progress(doStep=false)
|
80
|
+
step if doStep
|
81
|
+
"#{@current.to_s}/#{@total.to_s} done. Elapsed: #{elapsedf} Est Remain: #{est_remaining_timef}"
|
82
|
+
end
|
83
|
+
|
84
|
+
|
85
|
+
def pct_done
|
86
|
+
if @total > 0
|
87
|
+
pct = ((done.to_f / @total.to_f) * 100).to_i
|
88
|
+
else
|
89
|
+
pct = 0
|
90
|
+
end
|
91
|
+
|
92
|
+
pct.to_s.rjust(3) + '%'
|
93
|
+
end
|
94
|
+
|
95
|
+
def in_place_pct(doStep=false)
|
96
|
+
step if doStep
|
97
|
+
rubout = 8.chr
|
98
|
+
out = ''
|
99
|
+
out << (rubout * 4) if @in_place_called_already
|
100
|
+
out << pct_done
|
101
|
+
@in_place_called_already = true
|
102
|
+
out
|
103
|
+
end
|
104
|
+
end
|
data/cl/util/smtp.rb
ADDED
@@ -0,0 +1,131 @@
|
|
1
|
+
# $Id: smtp.rb,v 1.4 2008/12/09 06:58:56 chrismo Exp $
|
2
|
+
=begin
|
3
|
+
--------------------------------------------------------------------------
|
4
|
+
Copyright (c) 2001-2005, Chris Morris
|
5
|
+
All rights reserved.
|
6
|
+
|
7
|
+
Redistribution and use in source and binary forms, with or without modification,
|
8
|
+
are permitted provided that the following conditions are met:
|
9
|
+
|
10
|
+
1. Redistributions of source code must retain the above copyright notice, this
|
11
|
+
list of conditions and the following disclaimer.
|
12
|
+
|
13
|
+
2. Redistributions in binary form must reproduce the above copyright notice,
|
14
|
+
this list of conditions and the following disclaimer in the documentation and/or
|
15
|
+
other materials provided with the distribution.
|
16
|
+
|
17
|
+
3. Neither the names Chris Morris, cLabs nor the names of contributors to this
|
18
|
+
software may be used to endorse or promote products derived from this software
|
19
|
+
without specific prior written permission.
|
20
|
+
|
21
|
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS''
|
22
|
+
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
23
|
+
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
24
|
+
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE
|
25
|
+
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
26
|
+
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
27
|
+
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
28
|
+
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
|
29
|
+
TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
30
|
+
THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
31
|
+
--------------------------------------------------------------------------------
|
32
|
+
=end
|
33
|
+
require 'net/smtp'
|
34
|
+
require 'time'
|
35
|
+
|
36
|
+
def get_filedata(filename)
|
37
|
+
data = nil
|
38
|
+
File.open(filename, 'rb') do |f|
|
39
|
+
data = f.read()
|
40
|
+
end
|
41
|
+
data = [data].pack("m*")
|
42
|
+
data
|
43
|
+
end
|
44
|
+
|
45
|
+
def create_boundary()
|
46
|
+
return "_____clabs_smtp_boundary______#{Time.new.to_i.to_s}___"
|
47
|
+
end
|
48
|
+
|
49
|
+
def sendmail(to, from, subj, body, smtpsrv=nil, attachments=nil, extra_headers=nil)
|
50
|
+
smtpsrv = 'localhost' if !smtpsrv
|
51
|
+
attachments = [attachments].flatten
|
52
|
+
attachments.compact!
|
53
|
+
attachments = nil if attachments.empty?
|
54
|
+
to = [to].flatten
|
55
|
+
|
56
|
+
headers = ["Subject: #{subj}", "From: #{from}", "To: #{to.join(";")}", "Date: #{Time.now.rfc2822}", "MIME-Version: 1.0" ]
|
57
|
+
headers << extra_headers if !extra_headers.nil?
|
58
|
+
headers.flatten!
|
59
|
+
headers.collect! { |hdr| hdr.strip << "\n" }
|
60
|
+
msg = [ headers ].flatten
|
61
|
+
|
62
|
+
boundary = create_boundary
|
63
|
+
|
64
|
+
if attachments
|
65
|
+
msg << [
|
66
|
+
"Content-Type: multipart/mixed; boundary=\"#{boundary}\"\n",
|
67
|
+
"\n",
|
68
|
+
"This is a multi-part message in MIME format.\n",
|
69
|
+
"\n"
|
70
|
+
]
|
71
|
+
end
|
72
|
+
|
73
|
+
if body
|
74
|
+
msg << [ "--#{boundary}\n" ] if attachments
|
75
|
+
msg << [
|
76
|
+
"Content-Type: text/plain; charset=\"iso-8859-1\"\n",
|
77
|
+
"Content-Transfer-Encoding: 8bit\n",
|
78
|
+
"\n",
|
79
|
+
"#{body}\n",
|
80
|
+
"\n"
|
81
|
+
]
|
82
|
+
end
|
83
|
+
|
84
|
+
attachments.each do |filename|
|
85
|
+
basename = File.basename(filename)
|
86
|
+
filedata = get_filedata(filename)
|
87
|
+
msg << [
|
88
|
+
"--#{boundary}\n",
|
89
|
+
"Content-Type: application/octet-stream; name=\"#{basename}\"\n",
|
90
|
+
"Content-Transfer-Encoding: base64\n",
|
91
|
+
"Content-Disposition: attachment; filename=\"#{basename}\"\n",
|
92
|
+
"\n",
|
93
|
+
"#{filedata}", # no \n needed
|
94
|
+
"\n"
|
95
|
+
]
|
96
|
+
end if attachments
|
97
|
+
|
98
|
+
msg << ["--#{boundary}--\n"] if attachments
|
99
|
+
|
100
|
+
msg.flatten!
|
101
|
+
|
102
|
+
Net::SMTP.start(smtpsrv) do |smtp|
|
103
|
+
smtp.sendmail(msg, from, to)
|
104
|
+
end
|
105
|
+
end
|
106
|
+
|
107
|
+
if __FILE__ == $0
|
108
|
+
require 'test/unit'
|
109
|
+
|
110
|
+
class TestSendMail < Test::Unit::TestCase
|
111
|
+
def testsendmail
|
112
|
+
addr = 'chrismo@clabs.org'
|
113
|
+
sendmail(addr, addr, 'unit test', 'this is a unit test')
|
114
|
+
sendmail([addr, addr], addr, 'unit test', 'this is a unit test')
|
115
|
+
end
|
116
|
+
|
117
|
+
def testattachment
|
118
|
+
File.open('test.txt', 'w+') do |f| f.print "test attachment\n" end
|
119
|
+
addr = 'chrismo@clabs.org'
|
120
|
+
sendmail(addr, addr, 'unit test', 'this is a unit test', nil, 'test.txt')
|
121
|
+
sendmail(addr, addr, 'unit test', 'this is a unit test', nil, ['test.txt', 'smtp.rb'])
|
122
|
+
end
|
123
|
+
|
124
|
+
def test_thread
|
125
|
+
addr = 'chrismo@clabs.org'
|
126
|
+
headers = ["In-Reply-To: <foo@clabs.org>"]
|
127
|
+
sendmail(addr, addr, 'smtp.rb thread test', 'body', nil, nil, headers)
|
128
|
+
sendmail(addr, addr, 'smtp.rb thread test', 'body', nil, nil, headers)
|
129
|
+
end
|
130
|
+
end
|
131
|
+
end
|
data/cl/util/string.rb
ADDED
@@ -0,0 +1,65 @@
|
|
1
|
+
# $Id: string.rb,v 1.2 2003/06/27 17:46:03 chrismo Exp $
|
2
|
+
=begin
|
3
|
+
----------------------------------------------------------------------------
|
4
|
+
Copyright (c) 2001 - 2003, Chris Morris
|
5
|
+
All rights reserved.
|
6
|
+
|
7
|
+
Redistribution and use in source and binary forms, with or without
|
8
|
+
modification, are permitted provided that the following conditions are met:
|
9
|
+
|
10
|
+
1. Redistributions of source code must retain the above copyright notice,
|
11
|
+
this list of conditions and the following disclaimer.
|
12
|
+
|
13
|
+
2. Redistributions in binary form must reproduce the above copyright notice,
|
14
|
+
this list of conditions and the following disclaimer in the documentation
|
15
|
+
and/or other materials provided with the distribution.
|
16
|
+
|
17
|
+
3. Neither the names Chris Morris, cLabs nor the names of contributors to
|
18
|
+
this software may be used to endorse or promote products derived from this
|
19
|
+
software without specific prior written permission.
|
20
|
+
|
21
|
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS
|
22
|
+
IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
23
|
+
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
24
|
+
PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR
|
25
|
+
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
26
|
+
EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
27
|
+
PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
|
28
|
+
OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
29
|
+
WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
30
|
+
OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
31
|
+
ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
32
|
+
----------------------------------------------------------------------------
|
33
|
+
(based on BSD Open Source License)
|
34
|
+
=end
|
35
|
+
|
36
|
+
class String
|
37
|
+
def get_indent
|
38
|
+
scan(/^(\s*)/).to_s
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
def indent(s, amt)
|
43
|
+
a = s.split("\n", -1)
|
44
|
+
if amt >= 0
|
45
|
+
a.collect! do |ln|
|
46
|
+
if !ln.empty?
|
47
|
+
(' ' * amt) + ln
|
48
|
+
else
|
49
|
+
ln
|
50
|
+
end
|
51
|
+
end
|
52
|
+
else
|
53
|
+
a.collect! do |ln|
|
54
|
+
(1..amt.abs).each do ln = ln[1..-1] if ln[0..0] == ' ' end
|
55
|
+
ln
|
56
|
+
end
|
57
|
+
end
|
58
|
+
a.join("\n")
|
59
|
+
end
|
60
|
+
|
61
|
+
def here_ltrim(s, add_indent_amt=0)
|
62
|
+
a = s.split("\n", -1)
|
63
|
+
trim_indent_amt = a[0].get_indent.length
|
64
|
+
s = indent(s, add_indent_amt - trim_indent_amt)
|
65
|
+
end
|