iron_mailer 0.0.2
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/.gitignore +23 -0
- data/Gemfile +4 -0
- data/LICENSE +20 -0
- data/LICENSE.txt +22 -0
- data/README.md +2 -0
- data/Rakefile +1 -0
- data/iron_mailer.gemspec +29 -0
- data/lib/iron_mailer/mq_mailer.rb +16 -0
- data/lib/iron_mailer/send_email.rb +98 -0
- data/lib/iron_mailer/version.rb +3 -0
- data/lib/iron_mailer.rb +7 -0
- data/spec/iron_mailer/mq_mailer_spec.rb +44 -0
- data/spec/iron_mailer/send_email_spec.rb +317 -0
- metadata +189 -0
data/.gitignore
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
*.gem
|
2
|
+
*.rbc
|
3
|
+
.bundle
|
4
|
+
.config
|
5
|
+
config/*
|
6
|
+
.yardoc
|
7
|
+
Gemfile.lock
|
8
|
+
InstalledFiles
|
9
|
+
_yardoc
|
10
|
+
coverage
|
11
|
+
doc/
|
12
|
+
lib/bundler/man
|
13
|
+
pkg
|
14
|
+
rdoc
|
15
|
+
spec/reports
|
16
|
+
test/tmp
|
17
|
+
test/version_tmp
|
18
|
+
tmp
|
19
|
+
.ruby-gemset
|
20
|
+
.ruby-version
|
21
|
+
.rvmrc
|
22
|
+
spec/config/*
|
23
|
+
scratchpad/*
|
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2013 TeamDriveAway
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
6
|
+
this software and associated documentation files (the "Software"), to deal in
|
7
|
+
the Software without restriction, including without limitation the rights to
|
8
|
+
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
9
|
+
the Software, and to permit persons to whom the Software is furnished to do so,
|
10
|
+
subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
13
|
+
copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
17
|
+
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
18
|
+
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
19
|
+
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
20
|
+
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 erichhorde
|
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
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
data/iron_mailer.gemspec
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'iron_mailer/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "iron_mailer"
|
8
|
+
spec.version = IronMailer::VERSION
|
9
|
+
spec.authors = ["Erich Timkar"]
|
10
|
+
spec.email = ["erich@hordesoftware.com"]
|
11
|
+
spec.description = %q{A Rails mail delivery method using Iron MQ & Workers}
|
12
|
+
spec.summary = %q{A Rails mail delivery method using Iron MQ & Workers}
|
13
|
+
spec.homepage = ""
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files`.split($/)
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_development_dependency "bundler", "~> 1.3"
|
22
|
+
spec.add_development_dependency "rake"
|
23
|
+
spec.add_development_dependency "rspec"
|
24
|
+
spec.add_dependency "mail"
|
25
|
+
spec.add_dependency "iron_mq", '~> 4.0'
|
26
|
+
spec.add_dependency "iron_cache", '~> 1.4'
|
27
|
+
spec.add_dependency "typhoeus"
|
28
|
+
spec.add_dependency "uuidtools"
|
29
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
module IronMailer
|
2
|
+
class MqMailer
|
3
|
+
attr_reader :queue_name
|
4
|
+
def initialize(options={})
|
5
|
+
@queue_name = options[:queue_name]
|
6
|
+
end
|
7
|
+
|
8
|
+
|
9
|
+
def deliver!(mail)
|
10
|
+
@client=IronMQ::Client.new
|
11
|
+
@queue = @client.queue(@queue_name)
|
12
|
+
@queue.post(mail.encoded)
|
13
|
+
end
|
14
|
+
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,98 @@
|
|
1
|
+
require 'iron_cache'
|
2
|
+
require 'uuidtools'
|
3
|
+
class IronMailer::SendEmail
|
4
|
+
attr_reader :iron_mq_client, :iron_cache_client, :queue, :cache, :debug, :delivery_method, :delivery_method_settings
|
5
|
+
|
6
|
+
def initialize(options={})
|
7
|
+
@iron_mq_client = IronMQ::Client.new(options['iron_mq'])
|
8
|
+
@queue = @iron_mq_client.queue(options['iron_mq']['queue_name'])
|
9
|
+
@iron_cache_client = IronCache::Client.new(options['iron_cache'])
|
10
|
+
|
11
|
+
@cache = @iron_cache_client.cache(options['iron_cache']['cache_name'])
|
12
|
+
@debug = options['debug']
|
13
|
+
|
14
|
+
if options['delivery_method'].is_a?(Hash)
|
15
|
+
delivery_method_hash = options['delivery_method']
|
16
|
+
@delivery_method=delivery_method_hash.keys.first.to_sym
|
17
|
+
@delivery_method_settings = {}
|
18
|
+
|
19
|
+
params = delivery_method_hash.values.first.clone
|
20
|
+
|
21
|
+
params.keys.each do |key|
|
22
|
+
@delivery_method_settings[key.to_sym] = params[key]
|
23
|
+
end
|
24
|
+
|
25
|
+
else
|
26
|
+
@delivery_method=options['delivery_method'].to_sym
|
27
|
+
@delivery_method_settings={}
|
28
|
+
end
|
29
|
+
|
30
|
+
end
|
31
|
+
|
32
|
+
def split_email(source_email)
|
33
|
+
tos = source_email.to
|
34
|
+
tos.uniq.map{|destination|
|
35
|
+
duplicate = source_email.clone
|
36
|
+
duplicate.to = destination
|
37
|
+
|
38
|
+
if destination==tos.first
|
39
|
+
duplicate.message_id=source_email.message_id
|
40
|
+
duplicate.bcc=source_email.bcc
|
41
|
+
duplicate.cc=source_email.cc
|
42
|
+
else
|
43
|
+
duplicate.message_id = nil
|
44
|
+
duplicate.bcc = nil
|
45
|
+
duplicate.cc = nil
|
46
|
+
end
|
47
|
+
duplicate.header['X-SMTPAPI']={unique_args: {cache_key: UUIDTools::UUID.random_create.to_s}}.to_json
|
48
|
+
duplicate
|
49
|
+
}
|
50
|
+
end
|
51
|
+
|
52
|
+
def extract_cache_info(mail)
|
53
|
+
{'subject'=>mail.subject,
|
54
|
+
'date'=>mail.date,
|
55
|
+
'from'=>mail.from,
|
56
|
+
'to'=>mail.to,
|
57
|
+
'mail'=>mail.to_s
|
58
|
+
}
|
59
|
+
end
|
60
|
+
|
61
|
+
def cache_email(mail)
|
62
|
+
field = mail.header['X-SMTPAPI'].is_a?(Array) ? mail.header['X-SMTPAPI'].first : mail.header['X-SMTPAPI']
|
63
|
+
cache_key = JSON.parse(field.value)['unique_args']['cache_key']
|
64
|
+
self.cache.put(cache_key, self.extract_cache_info(mail).to_json)
|
65
|
+
end
|
66
|
+
|
67
|
+
def execute
|
68
|
+
messages = self.queue.get(:n=>100)
|
69
|
+
|
70
|
+
errors = []
|
71
|
+
messages.each do |message|
|
72
|
+
begin
|
73
|
+
source_email = Mail.new(message.body)
|
74
|
+
puts "Processing: #{source_email.subject}" if self.debug
|
75
|
+
puts self.delivery_method=>self.delivery_method_settings if self.debug
|
76
|
+
mails = self.split_email(source_email)
|
77
|
+
mails.each do |mail|
|
78
|
+
mail.delivery_method self.delivery_method, self.delivery_method_settings
|
79
|
+
mail.deliver
|
80
|
+
cache_email(mail)
|
81
|
+
end
|
82
|
+
message.delete
|
83
|
+
rescue Exception=>e
|
84
|
+
if self.debug
|
85
|
+
puts e.message
|
86
|
+
puts e.backtrace
|
87
|
+
end
|
88
|
+
errors << message
|
89
|
+
end
|
90
|
+
end
|
91
|
+
errors.each do |message|
|
92
|
+
puts "Releasing: #{message.id}" if self.debug
|
93
|
+
message.release
|
94
|
+
end
|
95
|
+
|
96
|
+
end
|
97
|
+
|
98
|
+
end
|
data/lib/iron_mailer.rb
ADDED
@@ -0,0 +1,44 @@
|
|
1
|
+
require 'iron_mailer'
|
2
|
+
|
3
|
+
describe IronMailer::MqMailer do
|
4
|
+
describe "initializer" do
|
5
|
+
it "should accept the queue name" do
|
6
|
+
IronMailer::MqMailer.new(queue_name: 'queue_name').queue_name.should == 'queue_name'
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
def test_email
|
11
|
+
test_email = Mail.new do
|
12
|
+
subject ="This is a subject"
|
13
|
+
to 'to@someone.com'
|
14
|
+
from 'from@someone.com'
|
15
|
+
text_part do
|
16
|
+
body "This is Text"
|
17
|
+
end
|
18
|
+
html_part do
|
19
|
+
content_type 'text/html; charset=UTF-8'
|
20
|
+
body "<h1>This is html</h1>"
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
describe "deliver!" do
|
26
|
+
before(:each) do
|
27
|
+
@queue_name='test_mail_queue'
|
28
|
+
@client=IronMQ::Client.new(:config=>'spec/config/iron_mq.json')
|
29
|
+
|
30
|
+
ENV['IRON_MQ_TOKEN'] = @client.token
|
31
|
+
ENV['IRON_MQ_PROJECT_ID'] = @client.project_id
|
32
|
+
|
33
|
+
@queue=@client.queue(@queue_name)
|
34
|
+
@mailer = IronMailer::MqMailer.new(queue_name: @queue_name)
|
35
|
+
end
|
36
|
+
|
37
|
+
it "should add an email message to the queue" do
|
38
|
+
lambda{
|
39
|
+
@mailer.deliver!(test_email)
|
40
|
+
@queue.reload
|
41
|
+
}.should change(@queue, :size)
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
@@ -0,0 +1,317 @@
|
|
1
|
+
require 'iron_mailer/send_email'
|
2
|
+
|
3
|
+
describe IronMailer::SendEmail do
|
4
|
+
|
5
|
+
|
6
|
+
describe "initializer" do
|
7
|
+
before(:each) do
|
8
|
+
@options = {
|
9
|
+
'iron_mq'=>{'token'=>'some set value', 'project_id'=>'some-24-char-project-id-', 'queue_name'=>'some_test_queue'},
|
10
|
+
'iron_cache'=>{'token'=>'some set value', 'project_id'=>'some-24-char-project-id-', 'cache_name'=>'some_test_cache_name'},
|
11
|
+
'delivery_method'=>{
|
12
|
+
'smtp'=>{
|
13
|
+
'address'=>'smtp.example.com',
|
14
|
+
'port'=>587,
|
15
|
+
'domain'=>'somedomain.com',
|
16
|
+
'user_name'=>'username',
|
17
|
+
'password'=>'password',
|
18
|
+
'authentication'=>'plain',
|
19
|
+
'enable_starttls_auto'=>'enable_starttls_auto'
|
20
|
+
}
|
21
|
+
}
|
22
|
+
}
|
23
|
+
@send_email = IronMailer::SendEmail.new(@options)
|
24
|
+
end
|
25
|
+
|
26
|
+
it "should allow setting of a test delivery_method" do
|
27
|
+
IronMailer::SendEmail.new(@options.merge('delivery_method'=>'test'))
|
28
|
+
@send_email.delivery_method.should == :smtp
|
29
|
+
@send_email.delivery_method_settings.class.should == Hash
|
30
|
+
end
|
31
|
+
|
32
|
+
describe "iron_mq_client" do
|
33
|
+
|
34
|
+
it "should assign the token" do
|
35
|
+
@send_email.iron_mq_client.token.should == @options['iron_mq']['token']
|
36
|
+
end
|
37
|
+
|
38
|
+
it "should assign the project_id" do
|
39
|
+
@send_email.iron_mq_client.project_id.should == @options['iron_mq']['project_id']
|
40
|
+
end
|
41
|
+
|
42
|
+
it "should assign the queue with the provided queue name" do
|
43
|
+
@send_email.queue.name.should == @options['iron_mq']['queue_name']
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
describe "iron_cache_client" do
|
48
|
+
it "should assign the token" do
|
49
|
+
@send_email.iron_cache_client.token.should == @options['iron_cache']['token']
|
50
|
+
end
|
51
|
+
|
52
|
+
it "should assign the project_id" do
|
53
|
+
@send_email.iron_cache_client.project_id.should == @options['iron_cache']['project_id']
|
54
|
+
end
|
55
|
+
|
56
|
+
it "should assign the cache with the provided cache name" do
|
57
|
+
@send_email.cache.name.should == @options['iron_cache']['cache_name']
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
it "should set delivery_method" do
|
62
|
+
@send_email.delivery_method.should == @options['delivery_method'].keys.first.to_sym
|
63
|
+
end
|
64
|
+
|
65
|
+
describe "smtp_config" do
|
66
|
+
it "should assign the address" do
|
67
|
+
@send_email.delivery_method_settings[:address].should == @options['delivery_method']['smtp']['address']
|
68
|
+
end
|
69
|
+
|
70
|
+
it "should assign the port" do
|
71
|
+
@send_email.delivery_method_settings[:port] == @options['delivery_method']['smtp']['port']
|
72
|
+
end
|
73
|
+
|
74
|
+
it "should assign the domain" do
|
75
|
+
@send_email.delivery_method_settings[:domain] == @options['delivery_method']['smtp']['domain']
|
76
|
+
end
|
77
|
+
|
78
|
+
it "should assign the user_name" do
|
79
|
+
@send_email.delivery_method_settings[:user_name] == @options['delivery_method']['smtp']['user_name']
|
80
|
+
end
|
81
|
+
|
82
|
+
it "should assign the password" do
|
83
|
+
@send_email.delivery_method_settings[:password] == @options['delivery_method']['smtp']['password']
|
84
|
+
end
|
85
|
+
|
86
|
+
it "should assign the authentication" do
|
87
|
+
@send_email.delivery_method_settings[:authentication] == @options['delivery_method']['smtp']['authentication']
|
88
|
+
end
|
89
|
+
|
90
|
+
it "should assign enable_starttls_auto" do
|
91
|
+
@send_email.delivery_method_settings[:enable_starttls_auto] == @options['delivery_method']['smtp']['enable_starttls_auto']
|
92
|
+
end
|
93
|
+
end
|
94
|
+
|
95
|
+
end
|
96
|
+
|
97
|
+
describe "execute" do
|
98
|
+
before(:each) do
|
99
|
+
@iron_mq_config = JSON.parse(File.read('spec/config/iron_mq.json'))
|
100
|
+
@send_email = IronMailer::SendEmail.new(test_config)
|
101
|
+
|
102
|
+
begin
|
103
|
+
@send_email.cache.size
|
104
|
+
rescue Rest::HttpError => e
|
105
|
+
@send_email.cache.put("some_key", 'some_value')
|
106
|
+
end
|
107
|
+
@test_email = test_email
|
108
|
+
@message = @send_email.queue.post(@test_email)
|
109
|
+
@execute=lambda{
|
110
|
+
@send_email.execute
|
111
|
+
@send_email.queue.reload
|
112
|
+
@send_email.cache.reload
|
113
|
+
}
|
114
|
+
end
|
115
|
+
|
116
|
+
after(:each) do
|
117
|
+
@send_email.queue.clear if @send_email.queue.size > 0
|
118
|
+
@send_email.cache.clear
|
119
|
+
end
|
120
|
+
|
121
|
+
it "should remove a message from the queue" do
|
122
|
+
@execute.should change(@send_email.queue, :size)
|
123
|
+
end
|
124
|
+
|
125
|
+
it "should add info about the email to the cache" do
|
126
|
+
@send_email.should_receive(:cache_email)
|
127
|
+
@execute.call
|
128
|
+
end
|
129
|
+
|
130
|
+
it "should call deliver with on the results of split_email" do
|
131
|
+
@test_email=test_email
|
132
|
+
@test_email.stub(:message_id).and_return(Time.now.to_f.to_s)
|
133
|
+
@send_email.stub(:split_email).and_return([@test_email])
|
134
|
+
@test_email.should_receive(:deliver)
|
135
|
+
@execute.call
|
136
|
+
end
|
137
|
+
|
138
|
+
it "should add the message back to the queue if there's an error " do
|
139
|
+
@send_email.queue.clear if @send_email.cache.size > 0
|
140
|
+
email = test_email
|
141
|
+
email.to.clear
|
142
|
+
class ErrorMailer
|
143
|
+
def initialize(*args)
|
144
|
+
end
|
145
|
+
def deliver!(*args)
|
146
|
+
raise
|
147
|
+
end
|
148
|
+
end
|
149
|
+
Mail.defaults do
|
150
|
+
delivery_method ErrorMailer
|
151
|
+
end
|
152
|
+
|
153
|
+
@send_email.queue.post(:error)
|
154
|
+
@execute.call
|
155
|
+
@send_email.queue.get.should_not be_nil
|
156
|
+
end
|
157
|
+
|
158
|
+
it "should send 'all' queued emails" do
|
159
|
+
@send_email.queue.post(test_email)
|
160
|
+
@send_email.queue.post(test_email)
|
161
|
+
@execute.should change(@send_email.queue, :size).to(0)
|
162
|
+
end
|
163
|
+
end
|
164
|
+
|
165
|
+
describe "cache_email" do
|
166
|
+
before(:each) do
|
167
|
+
@send_email = IronMailer::SendEmail.new(test_config)
|
168
|
+
@test_email = @send_email.split_email(test_email).first
|
169
|
+
@cache=lambda{
|
170
|
+
@send_email.cache_email(@test_email)
|
171
|
+
@send_email.cache.reload
|
172
|
+
}
|
173
|
+
end
|
174
|
+
|
175
|
+
|
176
|
+
after(:each) do
|
177
|
+
@send_email.cache.clear if @send_email.cache.size > 0
|
178
|
+
end
|
179
|
+
|
180
|
+
it "should add an item to the cache " do
|
181
|
+
@cache.should change(@send_email.cache, :size).by(1)
|
182
|
+
end
|
183
|
+
|
184
|
+
it "should use the cache key from the header" do
|
185
|
+
@cache.call
|
186
|
+
cache_key=JSON.parse(@test_email.header['X-SMTPAPI'].value)['unique_args']['cache_key']
|
187
|
+
@send_email.cache.get(cache_key).should_not be_nil
|
188
|
+
end
|
189
|
+
|
190
|
+
it "should blow up if the cache key is blank" do
|
191
|
+
@test_email.header['X-SMTPAPI'] = nil
|
192
|
+
@test_email.header['X-SMTPAPI'] = {unique_args: {cache_key: nil}}.to_json
|
193
|
+
@cache.should raise_error
|
194
|
+
end
|
195
|
+
|
196
|
+
it "should blow up if the header is blank" do
|
197
|
+
@test_email.header['X-SMTPAPI'] = nil
|
198
|
+
@test_email.header['X-SMTPAPI'] = ""
|
199
|
+
@cache.should raise_error
|
200
|
+
end
|
201
|
+
|
202
|
+
it "should handle 'X-SMTPAPI' being an array" do
|
203
|
+
@test_email.header['X-SMTPAPI'] = 'some_header_value'
|
204
|
+
@cache.should change(@send_email.cache, :size).by(1)
|
205
|
+
end
|
206
|
+
|
207
|
+
end
|
208
|
+
describe "extract_cache_info" do
|
209
|
+
before(:each) do
|
210
|
+
@send_email = IronMailer::SendEmail.new(test_config)
|
211
|
+
@test_email = test_email(['someother@example.com'])
|
212
|
+
end
|
213
|
+
it "should extract the subject" do
|
214
|
+
@send_email.extract_cache_info(@test_email)['subject'].should == @test_email.subject
|
215
|
+
end
|
216
|
+
|
217
|
+
it "should extract the sender" do
|
218
|
+
@send_email.extract_cache_info(@test_email)['from'].should == @test_email.from
|
219
|
+
end
|
220
|
+
|
221
|
+
it "should extract the recipient" do
|
222
|
+
@send_email.extract_cache_info(@test_email)['to'].should == @test_email.to
|
223
|
+
end
|
224
|
+
|
225
|
+
it "should extract the date" do
|
226
|
+
@test_email.stub(:date).and_return(DateTime.now)
|
227
|
+
@send_email.extract_cache_info(@test_email)['date'].should == @test_email.date
|
228
|
+
end
|
229
|
+
|
230
|
+
it "should extract the content" do
|
231
|
+
@send_email.extract_cache_info(@test_email)['mail'].should == @test_email.to_s
|
232
|
+
end
|
233
|
+
end
|
234
|
+
|
235
|
+
describe "split_email" do
|
236
|
+
before(:each) do
|
237
|
+
@send_email = IronMailer::SendEmail.new(test_config)
|
238
|
+
@test_email = test_email(['someother@example.com'])
|
239
|
+
end
|
240
|
+
|
241
|
+
it "should split a single email into one per recipient" do
|
242
|
+
@send_email.split_email(@test_email).length.should == 2
|
243
|
+
end
|
244
|
+
|
245
|
+
it "should copy to the html_part" do
|
246
|
+
@send_email.split_email(@test_email).first.html_part.to_s.should == @test_email.html_part.to_s
|
247
|
+
end
|
248
|
+
|
249
|
+
it "should handle the html_part being nil" do
|
250
|
+
@test_email.stub(:html_part).and_return(nil)
|
251
|
+
lambda{
|
252
|
+
@send_email.split_email(@test_email)
|
253
|
+
}.should_not raise_error
|
254
|
+
end
|
255
|
+
|
256
|
+
it "should copy the text_part" do
|
257
|
+
@send_email.split_email(@test_email).first.text_part.to_s.should == @test_email.text_part.to_s
|
258
|
+
end
|
259
|
+
|
260
|
+
it "should handle the text_part being nil" do
|
261
|
+
@test_email.stub(:text_part).and_return(nil)
|
262
|
+
lambda{
|
263
|
+
@send_email.split_email(@test_email)
|
264
|
+
}.should_not raise_error
|
265
|
+
end
|
266
|
+
|
267
|
+
it "should include any bcc's on the first emails" do
|
268
|
+
@test_email.bcc = 'bcc@me.com'
|
269
|
+
@send_email.split_email(@test_email).first.bcc.should == @test_email.bcc
|
270
|
+
end
|
271
|
+
|
272
|
+
it "should include any cc's on the first emails" do
|
273
|
+
@test_email.cc = 'cc@me.com'
|
274
|
+
@send_email.split_email(@test_email).first.cc.should == @test_email.cc
|
275
|
+
end
|
276
|
+
|
277
|
+
it "should handle non-multipart emails" do
|
278
|
+
@test_email=test_email{
|
279
|
+
"This is not multipart"
|
280
|
+
}
|
281
|
+
@send_email.split_email(@test_email).first.body.to_s.should =~ /This is not multipart/
|
282
|
+
end
|
283
|
+
|
284
|
+
it "should include a cache_id in the smtp headers" do
|
285
|
+
@email = @send_email.split_email(@test_email).first
|
286
|
+
JSON.parse(@email.header['X-SMTPAPI'].first.value)['unique_args']['cache_key'].should_not be_blank
|
287
|
+
end
|
288
|
+
end
|
289
|
+
|
290
|
+
def test_config
|
291
|
+
@iron_mq_config = JSON.parse(File.read('spec/config/iron_mq.json'))
|
292
|
+
@iron_cache_config = JSON.parse(File.read('spec/config/iron_cache.json'))
|
293
|
+
{'iron_mq'=>@iron_mq_config, 'iron_cache'=>@iron_cache_config.merge('cache_name'=>"test_email_cache"), 'delivery_method'=>'test', 'debug'=>false}
|
294
|
+
end
|
295
|
+
|
296
|
+
def test_email(other_tos=[])
|
297
|
+
to = (['to@example.com']<<other_tos)
|
298
|
+
|
299
|
+
mail=Mail.new do
|
300
|
+
to to
|
301
|
+
from "from@example.com"
|
302
|
+
subject "This is a test email"
|
303
|
+
if block_given?
|
304
|
+
body yield
|
305
|
+
else
|
306
|
+
text_part do
|
307
|
+
body "This is a test"
|
308
|
+
end
|
309
|
+
html_part do
|
310
|
+
content_type 'text/html; charset=UTF-8'
|
311
|
+
body "<h1>This is a test</h1>"
|
312
|
+
end
|
313
|
+
end
|
314
|
+
end
|
315
|
+
end
|
316
|
+
|
317
|
+
end
|
metadata
ADDED
@@ -0,0 +1,189 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: iron_mailer
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.2
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Erich Timkar
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2013-10-04 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: bundler
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ~>
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '1.3'
|
22
|
+
type: :development
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ~>
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '1.3'
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: rake
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ! '>='
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '0'
|
38
|
+
type: :development
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '0'
|
46
|
+
- !ruby/object:Gem::Dependency
|
47
|
+
name: rspec
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - ! '>='
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '0'
|
54
|
+
type: :development
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ! '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
- !ruby/object:Gem::Dependency
|
63
|
+
name: mail
|
64
|
+
requirement: !ruby/object:Gem::Requirement
|
65
|
+
none: false
|
66
|
+
requirements:
|
67
|
+
- - ! '>='
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '0'
|
70
|
+
type: :runtime
|
71
|
+
prerelease: false
|
72
|
+
version_requirements: !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
74
|
+
requirements:
|
75
|
+
- - ! '>='
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: '0'
|
78
|
+
- !ruby/object:Gem::Dependency
|
79
|
+
name: iron_mq
|
80
|
+
requirement: !ruby/object:Gem::Requirement
|
81
|
+
none: false
|
82
|
+
requirements:
|
83
|
+
- - ~>
|
84
|
+
- !ruby/object:Gem::Version
|
85
|
+
version: '4.0'
|
86
|
+
type: :runtime
|
87
|
+
prerelease: false
|
88
|
+
version_requirements: !ruby/object:Gem::Requirement
|
89
|
+
none: false
|
90
|
+
requirements:
|
91
|
+
- - ~>
|
92
|
+
- !ruby/object:Gem::Version
|
93
|
+
version: '4.0'
|
94
|
+
- !ruby/object:Gem::Dependency
|
95
|
+
name: iron_cache
|
96
|
+
requirement: !ruby/object:Gem::Requirement
|
97
|
+
none: false
|
98
|
+
requirements:
|
99
|
+
- - ~>
|
100
|
+
- !ruby/object:Gem::Version
|
101
|
+
version: '1.4'
|
102
|
+
type: :runtime
|
103
|
+
prerelease: false
|
104
|
+
version_requirements: !ruby/object:Gem::Requirement
|
105
|
+
none: false
|
106
|
+
requirements:
|
107
|
+
- - ~>
|
108
|
+
- !ruby/object:Gem::Version
|
109
|
+
version: '1.4'
|
110
|
+
- !ruby/object:Gem::Dependency
|
111
|
+
name: typhoeus
|
112
|
+
requirement: !ruby/object:Gem::Requirement
|
113
|
+
none: false
|
114
|
+
requirements:
|
115
|
+
- - ! '>='
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '0'
|
118
|
+
type: :runtime
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
none: false
|
122
|
+
requirements:
|
123
|
+
- - ! '>='
|
124
|
+
- !ruby/object:Gem::Version
|
125
|
+
version: '0'
|
126
|
+
- !ruby/object:Gem::Dependency
|
127
|
+
name: uuidtools
|
128
|
+
requirement: !ruby/object:Gem::Requirement
|
129
|
+
none: false
|
130
|
+
requirements:
|
131
|
+
- - ! '>='
|
132
|
+
- !ruby/object:Gem::Version
|
133
|
+
version: '0'
|
134
|
+
type: :runtime
|
135
|
+
prerelease: false
|
136
|
+
version_requirements: !ruby/object:Gem::Requirement
|
137
|
+
none: false
|
138
|
+
requirements:
|
139
|
+
- - ! '>='
|
140
|
+
- !ruby/object:Gem::Version
|
141
|
+
version: '0'
|
142
|
+
description: A Rails mail delivery method using Iron MQ & Workers
|
143
|
+
email:
|
144
|
+
- erich@hordesoftware.com
|
145
|
+
executables: []
|
146
|
+
extensions: []
|
147
|
+
extra_rdoc_files: []
|
148
|
+
files:
|
149
|
+
- .gitignore
|
150
|
+
- Gemfile
|
151
|
+
- LICENSE
|
152
|
+
- LICENSE.txt
|
153
|
+
- README.md
|
154
|
+
- Rakefile
|
155
|
+
- iron_mailer.gemspec
|
156
|
+
- lib/iron_mailer.rb
|
157
|
+
- lib/iron_mailer/mq_mailer.rb
|
158
|
+
- lib/iron_mailer/send_email.rb
|
159
|
+
- lib/iron_mailer/version.rb
|
160
|
+
- spec/iron_mailer/mq_mailer_spec.rb
|
161
|
+
- spec/iron_mailer/send_email_spec.rb
|
162
|
+
homepage: ''
|
163
|
+
licenses:
|
164
|
+
- MIT
|
165
|
+
post_install_message:
|
166
|
+
rdoc_options: []
|
167
|
+
require_paths:
|
168
|
+
- lib
|
169
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
170
|
+
none: false
|
171
|
+
requirements:
|
172
|
+
- - ! '>='
|
173
|
+
- !ruby/object:Gem::Version
|
174
|
+
version: '0'
|
175
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
176
|
+
none: false
|
177
|
+
requirements:
|
178
|
+
- - ! '>='
|
179
|
+
- !ruby/object:Gem::Version
|
180
|
+
version: '0'
|
181
|
+
requirements: []
|
182
|
+
rubyforge_project:
|
183
|
+
rubygems_version: 1.8.25
|
184
|
+
signing_key:
|
185
|
+
specification_version: 3
|
186
|
+
summary: A Rails mail delivery method using Iron MQ & Workers
|
187
|
+
test_files:
|
188
|
+
- spec/iron_mailer/mq_mailer_spec.rb
|
189
|
+
- spec/iron_mailer/send_email_spec.rb
|