mailfactory 0.5.2 → 1.0.2
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/lib/mailfactory.rb +40 -47
- data/tests/test_mailfactory.rb +23 -8
- metadata +7 -5
data/lib/mailfactory.rb
CHANGED
@@ -56,6 +56,8 @@ class MailFactory
|
|
56
56
|
@attachments = Array.new()
|
57
57
|
@attachmentboundary = generate_boundary()
|
58
58
|
@bodyboundary = generate_boundary()
|
59
|
+
@html = nil
|
60
|
+
@text = nil
|
59
61
|
end
|
60
62
|
|
61
63
|
|
@@ -82,50 +84,6 @@ class MailFactory
|
|
82
84
|
end
|
83
85
|
|
84
86
|
|
85
|
-
def to=(newto)
|
86
|
-
remove_header("To")
|
87
|
-
add_header("To", newto)
|
88
|
-
end
|
89
|
-
|
90
|
-
|
91
|
-
def to()
|
92
|
-
return(get_header("To")[0])
|
93
|
-
end
|
94
|
-
|
95
|
-
|
96
|
-
def from=(newfrom)
|
97
|
-
remove_header("From")
|
98
|
-
add_header("From", newfrom)
|
99
|
-
end
|
100
|
-
|
101
|
-
|
102
|
-
def from()
|
103
|
-
return(get_header("From")[0])
|
104
|
-
end
|
105
|
-
|
106
|
-
|
107
|
-
def subject=(newsubject)
|
108
|
-
remove_header("Subject")
|
109
|
-
add_header("Subject", newsubject)
|
110
|
-
end
|
111
|
-
|
112
|
-
|
113
|
-
def subject()
|
114
|
-
return(get_header("Subject")[0])
|
115
|
-
end
|
116
|
-
|
117
|
-
|
118
|
-
def cc=(newcc)
|
119
|
-
remove_header("CC")
|
120
|
-
add_header("CC", newcc)
|
121
|
-
end
|
122
|
-
|
123
|
-
|
124
|
-
def cc()
|
125
|
-
return(get_header("CC")[0])
|
126
|
-
end
|
127
|
-
|
128
|
-
|
129
87
|
def replyto=(newreplyto)
|
130
88
|
remove_header("Reply-To")
|
131
89
|
add_header("Reply-To", newreplyto)
|
@@ -156,6 +114,35 @@ class MailFactory
|
|
156
114
|
end
|
157
115
|
|
158
116
|
|
117
|
+
# implement method missing to provide helper methods for setting and getting headers.
|
118
|
+
# Headers with '-' characters may be set/gotten as 'x_mailer' or 'XMailer' (splitting
|
119
|
+
# will occur between capital letters or on '_' chracters)
|
120
|
+
def method_missing(methId, *args)
|
121
|
+
name = methId.id2name()
|
122
|
+
|
123
|
+
# mangle the name if we have to
|
124
|
+
if(name =~ /_/)
|
125
|
+
name = name.gsub(/_/, '-')
|
126
|
+
elsif(name =~ /[A-Z]/)
|
127
|
+
name = name.gsub(/([a-zA-Z])([A-Z])/, '\1-\2')
|
128
|
+
end
|
129
|
+
|
130
|
+
# determine if it sets or gets, and do the right thing
|
131
|
+
if(name =~ /=$/)
|
132
|
+
if(args.length != 1)
|
133
|
+
super(methId, args)
|
134
|
+
end
|
135
|
+
set_header(name[/^(.*)=$/, 1], args[0])
|
136
|
+
else
|
137
|
+
if(args.length != 0)
|
138
|
+
super(methId, args)
|
139
|
+
end
|
140
|
+
headers = get_header(name)
|
141
|
+
return(get_header(name))
|
142
|
+
end
|
143
|
+
end
|
144
|
+
|
145
|
+
|
159
146
|
# returns the value (or values) of the named header in an array
|
160
147
|
def get_header(header)
|
161
148
|
headers = Array.new()
|
@@ -182,10 +169,14 @@ class MailFactory
|
|
182
169
|
|
183
170
|
# returns a formatted email
|
184
171
|
def to_s()
|
172
|
+
# all emails get a unique message-id
|
173
|
+
remove_header("Message-ID")
|
174
|
+
add_header("Message-ID", "<#{Time.now.to_f()}.#{Process.euid()}.#{String.new.object_id()}>")
|
175
|
+
|
185
176
|
if(get_header("Date").length == 0)
|
186
177
|
add_header("Date", Time.now.strftime("%a, %d %B %Y %H:%M:%S %Z"))
|
187
178
|
end
|
188
|
-
|
179
|
+
|
189
180
|
# Add a mime header if we don't already have one and we have multiple parts
|
190
181
|
if(multipart?())
|
191
182
|
if(get_header("MIME-Version").length == 0)
|
@@ -257,13 +248,15 @@ class MailFactory
|
|
257
248
|
attachment[1] = type
|
258
249
|
end
|
259
250
|
|
260
|
-
if(
|
251
|
+
if(file.kind_of?(String) or file.kind_of?(Pathname))
|
261
252
|
# Open in rb mode to handle Windows, which mangles binary files opened in a text mode
|
262
253
|
File.open(file.to_s(), "rb") { |fp|
|
263
254
|
attachment[2] = Base64.b64encode(fp.read())
|
264
255
|
}
|
256
|
+
elsif(file.respond_to?(:read))
|
257
|
+
attachment[2] = Base64.b64encode(file.read())
|
265
258
|
else
|
266
|
-
|
259
|
+
raise(Exception, "file is not a supported type")
|
267
260
|
end
|
268
261
|
@attachments << attachment
|
269
262
|
end
|
data/tests/test_mailfactory.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
#!/usr/local/bin/ruby
|
2
2
|
|
3
3
|
require 'test/unit/ui/console/testrunner'
|
4
|
-
require '
|
4
|
+
require File.dirname(__FILE__) + '/../lib/mailfactory.rb'
|
5
5
|
|
6
6
|
|
7
7
|
def get_options()
|
@@ -54,7 +54,7 @@ class TC_MailFactory < Test::Unit::TestCase
|
|
54
54
|
@mail.to = "test@test.com"
|
55
55
|
}
|
56
56
|
|
57
|
-
assert_equal(@mail.to, "test@test.com", "to does not equal what it was set to")
|
57
|
+
assert_equal(@mail.to, ["test@test.com"], "to does not equal what it was set to")
|
58
58
|
|
59
59
|
assert_nothing_raised("exception raised while setting to=") {
|
60
60
|
@mail.to = "test@test2.com"
|
@@ -76,7 +76,7 @@ class TC_MailFactory < Test::Unit::TestCase
|
|
76
76
|
@mail.from = "test@test.com"
|
77
77
|
}
|
78
78
|
|
79
|
-
assert_equal(@mail.from, "test@test.com", "from does not equal what it was set to")
|
79
|
+
assert_equal(@mail.from, ["test@test.com"], "from does not equal what it was set to")
|
80
80
|
|
81
81
|
assert_nothing_raised("exception raised while setting from=") {
|
82
82
|
@mail.from = "test@test2.com"
|
@@ -98,7 +98,7 @@ class TC_MailFactory < Test::Unit::TestCase
|
|
98
98
|
@mail.subject = "Test Subject"
|
99
99
|
}
|
100
100
|
|
101
|
-
assert_equal(@mail.subject, "Test Subject", "subject does not equal what it was set to")
|
101
|
+
assert_equal(@mail.subject, ["Test Subject"], "subject does not equal what it was set to")
|
102
102
|
|
103
103
|
assert_nothing_raised("exception raised while setting subject=") {
|
104
104
|
@mail.subject = "A Different Subject"
|
@@ -121,6 +121,21 @@ class TC_MailFactory < Test::Unit::TestCase
|
|
121
121
|
}
|
122
122
|
|
123
123
|
assert_equal("some value", @mail.get_header("arbitrary")[0], "arbitrary header does not equal \"some value\"")
|
124
|
+
|
125
|
+
assert_nothing_raised("exception raised while setting arbitrary header with _") {
|
126
|
+
@mail.arbitrary_header = "some _ value"
|
127
|
+
}
|
128
|
+
|
129
|
+
assert_equal(["some _ value"], @mail.get_header("arbitrary-header"), "arbitrary header does not equal \"some _ value\"")
|
130
|
+
assert_equal(["some _ value"], @mail.arbitrary_header, "arbitrary header does not equal \"some _ value\"")
|
131
|
+
|
132
|
+
|
133
|
+
assert_nothing_raised("exception raised while setting arbitraryHeader") {
|
134
|
+
@mail.arbitraryHeader = "someValue"
|
135
|
+
}
|
136
|
+
|
137
|
+
assert_equal(["someValue"], @mail.get_header("arbitrary-header"), "arbitrary header does not equal \"someValue\"")
|
138
|
+
assert_equal(["someValue"], @mail.arbitraryHeader, "arbitrary header does not equal \"someValue\"")
|
124
139
|
end
|
125
140
|
|
126
141
|
|
@@ -137,8 +152,8 @@ class TC_MailFactory < Test::Unit::TestCase
|
|
137
152
|
@mail.subject="This is a test"
|
138
153
|
@mail.text = "This is a test message with\na few\n\nlines."
|
139
154
|
|
140
|
-
@mail.attach('testfile.txt')
|
141
|
-
@mail.attach('testsheet.xls')
|
155
|
+
@mail.attach(File.dirname(__FILE__) + '/testfile.txt')
|
156
|
+
@mail.attach(File.dirname(__FILE__) + '/testsheet.xls')
|
142
157
|
|
143
158
|
if($options['smtpserver'] != nil and $options['to'] != nil and $options['from'] != nil)
|
144
159
|
assert_nothing_raised() {
|
@@ -157,8 +172,8 @@ class TC_MailFactory < Test::Unit::TestCase
|
|
157
172
|
@mail.subject="This is a test"
|
158
173
|
@mail.text = "This is a test message with\na few\n\nlines."
|
159
174
|
|
160
|
-
@mail.add_attachment_as('testfile.txt', 'newname.txt')
|
161
|
-
@mail.add_attachment_as(File.open('testsheet.xls', 'rb'), 'newname.xls', 'application/vnd.ms-excel')
|
175
|
+
@mail.add_attachment_as(File.dirname(__FILE__) + '/testfile.txt', 'newname.txt')
|
176
|
+
@mail.add_attachment_as(File.open(File.dirname(__FILE__) + '/testsheet.xls', 'rb'), 'newname.xls', 'application/vnd.ms-excel')
|
162
177
|
|
163
178
|
if($options['smtpserver'] != nil and $options['to'] != nil and $options['from'] != nil)
|
164
179
|
assert_nothing_raised() {
|
metadata
CHANGED
@@ -1,10 +1,10 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
|
-
rubygems_version: 0.8.
|
2
|
+
rubygems_version: 0.8.11
|
3
3
|
specification_version: 1
|
4
4
|
name: mailfactory
|
5
5
|
version: !ruby/object:Gem::Version
|
6
|
-
version: 0.
|
7
|
-
date: 2005-
|
6
|
+
version: 1.0.2
|
7
|
+
date: 2005-09-16 00:00:00 -04:00
|
8
8
|
summary: MailFactory is a pure-ruby MIME mail generator
|
9
9
|
require_paths:
|
10
10
|
- lib
|
@@ -25,12 +25,14 @@ required_ruby_version: !ruby/object:Gem::Version::Requirement
|
|
25
25
|
version: 0.0.0
|
26
26
|
version:
|
27
27
|
platform: ruby
|
28
|
+
signing_key:
|
29
|
+
cert_chain:
|
28
30
|
authors:
|
29
31
|
- David Powers
|
30
32
|
files:
|
31
|
-
- lib/mailfactory.rb
|
33
|
+
- "./lib/mailfactory.rb"
|
32
34
|
test_files:
|
33
|
-
- tests/test_mailfactory.rb
|
35
|
+
- "./tests/test_mailfactory.rb"
|
34
36
|
rdoc_options: []
|
35
37
|
extra_rdoc_files: []
|
36
38
|
executables: []
|