egalite 1.1.2 → 1.2.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.
@@ -222,15 +222,15 @@ class FormHelper
222
222
  end
223
223
  def select_by_array(name, options, opts = {})
224
224
  optionstr = options.map {|o|
225
- (key,value) = if o.is_a?(Array)
225
+ (value,name) = if o.is_a?(Array)
226
226
  o
227
227
  else
228
228
  [o,o]
229
229
  end
230
- flag = key == @data[name]
231
- a = {:value => key}
230
+ flag = value == @data[name]
231
+ a = {:value => value}
232
232
  a[:selected] = 'selected' if flag
233
- "#{tag_open(:option, a)}#{escape_html(value)}</option>"
233
+ "#{tag_open(:option, a)}#{escape_html(name)}</option>"
234
234
  }.join('')
235
235
 
236
236
  raw "<select name='#{expand_name(name)}'#{opt(opts)}>#{optionstr}</select>"
@@ -26,13 +26,13 @@ require 'net/smtp'
26
26
  # 4. hash: { "Hoge Taro" => "hoge@example.com" }
27
27
 
28
28
  module Sendmail
29
- class QualifiedMailbox < String
30
- end
29
+ class QualifiedMailbox < String
30
+ end
31
+ @force_dkim = false
32
+ @mock = false
31
33
  class <<self
32
- @@mock = false
33
- def mock=(bool)
34
- @@mock=bool
35
- end
34
+ attr_accessor :mock, :force_dkim
35
+ attr_reader :lastmail
36
36
  def folding(h, s) # folding white space. see RFC5322, section 2.3.3 and 3.2.2.
37
37
  len = 78 - h.size - ": ".size
38
38
  len2nd = 78 - " ".size
@@ -207,25 +207,35 @@ module Sendmail
207
207
  addresses.flatten.compact.uniq
208
208
  end
209
209
  def _send(text, envelope_from, to, host = 'localhost')
210
- if @@mock
211
- @@lastmail = [text, envelope_from, to, host]
210
+ if @mock
211
+ @lastmail = [text, envelope_from, to, host]
212
212
  else
213
213
  Net::SMTP.start(host) { |smtp|
214
214
  smtp.send_message(text, envelope_from, to)
215
215
  }
216
216
  end
217
217
  end
218
- def lastmail # for unit testing purpose
219
- @@lastmail if @@lastmail
218
+ def read_private_key(pem_filename)
219
+ OpenSSL::PKey::RSA.new(open(pem_filename).read)
220
220
  end
221
- def send(body, params, host = 'localhost')
221
+ def send_inner_2(body, params, host, dkim, dkim_params)
222
+ text = message(body, params)
223
+ if dkim
224
+ text = Dkim.sign(text,dkim_params)
225
+ end
222
226
  _send(
223
- message(body, params),
227
+ text,
224
228
  _extract_addrspec(params[:envelope_from] || params[:sender] || params[:from]),
225
229
  to_addresses(params),
226
230
  host
227
231
  )
228
232
  end
233
+ def send(body, params, host = 'localhost')
234
+ send_inner_2(body, params, host, @force_dkim, {})
235
+ end
236
+ def send_with_dkim(body, params, host = 'localhost', dkim_params = {})
237
+ send_inner_2(body, params, host, true, dkim_params)
238
+ end
229
239
  def send_with_template(filename, params, host = 'localhost')
230
240
  File.open("mail/"+ filename ,"r") { |f|
231
241
  text = f.read
@@ -1,3 +1,3 @@
1
1
  module Egalite
2
- VERSION = "1.1.2"
2
+ VERSION = "1.2.0"
3
3
  end
data/test/test_helper.rb CHANGED
@@ -237,6 +237,34 @@ class T_FormHelper < Test::Unit::TestCase
237
237
  assert_equal("fooname", i.attributes["name"])
238
238
  end
239
239
 
240
+ def test_select_by_array_array
241
+ f = FormHelper.new()
242
+ array = [[1,:foo],[2,:bar]]
243
+ d = to_doc(f.select_by_array("test", array))
244
+ assert_equal(1, X(d, "/select").size)
245
+ assert_equal(2, X(d, "/select/option").size)
246
+ o0 = X(d, "/select/option")[0]
247
+ assert_equal("foo", o0.text)
248
+ assert_equal("1", o0.attributes["value"])
249
+ o1 = X(d, "/select/option")[1]
250
+ assert_equal("bar", o1.text)
251
+ assert_equal("2", o1.attributes["value"])
252
+ end
253
+
254
+ def test_select_by_array_string
255
+ f = FormHelper.new()
256
+ array = [:foo,:bar]
257
+ d = to_doc(f.select_by_array("test", array))
258
+ assert_equal(1, X(d, "/select").size)
259
+ assert_equal(2, X(d, "/select/option").size)
260
+ o0 = X(d, "/select/option")[0]
261
+ assert_equal("foo", o0.text)
262
+ assert_equal("foo", o0.attributes["value"])
263
+ o1 = X(d, "/select/option")[1]
264
+ assert_equal("bar", o1.text)
265
+ assert_equal("bar", o1.attributes["value"])
266
+ end
267
+
240
268
  def make_select_options
241
269
  [{:optname => "optvalue0", :id=> "id0"},
242
270
  {:optname => "optvalue1", :id=> "id1"}]
@@ -2,6 +2,7 @@ $LOAD_PATH << File.join(File.dirname(__FILE__), '..')
2
2
 
3
3
  require 'test/unit'
4
4
  require 'lib/egalite/sendmail'
5
+ require 'dkim'
5
6
 
6
7
  $KCODE = 'utf8'
7
8
 
@@ -144,5 +145,38 @@ class T_Sendmail < Test::Unit::TestCase
144
145
  assert a.include?(s)
145
146
  }
