recipient_interceptor 0.1.1 → 0.3.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,15 +1,7 @@
1
1
  ---
2
- !binary "U0hBMQ==":
3
- metadata.gz: !binary |-
4
- YjA2MjNlYmZjOGEyNzJiYzdlMDk5YjQ1OWVjM2ZhMWQyM2YzOGM0ZA==
5
- data.tar.gz: !binary |-
6
- YTk3ZTI0NTM4MGQyNjRmMzZlN2QxZjgzOTAyOGQzZmEyODBmY2U3OQ==
7
- !binary "U0hBNTEy":
8
- metadata.gz: !binary |-
9
- MWQ4YzI3MTIyNDFhZTNkNTM4ODJkNzQ2NmM5ZTM3NzRmMTJlZmI4MWM3NDQ5
10
- ODQ3Y2JlN2ZlMDlhYjgwMTQwMzY5ODdkMWQ1YzkyNjdhYzU2YTdmYTliNjQz
11
- OTg3ZWNlMjc0ODM3ZTJkYzBkZGU1NWQyNDZmOTgxNDkxNWY4NmE=
12
- data.tar.gz: !binary |-
13
- MDVlNTc1ZTQ3M2IzMTA4NWE1MmUwODk4NjNjODNlZDYwZjE3N2VjMDkyMzg4
14
- OTQ0MzljNmNkYTNlYWJkNDE5NmE5MjFlYWFjZTZhYzAwOGUzMjA0ZmVmYWUw
15
- MzE0NWZkZjViZDhlZGQ4NTAxNWMyNTM1ZTgyM2YzYzQ1ODI4MWI=
2
+ SHA256:
3
+ metadata.gz: 1f417db4c40adf06743a78da6452a691443b707c9a549fe44523e5013f41e1cc
4
+ data.tar.gz: d424e1deb3b45c81f32c382eb362e3cc83f94bad59cf1e6a735b4439fa000f6c
5
+ SHA512:
6
+ metadata.gz: 7b2b691e246882a96d0937b4142d8e6057489c9207ce38839c8f5b34ff61ea4bef2aad1274cfc6e2b1e8940fbf366f3b020ac28093e6eccee422dd743427a7c3
7
+ data.tar.gz: 238dae3f8fbb6de38f372da60136203c29f384fac31fac46565aea61663a87861e788e842170d5fc17e70c1df8afae35d6c850f177a8bac38789f400ffb9f025
@@ -1,38 +1,29 @@
1
- require 'mail'
1
+ require "mail"
2
2
 
3
3
  class RecipientInterceptor
4
- def initialize(recipients)
5
- @recipients = normalize_to_array(recipients)
6
- end
7
-
8
- def delivering_email(message)
9
- add_custom_headers message
10
- message.to = @recipients
11
- message.cc = nil
12
- message.bcc = nil
13
- end
14
-
15
- private
16
-
17
- def normalize_to_array(recipients)
18
- if recipients.respond_to? :split
19
- recipients.split ','
4
+ def initialize(recipients, opts = {})
5
+ @recipients = if recipients.respond_to?(:split)
6
+ recipients.split(",")
20
7
  else
21
8
  recipients
22
9
  end
10
+
11
+ @subject_prefix = opts[:subject_prefix]
23
12
  end
24
13
 
25
- def add_custom_headers(message)
26
- {
27
- 'X-Intercepted-To' => message.to,
28
- 'X-Intercepted-Cc' => message.cc,
29
- 'X-Intercepted-Bcc' => message.bcc
30
- }.each do |header, addresses|
31
- if addresses
32
- addresses.each do |address|
33
- message.header = "#{message.header}\n#{header}: #{address}"
34
- end
35
- end
14
+ def delivering_email(msg)
15
+ if @subject_prefix.respond_to?(:call)
16
+ msg.subject = "#{@subject_prefix.call(msg)} #{msg.subject}"
17
+ elsif @subject_prefix
18
+ msg.subject = "#{@subject_prefix} #{msg.subject}"
36
19
  end
20
+
21
+ msg.header["X-Intercepted-To"] = msg.to || []
22
+ msg.header["X-Intercepted-Cc"] = msg.cc || []
23
+ msg.header["X-Intercepted-Bcc"] = msg.bcc || []
24
+
25
+ msg.to = @recipients
26
+ msg.cc = nil if msg.cc
27
+ msg.bcc = nil if msg.bcc
37
28
  end
