gurgitate-mail 1.8.5 → 1.9.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/bin/gurgitate-mail +1 -1
- data/lib/gurgitate/deliver/maildir.rb +1 -1
- data/lib/gurgitate/header.rb +81 -0
- data/lib/gurgitate/headers.rb +3 -77
- data/lib/gurgitate/mailmessage.rb +6 -6
- data/test/gurgitate-test.rb +4 -18
- data/test/test_deliver.rb +76 -0
- data/test/test_gurgitate_delivery.rb +212 -0
- data/test/test_process.rb +0 -11
- data/test/test_rules.rb +0 -1
- data/test/test_writing.rb +52 -0
- metadata +13 -9
data/bin/gurgitate-mail
CHANGED
@@ -0,0 +1,81 @@
|
|
1
|
+
#!/opt/bin/ruby -w
|
2
|
+
|
3
|
+
module Gurgitate
|
4
|
+
class IllegalHeader < RuntimeError ; end
|
5
|
+
|
6
|
+
# A little class for a single header
|
7
|
+
class Header
|
8
|
+
# The name of the header
|
9
|
+
attr_accessor :name
|
10
|
+
# The contents of the header
|
11
|
+
attr_accessor :contents
|
12
|
+
|
13
|
+
alias_method :value, :contents
|
14
|
+
|
15
|
+
# A recent rash of viruses has forced me to canonicalize
|
16
|
+
# the capitalization of headers. Sigh.
|
17
|
+
def capitalize_words(s)
|
18
|
+
return s.split(/-/).map { |w| w.capitalize }.join("-")
|
19
|
+
rescue
|
20
|
+
return s
|
21
|
+
end
|
22
|
+
|
23
|
+
private :capitalize_words
|
24
|
+
|
25
|
+
# Creates a Header object.
|
26
|
+
# header::
|
27
|
+
# The text of the email-message header
|
28
|
+
def initialize(*header)
|
29
|
+
name,contents=nil,nil
|
30
|
+
if header.length == 1 then
|
31
|
+
# RFC822 says that a header consists of some (printable,
|
32
|
+
# non-whitespace) crap, followed by a colon, followed by
|
33
|
+
# some more (printable, but can include whitespaces)
|
34
|
+
# crap.
|
35
|
+
if(header[0] =~ /^[\x21-\x39\x3b-\x7e]+:/) then
|
36
|
+
(name,contents)=header[0].split(/:\s+/,2)
|
37
|
+
if(name =~ /:$/ and contents == nil) then
|
38
|
+
# It looks like someone is using Becky!
|
39
|
+
name=header[0].gsub(/:$/,"")
|
40
|
+
contents = ""
|
41
|
+
end
|
42
|
+
|
43
|
+
raise IllegalHeader, "Empty name" \
|
44
|
+
if (name == "" or name == nil)
|
45
|
+
contents="" if contents == nil
|
46
|
+
|
47
|
+
@@lastname=name
|
48
|
+
else
|
49
|
+
raise IllegalHeader, "Bad header syntax: no colon in #{header}"
|
50
|
+
end
|
51
|
+
elsif header.length == 2 then
|
52
|
+
name,contents = *header
|
53
|
+
end
|
54
|
+
|
55
|
+
@name=capitalize_words(name)
|
56
|
+
@contents=contents
|
57
|
+
end
|
58
|
+
|
59
|
+
# Extended header
|
60
|
+
def << (text)
|
61
|
+
@contents += "\n" + text
|
62
|
+
end
|
63
|
+
|
64
|
+
# Matches a header's contents.
|
65
|
+
# regex::
|
66
|
+
# The regular expression to match against the header's contents
|
67
|
+
def matches (regex)
|
68
|
+
if String === regex
|
69
|
+
regex = Regexp.new(Regexp.escape(regex))
|
70
|
+
end
|
71
|
+
@contents =~ regex
|
72
|
+
end
|
73
|
+
|
74
|
+
alias :=~ :matches
|
75
|
+
|
76
|
+
# Returns the header, ready to put into an email message
|
77
|
+
def to_s
|
78
|
+
@name+": "+@contents
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
data/lib/gurgitate/headers.rb
CHANGED
@@ -1,84 +1,10 @@
|
|
1
1
|
#!/opt/bin/ruby -w
|
2
2
|
|
3
|
+
require "gurgitate/header"
|
4
|
+
|
3
5
|
module Gurgitate
|
4
6
|
class IllegalHeader < RuntimeError ; end
|
5
7
|
|
6
|
-
# A little class for a single header
|
7
|
-
class Header
|
8
|
-
# The name of the header
|
9
|
-
attr_accessor :name
|
10
|
-
# The contents of the header
|
11
|
-
attr_accessor :contents
|
12
|
-
|
13
|
-
alias_method :value, :contents
|
14
|
-
|
15
|
-
# A recent rash of viruses has forced me to canonicalize
|
16
|
-
# the capitalization of headers. Sigh.
|
17
|
-
def capitalize_words(s)
|
18
|
-
return s.split(/-/).map { |w| w.capitalize }.join("-")
|
19
|
-
rescue
|
20
|
-
return s
|
21
|
-
end
|
22
|
-
|
23
|
-
private :capitalize_words
|
24
|
-
|
25
|
-
# Creates a Header object.
|
26
|
-
# header::
|
27
|
-
# The text of the email-message header
|
28
|
-
def initialize(*header)
|
29
|
-
name,contents=nil,nil
|
30
|
-
if header.length == 1 then
|
31
|
-
# RFC822 says that a header consists of some (printable,
|
32
|
-
# non-whitespace) crap, followed by a colon, followed by
|
33
|
-
# some more (printable, but can include whitespaces)
|
34
|
-
# crap.
|
35
|
-
if(header[0] =~ /^[\x21-\x39\x3b-\x7e]+:/) then
|
36
|
-
(name,contents)=header[0].split(/:\s+/,2)
|
37
|
-
if(name =~ /:$/ and contents == nil) then
|
38
|
-
# It looks like someone is using Becky!
|
39
|
-
name=header[0].gsub(/:$/,"")
|
40
|
-
contents = ""
|
41
|
-
end
|
42
|
-
|
43
|
-
raise IllegalHeader, "Empty name" \
|
44
|
-
if (name == "" or name == nil)
|
45
|
-
contents="" if contents == nil
|
46
|
-
|
47
|
-
@@lastname=name
|
48
|
-
else
|
49
|
-
raise IllegalHeader, "Bad header syntax: no colon in #{header}"
|
50
|
-
end
|
51
|
-
elsif header.length == 2 then
|
52
|
-
name,contents = *header
|
53
|
-
end
|
54
|
-
|
55
|
-
@name=capitalize_words(name)
|
56
|
-
@contents=contents
|
57
|
-
end
|
58
|
-
|
59
|
-
# Extended header
|
60
|
-
def << (text)
|
61
|
-
@contents += "\n" + text
|
62
|
-
end
|
63
|
-
|
64
|
-
# Matches a header's contents.
|
65
|
-
# regex::
|
66
|
-
# The regular expression to match against the header's contents
|
67
|
-
def matches (regex)
|
68
|
-
if String === regex
|
69
|
-
regex = Regexp.new(Regexp.escape(regex))
|
70
|
-
end
|
71
|
-
@contents =~ regex
|
72
|
-
end
|
73
|
-
|
74
|
-
alias :=~ :matches
|
75
|
-
|
76
|
-
# Returns the header, ready to put into an email message
|
77
|
-
def to_s
|
78
|
-
@name+": "+@contents
|
79
|
-
end
|
80
|
-
end
|
81
|
-
|
82
8
|
# ========================================================================
|
83
9
|
|
84
10
|
class HeaderBag < Array
|
@@ -223,7 +149,7 @@ module Gurgitate
|
|
223
149
|
# Creates a Headers object.
|
224
150
|
# headertext::
|
225
151
|
# The text of the message headers.
|
226
|
-
def initialize(headertext=nil,sender=nil, recipient=nil)
|
152
|
+
def initialize(headertext=nil, sender=nil, recipient=nil)
|
227
153
|
@from = sender
|
228
154
|
@to = recipient
|
229
155
|
@headers = Hash.new(nil)
|
@@ -33,9 +33,10 @@ module Gurgitate
|
|
33
33
|
body = args[0]
|
34
34
|
elsif Hash === args[0]
|
35
35
|
options = args[0]
|
36
|
+
else
|
37
|
+
options = {}
|
36
38
|
end
|
37
39
|
|
38
|
-
options = options.clone # just in case, since I'm meddling with it
|
39
40
|
message = self.new
|
40
41
|
|
41
42
|
message.instance_eval do
|
@@ -46,7 +47,7 @@ module Gurgitate
|
|
46
47
|
%w/sender recipient body/.each do |key|
|
47
48
|
if options.has_key? key.to_sym
|
48
49
|
instance_variable_set("@#{key}", options[key.to_sym])
|
49
|
-
options.delete key
|
50
|
+
options.delete key.to_sym
|
50
51
|
end
|
51
52
|
end
|
52
53
|
|
@@ -77,12 +78,11 @@ module Gurgitate
|
|
77
78
|
|
78
79
|
# custom accessors
|
79
80
|
|
80
|
-
# Returns the
|
81
|
+
# Returns the message's sender
|
81
82
|
def from; @sender || @headers.from; end
|
82
83
|
|
83
|
-
# Returns all the candidates for a
|
84
|
-
def to; @recipient || @headers["To", "Cc"]; end
|
85
|
-
# def to; @headers["To","Cc"]; end
|
84
|
+
# Returns all the candidates for a recipient
|
85
|
+
def to; @recipient || @headers["To", "Cc"][0].contents; end
|
86
86
|
|
87
87
|
# Returns the formatted mail message
|
88
88
|
def to_s; @headers.to_s + "\n\n" + ( @body || ""); end
|
data/test/gurgitate-test.rb
CHANGED
@@ -4,37 +4,23 @@ require 'stringio'
|
|
4
4
|
require 'fileutils'
|
5
5
|
require 'pathname'
|
6
6
|
require 'irb'
|
7
|
-
|
7
|
+
$:.unshift File.dirname(__FILE__) + "/.."
|
8
|
+
require "gurgitate-mail"
|
8
9
|
|
9
10
|
class GurgitateTest < Test::Unit::TestCase
|
10
11
|
def setup
|
11
12
|
currentdir = Pathname.new(File.join(File.dirname(__FILE__),
|
12
13
|
"..")).realpath.to_s
|
13
14
|
@testdir = File.join(currentdir,"test-data")
|
14
|
-
testdir = @testdir
|
15
15
|
@folders = File.join(@testdir,"folders")
|
16
|
-
folders = @folders
|
17
16
|
FileUtils.rmtree @testdir if File.exists? @testdir
|
18
17
|
Dir.mkdir @testdir
|
19
18
|
Dir.mkdir @folders
|
20
19
|
m = StringIO.new("From: me\nTo: you\nSubject: test\n\nHi.\n")
|
21
20
|
@gurgitate = nil
|
22
21
|
@gurgitate = Gurgitate::Gurgitate.new(m)
|
23
|
-
|
24
|
-
|
25
|
-
sendmail = @sendmail
|
26
|
-
|
27
|
-
Dir.mkdir File.join(@testdir,"bin")
|
28
|
-
|
29
|
-
File.open(@sendmail,"w") do |f|
|
30
|
-
f.puts "#!/bin/sh"
|
31
|
-
f.puts "exec > #{@testdir}/sendmail_output 2>&1"
|
32
|
-
f.puts 'echo "$@"'
|
33
|
-
f.puts 'cat'
|
34
|
-
end
|
35
|
-
|
36
|
-
FileUtils.chmod 0755, @sendmail
|
37
|
-
|
22
|
+
testdir = @testdir
|
23
|
+
folders = @folders
|
38
24
|
@gurgitate.instance_eval do
|
39
25
|
sendmail "/bin/cat"
|
40
26
|
homedir testdir
|
@@ -0,0 +1,76 @@
|
|
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 "test/gurgitate-test"
|
8
|
+
require "gurgitate/deliver"
|
9
|
+
|
10
|
+
class DeliverTest
|
11
|
+
include Gurgitate::Deliver
|
12
|
+
|
13
|
+
attr_accessor :folderstyle
|
14
|
+
|
15
|
+
def to_mbox
|
16
|
+
"From test\n" + to_s
|
17
|
+
end
|
18
|
+
|
19
|
+
def to_s
|
20
|
+
"From: test\nTo:test\nSubject: test\n\nTest\n"
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
class TC_Deliver < Test::Unit::TestCase
|
25
|
+
def setup
|
26
|
+
currentdir = Pathname.new(File.join(File.dirname(__FILE__),
|
27
|
+
"..")).realpath.to_s
|
28
|
+
@testdir = File.join(currentdir,"test-data")
|
29
|
+
@folders = File.join(@testdir,"folders")
|
30
|
+
FileUtils.rmtree @testdir if File.exists? @testdir
|
31
|
+
Dir.mkdir @testdir
|
32
|
+
Dir.mkdir @folders
|
33
|
+
m = StringIO.new("From: me\nTo: you\nSubject: test\n\nHi.\n")
|
34
|
+
@deliver_test = DeliverTest.new
|
35
|
+
testdir = @testdir
|
36
|
+
folders = @folders
|
37
|
+
@deliver_test.folderstyle = Gurgitate::Deliver::MBox
|
38
|
+
@spoolfile = File.join(testdir, "default")
|
39
|
+
end
|
40
|
+
|
41
|
+
def teardown
|
42
|
+
FileUtils.rmtree @testdir
|
43
|
+
end
|
44
|
+
|
45
|
+
# ------------------------------------------------------------------------
|
46
|
+
# And the tests
|
47
|
+
# ------------------------------------------------------------------------
|
48
|
+
def test_setup_worked
|
49
|
+
assert true
|
50
|
+
end
|
51
|
+
|
52
|
+
def test_basic_delivery
|
53
|
+
assert_nothing_raised do
|
54
|
+
@deliver_test.save(@spoolfile)
|
55
|
+
end
|
56
|
+
assert File.exists?(@spoolfile)
|
57
|
+
assert File.file?(@spoolfile)
|
58
|
+
assert_equal File.read(@spoolfile), @deliver_test.to_mbox
|
59
|
+
end
|
60
|
+
|
61
|
+
def test_basic_delivery_maildir
|
62
|
+
@deliver_test.folderstyle = Gurgitate::Deliver::Maildir
|
63
|
+
assert_nothing_raised do
|
64
|
+
@deliver_test.save(@spoolfile)
|
65
|
+
end
|
66
|
+
assert File.exists?(@spoolfile)
|
67
|
+
assert File.directory?(@spoolfile)
|
68
|
+
assert File.exists?(File.join(@spoolfile,"cur"))
|
69
|
+
assert File.exists?(File.join(@spoolfile,"new"))
|
70
|
+
assert File.exists?(File.join(@spoolfile,"tmp"))
|
71
|
+
contents = Dir[File.join(@spoolfile,"new","*")]
|
72
|
+
assert contents.length == 1
|
73
|
+
assert File.exists?(contents[0])
|
74
|
+
assert_equal File.read(contents[0]), @deliver_test.to_s
|
75
|
+
end
|
76
|
+
end
|
@@ -0,0 +1,212 @@
|
|
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
|
+
require "test/gurgitate-test"
|
9
|
+
|
10
|
+
class TC_Gurgitate_delivery < GurgitateTest
|
11
|
+
#************************************************************************
|
12
|
+
# tests
|
13
|
+
#************************************************************************
|
14
|
+
def test_basic_delivery
|
15
|
+
assert_nothing_raised do
|
16
|
+
@gurgitate.process { nil }
|
17
|
+
end
|
18
|
+
assert File.exists?(@spoolfile)
|
19
|
+
end
|
20
|
+
|
21
|
+
def test_detect_mbox
|
22
|
+
Dir.mkdir(@testdir) rescue nil
|
23
|
+
File.open(@spoolfile, File::WRONLY | File::CREAT) do |f|
|
24
|
+
f.print ""
|
25
|
+
end
|
26
|
+
|
27
|
+
assert_nothing_raised do
|
28
|
+
@gurgitate.process { nil }
|
29
|
+
end
|
30
|
+
|
31
|
+
assert File.exists?(@spoolfile)
|
32
|
+
end
|
33
|
+
|
34
|
+
def test_detect_maildir
|
35
|
+
maildirmake @spoolfile
|
36
|
+
|
37
|
+
assert_nothing_raised do
|
38
|
+
@gurgitate.process { nil }
|
39
|
+
end
|
40
|
+
|
41
|
+
assert Dir[File.join(@spoolfile,"new","*")].length > 0
|
42
|
+
assert File.exists?(Dir[File.join(@spoolfile,"new","*")][0])
|
43
|
+
FileUtils.rmtree @spoolfile
|
44
|
+
teardown
|
45
|
+
test_detect_mbox
|
46
|
+
setup
|
47
|
+
end
|
48
|
+
|
49
|
+
def test_save_folders
|
50
|
+
assert_nothing_raised do
|
51
|
+
@gurgitate.process do
|
52
|
+
save "=test"
|
53
|
+
break
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
assert File.exists?(File.join(@folders, "test"))
|
58
|
+
assert File.stat(File.join(@folders, "test")).file?
|
59
|
+
end
|
60
|
+
|
61
|
+
def test_save_guess_maildir
|
62
|
+
maildirmake File.join(@folders,"test")
|
63
|
+
|
64
|
+
assert File.exists?(File.join(@folders, "test"))
|
65
|
+
assert File.stat(File.join(@folders, "test")).directory?
|
66
|
+
assert File.exists?(File.join(@folders, "test", "new"))
|
67
|
+
|
68
|
+
assert_equal 0, Dir[File.join(@folders, "test", "new", "*")].length
|
69
|
+
assert_equal 0, Dir[File.join(@folders, "test", "cur", "*")].length
|
70
|
+
|
71
|
+
assert_nothing_raised do
|
72
|
+
@gurgitate.process do
|
73
|
+
save "=test"
|
74
|
+
break
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
assert File.exists?(File.join(@folders, "test"))
|
79
|
+
assert File.stat(File.join(@folders, "test")).directory?
|
80
|
+
assert File.exists?(File.join(@folders, "test", "new"))
|
81
|
+
assert File.stat(File.join(@folders, "test","new")).directory?
|
82
|
+
assert_equal 0, Dir[File.join(@folders, "test", "cur", "*")].length
|
83
|
+
assert_equal 1, Dir[File.join(@folders, "test", "new", "*")].length
|
84
|
+
end
|
85
|
+
|
86
|
+
def test_save_maildir_collision
|
87
|
+
maildirmake File.join(@folders,"test")
|
88
|
+
|
89
|
+
assert File.exists?(File.join(@folders, "test"))
|
90
|
+
assert File.stat(File.join(@folders, "test")).directory?
|
91
|
+
assert File.exists?(File.join(@folders, "test", "new"))
|
92
|
+
|
93
|
+
assert_equal 0, Dir[File.join(@folders, "test", "new", "*")].length
|
94
|
+
assert_equal 0, Dir[File.join(@folders, "test", "cur", "*")].length
|
95
|
+
|
96
|
+
assert_nothing_raised do
|
97
|
+
@gurgitate.process do
|
98
|
+
save "=test"
|
99
|
+
save "=test"
|
100
|
+
break
|
101
|
+
end
|
102
|
+
end
|
103
|
+
|
104
|
+
assert File.exists?(File.join(@folders, "test"))
|
105
|
+
assert File.stat(File.join(@folders, "test")).directory?
|
106
|
+
assert File.exists?(File.join(@folders, "test", "new"))
|
107
|
+
assert File.stat(File.join(@folders, "test","new")).directory?
|
108
|
+
assert_equal 0, Dir[File.join(@folders, "test", "cur", "*")].length
|
109
|
+
assert_equal 2, Dir[File.join(@folders, "test", "new", "*")].length
|
110
|
+
end
|
111
|
+
|
112
|
+
def test_save_create_maildir
|
113
|
+
maildirmake @spoolfile
|
114
|
+
|
115
|
+
assert_nothing_raised do
|
116
|
+
@gurgitate.process do
|
117
|
+
@folderstyle = Gurgitate::Deliver::Maildir
|
118
|
+
@maildir = @spoolfile
|
119
|
+
save "=test"
|
120
|
+
break
|
121
|
+
end
|
122
|
+
end
|
123
|
+
|
124
|
+
assert File.exists?(File.join(@spoolfile, ".test"))
|
125
|
+
assert File.stat(File.join(@spoolfile, ".test")).directory?
|
126
|
+
assert File.exists?(File.join(@spoolfile, ".test", "new"))
|
127
|
+
assert File.stat(File.join(@spoolfile, ".test","new")).directory?
|
128
|
+
assert_equal 0, Dir[File.join(@spoolfile, ".test", "cur", "*")].length
|
129
|
+
assert_equal 1, Dir[File.join(@spoolfile, ".test", "new", "*")].length
|
130
|
+
end
|
131
|
+
|
132
|
+
def test_save_bad_filename
|
133
|
+
assert_nothing_raised do
|
134
|
+
@gurgitate.process do
|
135
|
+
save "testing"
|
136
|
+
end
|
137
|
+
end
|
138
|
+
|
139
|
+
assert File.exists?(@spoolfile)
|
140
|
+
assert !File.exists?("testing")
|
141
|
+
end
|
142
|
+
|
143
|
+
def test_cannot_save
|
144
|
+
FileUtils.touch @spoolfile
|
145
|
+
FileUtils.chmod 0, @spoolfile
|
146
|
+
|
147
|
+
assert_raises Errno::EACCES do
|
148
|
+
@gurgitate.process do
|
149
|
+
nil
|
150
|
+
end
|
151
|
+
end
|
152
|
+
end
|
153
|
+
|
154
|
+
def test_mailbox_heuristics_mbox
|
155
|
+
@gurgitate.instance_eval do
|
156
|
+
@folderstyle = nil
|
157
|
+
end
|
158
|
+
|
159
|
+
assert_nothing_raised do
|
160
|
+
@gurgitate.process do
|
161
|
+
save "=test"
|
162
|
+
end
|
163
|
+
end
|
164
|
+
|
165
|
+
assert File.exists?(File.join(@folders, "test"))
|
166
|
+
assert File.stat(File.join(@folders, "test")).file?
|
167
|
+
end
|
168
|
+
|
169
|
+
def test_mailbox_heuristics_maildir
|
170
|
+
@gurgitate.instance_eval do
|
171
|
+
@folderstyle = nil
|
172
|
+
end
|
173
|
+
|
174
|
+
assert_nothing_raised do
|
175
|
+
@gurgitate.process do
|
176
|
+
save "=test/"
|
177
|
+
end
|
178
|
+
end
|
179
|
+
|
180
|
+
assert File.exists?(File.join(@folders, "test"))
|
181
|
+
assert File.stat(File.join(@folders, "test")).directory?
|
182
|
+
assert File.exists?(File.join(@folders, "test", "new"))
|
183
|
+
assert File.stat(File.join(@folders, "test","new")).directory?
|
184
|
+
assert_equal 0, Dir[File.join(@folders, "test", "cur", "*")].length
|
185
|
+
assert_equal 1, Dir[File.join(@folders, "test", "new", "*")].length
|
186
|
+
end
|
187
|
+
|
188
|
+
def test_message_parsed_correctly
|
189
|
+
assert_equal("From: me",@gurgitate.header("From"))
|
190
|
+
assert_equal("To: you", @gurgitate.header("To"))
|
191
|
+
assert_equal("Subject: test", @gurgitate.header("Subject"))
|
192
|
+
assert_equal("Hi.\n", @gurgitate.body, "Message body is wrong")
|
193
|
+
end
|
194
|
+
|
195
|
+
def test_message_written_correctly
|
196
|
+
test_message_parsed_correctly
|
197
|
+
assert_nothing_raised do
|
198
|
+
@gurgitate.process
|
199
|
+
end
|
200
|
+
|
201
|
+
mess=nil
|
202
|
+
assert_nothing_raised do
|
203
|
+
mess = Gurgitate::Mailmessage.new(File.read(@spoolfile))
|
204
|
+
end
|
205
|
+
|
206
|
+
assert_equal("From: me", mess.header("From"), "From header is wrong")
|
207
|
+
assert_equal("To: you", mess.header("To"), "To header is wrong")
|
208
|
+
assert_equal("Hi.\n", mess.body, "Body is wrong")
|
209
|
+
assert_equal("Subject: test", mess.header("Subject"), "Subject header wrong")
|
210
|
+
end
|
211
|
+
end
|
212
|
+
|
data/test/test_process.rb
CHANGED
@@ -23,17 +23,6 @@ class TC_Process < GurgitateTest
|
|
23
23
|
end
|
24
24
|
end
|
25
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
26
|
def test_break_does_not_deliver
|
38
27
|
assert_nothing_raised do
|
39
28
|
@gurgitate.process { break }
|
data/test/test_rules.rb
CHANGED
data/test/test_writing.rb
CHANGED
@@ -36,6 +36,8 @@ class TC_Writing < Test::Unit::TestCase
|
|
36
36
|
:from => "test@test",
|
37
37
|
:to => "test2@test"
|
38
38
|
assert_equal "This is a test", mess.body
|
39
|
+
assert_equal [ "From: test@test", "To: test2@test" ],
|
40
|
+
mess.headers.to_s.split(/\n/)
|
39
41
|
end
|
40
42
|
|
41
43
|
def test_initialization_headers_body_in_initialization_hash
|
@@ -43,6 +45,8 @@ class TC_Writing < Test::Unit::TestCase
|
|
43
45
|
:from => "test@test",
|
44
46
|
:to => "test2@test"
|
45
47
|
assert_equal "This is a test", mess.body
|
48
|
+
assert_equal [ "From: test@test", "To: test2@test" ],
|
49
|
+
mess.headers.to_s.split(/\n/)
|
46
50
|
end
|
47
51
|
|
48
52
|
def test_creation_round_trip
|
@@ -53,4 +57,52 @@ class TC_Writing < Test::Unit::TestCase
|
|
53
57
|
reparsed_mess = Gurgitate::Mailmessage.new(mess.to_s)
|
54
58
|
assert_equal reparsed_mess.to_s, mess.to_s
|
55
59
|
end
|
60
|
+
|
61
|
+
def test_creation_sender_specified
|
62
|
+
mess = Gurgitate::Mailmessage.create :body => "This is a test",
|
63
|
+
:from => "from@test",
|
64
|
+
:to => "to@test",
|
65
|
+
:sender => "sender@test"
|
66
|
+
assert_equal "This is a test", mess.body
|
67
|
+
assert_equal "From: from@test", mess.headers["From"].to_s
|
68
|
+
assert_equal "To: to@test", mess.headers["To"].to_s
|
69
|
+
assert_equal "sender@test", mess.from
|
70
|
+
end
|
71
|
+
|
72
|
+
def test_creation_recipient_specified
|
73
|
+
mess = Gurgitate::Mailmessage.create :body => "This is a test",
|
74
|
+
:from => "from@test",
|
75
|
+
:to => "to@test",
|
76
|
+
:recipient => "recipient@test"
|
77
|
+
assert_equal "This is a test", mess.body
|
78
|
+
assert_equal "From: from@test", mess.headers["From"].to_s
|
79
|
+
assert_equal "To: to@test", mess.headers["To"].to_s
|
80
|
+
assert_equal "recipient@test", mess.to
|
81
|
+
end
|
82
|
+
|
83
|
+
def test_creation_sender_not_specified
|
84
|
+
mess = Gurgitate::Mailmessage.create :body => "This is a test",
|
85
|
+
:from => "from@test",
|
86
|
+
:to => "to@test"
|
87
|
+
assert_equal "This is a test", mess.body
|
88
|
+
assert_equal "From: from@test", mess.headers["From"].to_s
|
89
|
+
assert_equal "To: to@test", mess.headers["To"].to_s
|
90
|
+
assert_equal "", mess.from
|
91
|
+
assert_equal "to@test", mess.to
|
92
|
+
end
|
93
|
+
|
94
|
+
def test_creation_incrementally
|
95
|
+
mess = Gurgitate::Mailmessage.create
|
96
|
+
mess.sender = "sender@test"
|
97
|
+
mess.recipient = "recipient@test"
|
98
|
+
mess.body = "This is a test"
|
99
|
+
mess.headers["From"] = "from@test"
|
100
|
+
mess.headers["To"] = "to@test"
|
101
|
+
|
102
|
+
assert_equal "sender@test", mess.from
|
103
|
+
assert_equal "recipient@test", mess.to
|
104
|
+
assert_equal "This is a test", mess.body
|
105
|
+
assert_equal "From: from@test", mess.headers["From"].to_s
|
106
|
+
assert_equal "To: to@test", mess.headers["To"].to_s
|
107
|
+
end
|
56
108
|
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.
|
7
|
-
date: 2007-
|
6
|
+
version: 1.9.0
|
7
|
+
date: 2007-12-12 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,21 +30,25 @@ authors:
|
|
30
30
|
- Dave Brown
|
31
31
|
files:
|
32
32
|
- lib/gurgitate-mail.rb
|
33
|
-
- lib/gurgitate/deliver/mbox.rb
|
34
|
-
- lib/gurgitate/deliver/maildir.rb
|
35
33
|
- lib/gurgitate/deliver.rb
|
36
|
-
- lib/gurgitate/mailmessage.rb
|
37
34
|
- lib/gurgitate/headers.rb
|
38
|
-
|
35
|
+
- lib/gurgitate/header.rb
|
36
|
+
- lib/gurgitate/mailmessage.rb
|
37
|
+
- lib/gurgitate/deliver/maildir.rb
|
38
|
+
- lib/gurgitate/deliver/mbox.rb
|
39
39
|
- test/test_header.rb
|
40
40
|
- test/runtests.rb
|
41
|
-
- test/test_delivery.rb
|
42
41
|
- test/test_rules.rb
|
43
|
-
- test/test_writing.rb
|
44
|
-
- test/gurgitate-test.rb
|
45
42
|
- test/test_process.rb
|
46
43
|
- test/test_configuration.rb
|
47
44
|
- test/test_headers.rb
|
45
|
+
- test/gurgitate-test.rb
|
46
|
+
- test/test_deliver.rb
|
47
|
+
- test/test_gurgitate_delivery.rb
|
48
|
+
- test/test_writing.rb
|
49
|
+
- test/test_delivery.rb
|
50
|
+
test_files:
|
51
|
+
- test/runtests.rb
|
48
52
|
rdoc_options: []
|
49
53
|
|
50
54
|
extra_rdoc_files: []
|