gitlab-mail_room 0.0.11 → 0.0.15

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: aed4391d3a022966a3f2adda086e9b2e059d3ce639755c088fb865a3fa694ffc
4
- data.tar.gz: 8c4f102bb223f73f914365d6c77dc7793b2149dbc47ce015e4c888de527d595d
3
+ metadata.gz: ec4ee38465229ec567497afa371c9001ba6b55f3f7b427815d2aeeaaa3916569
4
+ data.tar.gz: f98d83bd07c436f6d833c8ed9710a7cfe33d43a0f56891495eb495c75001ac6f
5
5
  SHA512:
6
- metadata.gz: 3018e959345d18859c40aae953bfcad1a779136f27cd9284da9a1c2edc44f6fcf5436aba4c2911ba0bb36147e4c066293768539802d4ff040a5136a16530a7cf
7
- data.tar.gz: afd251026ab38a1d54ac2e9fa88252a68f72971caa657b736e936f9151382879e05f2c90aa1a9026efac739cfa01a3604b6f48f542f3d098af8c20a0a59be5eb
6
+ metadata.gz: e7146b00f46e4ba842fad2234caf4f9145263f25aa4b21daaf16b17d5308d9cb7fc028c4cdaeede5e542bc05476bbbf95dff3f9fc5aae35fefca458004cfcd6e
7
+ data.tar.gz: c89588a3d43583ce20f1513b8488293f8b2f56b13bd15331276288f4331f2bef59abef77d790836cdcfe298d8af3fc9c4475586c44bb174fb485a6e1f4ac0834
@@ -3,5 +3,6 @@
3
3
  - [ ] create tag in https://gitlab.com/gitlab-org/gitlab-mail_room/
4
4
  - [ ] publish gem from this tag to rubygems.org
5
5
  - [ ] update https://gitlab.com/gitlab-org/gitlab/-/blob/master/Gemfile to use the new gem version