38
29
  end
metadata CHANGED
@@ -1,56 +1,39 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: recipient_interceptor
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dan Croak
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-02-25 00:00:00.000000000 Z
11
+ date: 2021-10-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: mail
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ! '>='
17
+ - - ">="
18
18
  - !ruby/object:Gem::Version
19
19
  version: '0'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - ! '>='
24
+ - - ">="
25
25
  - !ruby/object:Gem::Version
26
26
  version: '0'
27
- - !ruby/object:Gem::Dependency
28
- name: rspec
29
- requirement: !ruby/object:Gem::Requirement
30
- requirements:
31
- - - ! '>='
32
- - !ruby/object:Gem::Version
33
- version: '0'
34
- type: :development
35
- prerelease: false
36
- version_requirements: !ruby/object:Gem::Requirement
37
- requirements:
38
- - - ! '>='
39
- - !ruby/object:Gem::Version
40
- version: '0'
41
- description: ! " Use RecipientInterceptor when you don't want your Ruby program
42
- to\n accidentally send emails to addresses other than those on a whitelist\n
43
- \ which you configure. For example, you could use it in your web app's\n staging
44
- environment.\n"
45
- email: dan@thoughtbot.com
27
+ description: " Avoid emailing your users from non-production environments.\n"
28
+ email: dan@statusok.com
46
29
  executables: []
47
30
  extensions: []
48
31
  extra_rdoc_files: []
49
32
  files:
50
33
  - lib/recipient_interceptor.rb
51
- - spec/recipient_interceptor_spec.rb
52
34
  homepage: http://github.com/croaky/recipient_interceptor
53
- licenses: []
35
+ licenses:
36
+ - MIT
54
37
  metadata: {}
55
38
  post_install_message:
56
39
  rdoc_options: []
@@ -58,19 +41,17 @@ require_paths:
58
41
  - lib
59
42
  required_ruby_version: !ruby/object:Gem::Requirement
60
43
  requirements:
61
- - - ! '>='
44
+ - - ">="
62
45
  - !ruby/object:Gem::Version
63
46
  version: '0'
64
47
  required_rubygems_version: !ruby/object:Gem::Requirement
65
48
  requirements:
66
- - - ! '>='
49
+ - - ">="
67
50
  - !ruby/object:Gem::Version
68
51
  version: '0'
69
52
  requirements: []
70
- rubyforge_project:
71
- rubygems_version: 2.0.0
53
+ rubygems_version: 3.1.6
72
54
  signing_key:
73
55
  specification_version: 4
74
56
  summary: Intercept recipients when delivering email with the Mail gem.
75
- test_files:
76
- - spec/recipient_interceptor_spec.rb
57
+ test_files: []
@@ -1,47 +0,0 @@
1
- require File.join(File.dirname(__FILE__), '..', 'lib', 'recipient_interceptor')
2
-
3
- describe RecipientInterceptor do
4
- it 'overrides to/cc/bcc fields, copies original fields to custom headers' do
5
- Mail.register_interceptor RecipientInterceptor.new('staging@example.com')
6
-
7
- response = deliver_mail
8
-
9
- expect(response.to).to eq ['staging@example.com']
10
- expect(response.cc).to eq []
11
- expect(response.bcc).to eq []
12
-
13
- expect(response.header['X-Intercepted-To'].to_s).
14
- to eq "[original.to@example.com, staging@example.com]"
15
- expect(response.header['X-Intercepted-Cc'].to_s).
16
- to eq 'original.cc@example.com'
17
- expect(response.header['X-Intercepted-Bcc'].to_s).
18
- to eq 'original.bcc@example.com'
19
- end
20
-
21
- it 'accepts an array of recipients' do
22
- Mail.register_interceptor RecipientInterceptor.new(recipient_array)
23
-
24
- response = deliver_mail
25
-
26
- expect(response.to).to eq recipient_array
27
- end
28
-
29
- def deliver_mail
30
- Mail.defaults do
31
- delivery_method :test
32
- end
33
-
34
- mail = Mail.deliver do
35
- from 'original.from@example.com'
36
- to 'original.to@example.com'
37
- cc 'original.cc@example.com'
38
- bcc 'original.bcc@example.com'
39
- end
40
-
41
- mail.deliver!
42
- end
43
-
44
- def recipient_array
45
- ['one@example.com', 'two@example.com']
46
- end
47
- end