gitlab-mail_room 0.0.14 → 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 +4 -4
- data/CHANGELOG.md +4 -0
- data/CONTRIBUTING.md +40 -0
- data/lib/mail_room/connection.rb +8 -1
- data/lib/mail_room/microsoft_graph/connection.rb +17 -2
- data/lib/mail_room/version.rb +1 -1
- data/spec/lib/microsoft_graph/connection_spec.rb +51 -20
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ec4ee38465229ec567497afa371c9001ba6b55f3f7b427815d2aeeaaa3916569
|
4
|
+
data.tar.gz: f98d83bd07c436f6d833c8ed9710a7cfe33d43a0f56891495eb495c75001ac6f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e7146b00f46e4ba842fad2234caf4f9145263f25aa4b21daaf16b17d5308d9cb7fc028c4cdaeede5e542bc05476bbbf95dff3f9fc5aae35fefca458004cfcd6e
|
7
|
+
data.tar.gz: c89588a3d43583ce20f1513b8488293f8b2f56b13bd15331276288f4331f2bef59abef77d790836cdcfe298d8af3fc9c4475586c44bb174fb485a6e1f4ac0834
|
data/CHANGELOG.md
CHANGED
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/lib/mail_room/connection.rb
CHANGED
@@ -6,16 +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
|
-
def quit
|
24
|
+
def quit
|
25
|
+
@stopped = true
|
26
|
+
end
|
20
27
|
end
|
21
28
|
end
|
@@ -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
|
@@ -42,17 +44,30 @@ module MailRoom
|
|
42
44
|
private
|
43
45
|
|
44
46
|
def wait_for_new_messages
|
45
|
-
|
47
|
+
sleep_while_running(poll_interval)
|
46
48
|
end
|
47
49
|
|
48
50
|
def backoff
|
49
|
-
|
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
|
data/lib/mail_room/version.rb
CHANGED
@@ -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 '#
|
25
|
-
|
26
|
-
|
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
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
49
|
+
|
50
|
+
it 'returns true' do
|
51
|
+
connection.quit
|
52
|
+
|
53
|
+
expect(connection.stopped?).to be_truthy
|
54
|
+
end
|
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
|
44
61
|
end
|
62
|
+
end
|
45
63
|
|
64
|
+
context '#wait' do
|
46
65
|
before do
|
47
|
-
connection.stubs(:
|
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
|
|
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.
|
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-
|
11
|
+
date: 2021-12-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: net-imap
|
@@ -265,6 +265,7 @@ files:
|
|
265
265
|
- ".travis.yml"
|
266
266
|
- CHANGELOG.md
|
267
267
|
- CODE_OF_CONDUCT.md
|
268
|
+
- CONTRIBUTING.md
|
268
269
|
- Gemfile
|
269
270
|
- LICENSE.txt
|
270
271
|
- README.md
|