sanitize_email 1.0.8 → 1.0.9

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 440f53fcb711fc2460929f24e8bf21bd8eb0c8b2
4
+ data.tar.gz: d82a8ddecb3b756d9a6f2279f8e281d95e2716fd
5
+ SHA512:
6
+ metadata.gz: c7a542593a80ba4492eb77dad01e74c5d802ef9ad44a2a28c2e51ac65b95419757d8b834c15f0a69fb1e5398c1d1347f645aadfec15c006082677be13f9f9511
7
+ data.tar.gz: abf7bb45bc8927ad2c59d005116027738f5ed17e946fb947fafc595e9772fcc83b4f231b756c0e2a511232d693198a058c3ea4b88d36e6377e73211a459c610a
data/.travis.yml CHANGED
@@ -2,6 +2,7 @@ language: ruby
2
2
  rvm:
3
3
  - 1.9.3
4
4
  - 1.9.2
5
+ - 2.0.0
5
6
  - jruby-19mode
6
7
  - rbx-19mode
7
- - ruby-head
8
+ # - ruby-head
data/CHANGELOG.md CHANGED
@@ -1,10 +1,13 @@
1
+ Version 1.0.9 - AUG.31.2013
2
+ * \[Bug Fix\] More Fixes for #12 - Strange repeating headers, and repeated subject injection by Peter Boling
3
+
1
4
  Version 1.0.8 - AUG.30.2013
2
- * \[Bug Fix\] Fixes #12 - Streange repeating headers by Peter Boling
5
+ * \[Bug Fix\] Partial Fix for #12 - Strange repeating headers by Peter Boling
3
6
  * Lots of refactoring by Peter Boling
4
7
  * Properly supports when a to/cc field has multiple recipients sanitized and adds all to mail headers
5
8
  * Improved specs by Peter Boling
6
9
 
7
- Version 1.0.7 - AUG.06.2012
10
+ Version 1.0.7 - AUG.06.2013
8
11
 
9
12
  * \[Bug Fix\] Stripping the message headers before appending new headers.
10
13
  - In a scenario where there is a trailing space, adding the newline before we append results in a blank header which throws an error as illegal by Eric Musgrove
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- sanitize_email (1.0.7)
4
+ sanitize_email (1.0.8)
5
5
 
6
6
  GEM
7
7
  remote: http://rubygems.org/
@@ -3,7 +3,7 @@ module SanitizeEmail
3
3
 
4
4
  def self.prepend_subject_array(message)
5
5
  prepend = []
6
- prepend << SanitizeEmail::MailHeaderTools.prepend_email_to_subject(message.to) if SanitizeEmail.use_actual_email_prepended_to_subject
6
+ prepend << SanitizeEmail::MailHeaderTools.prepend_email_to_subject(Array(message.to)) if SanitizeEmail.use_actual_email_prepended_to_subject
7
7
  prepend << SanitizeEmail::MailHeaderTools.prepend_environment_to_subject if SanitizeEmail.use_actual_environment_prepended_to_subject
8
8
  prepend
9
9
  end
@@ -13,14 +13,14 @@ module SanitizeEmail
13
13
  end
14
14
 
15
15
  def self.prepend_email_to_subject(actual_addresses)
16
- "(#{actual_addresses.join(',').gsub(/@/, ' at ').gsub(/[<>]/, '~')})" if actual_addresses.respond_to?(:join)
16
+ "(#{actual_addresses.uniq.join(',').gsub(/@/, ' at ').gsub(/[<>]/, '~')})" if actual_addresses.respond_to?(:join)
17
17
  end
18
18
 
19
19
  def self.add_original_addresses_as_headers(message)
20
20
  ## Add headers by string concat. Setting hash values on message.headers does nothing, strangely. http://goo.gl/v46GY
