gitlab-mail_room 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (51) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +18 -0
  3. data/.gitlab-ci.yml +27 -0
  4. data/.ruby-version +1 -0
  5. data/.travis.yml +10 -0
  6. data/CHANGELOG.md +125 -0
  7. data/CODE_OF_CONDUCT.md +24 -0
  8. data/Gemfile +4 -0
  9. data/LICENSE.txt +22 -0
  10. data/README.md +361 -0
  11. data/Rakefile +6 -0
  12. data/bin/mail_room +5 -0
  13. data/lib/mail_room.rb +16 -0
  14. data/lib/mail_room/arbitration.rb +16 -0
  15. data/lib/mail_room/arbitration/noop.rb +18 -0
  16. data/lib/mail_room/arbitration/redis.rb +58 -0
  17. data/lib/mail_room/cli.rb +62 -0
  18. data/lib/mail_room/configuration.rb +36 -0
  19. data/lib/mail_room/connection.rb +195 -0
  20. data/lib/mail_room/coordinator.rb +41 -0
  21. data/lib/mail_room/crash_handler.rb +29 -0
  22. data/lib/mail_room/delivery.rb +24 -0
  23. data/lib/mail_room/delivery/letter_opener.rb +34 -0
  24. data/lib/mail_room/delivery/logger.rb +37 -0
  25. data/lib/mail_room/delivery/noop.rb +22 -0
  26. data/lib/mail_room/delivery/postback.rb +72 -0
  27. data/lib/mail_room/delivery/que.rb +63 -0
  28. data/lib/mail_room/delivery/sidekiq.rb +88 -0
  29. data/lib/mail_room/logger/structured.rb +21 -0
  30. data/lib/mail_room/mailbox.rb +182 -0
  31. data/lib/mail_room/mailbox_watcher.rb +62 -0
  32. data/lib/mail_room/version.rb +4 -0
  33. data/logfile.log +1 -0
  34. data/mail_room.gemspec +34 -0
  35. data/spec/fixtures/test_config.yml +16 -0
  36. data/spec/lib/arbitration/redis_spec.rb +146 -0
  37. data/spec/lib/cli_spec.rb +61 -0
  38. data/spec/lib/configuration_spec.rb +29 -0
  39. data/spec/lib/connection_spec.rb +65 -0
  40. data/spec/lib/coordinator_spec.rb +61 -0
  41. data/spec/lib/crash_handler_spec.rb +41 -0
  42. data/spec/lib/delivery/letter_opener_spec.rb +29 -0
  43. data/spec/lib/delivery/logger_spec.rb +46 -0
  44. data/spec/lib/delivery/postback_spec.rb +107 -0
  45. data/spec/lib/delivery/que_spec.rb +45 -0
  46. data/spec/lib/delivery/sidekiq_spec.rb +76 -0
  47. data/spec/lib/logger/structured_spec.rb +55 -0
  48. data/spec/lib/mailbox_spec.rb +132 -0
  49. data/spec/lib/mailbox_watcher_spec.rb +64 -0
  50. data/spec/spec_helper.rb +32 -0
  51. metadata +277 -0