146
147
  end
148
+ def test_mock
149
+ Sendmail.mock = true
150
+ Sendmail.force_dkim = false
151
+ Sendmail.send("Hello",:from => "arai@example.com", :to => "to@example.com")
152
+ assert_match "To: to@example.com\n", Sendmail.lastmail[0]
153
+ assert_match "From: arai@example.com\n", Sendmail.lastmail[0]
154
+ assert_match "\n\nHello", Sendmail.lastmail[0]
155
+ end
156
+ def test_dkim
157
+ Sendmail.mock = true
158
+ Sendmail.force_dkim = true
159
+ Dkim::domain = "example.com"
160
+ Dkim::selector = "test"
161
+ Dkim::private_key = <<EOS
162
+ -----BEGIN RSA PRIVATE KEY-----
163
+ MIICXgIBAAKBgQCkCI0PP7LbLEHyicGUrxGdA3ByTvdluRTEumu+AMNYIZaHL1oA
164
+ 9ShXrhRxX14f80jXSbOhzjbauuMwv0ypwuPbuxn2rDcg7qaHUu/9lzi9SJ/h5d8/
165
+ pYyuxXcg5WRfpv1YXV7zpRzlqg4WZzMMfsxekN/Td+tw/R+SdANp0gsYFwIDAQAB
166
+ AoGAHTgQuHimSXhWvvde7jdJMejc7N+4HfycAHccnhnQsjA5ehcrNyR0bTnrFk7g
167
+ m1xgy0iroNT03H2R3qsU4uB+aeqVyy2v/RgsKGQla3xMcxj78aQYYlGYwIQ6GAeX
168
+ mEgWo+9NA5A7ecYx2Kp5FzP6r2Ha9hu59ziJmMfADOt6DiECQQDV2Iadq6+HQ4c5
169
+ hhec5fYd7ozZ87sulSFQU2ykdGmMPDq9aOu5hO7KRky7ixu0rHpKoFEnDBO8nvIh
170
+ 7JDdoIyZAkEAxF5NM3KaJQB7jaRTUoYEfiz/nCs797YGqPdm2dXH4o1GXs+Xnbj9
171
+ SN9zyg4X4zbBe6jmpfSoltdZSOeY+eCILwJBAMWl/D3sui6eBnTvcBGvJjxiCMNF
172
+ l8MlSQYyJR8XDZr07CG2wPDWYdKJCVDp8PCb3eftpzQc4H0ct5UNTpPZWTkCQQCu
173
+ nkT8aP6VxNYZ4HSPv8kjApTSpMeQwXcurcHyF97FoWdgTC3A/Y2OTdZDaUDotfpc
174
+ IpfoH6YDbMBiykAIhBfVAkEAnvNjsnUsNrH3I31/0/+00EtjVxOUM+p1zaUaxtEt
175
+ nl+7ExHmNd0+V7EZzAePUjHWUIAOrj0p+AQQfglpCVXcvw==
176
+ -----END RSA PRIVATE KEY-----
177
+ EOS
178
+ Sendmail.send("Hello",:from => "arai@example.com", :to => "to@example.com")
179
+ assert_match "DKIM-Signature:", Sendmail.lastmail[0]
180
+ end
147
181
  end
148
182
 
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: egalite
3
3
  version: !ruby/object:Gem::Version
4
- hash: 23
4
+ hash: 31
5
5
  prerelease:
6
6
  segments:
7
7
  - 1
8
- - 1
9
8
  - 2
10
- version: 1.1.2
9
+ - 0
10
+ version: 1.2.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - Shunichi Arai
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2014-04-30 00:00:00 Z
18
+ date: 2014-05-14 00:00:00 Z
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
21
21
  name: bundler