mail_safe-sendgrid 0.0.2 → 0.0.3
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/LICENSE +19 -0
- data/README.md +54 -0
- data/lib/mail_safe-sendgrid.rb +24 -19
- data/mail_safe-sendgrid.gemspec +1 -1
- metadata +15 -13
data/LICENSE
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
Copyright (C) 2012 by Ed Shadi and Vijay Ramesh
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
4
|
+
of this software and associated documentation files (the "Software"), to deal
|
5
|
+
in the Software without restriction, including without limitation the rights
|
6
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
7
|
+
copies of the Software, and to permit persons to whom the Software is
|
8
|
+
furnished to do so, subject to the following conditions:
|
9
|
+
|
10
|
+
The above copyright notice and this permission notice shall be included in
|
11
|
+
all copies or substantial portions of the Software.
|
12
|
+
|
13
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
14
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
15
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
16
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
17
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
18
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
19
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,54 @@
|
|
1
|
+
# MailSafe Sendgrid
|
2
|
+
|
3
|
+
**MailSafe Sendgrid** adds Sendgrid support to Mail Safe by extending MailSafe::AddressReplacer to check for addresses included in the Sendgrid X-SMTPAPI headers. It automatically removes any offending (i.e., non-internal) addresses and removes the corresponding entries from any Sendgrid substitutions. The addresses that are removed are also passed to Mail Safe's postscript message (along with any :to, :cc, and :bcc addresses that were removed by Mail Safe itself).
|
4
|
+
|
5
|
+
## Basic usage
|
6
|
+
|
7
|
+
If you always want Mail Safe turned on, simply add `mail_safe-sendgrid` to your Gemfile immediately following `mail_safe`.
|
8
|
+
|
9
|
+
## Conditional usage
|
10
|
+
For a more complicated usage case (i.e., you only want `mail_safe` turned on in demo environments and not in production) make sure to add
|
11
|
+
|
12
|
+
|
13
|
+
```ruby
|
14
|
+
gem "mail_safe", :require => nil
|
15
|
+
gem "mail_safe-sendgrid", :require => nil
|
16
|
+
```
|
17
|
+
|
18
|
+
to your Gemfile and then manually require `mail_safe` and `mail_safe-sendgrid` after you do your environment checks
|
19
|
+
|
20
|
+
```ruby
|
21
|
+
module MailSafeFilter
|
22
|
+
def self.filter_email_addresses(environment = ['development', 'demo', 'staging'])
|
23
|
+
if environment.include? Rails.env
|
24
|
+
require 'mail_safe'
|
25
|
+
require 'mail_safe-sendgrid'
|
26
|
+
default_internal_address = /.*@internal\.com/i
|
27
|
+
|
28
|
+
if defined?(MailSafe::Config)
|
29
|
+
MailSafe::Config.internal_address_definition = lambda { |addr|
|
30
|
+
addr =~ default_internal_address
|
31
|
+
}
|
32
|
+
MailSafe::Config.replacement_address = "#{Rails.env}_firehose@replacement.com"
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
MailSafeFilter.filter_email_addresses
|
38
|
+
```
|
39
|
+
|
40
|
+
## Tests
|
41
|
+
|
42
|
+
All code is tested with [RSpec](https://github.com/rspec/rspec). To run the specs, clone the repository, install the dependencies with `bundle install`, and then run `rake`.
|
43
|
+
|
44
|
+
## Issues
|
45
|
+
|
46
|
+
If you have any problems or suggestions for the project, please open a GitHub issue.
|
47
|
+
|
48
|
+
## License
|
49
|
+
|
50
|
+
MailSafe Sendgrid is available under the included MIT license.
|
51
|
+
|
52
|
+
## Acknowledgements
|
53
|
+
|
54
|
+
Thank you to [Change.org](http://www.change.org/) for sponsoring the project.
|
data/lib/mail_safe-sendgrid.rb
CHANGED
@@ -10,11 +10,12 @@ module MailSafe
|
|
10
10
|
# we don't want to call add_body_postscript until after we've added the SendGrid SMTPAPI
|
11
11
|
# replaced addresses to the list of all addresses replaced by Mail Safe
|
12
12
|
@@replaced_addresses.reverse_merge! replaced_addresses
|
13
|
+
add_xsmtpapi_to_address_types if replaced_addresses[:X_SMTPAPI]
|
13
14
|
if call_super or replaced_addresses[:X_SMTPAPI]
|
14
|
-
add_xsmtpapi_to_address_types
|
15
15
|
add_body_postscript_without_mail_header(part, @@replaced_addresses)
|
16
|
-
remove_xsmtpapi_from_address_types
|
17
16
|
end
|
17
|
+
remove_xsmtpapi_from_address_types if replaced_addresses[:X_SMTPAPI]
|
18
|
+
|
18
19
|
end
|
19
20
|
alias_method_chain :add_body_postscript, :mail_header
|
20
21
|
|
@@ -26,26 +27,30 @@ module MailSafe
|
|
26
27
|
|
27
28
|
external_indices = []
|
28
29
|
# get a list of indices for external addresses
|
29
|
-
x_smtpapi['to']
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
v
|
40
|
-
|
30
|
+
if x_smtpapi['to']
|
31
|
+
x_smtpapi['to'].each_with_index do |address, index|
|
32
|
+
external_indices << index if !MailSafe::Config.is_internal_address?(address)
|
33
|
+
end
|
34
|
+
deleted_cnt = 0
|
35
|
+
deleted_addresses = []
|
36
|
+
external_indices.each do |i|
|
37
|
+
# remove any external address from :to
|
38
|
+
deleted_addresses << x_smtpapi['to'].delete_at(i - deleted_cnt)
|
39
|
+
# remove the related tokens for every array in :sub
|
40
|
+
x_smtpapi['sub'].each do |k, v|
|
41
|
+
v.delete_at(i-deleted_cnt)
|
42
|
+
x_smtpapi['sub'][k] = v
|
43
|
+
end
|
44
|
+
# the indices decrement as we remove elements, deleted_cnt accounts for this
|
45
|
+
deleted_cnt += 1
|
41
46
|
end
|
42
|
-
# the
|
43
|
-
|
47
|
+
# save the headers back to X-SMTPAPI
|
48
|
+
mail.header['X-SMTPAPI'].value = x_smtpapi.to_json.gsub(/(["\]}])([,:])(["\[{])/, '\\1\\2 \\3')
|
49
|
+
add_body_postscript(mail,{:X_SMTPAPI=>deleted_addresses}, true)
|
50
|
+
else
|
51
|
+
add_body_postscript(mail,{}, true)
|
44
52
|
end
|
45
|
-
# save the headers back to X-SMTPAPI
|
46
|
-
mail.header['X-SMTPAPI'].value = x_smtpapi.to_json.gsub(/(["\]}])([,:])(["\[{])/, '\\1\\2 \\3')
|
47
53
|
|
48
|
-
add_body_postscript(mail,{:X_SMTPAPI=>deleted_addresses}, true)
|
49
54
|
# we need to override add_text_postscript to include sendgrid x-smtpapi and not ADDRESS_TYPES only
|
50
55
|
|
51
56
|
end
|
data/mail_safe-sendgrid.gemspec
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
Gem::Specification.new do |s|
|
2
2
|
s.name = 'mail_safe-sendgrid'
|
3
|
-
s.version = '0.0.
|
3
|
+
s.version = '0.0.3'
|
4
4
|
s.date = '2012-03-13'
|
5
5
|
s.summary = 'Sendgrid support for Mail Safe'
|
6
6
|
s.description = 'Extends Mail Safe to look for and sanitize Sendgrid specific X-SMTPAPI headers'
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mail_safe-sendgrid
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -14,7 +14,7 @@ date: 2012-03-13 00:00:00.000000000 Z
|
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: json
|
17
|
-
requirement: &
|
17
|
+
requirement: &70096727984760 !ruby/object:Gem::Requirement
|
18
18
|
none: false
|
19
19
|
requirements:
|
20
20
|
- - ! '>='
|
@@ -22,10 +22,10 @@ dependencies:
|
|
22
22
|
version: '0'
|
23
23
|
type: :runtime
|
24
24
|
prerelease: false
|
25
|
-
version_requirements: *
|
25
|
+
version_requirements: *70096727984760
|
26
26
|
- !ruby/object:Gem::Dependency
|
27
27
|
name: mail_safe
|
28
|
-
requirement: &
|
28
|
+
requirement: &70096727983560 !ruby/object:Gem::Requirement
|
29
29
|
none: false
|
30
30
|
requirements:
|
31
31
|
- - ! '>='
|
@@ -33,10 +33,10 @@ dependencies:
|
|
33
33
|
version: '0'
|
34
34
|
type: :runtime
|
35
35
|
prerelease: false
|
36
|
-
version_requirements: *
|
36
|
+
version_requirements: *70096727983560
|
37
37
|
- !ruby/object:Gem::Dependency
|
38
38
|
name: sendgrid
|
39
|
-
requirement: &
|
39
|
+
requirement: &70096727980940 !ruby/object:Gem::Requirement
|
40
40
|
none: false
|
41
41
|
requirements:
|
42
42
|
- - ! '>='
|
@@ -44,10 +44,10 @@ dependencies:
|
|
44
44
|
version: '0'
|
45
45
|
type: :runtime
|
46
46
|
prerelease: false
|
47
|
-
version_requirements: *
|
47
|
+
version_requirements: *70096727980940
|
48
48
|
- !ruby/object:Gem::Dependency
|
49
49
|
name: actionmailer
|
50
|
-
requirement: &
|
50
|
+
requirement: &70096727979900 !ruby/object:Gem::Requirement
|
51
51
|
none: false
|
52
52
|
requirements:
|
53
53
|
- - ! '>='
|
@@ -55,10 +55,10 @@ dependencies:
|
|
55
55
|
version: '0'
|
56
56
|
type: :development
|
57
57
|
prerelease: false
|
58
|
-
version_requirements: *
|
58
|
+
version_requirements: *70096727979900
|
59
59
|
- !ruby/object:Gem::Dependency
|
60
60
|
name: rake
|
61
|
-
requirement: &
|
61
|
+
requirement: &70096727977420 !ruby/object:Gem::Requirement
|
62
62
|
none: false
|
63
63
|
requirements:
|
64
64
|
- - ! '>='
|
@@ -66,10 +66,10 @@ dependencies:
|
|
66
66
|
version: '0'
|
67
67
|
type: :development
|
68
68
|
prerelease: false
|
69
|
-
version_requirements: *
|
69
|
+
version_requirements: *70096727977420
|
70
70
|
- !ruby/object:Gem::Dependency
|
71
71
|
name: rspec
|
72
|
-
requirement: &
|
72
|
+
requirement: &70096728003320 !ruby/object:Gem::Requirement
|
73
73
|
none: false
|
74
74
|
requirements:
|
75
75
|
- - ! '>='
|
@@ -77,7 +77,7 @@ dependencies:
|
|
77
77
|
version: '0'
|
78
78
|
type: :development
|
79
79
|
prerelease: false
|
80
|
-
version_requirements: *
|
80
|
+
version_requirements: *70096728003320
|
81
81
|
description: Extends Mail Safe to look for and sanitize Sendgrid specific X-SMTPAPI
|
82
82
|
headers
|
83
83
|
email:
|
@@ -89,6 +89,8 @@ extra_rdoc_files: []
|
|
89
89
|
files:
|
90
90
|
- .gitignore
|
91
91
|
- Gemfile
|
92
|
+
- LICENSE
|
93
|
+
- README.md
|
92
94
|
- Rakefile
|
93
95
|
- lib/core_ext/kernel.rb
|
94
96
|
- lib/mail_safe-sendgrid.rb
|