mailfactory 0.5.3 → 1.0.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/lib/mailfactory.rb +29 -44
- data/tests/test_mailfactory.rb +18 -3
- metadata +1 -1
data/lib/mailfactory.rb
CHANGED
|
@@ -82,50 +82,6 @@ class MailFactory
|
|
|
82
82
|
end
|
|
83
83
|
|
|
84
84
|
|
|
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
85
|
def replyto=(newreplyto)
|
|
130
86
|
remove_header("Reply-To")
|
|
131
87
|
add_header("Reply-To", newreplyto)
|
|
@@ -156,6 +112,35 @@ class MailFactory
|
|
|
156
112
|
end
|
|
157
113
|
|
|
158
114
|
|
|
115
|
+
# implement method missing to provide helper methods for setting and getting headers.
|
|
116
|
+
# Headers with '-' characters may be set/gotten as 'x_mailer' or 'XMailer' (splitting
|
|
117
|
+
# will occur between capital letters or on '_' chracters)
|
|
118
|
+
def method_missing(methId, *args)
|
|
119
|
+
name = methId.id2name()
|
|
120
|
+
|
|
121
|
+
# mangle the name if we have to
|
|
122
|
+
if(name =~ /_/)
|
|
123
|
+
name = name.gsub(/_/, '-')
|
|
124
|
+
elsif(name =~ /[A-Z]/)
|
|
125
|
+
name = name.gsub(/([a-zA-Z])([A-Z])/, '\1-\2')
|
|
126
|
+
end
|
|
127
|
+
|
|
128
|
+
# determine if it sets or gets, and do the right thing
|
|
129
|
+
if(name =~ /=$/)
|
|
130
|
+
if(args.length != 1)
|
|
131
|
+
super(methId, args)
|
|
132
|
+
end
|
|
133
|
+
set_header(name[/^(.*)=$/, 1], args[0])
|
|
134
|
+
else
|
|
135
|
+
if(args.length != 0)
|
|
136
|
+
super(methId, args)
|
|
137
|
+
end
|
|
138
|
+
headers = get_header(name)
|
|
139
|
+
return(get_header(name))
|
|
140
|
+
end
|
|
141
|
+
end
|
|
142
|
+
|
|
143
|
+
|
|
159
144
|
# returns the value (or values) of the named header in an array
|
|
160
145
|
def get_header(header)
|
|
161
146
|
headers = Array.new()
|
data/tests/test_mailfactory.rb
CHANGED
|
@@ -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
|
|