egalite 0.0.6 → 0.0.7

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.
@@ -5,10 +5,10 @@ require 'time'
5
5
  # mailheaders
6
6
  # {
7
7
  # :date => Time.new,
8
- # :from => 'ARAI Shunichi <arai@example.com>', # encoded by Sendmail.address
8
+ # :from => {'ARAI Shunichi' => 'arai@example.com'},
9
9
  # :reply_to => ,
10
- # :to => 'tanaka@example.com', # encoded by Sendmail.address
11
- # :cc => '', # encoded by Sendmail.address
10
+ # :to => 'tanaka@example.com',
11
+ # :cc => '',
12
12
  # :bcc => '',
13
13
  # :message_id => '',
14
14
  # :in_reply_to => '',
@@ -16,6 +16,14 @@ require 'time'
16
16
  # :subject => '',
17
17
  # }
18
18
 
19
+ # many ways to designate mail addresses.
20
+ # 1. array: you can put multiple addresses (string) into array.
21
+ # 1b array of array:
22
+ # [["hoge@example.com","Hoge Taro"]]
23
+ # 2. simple string: "mailaddress@example.com" works just fine.
24
+ # 3. encoded string: Sendmail.address("hoge@example.com", "Hoge Taro")
25
+ # 4. hash: { "Hoge Taro" => "hoge@example.com" }
26
+
19
27
  module Sendmail
20
28
  class QualifiedMailbox < String
21
29
  end
@@ -124,9 +132,14 @@ module Sendmail
124
132
  end
125
133
  def mailboxlist(value, header = 'Reply-to')
126
134
  case value
127
- when QualifiedMailbox: value
128
- when String: parse_addrspec(value) ? value : nil
129
- when Hash: address(value[:address],value[:name],header)
135
+ when QualifiedMailbox
136
+ value
137
+ when String
138
+ parse_addrspec(value) ? value : nil
139
+ when Hash
140
+ folding(header, value.map { |name, address|
141
+ address(address,name)
142
+ }.join(', '))
130
143
  when Array
131
144
  folding(header, value.map { |v|
132
145
  v.is_a?(Array) ? address(v[0],v[1]) : mailboxlist(v,header)
@@ -168,8 +181,12 @@ module Sendmail
168
181
  when QualifiedMailbox
169
182
  value =~ /<(#{atext_loose}+?@#{atext_loose}+?)>\Z/
170
183
  $1
171
- when String: parse_addrspec(value) ? value : nil
172
- when Hash: parse_addrspec(value[:address]) ? value[:address] : nil
184
+ when String
185
+ parse_addrspec(value) ? value : nil
186
+ when Hash
187
+ value.values.map { |s|
188
+ parse_addrspec(s) ? s : nil
189
+ }
173
190
  when Array
174
191
  value.map { |v|
175
192
  if v.is_a?(Array)
@@ -197,7 +214,7 @@ module Sendmail
197
214
  }
198
215
  end
199
216
  end
200
- def lastmail
217
+ def lastmail # for unit testing purpose
201
218
  @@lastmail if @@lastmail
202
219
  end
203
220
  def send(body, params, host = 'localhost')
@@ -1,3 +1,3 @@
1
1
  module Egalite
2
- VERSION = "0.0.6"
2
+ VERSION = "0.0.7"
3
3
  end
data/lib/egalite.rb CHANGED
@@ -1,6 +1,6 @@
1
1
  $LOAD_PATH << File.dirname(__FILE__)
2
2
 
3
- require "egalite/version"
3
+ require "egalite/version"
4
4
 
5
5
  require 'rack'
6
6
  require 'egalite/blank'
@@ -117,7 +117,7 @@ module Egalite
117
117
 
118
118
  class Controller
119
119
  attr_accessor :env, :req, :params, :template_file, :log_values
120
- undef id
120
+ undef id if defined? id
121
121
 
122
122
  # filters
123
123
  def before_filter
@@ -1,7 +1,7 @@
1
1
  $LOAD_PATH << File.join(File.dirname(__FILE__), '..')
2
2
 
3
3
  require 'test/unit'
4
- require 'sendmail'
4
+ require 'lib/egalite/sendmail'
5
5
 
6
6
  $KCODE = 'utf8'
7
7
 
@@ -97,10 +97,11 @@ class T_Sendmail < Test::Unit::TestCase
97
97
  :from => 'hoge@example.com',
98
98
  :to => [Sendmail.address('arai@example.com','新井俊一'),
99
99
  ['tanaka@example.com','田中太郎'],
100
- {:address => 'takeda@example.com', :name => '武田一郎'},
100
+ ['takeda@example.com','武田一郎'],
101
101
  'ueno@example.com'
102
102
  ],
103
- :cc => Sendmail.address('foo@example.com', 'Foo Bar'),
103
+ :cc => {'Foo Bar' => 'foo@example.com',
104
+ 'Foo Who' => 'who@example.com'},
104
105
  :bcc => Sendmail.address('zzz@example.com', 'zzz'),
105
106
  :reply_to=> Sendmail.address('baz@example.com', 'Baz Bzz'),
106
107
  :subject => 'こんにちは',
@@ -133,12 +134,13 @@ class T_Sendmail < Test::Unit::TestCase
133
134
  assert_match '田中太郎', b
134
135
  assert_match '武田一郎', c
135
136
  assert_match '"Foo Bar" <foo@example.com>', h['Cc']
137
+ assert_match '"Foo Who" <who@example.com>', h['Cc']
136
138
  assert_match '"Baz Bzz" <baz@example.com>', h['Reply-To']
137
139
  assert_nil h['Bcc']
138
140
  end
139
141
  def test_to_addresses
140
142
  a = Sendmail.to_addresses(params)
141
- %w[foo@example.com arai@example.com tanaka@example.com takeda@example.com ueno@example.com zzz@example.com].each { |s|
143
+ %w[foo@example.com who@example.com arai@example.com tanaka@example.com takeda@example.com ueno@example.com zzz@example.com].each { |s|
142
144
  assert a.include?(s)
143
145
  }
144
146
  end
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: 19
4
+ hash: 17
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 6
10
- version: 0.0.6
9
+ - 7
10
+ version: 0.0.7
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: 2013-06-27 00:00:00 Z
18
+ date: 2013-07-11 00:00:00 Z
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
21
21
  name: bundler