21
21
  {
22
- 'X-Sanitize-Email-To' => message.to, # can be an array
23
- 'X-Sanitize-Email-Cc' => message.cc # can be an array
22
+ 'X-Sanitize-Email-To' => Array(message.to).uniq, # can be an array, so casting it as an array
23
+ 'X-Sanitize-Email-Cc' => Array(message.cc).uniq # can be an array, so casting it as an array
24
24
  # Don't write out the BCC, as those addresses should not be visible in message headers for obvious reasons
25
25
  }.each { |k, v|
26
26
  # For each type of address line
@@ -32,7 +32,7 @@ module SanitizeEmail
32
32
  message.subject.insert(0, SanitizeEmail::MailHeaderTools.prepend_subject_array(message).join(' ') + ' ')
33
33
  end
34
34
 
35
- # Add headers by string concat. Setting hash values on message.headers does nothing, strangely. http://goo.gl/v46GY
35
+ # According to https://github.com/mikel/mail this is the correct way to update headers.
36
36
  def self.update_header(k, v, message)
37
37
  # For each address, as v can be an array of addresses
38
38
  Array(v).each_with_index { |a, index|
@@ -43,6 +43,7 @@ module SanitizeEmail
43
43
  #puts "for #{num}: #{header_key}"
44
44
  message.header[header_key] = a.to_s
45
45
  # Old way
46
+ # Add headers by string concat. Setting hash values on message.headers does nothing, strangely. http://goo.gl/v46GY
46
47
  #message.header = message.header.to_s.strip + "\n#{k}: #{a}"
47
48
  } if v
48
49
  #puts "\nafter message.header:\n #{message.header}\n"
@@ -109,7 +109,7 @@ module SanitizeEmail
109
109
  addresses.map { |address|
110
110
  # If this address is on the good list then let it pass
111
111
  self.address_list_filter(list_type, address)
112
- }.compact
112
+ }.compact.uniq
113
113
  end
114
114
 
115
115
  def sanitize_addresses(type)
@@ -1,5 +1,5 @@
1
1
  #Copyright (c) 2008-12 Peter H. Boling of 9thBit LLC
2
2
  #Released under the MIT license
3
3
  module SanitizeEmail
4
- VERSION = '1.0.8'
4
+ VERSION = '1.0.9'
5
5
  end
@@ -54,6 +54,20 @@ describe SanitizeEmail do
54
54
  Mail.register_interceptor(SanitizeEmail::Bleach.new)
55
55
  end
56
56
 
57
+ def funky_config
58
+ SanitizeEmail::Config.configure do |config|
59
+ config[:sanitized_to] = %w( funky@sanitize_email.org yummy@sanitize_email.org same@example.org )
60
+ config[:sanitized_cc] = nil
61
+ config[:sanitized_bcc] = nil
62
+ # run/call whatever logic should turn sanitize_email on and off in this Proc:
63
+ config[:activation_proc] = Proc.new { Rails.env != 'production' }
64
+ config[:use_actual_email_prepended_to_subject] = true
65
+ config[:use_actual_environment_prepended_to_subject] = true
66
+ config[:use_actual_email_as_sanitized_user_name] = false
67
+ end
68
+ Mail.register_interceptor(SanitizeEmail::Bleach.new)
69
+ end
70
+
57
71
  def sanitary_mail_delivery(config_options = {})
58
72
  SanitizeEmail.sanitary(config_options) do
59
73
  mail_delivery
@@ -72,6 +86,17 @@ describe SanitizeEmail do
72
86
  end
73
87
  end
74
88
 
89
+ def mail_delivery_hot_mess
90
+ @email_message = Mail.deliver do
91
+ from 'same@example.org'
92
+ to %w( same@example.org same@example.org same@example.org same@example.org same@example.org )
93
+ cc 'same@example.org'
94
+ bcc 'same@example.org'
95
+ reply_to 'same@example.org'
96
+ subject 'original subject'
97
+ end
98
+ end
99
+
75
100
  def mail_delivery
76
101
  @email_message = Mail.deliver do
77
102
  from 'from@example.org'
@@ -198,6 +223,95 @@ describe SanitizeEmail do
198
223
  end
199
224
  end
200
225
 
