mail-x_smtpapi 1.0.0.alpha
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +14 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +43 -0
- data/Rakefile +10 -0
- data/lib/mail/x_smtpapi.rb +24 -0
- data/lib/mail_x_smtpapi.rb +5 -0
- data/lib/mail_x_smtpapi/accessors.rb +58 -0
- data/lib/mail_x_smtpapi/field.rb +39 -0
- data/lib/mail_x_smtpapi/version.rb +3 -0
- data/mail-x_smtpapi.gemspec +24 -0
- data/test/mail_accessors_test.rb +39 -0
- data/test/mail_integration_test.rb +47 -0
- data/test/mail_x_smtpapi_field_test.rb +38 -0
- data/test/test_helper.rb +7 -0
- metadata +105 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 8c8f40288af6ce36eda5971ed93ede0bdb8cf077
|
4
|
+
data.tar.gz: 7f79cd1c3ab012ae3ddee78820d42e1e6b5500c8
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 0be1d7588bd5278f3f042744254d2dc939a22df7c537d2ecdb1ce1de722aee27e6a30b102e8da8407d4b2137cabc7f89df3bccba07a42bd2c30cad1cca777a3c
|
7
|
+
data.tar.gz: f553f34ef34eedf8da1e84604b2f0023bc6e11618c2572540184f8af5cbd9311d10eef25a7fef173537d0a7f51184d0a4b7c4d49f6846316952d2cb88f245ee9
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 Kickstarter, Inc
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,43 @@
|
|
1
|
+
# Mail::X::Smtpapi
|
2
|
+
|
3
|
+
Integrates a custom X-SMTPAPI field into the [Mail](https://github.com/mikel/mail) gem.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem 'mail-x_smtpapi'
|
11
|
+
```
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
|
19
|
+
$ gem install mail-x_smtpapi
|
20
|
+
|
21
|
+
## Usage
|
22
|
+
|
23
|
+
Write into the SMTPAPI header from anywhere with access to the `mail` object.
|
24
|
+
|
25
|
+
### Example: Rails Mailer
|
26
|
+
|
27
|
+
(TODO)
|
28
|
+
|
29
|
+
### Example: Template Helper
|
30
|
+
|
31
|
+
(TODO)
|
32
|
+
|
33
|
+
### Example: Mail Interceptor
|
34
|
+
|
35
|
+
(TODO)
|
36
|
+
|
37
|
+
## Contributing
|
38
|
+
|
39
|
+
1. Fork it ( https://github.com/kickstarter/mail-x_smtpapi/fork )
|
40
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
41
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
42
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
43
|
+
5. Create a new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
require_relative '../mail_x_smtpapi/field'
|
2
|
+
require 'mail'
|
3
|
+
|
4
|
+
module Mail
|
5
|
+
class Message
|
6
|
+
def smtpapi
|
7
|
+
header.smtpapi
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
class Header
|
12
|
+
def smtpapi
|
13
|
+
name = MailXSMTPAPI::Field::FIELD_NAME
|
14
|
+
self.fields << Field.new(name) unless self[name]
|
15
|
+
self[name]
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
MailXSMTPAPI::Field::FIELD_NAME.tap do |name|
|
21
|
+
Mail::Field::FIELDS_MAP[name] = MailXSMTPAPI::Field
|
22
|
+
Mail::Field::FIELD_NAME_MAP[name] = MailXSMTPAPI::Field::CAPITALIZED_FIELD
|
23
|
+
Mail::Header::LIMITED_FIELDS << name
|
24
|
+
end
|
@@ -0,0 +1,58 @@
|
|
1
|
+
module MailXSMTPAPI
|
2
|
+
|
3
|
+
module Recipients
|
4
|
+
def to
|
5
|
+
value['to'] ||= []
|
6
|
+
end
|
7
|
+
|
8
|
+
def to=(val)
|
9
|
+
val = [val] unless val.is_a? Array
|
10
|
+
to.replace val
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
module Substitutions
|
15
|
+
def substitutions
|
16
|
+
value['sub'] ||= {}
|
17
|
+
end
|
18
|
+
|
19
|
+
def substitutions=(val)
|
20
|
+
raise ArgumentError unless val.is_a? Hash
|
21
|
+
substitutions.replace(val)
|
22
|
+
end
|
23
|
+
|
24
|
+
def merge_substitutions(name, val)
|
25
|
+
substitutions[name] ||= []
|
26
|
+
val = [val] unless val.is_a? Array
|
27
|
+
substitutions[name].concat val.map(&:to_s)
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
module UniqueArguments
|
32
|
+
def unique_args
|
33
|
+
value['unique_args'] ||= {}
|
34
|
+
end
|
35
|
+
|
36
|
+
def unique_args=(val)
|
37
|
+
raise ArgumentError unless val.is_a? Hash
|
38
|
+
unique_args.replace(val)
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
module Category
|
43
|
+
def category
|
44
|
+
value['category']
|
45
|
+
end
|
46
|
+
|
47
|
+
def category=(val)
|
48
|
+
value['category'] = val
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
module Filters
|
53
|
+
def filters
|
54
|
+
value['filters'] ||= {}
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
require 'mail'
|
2
|
+
require_relative 'accessors'
|
3
|
+
|
4
|
+
module MailXSMTPAPI
|
5
|
+
class Field < ::Mail::StructuredField
|
6
|
+
FIELD_NAME = 'x-smtpapi'
|
7
|
+
CAPITALIZED_FIELD = 'X-SMTPAPI'
|
8
|
+
|
9
|
+
# Accessors
|
10
|
+
include Recipients
|
11
|
+
include Substitutions
|
12
|
+
include UniqueArguments
|
13
|
+
include Category
|
14
|
+
include Filters
|
15
|
+
|
16
|
+
def initialize(value = nil, charset = 'utf-8')
|
17
|
+
super(FIELD_NAME, value || {}, charset)
|
18
|
+
end
|
19
|
+
|
20
|
+
# emits JSON with extra spaces inserted for line wrapping.
|
21
|
+
def encoded
|
22
|
+
if empty?
|
23
|
+
''
|
24
|
+
else
|
25
|
+
"#{CAPITALIZED_FIELD}: #{JSON.generate(value).gsub(/(["\]}])([,:])(["\[{])/, '\\1\\2 \\3')}\r\n"
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
# the decoded version is good for interacting with the header in code
|
30
|
+
# see: Mail::StructuredField#default
|
31
|
+
def decoded
|
32
|
+
value
|
33
|
+
end
|
34
|
+
|
35
|
+
def empty?
|
36
|
+
value.values.all?{|v| !v || v.empty? }
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'mail_x_smtpapi/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "mail-x_smtpapi"
|
8
|
+
spec.version = MailXSMTPAPI::VERSION
|
9
|
+
spec.authors = ["Lance Ivy"]
|
10
|
+
spec.email = ["lance@kickstarter.com"]
|
11
|
+
spec.summary = %q{Adds SendGrid X-SMTPAPI header support to Mail}
|
12
|
+
spec.homepage = "https://github.com/kickstarter/mail-x_smtpapi"
|
13
|
+
spec.license = "MIT"
|
14
|
+
|
15
|
+
spec.files = `git ls-files -z`.split("\x0")
|
16
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
17
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
18
|
+
spec.require_paths = ["lib"]
|
19
|
+
|
20
|
+
spec.add_development_dependency "bundler", "~> 1.7"
|
21
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
22
|
+
|
23
|
+
spec.add_dependency "mail", "> 2.6.0"
|
24
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
require_relative 'test_helper'
|
2
|
+
|
3
|
+
class MailXSMTPAPI::AccessorsTest < MiniTest::Unit::TestCase
|
4
|
+
|
5
|
+
def test_to
|
6
|
+
subject.to = 'a@example.com'
|
7
|
+
assert_equal ['a@example.com'], subject.to
|
8
|
+
subject.to << 'b@example.com'
|
9
|
+
assert_equal ['a@example.com', 'b@example.com'], subject.to
|
10
|
+
end
|
11
|
+
|
12
|
+
def test_substitutions
|
13
|
+
subject.substitutions['foo'] = ['bar']
|
14
|
+
assert_equal ['bar'], subject.substitutions['foo']
|
15
|
+
|
16
|
+
subject.merge_substitutions('foo', ['baz', 'qux'])
|
17
|
+
assert_equal ['bar', 'baz', 'qux'], subject.substitutions['foo']
|
18
|
+
end
|
19
|
+
|
20
|
+
def test_unique_args
|
21
|
+
subject.unique_args['foo'] = 'bar'
|
22
|
+
assert_equal 'bar', subject.unique_args['foo']
|
23
|
+
|
24
|
+
subject.unique_args = {'hello' => 'world'}
|
25
|
+
refute subject.unique_args['foo']
|
26
|
+
assert_equal 'world', subject.unique_args['hello']
|
27
|
+
end
|
28
|
+
|
29
|
+
def test_category
|
30
|
+
subject.category = 'password_reset'
|
31
|
+
assert_equal 'password_reset', subject.category
|
32
|
+
end
|
33
|
+
|
34
|
+
private
|
35
|
+
|
36
|
+
def subject
|
37
|
+
@subject ||= MailXSMTPAPI::Field.new
|
38
|
+
end
|
39
|
+
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
require_relative 'test_helper'
|
2
|
+
|
3
|
+
class MailIntegrationTest < MiniTest::Unit::TestCase
|
4
|
+
|
5
|
+
def test_smtpapi_accessor
|
6
|
+
assert subject.smtpapi
|
7
|
+
assert subject.smtpapi.empty?
|
8
|
+
|
9
|
+
subject.smtpapi.value['to'] = 'c@example.com'
|
10
|
+
refute subject.smtpapi.empty?
|
11
|
+
|
12
|
+
assert_equal 'c@example.com', subject.smtpapi.value['to']
|
13
|
+
end
|
14
|
+
|
15
|
+
def test_hash_reader
|
16
|
+
assert_equal subject.smtpapi, subject['x-smtpapi']
|
17
|
+
assert_equal subject.smtpapi, subject['X_SMTPAPI']
|
18
|
+
end
|
19
|
+
|
20
|
+
def test_hash_writer
|
21
|
+
subject['x-smtpapi'] = {'to' => 'c@example.com'}
|
22
|
+
assert_equal 'c@example.com', subject.smtpapi.value['to']
|
23
|
+
end
|
24
|
+
|
25
|
+
def test_limited_field
|
26
|
+
subject['x-smtpapi'] = {'to' => 'c@example.com'}
|
27
|
+
subject['x-smtpapi'] = {'to' => 'd@example.com'}
|
28
|
+
|
29
|
+
refute subject['x-smtpapi'].is_a?(Array)
|
30
|
+
assert_equal 'd@example.com', subject['x-smtpapi'].value['to']
|
31
|
+
end
|
32
|
+
|
33
|
+
def test_field_name
|
34
|
+
assert_equal 'X-SMTPAPI', subject.smtpapi.name
|
35
|
+
end
|
36
|
+
|
37
|
+
private
|
38
|
+
|
39
|
+
def subject
|
40
|
+
@subject ||= ::Mail.new do
|
41
|
+
to 'a@example.com'
|
42
|
+
reply_to 'b@example.com'
|
43
|
+
date Time.now
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
require_relative 'test_helper'
|
2
|
+
|
3
|
+
class MailXSMTPAPI::FieldTest < MiniTest::Unit::TestCase
|
4
|
+
def test_encoded_with_blank_values
|
5
|
+
assert_equal '', subject.new.encoded
|
6
|
+
end
|
7
|
+
|
8
|
+
def test_encoded_has_field_name
|
9
|
+
f = subject.new({'to' => ['a@example.com', 'b@example.com']})
|
10
|
+
assert f.encoded.match(/^X-SMTPAPI: /), f.encoded
|
11
|
+
end
|
12
|
+
|
13
|
+
def test_encoded_has_spaces_in_json
|
14
|
+
f = subject.new({'to' => ['a@example.com', 'b@example.com']})
|
15
|
+
assert f.encoded.include?('{"to": ["a@example.com", "b@example.com"]}')
|
16
|
+
end
|
17
|
+
|
18
|
+
def test_encoded_ends_with_crlf
|
19
|
+
f = subject.new({'to' => ['a@example.com', 'b@example.com']})
|
20
|
+
assert f.encoded.match(/\r\n$/)
|
21
|
+
end
|
22
|
+
|
23
|
+
def test_decoded
|
24
|
+
h = {'to' => ['a@example.com']}
|
25
|
+
assert_equal h, subject.new(h).decoded
|
26
|
+
end
|
27
|
+
|
28
|
+
def test_empty?
|
29
|
+
refute subject.new({'to' => ['a@example.com']}).empty?
|
30
|
+
assert subject.new({'to' => []}).empty?
|
31
|
+
end
|
32
|
+
|
33
|
+
private
|
34
|
+
|
35
|
+
def subject
|
36
|
+
MailXSMTPAPI::Field
|
37
|
+
end
|
38
|
+
end
|
data/test/test_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,105 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: mail-x_smtpapi
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0.alpha
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Lance Ivy
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-12-09 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.7'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.7'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: mail
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: 2.6.0
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 2.6.0
|
55
|
+
description:
|
56
|
+
email:
|
57
|
+
- lance@kickstarter.com
|
58
|
+
executables: []
|
59
|
+
extensions: []
|
60
|
+
extra_rdoc_files: []
|
61
|
+
files:
|
62
|
+
- ".gitignore"
|
63
|
+
- Gemfile
|
64
|
+
- LICENSE.txt
|
65
|
+
- README.md
|
66
|
+
- Rakefile
|
67
|
+
- lib/mail/x_smtpapi.rb
|
68
|
+
- lib/mail_x_smtpapi.rb
|
69
|
+
- lib/mail_x_smtpapi/accessors.rb
|
70
|
+
- lib/mail_x_smtpapi/field.rb
|
71
|
+
- lib/mail_x_smtpapi/version.rb
|
72
|
+
- mail-x_smtpapi.gemspec
|
73
|
+
- test/mail_accessors_test.rb
|
74
|
+
- test/mail_integration_test.rb
|
75
|
+
- test/mail_x_smtpapi_field_test.rb
|
76
|
+
- test/test_helper.rb
|
77
|
+
homepage: https://github.com/kickstarter/mail-x_smtpapi
|
78
|
+
licenses:
|
79
|
+
- MIT
|
80
|
+
metadata: {}
|
81
|
+
post_install_message:
|
82
|
+
rdoc_options: []
|
83
|
+
require_paths:
|
84
|
+
- lib
|
85
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
91
|
+
requirements:
|
92
|
+
- - ">"
|
93
|
+
- !ruby/object:Gem::Version
|
94
|
+
version: 1.3.1
|
95
|
+
requirements: []
|
96
|
+
rubyforge_project:
|
97
|
+
rubygems_version: 2.2.2
|
98
|
+
signing_key:
|
99
|
+
specification_version: 4
|
100
|
+
summary: Adds SendGrid X-SMTPAPI header support to Mail
|
101
|
+
test_files:
|
102
|
+
- test/mail_accessors_test.rb
|
103
|
+
- test/mail_integration_test.rb
|
104
|
+
- test/mail_x_smtpapi_field_test.rb
|
105
|
+
- test/test_helper.rb
|