@@ -0,0 +1,64 @@
1
+ require 'spec_helper'
2
+
3
+ describe MailRoom::MailboxWatcher do
4
+ let(:mailbox) {build_mailbox}
5
+
6
+ describe '#running?' do
7
+ it 'is false by default' do
8
+ watcher = MailRoom::MailboxWatcher.new(mailbox)
9
+ expect(watcher.running?).to eq(false)
10
+ end
11
+ end
12
+
13
+ describe '#run' do
14
+ let(:imap) {stub(:login => true, :select => true)}
15
+ let(:watcher) {MailRoom::MailboxWatcher.new(mailbox)}
16
+
17
+ before :each do
18
+ Net::IMAP.stubs(:new).returns(imap) # prevent connection
19
+ end
20
+
21
+ it 'loops over wait while running' do
22
+ connection = MailRoom::Connection.new(mailbox)
23
+ connection.stubs(:on_new_message)
24
+ connection.stubs(:wait)
25
+
26
+ MailRoom::Connection.stubs(:new).returns(connection)
27
+
28
+ watcher.stubs(:running?).returns(true).then.returns(false)
29
+
30
+ watcher.run
31
+ watcher.watching_thread.join # wait for finishing run
32
+
33
+ expect(watcher).to have_received(:running?).times(2)
34
+ expect(connection).to have_received(:wait).once
35
+ expect(connection).to have_received(:on_new_message).once
36
+ end
37
+ end
38
+
39
+ describe '#quit' do
40
+ let(:imap) {stub(:login => true, :select => true)}
41
+ let(:watcher) {MailRoom::MailboxWatcher.new(mailbox)}
42
+
43
+ before :each do
44
+ Net::IMAP.stubs(:new).returns(imap) # prevent connection
45
+ end
46
+
47
+ it 'closes and waits for the connection' do
48
+ connection = MailRoom::Connection.new(mailbox)
49
+ connection.stubs(:wait)
50
+ connection.stubs(:quit)
51
+
52
+ MailRoom::Connection.stubs(:new).returns(connection)
53
+
54
+ watcher.run
55
+
56
+ expect(watcher.running?).to eq(true)
57
+
58
+ watcher.quit
59
+
60
+ expect(connection).to have_received(:quit)
61
+ expect(watcher.running?).to eq(false)
62
+ end
63
+ end
64
+ end
@@ -0,0 +1,32 @@
1
+ require 'simplecov'
2
+ SimpleCov.start
3
+
4
+ require 'bundler/setup'
5
+
6
+ require 'rspec'
7
+ require 'mocha/api'
8
+ require 'bourne'
9
+
10
+ require File.expand_path('../../lib/mail_room', __FILE__)
11
+
12
+ RSpec.configure do |config|
13
+ config.mock_with :mocha
14
+ config.run_all_when_everything_filtered = true
15
+ config.filter_run :focus
16
+
17
+ # Run specs in random order to surface order dependencies. If you find an
18
+ # order dependency and want to debug it, you can fix the order by providing
19
+ # the seed, which is printed after each run.
20
+ # --seed 1234
21
+ config.order = 'random'
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 ADDED
@@ -0,0 +1,277 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: gitlab-mail_room
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.2
5
+ platform: ruby
6
+ authors:
7
+ - Tony Pitale
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2020-02-25 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rake
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
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
+ - !ruby/object:Gem::Dependency
42
+ name: mocha
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: bourne
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: simplecov
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: faraday
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: mail
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: letter_opener
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ - !ruby/object:Gem::Dependency
126
+ name: redis
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - "~>"
130
+ - !ruby/object:Gem::Version
131
+ version: 3.3.1
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - "~>"
137
+ - !ruby/object:Gem::Version
138
+ version: 3.3.1
139
+ - !ruby/object:Gem::Dependency
140
+ name: redis-namespace
141
+ requirement: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - ">="
144
+ - !ruby/object:Gem::Version
145
+ version: '0'
146
+ type: :development
147
+ prerelease: false
148
+ version_requirements: !ruby/object:Gem::Requirement
149
+ requirements:
150
+ - - ">="
151
+ - !ruby/object:Gem::Version
152
+ version: '0'
153
+ - !ruby/object:Gem::Dependency
154
+ name: pg
155
+ requirement: !ruby/object:Gem::Requirement
156
+ requirements:
157
+ - - ">="
158
+ - !ruby/object:Gem::Version
159
+ version: '0'
160
+ type: :development
161
+ prerelease: false
162
+ version_requirements: !ruby/object:Gem::Requirement
163
+ requirements:
164
+ - - ">="
165
+ - !ruby/object:Gem::Version
166
+ version: '0'
167
+ - !ruby/object:Gem::Dependency
168
+ name: charlock_holmes
169
+ requirement: !ruby/object:Gem::Requirement
170
+ requirements:
171
+ - - ">="
172
+ - !ruby/object:Gem::Version
173
+ version: '0'
174
+ type: :development
175
+ prerelease: false
176
+ version_requirements: !ruby/object:Gem::Requirement
177
+ requirements:
178
+ - - ">="
179
+ - !ruby/object:Gem::Version
180
+ version: '0'
181
+ description: mail_room will proxy email (gmail) from IMAP to a delivery method
182
+ email:
183
+ - tpitale@gmail.com
184
+ executables:
185
+ - mail_room
186
+ extensions: []
187
+ extra_rdoc_files: []
188
+ files:
189
+ - ".gitignore"
190
+ - ".gitlab-ci.yml"
191
+ - ".ruby-version"
192
+ - ".travis.yml"
193
+ - CHANGELOG.md
194
+ - CODE_OF_CONDUCT.md
195
+ - Gemfile
196
+ - LICENSE.txt
197
+ - README.md
198
+ - Rakefile
199
+ - bin/mail_room
200
+ - lib/mail_room.rb
201
+ - lib/mail_room/arbitration.rb
202
+ - lib/mail_room/arbitration/noop.rb
203
+ - lib/mail_room/arbitration/redis.rb
204
+ - lib/mail_room/cli.rb
205
+ - lib/mail_room/configuration.rb
206
+ - lib/mail_room/connection.rb
207
+ - lib/mail_room/coordinator.rb
208
+ - lib/mail_room/crash_handler.rb
209
+ - lib/mail_room/delivery.rb
210
+ - lib/mail_room/delivery/letter_opener.rb
211
+ - lib/mail_room/delivery/logger.rb
212
+ - lib/mail_room/delivery/noop.rb
213
+ - lib/mail_room/delivery/postback.rb
214
+ - lib/mail_room/delivery/que.rb
215
+ - lib/mail_room/delivery/sidekiq.rb
216
+ - lib/mail_room/logger/structured.rb
217
+ - lib/mail_room/mailbox.rb
218
+ - lib/mail_room/mailbox_watcher.rb
219
+ - lib/mail_room/version.rb
220
+ - logfile.log
221
+ - mail_room.gemspec
222
+ - spec/fixtures/test_config.yml
223
+ - spec/lib/arbitration/redis_spec.rb
224
+ - spec/lib/cli_spec.rb
225
+ - spec/lib/configuration_spec.rb
226
+ - spec/lib/connection_spec.rb
227
+ - spec/lib/coordinator_spec.rb
228
+ - spec/lib/crash_handler_spec.rb
229
+ - spec/lib/delivery/letter_opener_spec.rb
230
+ - spec/lib/delivery/logger_spec.rb
231
+ - spec/lib/delivery/postback_spec.rb
232
+ - spec/lib/delivery/que_spec.rb
233
+ - spec/lib/delivery/sidekiq_spec.rb
234
+ - spec/lib/logger/structured_spec.rb
235
+ - spec/lib/mailbox_spec.rb
236
+ - spec/lib/mailbox_watcher_spec.rb
237
+ - spec/spec_helper.rb
238
+ homepage: http://github.com/tpitale/mail_room
239
+ licenses: []
240
+ metadata: {}
241
+ post_install_message:
242
+ rdoc_options: []
243
+ require_paths:
244
+ - lib
245
+ required_ruby_version: !ruby/object:Gem::Requirement
246
+ requirements:
247
+ - - ">="
248
+ - !ruby/object:Gem::Version
249
+ version: '0'
250
+ required_rubygems_version: !ruby/object:Gem::Requirement
251
+ requirements:
252
+ - - ">="
253
+ - !ruby/object:Gem::Version
254
+ version: '0'
255
+ requirements: []
256
+ rubygems_version: 3.1.2
257
+ signing_key:
258
+ specification_version: 4
259
+ summary: mail_room will proxy email (gmail) from IMAP to a callback URL, logger, or
260
+ letter_opener
261
+ test_files:
262
+ - spec/fixtures/test_config.yml
263
+ - spec/lib/arbitration/redis_spec.rb
264
+ - spec/lib/cli_spec.rb
265
+ - spec/lib/configuration_spec.rb
266
+ - spec/lib/connection_spec.rb
267
+ - spec/lib/coordinator_spec.rb
268
+ - spec/lib/crash_handler_spec.rb
269
+ - spec/lib/delivery/letter_opener_spec.rb
270
+ - spec/lib/delivery/logger_spec.rb
271
+ - spec/lib/delivery/postback_spec.rb
272
+ - spec/lib/delivery/que_spec.rb
273
+ - spec/lib/delivery/sidekiq_spec.rb
274
+ - spec/lib/logger/structured_spec.rb
275
+ - spec/lib/mailbox_spec.rb
276
+ - spec/lib/mailbox_watcher_spec.rb
277
+ - spec/spec_helper.rb