226
+ context "sanitary with funky config" do
227
+ before(:each) do
228
+ funky_config
229
+ SanitizeEmail.force_sanitize = true
230
+ mail_delivery
231
+ end
232
+ it "original to is prepended to subject" do
233
+ @email_message.should have_subject(/\(to at example.org\).*original subject/)
234
+ end
235
+ it "original to is only prepended once to subject" do
236
+ @email_message.should_not have_subject(/\(to at example.org\).*\(to at example.org\).*original subject/)
237
+ end
238
+ it "should not alter non-sanitized attributes" do
239
+ @email_message.should have_from('from@example.org')
240
+ @email_message.should have_reply_to('reply_to@example.org')
241
+ end
242
+ it "should not prepend overrides" do
243
+ @email_message.should_not have_to_username("to at sanitize_email.org")
244
+ @email_message.should_not have_subject(/.*\(to at sanitize_email.org\).*/)
245
+ end
246
+ it "should override where original recipients were not nil" do
247
+ @email_message.should have_to("funky@sanitize_email.org")
248
+ end
249
+ it "should not override where original recipients were nil" do
250
+ @email_message.should_not have_cc("cc@sanitize_email.org")
251
+ @email_message.should_not have_bcc("bcc@sanitize_email.org")
252
+ end
253
+ it "should set headers of originals" do
254
+ @email_message.should have_header("X-Sanitize-Email-To", "to@example.org")
255
+ @email_message.should have_header("X-Sanitize-Email-Cc", "cc@example.org")
256
+ end
257
+ it "should not set headers of bcc" do
258
+ @email_message.should_not have_header("X-Sanitize-Email-Bcc", "bcc@sanitize_email.org")
259
+ end
260
+ it "should not set headers of overrides" do
261
+ @email_message.should_not have_header("X-Sanitize-Email-To", "funky@sanitize_email.org")
262
+ @email_message.should_not have_header("X-Sanitize-Email-Cc", "cc@sanitize_email.org")
263
+ @email_message.should_not have_header("X-Sanitize-Email-Bcc", "bcc@sanitize_email.org")
264
+ #puts "email headers:\n#{@email_message.header}"
265
+ end
266
+ it "should not prepend originals by default" do
267
+ @email_message.should_not have_to_username("to at example.org <to@sanitize_email.org>")
268
+ @email_message.should_not have_subject("(to at example.org) original subject")
269
+ end
270
+ end
271
+
272
+ context "sanitary with funky config and hot mess delivery" do
273
+ before(:each) do
274
+ funky_config
275
+ SanitizeEmail.force_sanitize = true
276
+ mail_delivery_hot_mess
277
+ end
278
+ it "original to is prepended to subject" do
279
+ @email_message.should have_subject(/\(same at example.org\).*original subject/)
280
+ end
281
+ it "original to is only prepended once to subject" do
282
+ @email_message.should_not have_subject(/\(same at example.org\).*\(same at example.org\).*original subject/)
283
+ end
284
+ it "should not alter non-sanitized attributes" do
285
+ @email_message.should have_from('same@example.org')
286
+ @email_message.should have_reply_to('same@example.org')
287
+ end
288
+ it "should not prepend overrides" do
289
+ @email_message.should_not have_to_username("same at example.org")
290
+ end
291
+ it "should override where original recipients were not nil" do
292
+ @email_message.should have_to("same@example.org")
293
+ end
294
+ it "should not override where original recipients were nil" do
295
+ @email_message.should_not have_cc("same@example.org")
296
+ @email_message.should_not have_bcc("same@example.org")
297
+ end
298
+ it "should set headers of originals" do
299
+ @email_message.should have_header("X-Sanitize-Email-To", "same@example.org")
300
+ @email_message.should have_header("X-Sanitize-Email-Cc", "same@example.org")
301
+ end
302
+ it "should not set headers of bcc" do
303
+ @email_message.should_not have_header("X-Sanitize-Email-Bcc", "same@example.org")
304
+ end
305
+ it "should not set headers of overrides" do
306
+ @email_message.should_not have_header("X-Sanitize-Email-Bcc", "same@example.org")
307
+ puts "email headers:\n#{@email_message.header}"
308
+ end
309
+ it "should not prepend originals by default" do
310
+ @email_message.should_not have_to_username("same at example.org <same@example.org>")
311
+ @email_message.should_not have_subject("(same at example.org) original subject")
312
+ end
313
+ end
314
+
201
315
  context "force_sanitize" do
202
316
  context "true" do
203
317
  before(:each) do
metadata CHANGED
@@ -1,8 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sanitize_email
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.8
5
- prerelease:
4
+ version: 1.0.9
6
5
  platform: ruby
7
6
  authors:
8
7
  - Peter Boling
@@ -11,185 +10,163 @@ authors:
11
10
  autorequire:
12
11
  bindir: bin
13
12
  cert_chain: []
14
- date: 2013-08-30 00:00:00.000000000 Z
13
+ date: 2013-08-31 00:00:00.000000000 Z
15
14
  dependencies:
