gurgitate-mail 1.8.4 → 1.8.5
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/bin/gurgitate-mail +5 -1
- data/lib/gurgitate-mail.rb +30 -28
- data/lib/gurgitate/deliver.rb +8 -11
- data/lib/gurgitate/deliver/maildir.rb +5 -1
- data/lib/gurgitate/headers.rb +106 -51
- data/lib/gurgitate/mailmessage.rb +56 -11
- data/test/gurgitate-test.rb +62 -0
- data/{test.rb → test/runtests.rb} +4 -1
- data/test/test_configuration.rb +35 -0
- data/test/test_delivery.rb +213 -0
- data/test/test_header.rb +154 -0
- data/test/test_headers.rb +478 -0
- data/test/test_process.rb +87 -0
- data/test/test_rules.rb +108 -0
- data/test/test_writing.rb +56 -0
- metadata +14 -6
@@ -0,0 +1,87 @@
|
|
1
|
+
require 'test/unit'
|
2
|
+
require 'test/unit/ui/console/testrunner'
|
3
|
+
require 'stringio'
|
4
|
+
require 'fileutils'
|
5
|
+
require 'pathname'
|
6
|
+
require 'irb'
|
7
|
+
require "./gurgitate-mail"
|
8
|
+
|
9
|
+
class TC_Process < GurgitateTest
|
10
|
+
#************************************************************************
|
11
|
+
# tests
|
12
|
+
#************************************************************************
|
13
|
+
def test_basic_delivery
|
14
|
+
assert_nothing_raised do
|
15
|
+
@gurgitate.process { nil }
|
16
|
+
end
|
17
|
+
assert File.exists?(@spoolfile)
|
18
|
+
end
|
19
|
+
|
20
|
+
def test_pipe_raises_no_exceptions
|
21
|
+
assert_nothing_raised do
|
22
|
+
@gurgitate.process { pipe('cat > /dev/null') }
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
def test_bad_pipe_goes_to_spoolfile_anyway
|
27
|
+
assert_nothing_raised do
|
28
|
+
# if you have a program called this on your system,
|
29
|
+
# I want to see its man page
|
30
|
+
@gurgitate.process { pipe("/bin/flortglenuggets >/dev/null 2>&1") }
|
31
|
+
end
|
32
|
+
|
33
|
+
assert File.exists?(@spoolfile)
|
34
|
+
assert File.stat(@spoolfile).file?
|
35
|
+
end
|
36
|
+
|
37
|
+
def test_break_does_not_deliver
|
38
|
+
assert_nothing_raised do
|
39
|
+
@gurgitate.process { break }
|
40
|
+
end
|
41
|
+
|
42
|
+
assert !File.exists?(@spoolfile)
|
43
|
+
end
|
44
|
+
|
45
|
+
def test_message_parsed_correctly
|
46
|
+
assert_equal("From: me",@gurgitate.header("From"))
|
47
|
+
assert_equal("To: you", @gurgitate.header("To"))
|
48
|
+
assert_equal("Subject: test", @gurgitate.header("Subject"))
|
49
|
+
assert_equal("Hi.\n", @gurgitate.body, "Message body is wrong")
|
50
|
+
end
|
51
|
+
|
52
|
+
def test_message_written_correctly
|
53
|
+
test_message_parsed_correctly
|
54
|
+
assert_nothing_raised do
|
55
|
+
@gurgitate.process
|
56
|
+
end
|
57
|
+
|
58
|
+
mess=nil
|
59
|
+
assert_nothing_raised do
|
60
|
+
mess = Gurgitate::Mailmessage.new(File.read(@spoolfile))
|
61
|
+
end
|
62
|
+
|
63
|
+
assert_equal("From: me", mess.header("From"), "From header is wrong")
|
64
|
+
assert_equal("To: you", mess.header("To"), "To header is wrong")
|
65
|
+
assert_equal("Hi.\n", mess.body, "Body is wrong")
|
66
|
+
assert_equal("Subject: test", mess.header("Subject"), "Subject header wrong")
|
67
|
+
end
|
68
|
+
|
69
|
+
def test_method_missing
|
70
|
+
assert_equal "test", @gurgitate.subject[0].contents
|
71
|
+
assert_raises NameError do
|
72
|
+
p @gurgitate.nonexistentheader
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
def test_filter
|
77
|
+
new_obj = nil
|
78
|
+
assert_nothing_raised do
|
79
|
+
new_obj = @gurgitate.filter("tr a-z A-Z")
|
80
|
+
end
|
81
|
+
|
82
|
+
assert_equal "HI.\n", new_obj.body
|
83
|
+
assert_equal "ME", new_obj.from
|
84
|
+
assert_equal "TEST", new_obj.subject[0].contents
|
85
|
+
|
86
|
+
end
|
87
|
+
end
|
data/test/test_rules.rb
ADDED
@@ -0,0 +1,108 @@
|
|
1
|
+
require "test/gurgitate-test"
|
2
|
+
require "etc"
|
3
|
+
|
4
|
+
class TC_Rules < GurgitateTest
|
5
|
+
def setup
|
6
|
+
super
|
7
|
+
@rulesfile = File.join(@testdir, "rules_1.rb")
|
8
|
+
File.open(rulesfile, File::CREAT|File::WRONLY) do |f|
|
9
|
+
f.puts "nil"
|
10
|
+
end
|
11
|
+
|
12
|
+
@defaultrules = File.join(@testdir, ".gurgitate-rules.rb")
|
13
|
+
File.open File.join(@defaultrules), File::CREAT|File::WRONLY do |f|
|
14
|
+
f.puts "nil"
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
attr_reader :rulesfile
|
19
|
+
|
20
|
+
def teardown
|
21
|
+
File.unlink rulesfile if File.exist? rulesfile
|
22
|
+
super
|
23
|
+
end
|
24
|
+
|
25
|
+
def test_add_rules_normal
|
26
|
+
assert @gurgitate.add_rules(rulesfile)
|
27
|
+
|
28
|
+
assert_equal [rulesfile], @gurgitate.instance_variable_get("@rules")
|
29
|
+
end
|
30
|
+
|
31
|
+
def test_add_unreadable_rules
|
32
|
+
FileUtils.chmod 0, rulesfile
|
33
|
+
|
34
|
+
assert_equal false, @gurgitate.add_rules(rulesfile)
|
35
|
+
end
|
36
|
+
|
37
|
+
def test_add_nonexistent_rules
|
38
|
+
File.unlink rulesfile
|
39
|
+
assert_equal false, @gurgitate.add_rules(rulesfile)
|
40
|
+
end
|
41
|
+
|
42
|
+
def test_add_default_rules
|
43
|
+
assert_nothing_raised do
|
44
|
+
@gurgitate.add_rules :default
|
45
|
+
end
|
46
|
+
|
47
|
+
assert_equal [@defaultrules],
|
48
|
+
@gurgitate.instance_variable_get("@rules")
|
49
|
+
end
|
50
|
+
|
51
|
+
def test_add_system_rules
|
52
|
+
unless Etc.getpwuid.uid == 0
|
53
|
+
assert_equal false, @gurgitate.add_rules(rulesfile, :system => true)
|
54
|
+
else
|
55
|
+
# but really, fer crying out loud, DON'T RUN TESTS AS ROOT
|
56
|
+
assert true, @gurgitate.add_rules(rulesfile, :system => true)
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
def test_add_user_rules
|
61
|
+
assert @gurgitate.add_rules(rulesfile, :user => true)
|
62
|
+
end
|
63
|
+
|
64
|
+
def test_add_user_rules_file_not_found
|
65
|
+
File.unlink rulesfile
|
66
|
+
assert_equal false, @gurgitate.add_rules(rulesfile, :user => true)
|
67
|
+
end
|
68
|
+
|
69
|
+
def test_bad_syntax
|
70
|
+
assert_raises ArgumentError do
|
71
|
+
@gurgitate.add_rules(rulesfile, :honk)
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
class TC_ExecuteRules < TC_Rules
|
77
|
+
def setup
|
78
|
+
super
|
79
|
+
@invalidrules = File.join(@testdir, "rules_invalid.rb")
|
80
|
+
File.open @invalidrules, "w" do |f|
|
81
|
+
f.puts "invalid syntax"
|
82
|
+
end
|
83
|
+
@exceptionrules = File.join(@testdir, "rules_exception.rb")
|
84
|
+
File.open @exceptionrules, "w" do |f|
|
85
|
+
f.puts "raise RuntimeError, 'testing'"
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
def teardown
|
90
|
+
File.unlink @invalidrules if File.exists? @invalidrules
|
91
|
+
end
|
92
|
+
|
93
|
+
def test_process_default
|
94
|
+
@gurgitate.add_rules :default
|
95
|
+
assert_nothing_raised do
|
96
|
+
@gurgitate.process
|
97
|
+
end
|
98
|
+
end
|
99
|
+
|
100
|
+
def test_process_rules_not_found
|
101
|
+
@gurgitate.add_rules @rulesfile
|
102
|
+
File.unlink @rulesfile
|
103
|
+
assert_nothing_raised do
|
104
|
+
@gurgitate.process
|
105
|
+
end
|
106
|
+
assert File.exists?(@spoolfile)
|
107
|
+
end
|
108
|
+
end
|
@@ -0,0 +1,56 @@
|
|
1
|
+
#/opt/bin/ruby -w
|
2
|
+
|
3
|
+
require 'test/unit'
|
4
|
+
require 'test/unit/ui/console/testrunner'
|
5
|
+
require 'stringio'
|
6
|
+
|
7
|
+
class TC_Writing < Test::Unit::TestCase
|
8
|
+
def test_null_message
|
9
|
+
assert_nothing_raised do
|
10
|
+
Gurgitate::Mailmessage.new
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
def test_one_header_message
|
15
|
+
mess = Gurgitate::Mailmessage.new
|
16
|
+
mess.headers["From"] = "test@test"
|
17
|
+
assert_equal "From: test@test", mess.headers.to_s
|
18
|
+
assert_equal "From: test@test\n\n", mess.to_s
|
19
|
+
end
|
20
|
+
|
21
|
+
def test_two_headers_message
|
22
|
+
mess = Gurgitate::Mailmessage.new
|
23
|
+
mess.headers["From"] = "test@test"
|
24
|
+
mess.headers["To"] = "test2@test2"
|
25
|
+
assert_equal "From: test@test\nTo: test2@test2", mess.headers.to_s
|
26
|
+
end
|
27
|
+
|
28
|
+
def test_initialization_headers_only
|
29
|
+
mess = Gurgitate::Mailmessage.create :from => "test@test", :to => "test2@test2"
|
30
|
+
assert_equal [ "From: test@test", "To: test2@test2" ],
|
31
|
+
mess.headers.to_s.split(/\n/)
|
32
|
+
end
|
33
|
+
|
34
|
+
def test_initialization_headers_and_body
|
35
|
+
mess = Gurgitate::Mailmessage.create "This is a test",
|
36
|
+
:from => "test@test",
|
37
|
+
:to => "test2@test"
|
38
|
+
assert_equal "This is a test", mess.body
|
39
|
+
end
|
40
|
+
|
41
|
+
def test_initialization_headers_body_in_initialization_hash
|
42
|
+
mess = Gurgitate::Mailmessage.create :body => "This is a test",
|
43
|
+
:from => "test@test",
|
44
|
+
:to => "test2@test"
|
45
|
+
assert_equal "This is a test", mess.body
|
46
|
+
end
|
47
|
+
|
48
|
+
def test_creation_round_trip
|
49
|
+
mess = Gurgitate::Mailmessage.create "This is a test",
|
50
|
+
:from => "test@test",
|
51
|
+
:to => "test2@test2",
|
52
|
+
:subject => "Test subject"
|
53
|
+
reparsed_mess = Gurgitate::Mailmessage.new(mess.to_s)
|
54
|
+
assert_equal reparsed_mess.to_s, mess.to_s
|
55
|
+
end
|
56
|
+
end
|
metadata
CHANGED
@@ -3,8 +3,8 @@ rubygems_version: 0.9.2
|
|
3
3
|
specification_version: 1
|
4
4
|
name: gurgitate-mail
|
5
5
|
version: !ruby/object:Gem::Version
|
6
|
-
version: 1.8.
|
7
|
-
date: 2007-
|
6
|
+
version: 1.8.5
|
7
|
+
date: 2007-05-23 00:00:00 +09:00
|
8
8
|
summary: gurgitate-mail is a mail filter (and a mail-delivery agent)
|
9
9
|
require_paths:
|
10
10
|
- lib
|
@@ -30,13 +30,21 @@ authors:
|
|
30
30
|
- Dave Brown
|
31
31
|
files:
|
32
32
|
- lib/gurgitate-mail.rb
|
33
|
-
- lib/gurgitate/deliver.rb
|
34
|
-
- lib/gurgitate/headers.rb
|
35
|
-
- lib/gurgitate/mailmessage.rb
|
36
33
|
- lib/gurgitate/deliver/mbox.rb
|
37
34
|
- lib/gurgitate/deliver/maildir.rb
|
35
|
+
- lib/gurgitate/deliver.rb
|
36
|
+
- lib/gurgitate/mailmessage.rb
|
37
|
+
- lib/gurgitate/headers.rb
|
38
38
|
test_files:
|
39
|
-
- test.rb
|
39
|
+
- test/test_header.rb
|
40
|
+
- test/runtests.rb
|
41
|
+
- test/test_delivery.rb
|
42
|
+
- test/test_rules.rb
|
43
|
+
- test/test_writing.rb
|
44
|
+
- test/gurgitate-test.rb
|
45
|
+
- test/test_process.rb
|
46
|
+
- test/test_configuration.rb
|
47
|
+
- test/test_headers.rb
|
40
48
|
rdoc_options: []
|
41
49
|
|
42
50
|
extra_rdoc_files: []
|