mail_room 0.9.1 → 0.10.0
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.
- checksums.yaml +5 -5
- data/.ruby-version +1 -1
- data/.travis.yml +5 -3
- data/CHANGELOG.md +21 -0
- data/README.md +38 -1
- data/lib/mail_room.rb +1 -1
- data/lib/mail_room/arbitration/redis.rb +8 -15
- data/lib/mail_room/connection.rb +28 -8
- data/lib/mail_room/delivery/postback.rb +36 -6
- data/lib/mail_room/delivery/que.rb +4 -2
- data/lib/mail_room/delivery/sidekiq.rb +4 -3
- data/lib/mail_room/logger/structured.rb +21 -0
- data/lib/mail_room/mailbox.rb +53 -14
- data/lib/mail_room/mailbox_watcher.rb +2 -0
- data/lib/mail_room/version.rb +1 -1
- data/logfile.log +1 -0
- data/mail_room.gemspec +1 -1
- data/spec/fixtures/test_config.yml +2 -0
- data/spec/lib/arbitration/redis_spec.rb +42 -23
- data/spec/lib/configuration_spec.rb +13 -9
- data/spec/lib/connection_spec.rb +4 -2
- data/spec/lib/delivery/letter_opener_spec.rb +1 -1
- data/spec/lib/delivery/logger_spec.rb +3 -3
- data/spec/lib/delivery/postback_spec.rb +57 -17
- data/spec/lib/delivery/que_spec.rb +1 -1
- data/spec/lib/delivery/sidekiq_spec.rb +5 -5
- data/spec/lib/logger/structured_spec.rb +55 -0
- data/spec/lib/mailbox_spec.rb +38 -13
- data/spec/lib/mailbox_watcher_spec.rb +1 -1
- data/spec/spec_helper.rb +10 -1
- metadata +15 -13
- data/lib/mail_room/backports/imap.rb +0 -33
data/spec/lib/mailbox_spec.rb
CHANGED
@@ -1,10 +1,12 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe MailRoom::Mailbox do
|
4
|
+
let(:sample_message) { {'RFC822' => 'a message', 'UID' => 123} }
|
5
|
+
|
4
6
|
describe "#deliver" do
|
5
7
|
context "with arbitration_method of noop" do
|
6
8
|
it 'arbitrates with a Noop instance' do
|
7
|
-
mailbox =
|
9
|
+
mailbox = build_mailbox({:arbitration_method => 'noop'})
|
8
10
|
noop = stub(:deliver?)
|
9
11
|
MailRoom::Arbitration['noop'].stubs(:new => noop)
|
10
12
|
|
@@ -18,12 +20,12 @@ describe MailRoom::Mailbox do
|
|
18
20
|
|
19
21
|
context "with arbitration_method of redis" do
|
20
22
|
it 'arbitrates with a Redis instance' do
|
21
|
-
mailbox =
|
23
|
+
mailbox = build_mailbox({:arbitration_method => 'redis'})
|
22
24
|
redis = stub(:deliver?)
|
23
25
|
MailRoom::Arbitration['redis'].stubs(:new => redis)
|
24
26
|
|
25
27
|
uid = 123
|
26
|
-
|
28
|
+
|
27
29
|
mailbox.deliver?(uid)
|
28
30
|
|
29
31
|
expect(redis).to have_received(:deliver?).with(uid)
|
@@ -32,11 +34,11 @@ describe MailRoom::Mailbox do
|
|
32
34
|
|
33
35
|
context "with delivery_method of noop" do
|
34
36
|
it 'delivers with a Noop instance' do
|
35
|
-
mailbox =
|
37
|
+
mailbox = build_mailbox({:delivery_method => 'noop'})
|
36
38
|
noop = stub(:deliver)
|
37
39
|
MailRoom::Delivery['noop'].stubs(:new => noop)
|
38
40
|
|
39
|
-
mailbox.deliver(stub(:attr =>
|
41
|
+
mailbox.deliver(stub(:attr => sample_message))
|
40
42
|
|
41
43
|
expect(noop).to have_received(:deliver).with('a message')
|
42
44
|
end
|
@@ -44,11 +46,11 @@ describe MailRoom::Mailbox do
|
|
44
46
|
|
45
47
|
context "with delivery_method of logger" do
|
46
48
|
it 'delivers with a Logger instance' do
|
47
|
-
mailbox =
|
49
|
+
mailbox = build_mailbox({:delivery_method => 'logger'})
|
48
50
|
logger = stub(:deliver)
|
49
51
|
MailRoom::Delivery['logger'].stubs(:new => logger)
|
50
52
|
|
51
|
-
mailbox.deliver(stub(:attr =>
|
53
|
+
mailbox.deliver(stub(:attr => sample_message))
|
52
54
|
|
53
55
|
expect(logger).to have_received(:deliver).with('a message')
|
54
56
|
end
|
@@ -56,11 +58,11 @@ describe MailRoom::Mailbox do
|
|
56
58
|
|
57
59
|
context "with delivery_method of postback" do
|
58
60
|
it 'delivers with a Postback instance' do
|
59
|
-
mailbox =
|
61
|
+
mailbox = build_mailbox({:delivery_method => 'postback'})
|
60
62
|
postback = stub(:deliver)
|
61
63
|
MailRoom::Delivery['postback'].stubs(:new => postback)
|
62
64
|
|
63
|
-
mailbox.deliver(stub(:attr =>
|
65
|
+
mailbox.deliver(stub(:attr => sample_message))
|
64
66
|
|
65
67
|
expect(postback).to have_received(:deliver).with('a message')
|
66
68
|
end
|
@@ -68,11 +70,11 @@ describe MailRoom::Mailbox do
|
|
68
70
|
|
69
71
|
context "with delivery_method of letter_opener" do
|
70
72
|
it 'delivers with a LetterOpener instance' do
|
71
|
-
mailbox =
|
73
|
+
mailbox = build_mailbox({:delivery_method => 'letter_opener'})
|
72
74
|
letter_opener = stub(:deliver)
|
73
75
|
MailRoom::Delivery['letter_opener'].stubs(:new => letter_opener)
|
74
76
|
|
75
|
-
mailbox.deliver(stub(:attr =>
|
77
|
+
mailbox.deliver(stub(:attr => sample_message))
|
76
78
|
|
77
79
|
expect(letter_opener).to have_received(:deliver).with('a message')
|
78
80
|
end
|
@@ -80,7 +82,7 @@ describe MailRoom::Mailbox do
|
|
80
82
|
|
81
83
|
context "without an RFC822 attribute" do
|
82
84
|
it "doesn't deliver the message" do
|
83
|
-
mailbox =
|
85
|
+
mailbox = build_mailbox({ name: "magic mailbox", delivery_method: 'noop' })
|
84
86
|
noop = stub(:deliver)
|
85
87
|
MailRoom::Delivery['noop'].stubs(:new => noop)
|
86
88
|
|
@@ -92,10 +94,33 @@ describe MailRoom::Mailbox do
|
|
92
94
|
|
93
95
|
context "with ssl options hash" do
|
94
96
|
it 'replaces verify mode with constant' do
|
95
|
-
mailbox =
|
97
|
+
mailbox = build_mailbox({:ssl => {:verify_mode => :none}})
|
96
98
|
|
97
99
|
expect(mailbox.ssl_options).to eq({:verify_mode => OpenSSL::SSL::VERIFY_NONE})
|
98
100
|
end
|
99
101
|
end
|
102
|
+
|
103
|
+
context 'structured logger setup' do
|
104
|
+
it 'sets up the logger correctly and does not error' do
|
105
|
+
mailbox = build_mailbox({ name: "magic mailbox", logger: { log_path: '/dev/null' } })
|
106
|
+
|
107
|
+
expect{ mailbox.logger.info(message: "asdf") }.not_to raise_error
|
108
|
+
end
|
109
|
+
|
110
|
+
it 'sets up the noop logger correctly and does not error' do
|
111
|
+
mailbox = build_mailbox({ name: "magic mailbox" })
|
112
|
+
|
113
|
+
expect{ mailbox.logger.info(message: "asdf") }.not_to raise_error
|
114
|
+
end
|
115
|
+
end
|
116
|
+
end
|
117
|
+
|
118
|
+
describe "#validate!" do
|
119
|
+
context "with missing configuration" do
|
120
|
+
it 'raises an error' do
|
121
|
+
expect { build_mailbox({:name => nil}) }.to raise_error(MailRoom::ConfigurationError)
|
122
|
+
expect { build_mailbox({:host => nil}) }.to raise_error(MailRoom::ConfigurationError)
|
123
|
+
end
|
124
|
+
end
|
100
125
|
end
|
101
126
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -6,7 +6,6 @@ require 'bundler/setup'
|
|
6
6
|
require 'rspec'
|
7
7
|
require 'mocha/api'
|
8
8
|
require 'bourne'
|
9
|
-
require 'fakeredis/rspec'
|
10
9
|
|
11
10
|
require File.expand_path('../../lib/mail_room', __FILE__)
|
12
11
|
|
@@ -21,3 +20,13 @@ RSpec.configure do |config|
|
|
21
20
|
# --seed 1234
|
22
21
|
config.order = 'random'
|
23
22
|
end
|
23
|
+
|
24
|
+
REQUIRED_MAILBOX_DEFAULTS = {
|
25
|
+
:name => "inbox",
|
26
|
+
:email => "user@example.com",
|
27
|
+
:password => "password123"
|
28
|
+
}
|
29
|
+
|
30
|
+
def build_mailbox(options = {})
|
31
|
+
MailRoom::Mailbox.new(REQUIRED_MAILBOX_DEFAULTS.merge(options))
|
32
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mail_room
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.10.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Tony Pitale
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2019-10-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|
@@ -81,7 +81,7 @@ dependencies:
|
|
81
81
|
- !ruby/object:Gem::Version
|
82
82
|
version: '0'
|
83
83
|
- !ruby/object:Gem::Dependency
|
84
|
-
name:
|
84
|
+
name: faraday
|
85
85
|
requirement: !ruby/object:Gem::Requirement
|
86
86
|
requirements:
|
87
87
|
- - ">="
|
@@ -95,7 +95,7 @@ dependencies:
|
|
95
95
|
- !ruby/object:Gem::Version
|
96
96
|
version: '0'
|
97
97
|
- !ruby/object:Gem::Dependency
|
98
|
-
name:
|
98
|
+
name: mail
|
99
99
|
requirement: !ruby/object:Gem::Requirement
|
100
100
|
requirements:
|
101
101
|
- - ">="
|
@@ -109,7 +109,7 @@ dependencies:
|
|
109
109
|
- !ruby/object:Gem::Version
|
110
110
|
version: '0'
|
111
111
|
- !ruby/object:Gem::Dependency
|
112
|
-
name:
|
112
|
+
name: letter_opener
|
113
113
|
requirement: !ruby/object:Gem::Requirement
|
114
114
|
requirements:
|
115
115
|
- - ">="
|
@@ -123,19 +123,19 @@ dependencies:
|
|
123
123
|
- !ruby/object:Gem::Version
|
124
124
|
version: '0'
|
125
125
|
- !ruby/object:Gem::Dependency
|
126
|
-
name:
|
126
|
+
name: redis
|
127
127
|
requirement: !ruby/object:Gem::Requirement
|
128
128
|
requirements:
|
129
|
-
- - "
|
129
|
+
- - "~>"
|
130
130
|
- !ruby/object:Gem::Version
|
131
|
-
version:
|
131
|
+
version: 3.3.1
|
132
132
|
type: :development
|
133
133
|
prerelease: false
|
134
134
|
version_requirements: !ruby/object:Gem::Requirement
|
135
135
|
requirements:
|
136
|
-
- - "
|
136
|
+
- - "~>"
|
137
137
|
- !ruby/object:Gem::Version
|
138
|
-
version:
|
138
|
+
version: 3.3.1
|
139
139
|
- !ruby/object:Gem::Dependency
|
140
140
|
name: redis-namespace
|
141
141
|
requirement: !ruby/object:Gem::Requirement
|
@@ -201,7 +201,6 @@ files:
|
|
201
201
|
- lib/mail_room/arbitration.rb
|
202
202
|
- lib/mail_room/arbitration/noop.rb
|
203
203
|
- lib/mail_room/arbitration/redis.rb
|
204
|
-
- lib/mail_room/backports/imap.rb
|
205
204
|
- lib/mail_room/cli.rb
|
206
205
|
- lib/mail_room/configuration.rb
|
207
206
|
- lib/mail_room/connection.rb
|
@@ -213,9 +212,11 @@ files:
|
|
213
212
|
- lib/mail_room/delivery/postback.rb
|
214
213
|
- lib/mail_room/delivery/que.rb
|
215
214
|
- lib/mail_room/delivery/sidekiq.rb
|
215
|
+
- lib/mail_room/logger/structured.rb
|
216
216
|
- lib/mail_room/mailbox.rb
|
217
217
|
- lib/mail_room/mailbox_watcher.rb
|
218
218
|
- lib/mail_room/version.rb
|
219
|
+
- logfile.log
|
219
220
|
- mail_room.gemspec
|
220
221
|
- spec/fixtures/test_config.yml
|
221
222
|
- spec/lib/arbitration/redis_spec.rb
|
@@ -228,6 +229,7 @@ files:
|
|
228
229
|
- spec/lib/delivery/postback_spec.rb
|
229
230
|
- spec/lib/delivery/que_spec.rb
|
230
231
|
- spec/lib/delivery/sidekiq_spec.rb
|
232
|
+
- spec/lib/logger/structured_spec.rb
|
231
233
|
- spec/lib/mailbox_spec.rb
|
232
234
|
- spec/lib/mailbox_watcher_spec.rb
|
233
235
|
- spec/spec_helper.rb
|
@@ -249,8 +251,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
249
251
|
- !ruby/object:Gem::Version
|
250
252
|
version: '0'
|
251
253
|
requirements: []
|
252
|
-
|
253
|
-
rubygems_version: 2.4.5.1
|
254
|
+
rubygems_version: 3.0.3
|
254
255
|
signing_key:
|
255
256
|
specification_version: 4
|
256
257
|
summary: mail_room will proxy email (gmail) from IMAP to a callback URL, logger, or
|
@@ -267,6 +268,7 @@ test_files:
|
|
267
268
|
- spec/lib/delivery/postback_spec.rb
|
268
269
|
- spec/lib/delivery/que_spec.rb
|
269
270
|
- spec/lib/delivery/sidekiq_spec.rb
|
271
|
+
- spec/lib/logger/structured_spec.rb
|
270
272
|
- spec/lib/mailbox_spec.rb
|
271
273
|
- spec/lib/mailbox_watcher_spec.rb
|
272
274
|
- spec/spec_helper.rb
|
@@ -1,33 +0,0 @@
|
|
1
|
-
module MailRoom
|
2
|
-
class IMAP < Net::IMAP
|
3
|
-
# Backported 2.3.0 version of net/imap idle command to support timeout
|
4
|
-
def idle(timeout = nil, &response_handler)
|
5
|
-
raise LocalJumpError, "no block given" unless response_handler
|
6
|
-
|
7
|
-
response = nil
|
8
|
-
|
9
|
-
synchronize do
|
10
|
-
tag = Thread.current[:net_imap_tag] = generate_tag
|
11
|
-
put_string("#{tag} IDLE#{CRLF}")
|
12
|
-
|
13
|
-
begin
|
14
|
-
add_response_handler(response_handler)
|
15
|
-
@idle_done_cond = new_cond
|
16
|
-
@idle_done_cond.wait(timeout)
|
17
|
-
@idle_done_cond = nil
|
18
|
-
if @receiver_thread_terminating
|
19
|
-
raise Net::IMAP::Error, "connection closed"
|
20
|
-
end
|
21
|
-
ensure
|
22
|
-
unless @receiver_thread_terminating
|
23
|
-
remove_response_handler(response_handler)
|
24
|
-
put_string("DONE#{CRLF}")
|
25
|
-
response = get_tagged_response(tag, "IDLE")
|
26
|
-
end
|
27
|
-
end
|
28
|
-
end
|
29
|
-
|
30
|
-
return response
|
31
|
-
end
|
32
|
-
end
|
33
|
-
end
|