6
+ - [ ] update https://gitlab.com/gitlab-org/omnibus-gitlab/-/blob/master/config/software/mail_room.rb to use the new gem version
6
7
  - [ ] update gitlab-org/build/CNG to build container images from the new gem (example: https://gitlab.com/gitlab-org/build/CNG/-/merge_requests/451/diffs)
7
8
  - [ ] to deploy the new version to gitlab.com, update gitlab-com/gl-infra/k8s-workloads/gitlab-com to pin the new mailroom container image version and assign it the [release managers](https://about.gitlab.com/community/release-managers/) (example: https://gitlab.com/gitlab-com/gl-infra/k8s-workloads/gitlab-com/-/merge_requests/236/diffs)
data/.gitlab-ci.yml CHANGED
@@ -19,10 +19,6 @@ services:
19
19
  - gem install bundler --no-document # Bundler is not installed with the image
20
20
  - bundle install -j $(nproc) --path vendor # Install dependencies into ./vendor/ruby
21
21
 
22
- rspec-2.5:
23
- image: "ruby:2.5"
24
- <<: *test
25
-
26
22
  rspec-2.6:
27
23
  image: "ruby:2.6"
28
24
  <<: *test
data/.rubocop.yml ADDED
@@ -0,0 +1,5 @@
1
+ inherit_from: .rubocop_todo.yml
2
+
3
+ Style/HashSyntax:
4
+ Enabled: true
5
+ EnforcedStyle: ruby19_no_mixed_keys
data/.rubocop_todo.yml ADDED
@@ -0,0 +1,501 @@
1
+ # This configuration was generated by
2
+ # `rubocop --auto-gen-config`
3
+ # on 2021-04-26 06:46:39 UTC using RuboCop version 1.11.0.
4
+ # The point is for the user to remove these configuration records
5
+ # one by one as the offenses are removed from the code base.
6
+ # Note that changes in the inspected code, or installation of new
7
+ # versions of RuboCop, may require this file to be generated again.
8
+
9
+ # Offense count: 5
10
+ # Cop supports --auto-correct.
11
+ # Configuration parameters: TreatCommentsAsGroupSeparators, ConsiderPunctuation, Include.
12
+ # Include: **/*.gemspec
13
+ Gemspec/OrderedDependencies:
14
+ Exclude:
15
+ - 'mail_room.gemspec'
16
+
17
+ # Offense count: 1
18
+ # Configuration parameters: Include.
19
+ # Include: **/*.gemspec
20
+ Gemspec/RequiredRubyVersion:
21
+ Exclude:
22
+ - 'mail_room.gemspec'
23
+
24
+ # Offense count: 4
25
+ # Cop supports --auto-correct.
26
+ Layout/BlockEndNewline:
27
+ Exclude:
28
+ - 'spec/lib/delivery/postback_spec.rb'
29
+ - 'spec/lib/delivery/que_spec.rb'
30
+
31
+ # Offense count: 5
32
+ # Cop supports --auto-correct.
33
+ # Configuration parameters: EnforcedStyle, IndentOneStep, IndentationWidth.
34
+ # SupportedStyles: case, end
35
+ Layout/CaseIndentation:
36
+ Exclude:
37
+ - 'lib/mail_room/mailbox.rb'
38
+
39
+ # Offense count: 1
40
+ # Cop supports --auto-correct.
41
+ Layout/EmptyLineAfterMagicComment:
42
+ Exclude:
43
+ - 'mail_room.gemspec'
44
+
45
+ # Offense count: 2
46
+ # Cop supports --auto-correct.
47
+ # Configuration parameters: EnforcedStyle.
48
+ # SupportedStyles: around, only_before
49
+ Layout/EmptyLinesAroundAccessModifier:
50
+ Exclude:
51
+ - 'lib/mail_room/coordinator.rb'
52
+ - 'lib/mail_room/delivery/que.rb'
53
+
54
+ # Offense count: 4
55
+ # Cop supports --auto-correct.
56
+ # Configuration parameters: EnforcedStyle.
57
+ # SupportedStyles: empty_lines, no_empty_lines
58
+ Layout/EmptyLinesAroundBlockBody:
59
+ Exclude:
60
+ - 'spec/lib/crash_handler_spec.rb'
61
+ - 'spec/lib/delivery/sidekiq_spec.rb'
62
+ - 'spec/lib/logger/structured_spec.rb'
63
+
64
+ # Offense count: 1
65
+ # Cop supports --auto-correct.
66
+ # Configuration parameters: EnforcedStyle.
67
+ # SupportedStyles: empty_lines, empty_lines_except_namespace, empty_lines_special, no_empty_lines, beginning_only, ending_only
68
+ Layout/EmptyLinesAroundClassBody:
69
+ Exclude:
70
+ - 'lib/mail_room/logger/structured.rb'
71
+
72
+ # Offense count: 13
73
+ # Cop supports --auto-correct.
74
+ # Configuration parameters: EnforcedStyle, IndentationWidth.
75
+ # SupportedStyles: special_inside_parentheses, consistent, align_braces
76
+ Layout/FirstHashElementIndentation:
77
+ Exclude:
78
+ - 'spec/lib/delivery/postback_spec.rb'
79
+ - 'spec/lib/delivery/que_spec.rb'
80
+ - 'spec/lib/logger/structured_spec.rb'
81
+
82
+ # Offense count: 5
83
+ # Cop supports --auto-correct.
84
+ # Configuration parameters: AllowMultipleStyles, EnforcedHashRocketStyle, EnforcedColonStyle, EnforcedLastArgumentHashStyle.
85
+ # SupportedHashRocketStyles: key, separator, table
86
+ # SupportedColonStyles: key, separator, table
87
+ # SupportedLastArgumentHashStyles: always_inspect, always_ignore, ignore_implicit, ignore_explicit
88
+ Layout/HashAlignment:
89
+ Exclude:
90
+ - 'lib/mail_room/delivery/sidekiq.rb'
91
+
92
+ # Offense count: 2
93
+ # Cop supports --auto-correct.
94
+ # Configuration parameters: AllowDoxygenCommentStyle, AllowGemfileRubyComment.
95
+ Layout/LeadingCommentSpace:
96
+ Exclude:
97
+ - 'lib/mail_room/mailbox.rb'
98
+ - 'spec/lib/arbitration/redis_spec.rb'
99
+
100
+ # Offense count: 4
101
+ # Cop supports --auto-correct.
102
+ Layout/MultilineBlockLayout:
103
+ Exclude:
104
+ - 'spec/lib/delivery/postback_spec.rb'
105
+ - 'spec/lib/delivery/que_spec.rb'
106
+
107
+ # Offense count: 3
108
+ # Cop supports --auto-correct.
109
+ # Configuration parameters: EnforcedStyle.
110
+ # SupportedStyles: space, no_space
111
+ Layout/SpaceAroundEqualsInParameterDefault:
112
+ Exclude:
113
+ - 'lib/mail_room/configuration.rb'
114
+ - 'lib/mail_room/crash_handler.rb'
115
+ - 'lib/mail_room/mailbox.rb'
116
+
117
+ # Offense count: 2
118
+ # Cop supports --auto-correct.
119
+ Layout/SpaceAroundKeyword:
120
+ Exclude:
121
+ - 'lib/mail_room/coordinator.rb'
122
+ - 'lib/mail_room/mailbox_watcher.rb'
123
+
124
+ # Offense count: 2
125
+ # Cop supports --auto-correct.
126
+ # Configuration parameters: AllowForAlignment, EnforcedStyleForExponentOperator.
127
+ # SupportedStylesForExponentOperator: space, no_space
128
+ Layout/SpaceAroundOperators:
129
+ Exclude:
130
+ - 'lib/mail_room/mailbox.rb'
131
+ - 'spec/lib/arbitration/redis_spec.rb'
132
+
133
+ # Offense count: 7
134
+ # Cop supports --auto-correct.
135
+ # Configuration parameters: EnforcedStyle, EnforcedStyleForEmptyBraces.
136
+ # SupportedStyles: space, no_space
137
+ # SupportedStylesForEmptyBraces: space, no_space
138
+ Layout/SpaceBeforeBlockBraces:
139
+ Exclude:
140
+ - 'mail_room.gemspec'
141
+ - 'spec/lib/crash_handler_spec.rb'
142
+ - 'spec/lib/mailbox_spec.rb'
143
+
144
+ # Offense count: 50
145
+ # Cop supports --auto-correct.
146
+ # Configuration parameters: EnforcedStyle, EnforcedStyleForEmptyBraces, SpaceBeforeBlockParameters.
147
+ # SupportedStyles: space, no_space
148
+ # SupportedStylesForEmptyBraces: space, no_space
149
+ Layout/SpaceInsideBlockBraces:
150
+ Exclude:
151
+ - 'lib/mail_room/coordinator.rb'
152
+ - 'spec/lib/cli_spec.rb'
153
+ - 'spec/lib/configuration_spec.rb'
154
+ - 'spec/lib/delivery/letter_opener_spec.rb'
155
+ - 'spec/lib/delivery/logger_spec.rb'
156
+ - 'spec/lib/delivery/postback_spec.rb'
157
+ - 'spec/lib/delivery/que_spec.rb'
158
+ - 'spec/lib/imap/connection_spec.rb'
159
+ - 'spec/lib/mailbox_watcher_spec.rb'
160
+
161
+ # Offense count: 34
162
+ # Cop supports --auto-correct.
163
+ # Configuration parameters: EnforcedStyle, EnforcedStyleForEmptyBraces.
164
+ # SupportedStyles: space, no_space, compact
165
+ # SupportedStylesForEmptyBraces: space, no_space
166
+ Layout/SpaceInsideHashLiteralBraces:
167
+ Exclude:
168
+ - 'lib/mail_room/arbitration/redis.rb'
169
+ - 'lib/mail_room/mailbox.rb'
170
+ - 'spec/lib/cli_spec.rb'
171
+ - 'spec/lib/mailbox_spec.rb'
172
+
173
+ # Offense count: 1
174
+ # Cop supports --auto-correct.
175
+ # Configuration parameters: EnforcedStyle.
176
+ # SupportedStyles: space, no_space
177
+ Layout/SpaceInsideParens:
178
+ Exclude:
179
+ - 'spec/lib/logger/structured_spec.rb'
180
+
181
+ # Offense count: 1
182
+ # Cop supports --auto-correct.
183
+ # Configuration parameters: EnforcedStyle.
184
+ # SupportedStyles: final_newline, final_blank_line
185
+ Layout/TrailingEmptyLines:
186
+ Exclude:
187
+ - 'spec/lib/delivery/letter_opener_spec.rb'
188
+
189
+ # Offense count: 7
190
+ # Cop supports --auto-correct.
191
+ # Configuration parameters: AllowInHeredoc.
192
+ Layout/TrailingWhitespace:
193
+ Exclude:
194
+ - 'lib/mail_room/coordinator.rb'
195
+ - 'lib/mail_room/imap.rb'
196
+ - 'spec/lib/coordinator_spec.rb'
197
+ - 'spec/lib/delivery/postback_spec.rb'
198
+
199
+ # Offense count: 5
200
+ # Configuration parameters: AllowedMethods.
201
+ # AllowedMethods: enums
202
+ Lint/ConstantDefinitionInBlock:
203
+ Exclude:
204
+ - 'lib/mail_room/mailbox.rb'
205
+
206
+ # Offense count: 1
207
+ Lint/RescueException:
208
+ Exclude:
209
+ - 'lib/mail_room/cli.rb'
210
+
211
+ # Offense count: 1
212
+ # Cop supports --auto-correct.
213
+ # Configuration parameters: AllowUnusedKeywordArguments, IgnoreEmptyMethods, IgnoreNotImplementedMethods.
214
+ Lint/UnusedMethodArgument:
215
+ Exclude:
216
+ - 'lib/mail_room/logger/structured.rb'
217
+
218
+ # Offense count: 4
219
+ # Configuration parameters: IgnoredMethods, CountRepeatedAttributes.
220
+ Metrics/AbcSize:
221
+ Max: 27
222
+
223
+ # Offense count: 27
224
+ # Configuration parameters: CountComments, CountAsOne, ExcludedMethods, IgnoredMethods.
225
+ # IgnoredMethods: refine
226
+ Metrics/BlockLength:
227
+ Max: 145
228
+
229
+ # Offense count: 3
230
+ # Configuration parameters: CountComments, CountAsOne.
231
+ Metrics/ClassLength:
232
+ Max: 151
233
+
234
+ # Offense count: 1
235
+ # Configuration parameters: IgnoredMethods.
236
+ Metrics/CyclomaticComplexity:
237
+ Max: 8
238
+
239
+ # Offense count: 13
240
+ # Configuration parameters: CountComments, CountAsOne, ExcludedMethods, IgnoredMethods.
241
+ Metrics/MethodLength:
242
+ Max: 22
243
+
244
+ # Offense count: 1
245
+ # Configuration parameters: CountComments, CountAsOne.
246
+ Metrics/ModuleLength:
247
+ Max: 172
248
+
249
+ # Offense count: 1
250
+ Naming/AccessorMethodName:
251
+ Exclude:
252
+ - 'lib/mail_room/configuration.rb'
253
+
254
+ # Offense count: 1
255
+ # Cop supports --auto-correct.
256
+ Security/YAMLLoad:
257
+ Exclude:
258
+ - 'lib/mail_room/configuration.rb'
259
+
260
+ # Offense count: 2
261
+ # Configuration parameters: EnforcedStyle, AllowModifiersOnSymbols.
262
+ # SupportedStyles: inline, group
263
+ Style/AccessModifierDeclarations:
264
+ Exclude:
265
+ - 'lib/mail_room/arbitration.rb'
266
+ - 'lib/mail_room/delivery.rb'
267
+
268
+ # Offense count: 1
269
+ # Cop supports --auto-correct.
270
+ # Configuration parameters: EnforcedStyle.
271
+ # SupportedStyles: prefer_alias, prefer_alias_method
272
+ Style/Alias:
273
+ Exclude:
274
+ - 'lib/mail_room/coordinator.rb'
275
+
276
+ # Offense count: 14
277
+ # Cop supports --auto-correct.
278
+ # Configuration parameters: EnforcedStyle, ProceduralMethods, FunctionalMethods, IgnoredMethods, AllowBracesOnProceduralOneLiners, BracesRequiredMethods.
279
+ # SupportedStyles: line_count_based, semantic, braces_for_chaining, always_braces
280
+ # ProceduralMethods: benchmark, bm, bmbm, create, each_with_object, measure, new, realtime, tap, with_object
281
+ # FunctionalMethods: let, let!, subject, watch
282
+ # IgnoredMethods: lambda, proc, it
283
+ Style/BlockDelimiters:
284
+ Exclude:
285
+ - 'spec/lib/arbitration/redis_spec.rb'
286
+ - 'spec/lib/delivery/postback_spec.rb'
287
+ - 'spec/lib/delivery/que_spec.rb'
288
+ - 'spec/lib/delivery/sidekiq_spec.rb'
289
+
290
+ # Offense count: 12
291
+ Style/Documentation:
292
+ Exclude:
293
+ - 'spec/**/*'
294
+ - 'test/**/*'
295
+ - 'lib/mail_room.rb'
296
+ - 'lib/mail_room/arbitration.rb'
297
+ - 'lib/mail_room/arbitration/noop.rb'
298
+ - 'lib/mail_room/arbitration/redis.rb'
299
+ - 'lib/mail_room/connection.rb'
300
+ - 'lib/mail_room/crash_handler.rb'
301
+ - 'lib/mail_room/delivery.rb'
302
+ - 'lib/mail_room/imap/connection.rb'
303
+ - 'lib/mail_room/imap/message.rb'
304
+ - 'lib/mail_room/logger/structured.rb'
305
+ - 'lib/mail_room/message.rb'
306
+ - 'lib/mail_room/microsoft_graph/connection.rb'
307
+
308
+ # Offense count: 2
309
+ # Cop supports --auto-correct.
310
+ # Configuration parameters: EnforcedStyle.
311
+ # SupportedStyles: compact, expanded
312
+ Style/EmptyMethod:
313
+ Exclude:
314
+ - 'lib/mail_room/arbitration/noop.rb'
315
+ - 'lib/mail_room/delivery/noop.rb'
316
+
317
+ # Offense count: 1
318
+ # Cop supports --auto-correct.
319
+ Style/Encoding:
320
+ Exclude:
321
+ - 'mail_room.gemspec'
322
+
323
+ # Offense count: 2
324
+ # Cop supports --auto-correct.
325
+ Style/ExpandPathArguments:
326
+ Exclude:
327
+ - 'mail_room.gemspec'
328
+ - 'spec/spec_helper.rb'
329
+
330
+ # Offense count: 38
331
+ # Cop supports --auto-correct.
332
+ # Configuration parameters: EnforcedStyle.
333
+ # SupportedStyles: always, always_true, never
334
+ Style/FrozenStringLiteralComment:
335
+ Enabled: false
336
+
337
+ # Offense count: 5
338
+ # Cop supports --auto-correct.
339
+ Style/GlobalStdStream:
340
+ Exclude:
341
+ - 'lib/mail_room/crash_handler.rb'
342
+ - 'lib/mail_room/delivery/logger.rb'
343
+ - 'lib/mail_room/mailbox.rb'
344
+ - 'spec/lib/delivery/logger_spec.rb'
345
+
346
+ # Offense count: 3
347
+ # Configuration parameters: MinBodyLength.
348
+ Style/GuardClause:
349
+ Exclude:
350
+ - 'lib/mail_room/configuration.rb'
351
+ - 'lib/mail_room/imap/connection.rb'
352
+ - 'lib/mail_room/mailbox_watcher.rb'
353
+
354
+ # Offense count: 1
355
+ # Cop supports --auto-correct.
356
+ # Configuration parameters: EnforcedStyle, UseHashRocketsWithSymbolValues, PreferHashRocketsForNonAlnumEndingSymbols.
357
+ # SupportedStyles: ruby19, hash_rockets, no_mixed_keys, ruby19_no_mixed_keys
358
+ Style/HashSyntax:
359
+ Exclude:
360
+ - 'spec/lib/microsoft_graph/connection_spec.rb'
361
+
362
+ # Offense count: 1
363
+ # Cop supports --auto-correct.
364
+ Style/IfUnlessModifier:
365
+ Exclude:
366
+ - 'lib/mail_room/mailbox_watcher.rb'
367
+
368
+ # Offense count: 5
369
+ # Cop supports --auto-correct.
370
+ # Configuration parameters: EnforcedStyle.
371
+ # SupportedStyles: literals, strict
372
+ Style/MutableConstant:
373
+ Exclude:
374
+ - 'lib/mail_room/crash_handler.rb'
375
+ - 'lib/mail_room/mailbox.rb'
376
+ - 'lib/mail_room/version.rb'
377
+ - 'spec/spec_helper.rb'
378
+
379
+ # Offense count: 1
380
+ # Cop supports --auto-correct.
381
+ # Configuration parameters: EnforcedStyle, IgnoredMethods.
382
+ # SupportedStyles: predicate, comparison
383
+ Style/NumericPredicate:
384
+ Exclude:
385
+ - 'spec/**/*'
386
+ - 'lib/mail_room/imap/connection.rb'
387
+
388
+ # Offense count: 2
389
+ # Cop supports --auto-correct.
390
+ # Configuration parameters: EnforcedStyle.
391
+ # SupportedStyles: short, verbose
392
+ Style/PreferredHashMethods:
393
+ Exclude:
394
+ - 'lib/mail_room/configuration.rb'
395
+ - 'lib/mail_room/mailbox.rb'
396
+
397
+ # Offense count: 1
398
+ # Cop supports --auto-correct.
399
+ # Configuration parameters: EnforcedStyle, AllowedCompactTypes.
400
+ # SupportedStyles: compact, exploded
401
+ Style/RaiseArgs:
402
+ Exclude:
403
+ - 'lib/mail_room/logger/structured.rb'
404
+
405
+ # Offense count: 2
406
+ # Cop supports --auto-correct.
407
+ Style/RedundantPercentQ:
408
+ Exclude:
409
+ - 'mail_room.gemspec'
410
+
411
+ # Offense count: 7
412
+ # Cop supports --auto-correct.
413
+ Style/RedundantSelf:
414
+ Exclude:
415
+ - 'lib/mail_room/configuration.rb'
416
+ - 'lib/mail_room/coordinator.rb'
417
+ - 'lib/mail_room/mailbox.rb'
418
+ - 'lib/mail_room/mailbox_watcher.rb'
419
+
420
+ # Offense count: 1
421
+ # Cop supports --auto-correct.
422
+ # Configuration parameters: EnforcedStyle.
423
+ # SupportedStyles: implicit, explicit
424
+ Style/RescueStandardError:
425
+ Exclude:
426
+ - 'lib/mail_room/configuration.rb'
427
+
428
+ # Offense count: 1
429
+ # Cop supports --auto-correct.
430
+ # Configuration parameters: ConvertCodeThatCanStartToReturnNil, AllowedMethods.
431
+ # AllowedMethods: present?, blank?, presence, try, try!
432
+ Style/SafeNavigation:
433
+ Exclude:
434
+ - 'lib/mail_room/mailbox_watcher.rb'
435
+
436
+ # Offense count: 1
437
+ # Cop supports --auto-correct.
438
+ # Configuration parameters: EnforcedStyle.
439
+ # SupportedStyles: use_perl_names, use_english_names
440
+ Style/SpecialGlobalVars:
441
+ Exclude:
442
+ - 'mail_room.gemspec'
443
+
444
+ # Offense count: 1
445
+ # Cop supports --auto-correct.
446
+ Style/StringConcatenation:
447
+ Exclude:
448
+ - 'lib/mail_room/logger/structured.rb'
449
+
450
+ # Offense count: 135
451
+ # Cop supports --auto-correct.
452
+ # Configuration parameters: EnforcedStyle, ConsistentQuotesInMultiline.
453
+ # SupportedStyles: single_quotes, double_quotes
454
+ Style/StringLiterals:
455
+ Enabled: false
456
+
457
+ # Offense count: 4
458
+ # Cop supports --auto-correct.
459
+ # Configuration parameters: EnforcedStyle, MinSize.
460
+ # SupportedStyles: percent, brackets
461
+ Style/SymbolArray:
462
+ Exclude:
463
+ - 'lib/mail_room/mailbox.rb'
464
+ - 'spec/lib/logger/structured_spec.rb'
465
+
466
+ # Offense count: 2
467
+ # Cop supports --auto-correct.
468
+ # Configuration parameters: EnforcedStyleForMultiline.
469
+ # SupportedStylesForMultiline: comma, consistent_comma, no_comma
470
+ Style/TrailingCommaInHashLiteral:
471
+ Exclude:
472
+ - 'spec/lib/mailbox_spec.rb'
473
+ - 'spec/spec_helper.rb'
474
+
475
+ # Offense count: 1
476
+ # Cop supports --auto-correct.
477
+ Style/WhileUntilDo:
478
+ Exclude:
479
+ - 'lib/mail_room/mailbox_watcher.rb'
480
+
481
+ # Offense count: 2
482
+ # Cop supports --auto-correct.
483
+ Style/WhileUntilModifier:
484
+ Exclude:
485
+ - 'lib/mail_room/coordinator.rb'
486
+ - 'lib/mail_room/mailbox_watcher.rb'
487
+
488
+ # Offense count: 3
489
+ # Cop supports --auto-correct.
490
+ # Configuration parameters: WordRegex.
491
+ # SupportedStyles: percent, brackets
492
+ Style/WordArray:
493
+ EnforcedStyle: percent
494
+ MinSize: 3
495
+
496
+ # Offense count: 6
497
+ # Cop supports --auto-correct.
498
+ # Configuration parameters: AutoCorrect, AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, IgnoredPatterns.
499
+ # URISchemes: http, https
500
+ Layout/LineLength:
501
+ Max: 177
data/.travis.yml CHANGED
@@ -6,6 +6,12 @@ rvm:
6
6
  - 3.0
7
7
  - truffleruby
8
8
  services:
9
- - redis-server
10
- script: bundle exec rspec spec
11
- sudo: false
9
+ - redis
10
+ script:
11
+ - bundle exec rspec spec
12
+
13
+ jobs:
14
+ - language: ruby
15
+ rvm: 2.7
16
+ script:
17
+ - bundle exec rubocop
data/CHANGELOG.md CHANGED
@@ -1,3 +1,7 @@
1
+ ## mail_room 0.10.1 ##
2
+
3
+ * Fix db attribute on redis URL PR#130 - @jarkaK
4
+
1
5
  ## mail_room 0.10.0 ##
2
6
 
3
7
  * Remove imap backports
data/CONTRIBUTING.md ADDED
@@ -0,0 +1,40 @@
1
+ ## Developer Certificate of Origin and License
2
+
3
+ By contributing to GitLab B.V., you accept and agree to the following terms and
4
+ conditions for your present and future contributions submitted to GitLab B.V.
5
+ Except for the license granted herein to GitLab B.V. and recipients of software
6
+ distributed by GitLab B.V., you reserve all right, title, and interest in and to
7
+ your Contributions.
8
+
9
+ All contributions are subject to the Developer Certificate of Origin and license set out at [docs.gitlab.com/ce/legal/developer_certificate_of_origin](https://docs.gitlab.com/ce/legal/developer_certificate_of_origin).
10
+
11
+ _This notice should stay as the first item in the CONTRIBUTING.md file._
12
+
13
+ ## Code of conduct
14
+
15
+ As contributors and maintainers of this project, we pledge to respect all people
16
+ who contribute through reporting issues, posting feature requests, updating
17
+ documentation, submitting pull requests or patches, and other activities.
18
+
19
+ We are committed to making participation in this project a harassment-free
20
+ experience for everyone, regardless of level of experience, gender, gender
21
+ identity and expression, sexual orientation, disability, personal appearance,
22
+ body size, race, ethnicity, age, or religion.
23
+
24
+ Examples of unacceptable behavior by participants include the use of sexual
25
+ language or imagery, derogatory comments or personal attacks, trolling, public
26
+ or private harassment, insults, or other unprofessional conduct.
27
+
28
+ Project maintainers have the right and responsibility to remove, edit, or reject
29
+ comments, commits, code, wiki edits, issues, and other contributions that are
30
+ not aligned to this Code of Conduct. Project maintainers who do not follow the
31
+ Code of Conduct may be removed from the project team.
32
+
33
+ This code of conduct applies both within project spaces and in public spaces
34
+ when an individual is representing the project or its community.
35
+
36
+ Instances of abusive, harassing, or otherwise unacceptable behavior can be
37
+ reported by emailing contact@gitlab.com.
38
+
39
+ This Code of Conduct is adapted from the [Contributor Covenant](https://contributor-covenant.org), version 1.1.0,
40
+ available at [https://contributor-covenant.org/version/1/1/0/](https://contributor-covenant.org/version/1/1/0/).
data/Rakefile CHANGED
@@ -3,4 +3,4 @@ require 'rspec/core/rake_task'
3
3
 
4
4
  RSpec::Core::RakeTask.new(:spec)
5
5
 
6
- task :default => :spec
6
+ task default: :spec
@@ -31,7 +31,7 @@ module MailRoom
31
31
  # Any subsequent failure in the instance which gets the lock will be dealt
32
32
  # with by the expiration, at which time another instance can pick up the
33
33
  # message and try again.
34
- client.set(key, 1, {:nx => true, :ex => expiration})
34
+ client.set(key, 1, {nx: true, ex: expiration})
35
35
  end
36
36
 
37
37
  private
@@ -6,18 +6,23 @@ module MailRoom
6
6
 
7
7
  def initialize(mailbox)
8
8
  @mailbox = mailbox
9
+ @stopped = false
9
10
  end
10
11
 
11
12
  def on_new_message(&block)
12
13
  @new_message_handler = block
13
14
  end
14
15
 
16
+ def stopped?
17
+ @stopped
18
+ end
19
+
15
20
  def wait
16
21
  raise NotImplementedError
17
22
  end
18
23
 
19
24
  def quit
20
- raise NotImplementedError
25
+ @stopped = true
21
26
  end
22
27
  end
23
28
  end
@@ -24,7 +24,7 @@ module MailRoom
24
24
  # Trigger `LetterOpener` to deliver our message
25
25
  # @param message [String] the email message as a string, RFC822 format
26
26
  def deliver(message)
27
- method = ::LetterOpener::DeliveryMethod.new(:location => @delivery_options.location)
27
+ method = ::LetterOpener::DeliveryMethod.new(location: @delivery_options.location)
28
28
  method.deliver!(Mail.read_from_string(message))
29
29
 
30
30
  true
@@ -8,16 +8,17 @@ module MailRoom
8
8
  # Sidekiq Delivery method
9
9
  # @author Douwe Maan
10
10
  class Sidekiq
11
- Options = Struct.new(:redis_url, :namespace, :sentinels, :queue, :worker, :logger) do
11
+ Options = Struct.new(:redis_url, :namespace, :sentinels, :queue, :worker, :logger, :redis_db) do
12
12
  def initialize(mailbox)
13
13
  redis_url = mailbox.delivery_options[:redis_url] || "redis://localhost:6379"
14
+ redis_db = mailbox.delivery_options[:redis_db] || 0
14
15
  namespace = mailbox.delivery_options[:namespace]
15
16
  sentinels = mailbox.delivery_options[:sentinels]
16
17
  queue = mailbox.delivery_options[:queue] || "default"
17
18
  worker = mailbox.delivery_options[:worker]
18
19
  logger = mailbox.logger
19
20
 
20
- super(redis_url, namespace, sentinels, queue, worker, logger)
21
+ super(redis_url, namespace, sentinels, queue, worker, logger, redis_db)
21
22
  end
22
23
  end
23
24
 
@@ -45,7 +46,7 @@ module MailRoom
45
46
  def client
46
47
  @client ||= begin
47
48
  sentinels = options.sentinels
48
- redis_options = { url: options.redis_url }
49
+ redis_options = { url: options.redis_url, db: options.redis_db }
49
50
  redis_options[:sentinels] = sentinels if sentinels
50
51
 
51
52
  redis = ::Redis.new(redis_options)
@@ -51,20 +51,20 @@ module MailRoom
51
51
 
52
52
  # Default attributes for the mailbox configuration
53
53
  DEFAULTS = {
54
- :search_command => 'UNSEEN',
55
- :delivery_method => 'postback',
56
- :host => 'imap.gmail.com',
57
- :port => 993,
58
- :ssl => true,
59
- :start_tls => false,
60
- :limit_max_unread => 0,
61
- :idle_timeout => IMAP_IDLE_TIMEOUT,
62
- :delete_after_delivery => false,
63
- :expunge_deleted => false,
64
- :delivery_options => {},
65
- :arbitration_method => 'noop',
66
- :arbitration_options => {},
67
- :logger => {}
54
+ search_command: 'UNSEEN',
55
+ delivery_method: 'postback',
56
+ host: 'imap.gmail.com',
57
+ port: 993,
58
+ ssl: true,
59
+ start_tls: false,
60
+ limit_max_unread: 0,
61
+ idle_timeout: IMAP_IDLE_TIMEOUT,
62
+ delete_after_delivery: false,
63
+ expunge_deleted: false,
64
+ delivery_options: {},
65
+ arbitration_method: 'noop',
66
+ arbitration_options: {},
67
+ logger: {}
68
68
  }
69
69
 
70
70
  # Store the configuration and require the appropriate delivery method
@@ -22,6 +22,8 @@ module MailRoom
22
22
  end
23
23
 
24
24
  def wait
25
+ return if stopped?
26
+
25
27
  process_mailbox
26
28
 
27
29
  @throttled_count = 0
@@ -32,7 +34,7 @@ module MailRoom
32
34
  @mailbox.logger.warn({ context: @mailbox.context, action: 'Too many requests, backing off...', backoff_s: backoff_secs, error: e.message, error_backtrace: e.backtrace })
33
35
 
34
36
  backoff
35
- rescue OAuth2::Error, IOError => e
37
+ rescue IOError => e
36
38
  @mailbox.logger.warn({ context: @mailbox.context, action: 'Disconnected. Resetting...', error: e.message, error_backtrace: e.backtrace })
37
39
 
38
40
  reset
@@ -42,17 +44,30 @@ module MailRoom
42
44
  private
43
45
 
44
46
  def wait_for_new_messages
45
- sleep poll_interval
47
+ sleep_while_running(poll_interval)
46
48
  end
47
49
 
48
50
  def backoff
49
- sleep backoff_secs
51
+ sleep_while_running(backoff_secs)
50
52
  end
51
53
 
52
54
  def backoff_secs
53
55
  [60 * 10, 2**throttled_count].min
54
56
  end
55
57
 
58
+ # Unless wake up periodically, we won't notice that the thread was stopped
59
+ # if we sleep the entire interval.
60
+ def sleep_while_running(sleep_interval)
61
+ sleep_interval.times do
62
+ do_sleep(1)
63
+ return if stopped?
64
+ end
65
+ end
66
+
67
+ def do_sleep(interval)
68
+ sleep(interval)
69
+ end
70
+
56
71
  def reset
57
72
  @token = nil
58
73
  @throttled_count = 0
@@ -166,8 +181,9 @@ module MailRoom
166
181
  def get(url)
167
182
  response = token.get(url, { raise_errors: false })
168
183
 
184
+ # https://docs.microsoft.com/en-us/graph/errors
169
185
  case response.status
170
- when 429
186
+ when 509, 429
171
187
  raise TooManyRequestsError
172
188
  when 400..599
173
189
  raise OAuth2::Error, response
@@ -1,4 +1,4 @@
1
1
  module MailRoom
2
2
  # Current version of gitlab-mail_room gem
3
- VERSION = "0.0.11"
3
+ VERSION = "0.0.15"
4
4
  end
data/mail_room.gemspec CHANGED
@@ -20,8 +20,12 @@ Gem::Specification.new do |gem|
20
20
  gem.add_dependency "net-imap", ">= 0.2.1"
21
21
  gem.add_dependency "oauth2", "~> 1.4.4"
22
22
 
23
+ # Pinning io-wait to 0.1.0, which is the last version to support Ruby < 3
24
+ gem.add_dependency "io-wait", "~> 0.1.0"
25
+
23
26
  gem.add_development_dependency "rake"
24
27
  gem.add_development_dependency "rspec", "~> 3.9"
28
+ gem.add_development_dependency "rubocop", "~> 1.11"
25
29
  gem.add_development_dependency "mocha", "~> 1.11"
26
30
  gem.add_development_dependency "simplecov"
27
31
  gem.add_development_dependency "webrick", "~> 1.6"
data/spec/lib/cli_spec.rb CHANGED
@@ -2,8 +2,8 @@ require 'spec_helper'
2
2
 
3
3
  describe MailRoom::CLI do
4
4
  let(:config_path) {File.expand_path('../fixtures/test_config.yml', File.dirname(__FILE__))}
5
- let!(:configuration) {MailRoom::Configuration.new({:config_path => config_path})}
6
- let(:coordinator) {stub(:run => true, :quit => true)}
5
+ let!(:configuration) {MailRoom::Configuration.new({config_path: config_path})}
6
+ let(:coordinator) {stub(run: true, quit: true)}
7
7
  let(:configuration_args) { anything }
8
8
  let(:coordinator_args) { [anything, anything] }
9
9
 
@@ -17,7 +17,7 @@ describe MailRoom::CLI do
17
17
 
18
18
  context 'with configuration args' do
19
19
  let(:configuration_args) do
20
- {:config_path => 'a path'}
20
+ {config_path: 'a path'}
21
21
  end
22
22
 
23
23
  it 'parses arguments into configuration' do
@@ -5,7 +5,7 @@ describe MailRoom::Configuration do
5
5
 
6
6
  describe '#initalize' do
7
7
  context 'with config_path' do
8
- let(:configuration) { MailRoom::Configuration.new(:config_path => config_path) }
8
+ let(:configuration) { MailRoom::Configuration.new(config_path: config_path) }
9
9
 
10
10
  it 'parses yaml into mailbox objects' do
11
11
  MailRoom::Mailbox.stubs(:new).returns('mailbox1', 'mailbox2')
@@ -3,7 +3,7 @@ require 'mail_room/delivery/letter_opener'
3
3
 
4
4
  describe MailRoom::Delivery::LetterOpener do
5
5
  describe '#deliver' do
6
- let(:mailbox) {build_mailbox(:location => '/tmp/somewhere')}
6
+ let(:mailbox) {build_mailbox(location: '/tmp/somewhere')}
7
7
  let(:delivery_method) {stub(:deliver!)}
8
8
  let(:mail) {stub}
9
9
 
@@ -13,7 +13,7 @@ describe MailRoom::Delivery::LetterOpener do
13
13
  end
14
14
 
15
15
  it 'creates a new LetterOpener::DeliveryMethod' do
16
- ::LetterOpener::DeliveryMethod.expects(:new).with(:location => '/tmp/somewhere').returns(delivery_method)
16
+ ::LetterOpener::DeliveryMethod.expects(:new).with(location: '/tmp/somewhere').returns(delivery_method)
17
17
 
18
18
  MailRoom::Delivery::LetterOpener.new(mailbox).deliver('a message')
19
19
  end
@@ -16,7 +16,7 @@ describe MailRoom::Delivery::Logger do
16
16
  end
17
17
 
18
18
  context "with a log path" do
19
- let(:mailbox) {build_mailbox(:log_path => '/var/log/mail-room.log')}
19
+ let(:mailbox) {build_mailbox(log_path: '/var/log/mail-room.log')}
20
20
 
21
21
  it 'creates a new file to append to' do
22
22
  file = stub(:sync=)
@@ -5,8 +5,8 @@ describe MailRoom::Delivery::Postback do
5
5
  describe '#deliver' do
6
6
  context 'with token auth delivery' do
7
7
  let(:mailbox) {build_mailbox({
8
- :delivery_url => 'http://localhost/inbox',
9
- :delivery_token => 'abcdefg'
8
+ delivery_url: 'http://localhost/inbox',
9
+ delivery_token: 'abcdefg'
10
10
  })}
11
11
 
12
12
  let(:delivery_options) {
@@ -30,10 +30,10 @@ describe MailRoom::Delivery::Postback do
30
30
 
31
31
  context 'with basic auth delivery options' do
32
32
  let(:mailbox) {build_mailbox({
33
- :delivery_options => {
34
- :url => 'http://localhost/inbox',
35
- :username => 'user1',
36
- :password => 'password123abc'
33
+ delivery_options: {
34
+ url: 'http://localhost/inbox',
35
+ username: 'user1',
36
+ password: 'password123abc'
37
37
  }
38
38
  })}
39
39
 
@@ -57,11 +57,11 @@ describe MailRoom::Delivery::Postback do
57
57
 
58
58
  context 'with content type in the delivery options' do
59
59
  let(:mailbox) {build_mailbox({
60
- :delivery_options => {
61
- :url => 'http://localhost/inbox',
62
- :username => 'user1',
63
- :password => 'password123abc',
64
- :content_type => 'text/plain'
60
+ delivery_options: {
61
+ url: 'http://localhost/inbox',
62
+ username: 'user1',
63
+ password: 'password123abc',
64
+ content_type: 'text/plain'
65
65
  }
66
66
  })}
67
67
 
@@ -8,23 +8,45 @@ describe MailRoom::Delivery::Sidekiq do
8
8
 
9
9
  describe '#options' do
10
10
  let(:redis_url) { 'redis://localhost' }
11
+ let(:redis_options) { { redis_url: redis_url } }
11
12
 
12
13
  context 'when only redis_url is specified' do
13
14
  let(:mailbox) {
14
15
  build_mailbox(
15
16
  delivery_method: :sidekiq,
16
- delivery_options: {
17
- redis_url: redis_url
18
- }
17
+ delivery_options: redis_options
19
18
  )
20
19
  }
21
20
 
22
- it 'client has same specified redis_url' do
23
- expect(redis.client.options[:url]).to eq(redis_url)
21
+ context 'with simple redis url' do
22
+ it 'client has same specified redis_url' do
23
+ expect(redis.client.options[:url]).to eq(redis_url)
24
+ end
25
+
26
+ it 'client is a instance of RedisNamespace class' do
27
+ expect(redis).to be_a ::Redis
28
+ end
29
+
30
+ it 'connection has correct values' do
31
+ expect(redis.connection[:host]).to eq('localhost')
32
+ expect(redis.connection[:db]).to eq(0)
33
+ end
24
34
  end
25
35
 
26
- it 'client is a instance of RedisNamespace class' do
27
- expect(redis).to be_a ::Redis
36
+ context 'with redis_db specified in options' do
37
+ before do
38
+ redis_options[:redis_db] = 4
39
+ end
40
+
41
+ it 'client has correct redis_url' do
42
+ expect(redis.client.options[:url]).to eq(redis_url)
43
+ end
44
+
45
+
46
+ it 'connection has correct values' do
47
+ expect(redis.connection[:host]).to eq('localhost')
48
+ expect(redis.connection[:db]).to eq(4)
49
+ end
28
50
  end
29
51
  end
30
52
 
@@ -17,9 +17,9 @@ describe MailRoom::Mailbox do
17
17
  describe "#deliver" do
18
18
  context "with arbitration_method of noop" do
19
19
  it 'arbitrates with a Noop instance' do
20
- mailbox = build_mailbox({:arbitration_method => 'noop'})
20
+ mailbox = build_mailbox({arbitration_method: 'noop'})
21
21
  noop = stub(:deliver?)
22
- MailRoom::Arbitration['noop'].stubs(:new => noop)
22
+ MailRoom::Arbitration['noop'].stubs(new: noop)
23
23
 
24
24
  uid = 123
25
25
 
@@ -31,9 +31,9 @@ describe MailRoom::Mailbox do
31
31
 
32
32
  context "with arbitration_method of redis" do
33
33
  it 'arbitrates with a Redis instance' do
34
- mailbox = build_mailbox({:arbitration_method => 'redis'})
34
+ mailbox = build_mailbox({arbitration_method: 'redis'})
35
35
  redis = stub(:deliver?)
36
- MailRoom::Arbitration['redis'].stubs(:new => redis)
36
+ MailRoom::Arbitration['redis'].stubs(new: redis)
37
37
  uid = 123
38
38
  redis.expects(:deliver?).with(uid)
39
39
 
@@ -43,9 +43,9 @@ describe MailRoom::Mailbox do
43
43
 
44
44
  context "with delivery_method of noop" do
45
45
  it 'delivers with a Noop instance' do
46
- mailbox = build_mailbox({:delivery_method => 'noop'})
46
+ mailbox = build_mailbox({delivery_method: 'noop'})
47
47
  noop = stub(:deliver)
48
- MailRoom::Delivery['noop'].stubs(:new => noop)
48
+ MailRoom::Delivery['noop'].stubs(new: noop)
49
49
 
50
50
  noop.expects(:deliver).with(sample_message.body)
51
51
 
@@ -55,9 +55,9 @@ describe MailRoom::Mailbox do
55
55
 
56
56
  context "with delivery_method of logger" do
57
57
  it 'delivers with a Logger instance' do
58
- mailbox = build_mailbox({:delivery_method => 'logger'})
58
+ mailbox = build_mailbox({delivery_method: 'logger'})
59
59
  logger = stub(:deliver)
60
- MailRoom::Delivery['logger'].stubs(:new => logger)
60
+ MailRoom::Delivery['logger'].stubs(new: logger)
61
61
 
62
62
  logger.expects(:deliver).with(sample_message.body)
63
63
 
@@ -67,9 +67,9 @@ describe MailRoom::Mailbox do
67
67
 
68
68
  context "with delivery_method of postback" do
69
69
  it 'delivers with a Postback instance' do
70
- mailbox = build_mailbox({:delivery_method => 'postback'})
70
+ mailbox = build_mailbox({delivery_method: 'postback'})
71
71
  postback = stub(:deliver)
72
- MailRoom::Delivery['postback'].stubs(:new => postback)
72
+ MailRoom::Delivery['postback'].stubs(new: postback)
73
73
 
74
74
  postback.expects(:deliver).with(sample_message.body)
75
75
 
@@ -79,9 +79,9 @@ describe MailRoom::Mailbox do
79
79
 
80
80
  context "with delivery_method of letter_opener" do
81
81
  it 'delivers with a LetterOpener instance' do
82
- mailbox = build_mailbox({:delivery_method => 'letter_opener'})
82
+ mailbox = build_mailbox({delivery_method: 'letter_opener'})
83
83
  letter_opener = stub(:deliver)
84
- MailRoom::Delivery['letter_opener'].stubs(:new => letter_opener)
84
+ MailRoom::Delivery['letter_opener'].stubs(new: letter_opener)
85
85
 
86
86
  letter_opener.expects(:deliver).with(sample_message.body)
87
87
 
@@ -93,7 +93,7 @@ describe MailRoom::Mailbox do
93
93
  it "doesn't deliver the message" do
94
94
  mailbox = build_mailbox({ name: "magic mailbox", delivery_method: 'noop' })
95
95
  noop = stub(:deliver)
96
- MailRoom::Delivery['noop'].stubs(:new => noop)
96
+ MailRoom::Delivery['noop'].stubs(new: noop)
97
97
  noop.expects(:deliver).never
98
98
 
99
99
  mailbox.deliver(MailRoom::Message.new(uid: 1234, body: nil))
@@ -102,9 +102,9 @@ describe MailRoom::Mailbox do
102
102
 
103
103
  context "with ssl options hash" do
104
104
  it 'replaces verify mode with constant' do
105
- mailbox = build_mailbox({:ssl => {:verify_mode => :none}})
105
+ mailbox = build_mailbox({ssl: {verify_mode: :none}})
106
106
 
107
- expect(mailbox.ssl_options).to eq({:verify_mode => OpenSSL::SSL::VERIFY_NONE})
107
+ expect(mailbox.ssl_options).to eq({verify_mode: OpenSSL::SSL::VERIFY_NONE})
108
108
  end
109
109
  end
110
110
 
@@ -132,8 +132,8 @@ describe MailRoom::Mailbox do
132
132
  describe "#validate!" do
133
133
  context "with missing configuration" do
134
134
  it 'raises an error' do
135
- expect { build_mailbox({:name => nil}) }.to raise_error(MailRoom::ConfigurationError)
136
- expect { build_mailbox({:host => nil}) }.to raise_error(MailRoom::ConfigurationError)
135
+ expect { build_mailbox({name: nil}) }.to raise_error(MailRoom::ConfigurationError)
136
+ expect { build_mailbox({host: nil}) }.to raise_error(MailRoom::ConfigurationError)
137
137
  end
138
138
  end
139
139
 
@@ -12,7 +12,7 @@ describe MailRoom::MailboxWatcher do
12
12
  end
13
13
 
14
14
  describe '#run' do
15
- let(:imap) {stub(:login => true, :select => true)}
15
+ let(:imap) {stub(login: true, select: true)}
16
16
  let(:watcher) {MailRoom::MailboxWatcher.new(mailbox)}
17
17
 
18
18
  before :each do
@@ -34,7 +34,7 @@ describe MailRoom::MailboxWatcher do
34
34
  end
35
35
 
36
36
  describe '#quit' do
37
- let(:imap) {stub(:login => true, :select => true)}
37
+ let(:imap) {stub(login: true, select: true)}
38
38
  let(:watcher) {MailRoom::MailboxWatcher.new(mailbox)}
39
39
 
40
40
  before :each do
@@ -17,34 +17,53 @@ describe MailRoom::MicrosoftGraph::Connection do
17
17
  let(:base_url) { 'https://graph.microsoft.com/v1.0/users/user@example.com/mailFolders/inbox/messages' }
18
18
  let(:message_base_url) { 'https://graph.microsoft.com/v1.0/users/user@example.com/messages' }
19
19
 
20
+ let(:connection) { described_class.new(mailbox) }
21
+ let(:uid) { 1 }
22
+ let(:access_token) { SecureRandom.hex }
23
+ let(:refresh_token) { SecureRandom.hex }
24
+ let(:expires_in) { Time.now + 3600 }
25
+ let(:unread_messages_body) { '' }
26
+ let(:status) { 200 }
27
+ let!(:stub_token) do
28
+ stub_request(:post, "https://login.microsoftonline.com/#{tenant_id}/oauth2/v2.0/token").to_return(
29
+ body: { 'access_token' => access_token, 'refresh_token' => refresh_token, 'expires_in' => expires_in }.to_json,
30
+ headers: { 'Content-Type' => 'application/json' }
31
+ )
32
+ end
33
+ let!(:stub_unread_messages_request) do
34
+ stub_request(:get, "#{base_url}?$filter=isRead%20eq%20false").to_return(
35
+ status: status,
36
+ body: unread_messages_body.to_json,
37
+ headers: { 'Content-Type' => 'application/json' }
38
+ )
39
+ end
40
+
20
41
  before do
21
42
  WebMock.enable!
22
43
  end
23
44
 
24
- context '#wait' do
25
- let(:connection) { described_class.new(mailbox) }
26
- let(:uid) { 1 }
27
- let(:access_token) { SecureRandom.hex }
28
- let(:refresh_token) { SecureRandom.hex }
29
- let(:expires_in) { Time.now + 3600 }
30
- let(:unread_messages_body) { '' }
31
- let(:status) { 200 }
32
- let!(:stub_token) do
33
- stub_request(:post, "https://login.microsoftonline.com/#{tenant_id}/oauth2/v2.0/token").to_return(
34
- body: { 'access_token' => access_token, 'refresh_token' => refresh_token, 'expires_in' => expires_in }.to_json,
35
- headers: { 'Content-Type' => 'application/json' }
36
- )
45
+ context '#quit' do
46
+ it 'returns false' do
47
+ expect(connection.stopped?).to be_falsey
37
48
  end
38
- let!(:stub_unread_messages_request) do
39
- stub_request(:get, "#{base_url}?$filter=isRead%20eq%20false").to_return(
40
- status: status,
41
- body: unread_messages_body.to_json,
42
- headers: { 'Content-Type' => 'application/json' }
43
- )
49
+
50
+ it 'returns true' do
51
+ connection.quit
52
+
53
+ expect(connection.stopped?).to be_truthy
44
54
  end
45
55
 
56
+ it 'does not attempt to process the mailbox' do
57
+ connection.quit
58
+
59
+ connection.expects(:process_mailbox).times(0)
60
+ connection.wait
61
+ end
62
+ end
63
+
64
+ context '#wait' do
46
65
  before do
47
- connection.stubs(:wait_for_new_messages)
66
+ connection.stubs(:do_sleep)
48
67
  end
49
68
 
50
69
  describe 'poll interval' do
@@ -52,6 +71,12 @@ describe MailRoom::MicrosoftGraph::Connection do
52
71
  expect(connection.send(:poll_interval)).to eq(60)
53
72
  end
54
73
 
74
+ it 'calls do_sleep 60 times' do
75
+ connection.expects(:do_sleep).with(1).times(60)
76
+
77
+ connection.wait
78
+ end
79
+
55
80
  context 'interval set to 10' do
56
81
  let(:options) do
57
82
  {
@@ -68,6 +93,12 @@ describe MailRoom::MicrosoftGraph::Connection do
68
93
  it 'sets the poll interval to 10' do
69
94
  expect(connection.send(:poll_interval)).to eq(10)
70
95
  end
96
+
97
+ it 'calls do_sleep 10 times' do
98
+ connection.expects(:do_sleep).with(1).times(10)
99
+
100
+ connection.wait
101
+ end
71
102
  end
72
103
  end
73
104
 
@@ -143,9 +174,7 @@ describe MailRoom::MicrosoftGraph::Connection do
143
174
  end
144
175
  end
145
176
 
146
- context 'too many requests' do
147
- let(:status) { 429 }
148
-
177
+ shared_examples 'request backoff' do
149
178
  it 'backs off' do
150
179
  connection.expects(:backoff)
151
180
 
@@ -156,6 +185,18 @@ describe MailRoom::MicrosoftGraph::Connection do
156
185
  end
157
186
  end
158
187
 
188
+ context 'too many requests' do
189
+ let(:status) { 429 }
190
+
191
+ it_behaves_like 'request backoff'
192
+ end
193
+
194
+ context 'too much bandwidth' do
195
+ let(:status) { 509 }
196
+
197
+ it_behaves_like 'request backoff'
198
+ end
199
+
159
200
  context 'invalid JSON response' do
160
201
  let(:body) { 'this is something' }
161
202
 
@@ -170,13 +211,10 @@ describe MailRoom::MicrosoftGraph::Connection do
170
211
  context '500 error' do
171
212
  let(:status) { 500 }
172
213
 
173
- it 'resets the state and logs a warning' do
174
- connection.expects(:reset)
175
- connection.expects(:setup)
176
- mailbox.logger.expects(:warn)
177
-
214
+ it 'terminates due to error' do
178
215
  connection.on_new_message {}
179
- connection.wait
216
+
217
+ expect { connection.wait }.to raise_error(OAuth2::Error)
180
218
  end
181
219
  end
182
220
  end
data/spec/spec_helper.rb CHANGED
@@ -22,9 +22,9 @@ RSpec.configure do |config|
22
22
  end
23
23
 
24
24
  REQUIRED_MAILBOX_DEFAULTS = {
25
- :name => "inbox",
26
- :email => "user@example.com",
27
- :password => "password123"
25
+ name: "inbox",
26
+ email: "user@example.com",
27
+ password: "password123"
28
28
  }
29
29
 
30
30
  REQUIRED_MICROSOFT_GRAPH_DEFAULTS = {
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gitlab-mail_room
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.11
4
+ version: 0.0.15
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tony Pitale
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-03-30 00:00:00.000000000 Z
11
+ date: 2021-12-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: net-imap
@@ -38,6 +38,20 @@ dependencies:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
40
  version: 1.4.4
41
+ - !ruby/object:Gem::Dependency
42
+ name: io-wait
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: 0.1.0
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: 0.1.0
41
55
  - !ruby/object:Gem::Dependency
42
56
  name: rake
43
57
  requirement: !ruby/object:Gem::Requirement
@@ -66,6 +80,20 @@ dependencies:
66
80
  - - "~>"
67
81
  - !ruby/object:Gem::Version
68
82
  version: '3.9'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rubocop
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '1.11'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '1.11'
69
97
  - !ruby/object:Gem::Dependency
70
98
  name: mocha
71
99
  requirement: !ruby/object:Gem::Requirement
@@ -231,10 +259,13 @@ files:
231
259
  - ".gitignore"
232
260
  - ".gitlab-ci.yml"
233
261
  - ".gitlab/issue_templates/Release.md"
262
+ - ".rubocop.yml"
263
+ - ".rubocop_todo.yml"
234
264
  - ".ruby-version"
235
265
  - ".travis.yml"
236
266
  - CHANGELOG.md
237
267
  - CODE_OF_CONDUCT.md
268
+ - CONTRIBUTING.md
238
269
  - Gemfile
239
270
  - LICENSE.txt
240
271
  - README.md