16
15
  - !ruby/object:Gem::Dependency
17
16
  name: rails
18
17
  requirement: !ruby/object:Gem::Requirement
19
- none: false
20
18
  requirements:
21
- - - ! '>'
19
+ - - '>'
22
20
  - !ruby/object:Gem::Version
23
21
  version: '3'
24
22
  type: :development
25
23
  prerelease: false
26
24
  version_requirements: !ruby/object:Gem::Requirement
27
- none: false
28
25
  requirements:
29
- - - ! '>'
26
+ - - '>'
30
27
  - !ruby/object:Gem::Version
31
28
  version: '3'
32
29
  - !ruby/object:Gem::Dependency
33
30
  name: actionmailer
34
31
  requirement: !ruby/object:Gem::Requirement
35
- none: false
36
32
  requirements:
37
- - - ! '>'
33
+ - - '>'
38
34
  - !ruby/object:Gem::Version
39
35
  version: '3'
40
36
  type: :development
41
37
  prerelease: false
42
38
  version_requirements: !ruby/object:Gem::Requirement
43
- none: false
44
39
  requirements:
45
- - - ! '>'
40
+ - - '>'
46
41
  - !ruby/object:Gem::Version
47
42
  version: '3'
48
43
  - !ruby/object:Gem::Dependency
49
44
  name: letter_opener
50
45
  requirement: !ruby/object:Gem::Requirement
51
- none: false
52
46
  requirements:
53
- - - ! '>='
47
+ - - '>='
54
48
  - !ruby/object:Gem::Version
55
49
  version: '0'
56
50
  type: :development
57
51
  prerelease: false
58
52
  version_requirements: !ruby/object:Gem::Requirement
59
- none: false
60
53
  requirements:
61
- - - ! '>='
54
+ - - '>='
62
55
  - !ruby/object:Gem::Version
63
56
  version: '0'
64
57
  - !ruby/object:Gem::Dependency
65
58
  name: launchy
66
59
  requirement: !ruby/object:Gem::Requirement
67
- none: false
68
60
  requirements:
69
- - - ! '>='
61
+ - - '>='
70
62
  - !ruby/object:Gem::Version
71
63
  version: '0'
72
64
  type: :development
73
65
  prerelease: false
74
66
  version_requirements: !ruby/object:Gem::Requirement
75
- none: false
76
67
  requirements:
77
- - - ! '>='
68
+ - - '>='
78
69
  - !ruby/object:Gem::Version
79
70
  version: '0'
80
71
  - !ruby/object:Gem::Dependency
81
72
  name: rspec
82
73
  requirement: !ruby/object:Gem::Requirement
83
- none: false
84
74
  requirements:
85
- - - ! '>='
75
+ - - '>='
86
76
  - !ruby/object:Gem::Version
87
77
  version: '2.11'
88
78
  type: :development
89
79
  prerelease: false
90
80
  version_requirements: !ruby/object:Gem::Requirement
91
- none: false
92
81
  requirements:
93
- - - ! '>='
82
+ - - '>='
94
83
  - !ruby/object:Gem::Version
95
84
  version: '2.11'
96
85
  - !ruby/object:Gem::Dependency
97
86
  name: mail
98
87
  requirement: !ruby/object:Gem::Requirement
99
- none: false
100
88
  requirements:
101
- - - ! '>='
89
+ - - '>='
102
90
  - !ruby/object:Gem::Version
103
91
  version: '0'
104
92
  type: :development
105
93
  prerelease: false
106
94
  version_requirements: !ruby/object:Gem::Requirement
107
- none: false
108
95
  requirements:
109
- - - ! '>='
96
+ - - '>='
110
97
  - !ruby/object:Gem::Version
111
98
  version: '0'
112
99
  - !ruby/object:Gem::Dependency
113
100
  name: rdoc
114
101
  requirement: !ruby/object:Gem::Requirement
115
- none: false
116
102
  requirements:
117
- - - ! '>='
103
+ - - '>='
118
104
  - !ruby/object:Gem::Version
119
105
  version: '3.12'
120
106
  type: :development
121
107
  prerelease: false
122
108
  version_requirements: !ruby/object:Gem::Requirement
123
- none: false
124
109
  requirements:
125
- - - ! '>='
110
+ - - '>='
126
111
  - !ruby/object:Gem::Version
127
112
  version: '3.12'
128
113
  - !ruby/object:Gem::Dependency
129
114
  name: reek
130
115
  requirement: !ruby/object:Gem::Requirement
131
- none: false
132
116
  requirements:
133
- - - ! '>='
117
+ - - '>='
134
118
  - !ruby/object:Gem::Version
135
119
  version: 1.2.8
136
120
  type: :development
137
121
  prerelease: false
138
122
  version_requirements: !ruby/object:Gem::Requirement
139
- none: false
140
123
  requirements:
141
- - - ! '>='
124
+ - - '>='
142
125
  - !ruby/object:Gem::Version
143
126
  version: 1.2.8
144
127
  - !ruby/object:Gem::Dependency
145
128
  name: roodi
146
129
  requirement: !ruby/object:Gem::Requirement
147
- none: false
148
130
  requirements:
149
- - - ! '>='
131
+ - - '>='
150
132
  - !ruby/object:Gem::Version
151
133
  version: 2.1.0
152
134
  type: :development
153
135
  prerelease: false
154
136
  version_requirements: !ruby/object:Gem::Requirement
155
- none: false
156
137
  requirements:
157
- - - ! '>='
138
+ - - '>='
158
139
  - !ruby/object:Gem::Version
159
140
  version: 2.1.0
160
141
  - !ruby/object:Gem::Dependency
161
142
  name: rake
162
143
  requirement: !ruby/object:Gem::Requirement
163
- none: false
164
144
  requirements:
165
- - - ! '>='
145
+ - - '>='
166
146
  - !ruby/object:Gem::Version
167
147
  version: '0'
168
148
  type: :development
169
149
  prerelease: false
170
150
  version_requirements: !ruby/object:Gem::Requirement
171
- none: false
172
151
  requirements:
173
- - - ! '>='
152
+ - - '>='
174
153
  - !ruby/object:Gem::Version
175
154
  version: '0'
176
155
  - !ruby/object:Gem::Dependency
177
156
  name: email_spec
178
157
  requirement: !ruby/object:Gem::Requirement
179
- none: false
180
158
  requirements:
181
- - - ! '>='
159
+ - - '>='
182
160
  - !ruby/object:Gem::Version
183
161
  version: '0'
184
162
  type: :development
185
163
  prerelease: false
186
164
  version_requirements: !ruby/object:Gem::Requirement
187
- none: false
188
165
  requirements:
189
- - - ! '>='
166
+ - - '>='
190
167
  - !ruby/object:Gem::Version
191
168
  version: '0'
192
- description: ! 'In Rails, Sinatra, or simply the mail gem: Aids in development, testing,
169
+ description: 'In Rails, Sinatra, or simply the mail gem: Aids in development, testing,
193
170
  qa, and production troubleshooting of email issues without worrying that emails
194
171
  will get sent to actual live addresses.'
195
172
  email: peter.boling@gmail.com
@@ -228,28 +205,27 @@ files:
228
205
  homepage: http://github.com/pboling/sanitize_email
229
206
  licenses:
230
207
  - MIT
208
+ metadata: {}
231
209
  post_install_message:
232
210
  rdoc_options: []
233
211
  require_paths:
234
212
  - lib
235
213
  required_ruby_version: !ruby/object:Gem::Requirement
236
- none: false
237
214
  requirements:
238
- - - ! '>='
215
+ - - '>='
239
216
  - !ruby/object:Gem::Version
240
217
  version: '0'
241
218
  required_rubygems_version: !ruby/object:Gem::Requirement
242
- none: false
243
219
  requirements:
244
- - - ! '>='
220
+ - - '>='
245
221
  - !ruby/object:Gem::Version
246
222
  version: '0'
247
223
  requirements: []
248
224
  rubyforge_project:
249
- rubygems_version: 1.8.25
225
+ rubygems_version: 2.0.3
250
226
  signing_key:
251
- specification_version: 3
252
- summary: ! 'Rails/Sinatra/Mail gem: Test email abilities without ever sending a message
227
+ specification_version: 4
228
+ summary: 'Rails/Sinatra/Mail gem: Test email abilities without ever sending a message
253
229
  to actual live addresses'
254
230
  test_files:
255
231
  - spec/sanitize_email_spec.rb