mailhandler 1.0.38 → 1.0.39
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.rubocop.yml +26 -0
- data/Gemfile +2 -0
- data/lib/mailhandler.rb +2 -10
- data/lib/mailhandler/errors.rb +1 -0
- data/lib/mailhandler/receiver.rb +14 -6
- data/lib/mailhandler/receiving/base.rb +28 -22
- data/lib/mailhandler/receiving/filelist/base.rb +17 -6
- data/lib/mailhandler/receiving/filelist/filter/base.rb +8 -3
- data/lib/mailhandler/receiving/filelist/filter/email.rb +3 -0
- data/lib/mailhandler/receiving/folder.rb +8 -3
- data/lib/mailhandler/receiving/imap.rb +53 -51
- data/lib/mailhandler/receiving/mail.rb +6 -13
- data/lib/mailhandler/receiving/notification/console.rb +2 -1
- data/lib/mailhandler/receiving/notification/email.rb +7 -4
- data/lib/mailhandler/receiving/notification/email/content.rb +1 -4
- data/lib/mailhandler/receiving/notification/email/states.rb +23 -20
- data/lib/mailhandler/receiving/observer.rb +2 -1
- data/lib/mailhandler/sender.rb +1 -1
- data/lib/mailhandler/sending/api.rb +3 -3
- data/lib/mailhandler/sending/api_batch.rb +4 -1
- data/lib/mailhandler/sending/base.rb +4 -1
- data/lib/mailhandler/sending/smtp.rb +0 -1
- data/lib/mailhandler/version.rb +1 -1
- data/mailhandler.gemspec +1 -2
- data/spec/unit/mailhandler/receiver_spec.rb +23 -15
- data/spec/unit/mailhandler/receiving/base_spec.rb +8 -7
- data/spec/unit/mailhandler/receiving/folder_spec.rb +42 -29
- data/spec/unit/mailhandler/receiving/imap_spec.rb +4 -5
- data/spec/unit/mailhandler/receiving/notification/console_spec.rb +5 -5
- data/spec/unit/mailhandler/receiving/notification/email/content_spec.rb +22 -18
- data/spec/unit/mailhandler/receiving/notification/email_spec.rb +12 -12
- data/spec/unit/mailhandler/sender_spec.rb +7 -3
- data/spec/unit/mailhandler/sending/sender_api_batch_spec.rb +9 -7
- data/spec/unit/mailhandler/sending/sender_api_spec.rb +4 -4
- data/spec/unit/mailhandler/sending/sender_smtp_spec.rb +7 -7
- data/spec/unit/mailhandler_spec.rb +10 -9
- metadata +6 -6
@@ -1,15 +1,14 @@
|
|
1
|
-
|
2
1
|
require 'spec_helper'
|
3
2
|
|
4
3
|
describe MailHandler::Receiving::FolderChecker do
|
5
|
-
subject {
|
4
|
+
subject(:folder_checker) { described_class.new }
|
6
5
|
|
7
6
|
it '.create' do
|
8
|
-
|
7
|
+
expect(folder_checker).to be_kind_of MailHandler::Receiving::Checker
|
9
8
|
end
|
10
9
|
|
11
10
|
context 'search emails' do
|
12
|
-
let(:checker) {
|
11
|
+
let(:checker) { described_class.new(data_folder, data_folder) }
|
13
12
|
|
14
13
|
context '.find email' do
|
15
14
|
context 'search options' do
|
@@ -81,7 +80,7 @@ describe MailHandler::Receiving::FolderChecker do
|
|
81
80
|
expect(checker.find(by_subject: 'test123')).to be false
|
82
81
|
end
|
83
82
|
|
84
|
-
it 'by
|
83
|
+
it 'by folder_checker' do
|
85
84
|
checker.find(by_subject: 'test123')
|
86
85
|
expect(checker.found_emails).to be_empty
|
87
86
|
end
|
@@ -121,7 +120,7 @@ describe MailHandler::Receiving::FolderChecker do
|
|
121
120
|
expect(checker.find(by_subject: mail1.subject)).to be true
|
122
121
|
end
|
123
122
|
|
124
|
-
it 'by
|
123
|
+
it 'by folder_checker - single' do
|
125
124
|
checker.find(by_subject: mail1.subject)
|
126
125
|
|
127
126
|
aggregate_failures 'found mail details' do
|
@@ -136,7 +135,7 @@ describe MailHandler::Receiving::FolderChecker do
|
|
136
135
|
expect(checker.found_emails.size).to be 1
|
137
136
|
end
|
138
137
|
|
139
|
-
it 'by
|
138
|
+
it 'by folder_checker - multiple' do
|
140
139
|
checker.find(by_subject: 'test')
|
141
140
|
|
142
141
|
aggregate_failures 'found mail details' do
|
@@ -156,22 +155,26 @@ describe MailHandler::Receiving::FolderChecker do
|
|
156
155
|
expect(checker.found_emails.size).to be 4
|
157
156
|
end
|
158
157
|
|
159
|
-
|
160
|
-
|
161
|
-
|
158
|
+
context 'by recipient' do
|
159
|
+
it 'check by one recipient' do
|
160
|
+
checker.find(by_recipient: { to: 'igor1@example.com' })
|
161
|
+
expect(checker.found_emails.size).to be 1
|
162
|
+
end
|
162
163
|
|
163
|
-
|
164
|
-
|
164
|
+
it 'check by other recipient' do
|
165
|
+
checker.find(by_recipient: { to: 'igor2@example.com' })
|
166
|
+
expect(checker.found_emails.size).to be 1
|
167
|
+
end
|
165
168
|
end
|
166
169
|
|
167
170
|
context 'unicode' do
|
168
|
-
it 'by
|
171
|
+
it 'by folder_checker - cyrillic' do
|
169
172
|
skip
|
170
173
|
checker.find(by_subject: 'Е-маил пример')
|
171
174
|
expect(checker.found_emails.size).to be 1
|
172
175
|
end
|
173
176
|
|
174
|
-
it 'by
|
177
|
+
it 'by folder_checker - german' do
|
175
178
|
skip
|
176
179
|
checker.find(by_subject: 'möglich')
|
177
180
|
expect(checker.found_emails.size).to be 1
|
@@ -179,11 +182,11 @@ describe MailHandler::Receiving::FolderChecker do
|
|
179
182
|
end
|
180
183
|
|
181
184
|
context 'archiving emails' do
|
182
|
-
before
|
185
|
+
before do
|
183
186
|
FileUtils.mkdir "#{data_folder}/checked" unless Dir.exist? "#{data_folder}/checked"
|
184
187
|
end
|
185
188
|
|
186
|
-
after
|
189
|
+
after do
|
187
190
|
FileUtils.rm_r "#{data_folder}/checked", force: false if Dir.exist? data_folder.to_s
|
188
191
|
end
|
189
192
|
|
@@ -194,22 +197,32 @@ describe MailHandler::Receiving::FolderChecker do
|
|
194
197
|
mail
|
195
198
|
end
|
196
199
|
|
197
|
-
let(:checker_archive) {
|
200
|
+
let(:checker_archive) { described_class.new(data_folder, "#{data_folder}/checked") }
|
198
201
|
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
+
context 'to same folder' do
|
203
|
+
it 'delete' do
|
204
|
+
checker.find(by_subject: mail.subject, archive: true)
|
205
|
+
expect(checker.found_emails.size).to be 1
|
206
|
+
end
|
202
207
|
|
203
|
-
|
204
|
-
|
208
|
+
it 'delete all' do
|
209
|
+
checker.find(by_subject: mail.subject, archive: true)
|
210
|
+
checker.find(by_subject: mail.subject, archive: true)
|
211
|
+
expect(checker.found_emails).to be_empty
|
212
|
+
end
|
205
213
|
end
|
206
214
|
|
207
|
-
|
208
|
-
|
209
|
-
|
215
|
+
context 'to separate folder' do
|
216
|
+
it 'delete' do
|
217
|
+
checker_archive.find(by_subject: mail.subject, archive: true)
|
218
|
+
expect(checker_archive.found_emails.size).to be 1
|
219
|
+
end
|
210
220
|
|
211
|
-
|
212
|
-
|
221
|
+
it 'delete all' do
|
222
|
+
checker_archive.find(by_subject: mail.subject, archive: true)
|
223
|
+
checker_archive.find(by_subject: mail.subject, archive: true)
|
224
|
+
expect(checker_archive.found_emails).to be_empty
|
225
|
+
end
|
213
226
|
end
|
214
227
|
end
|
215
228
|
end
|
@@ -218,12 +231,12 @@ describe MailHandler::Receiving::FolderChecker do
|
|
218
231
|
|
219
232
|
context 'invalid folders' do
|
220
233
|
it 'inbox folder' do
|
221
|
-
checker =
|
234
|
+
checker = described_class.new('test', data_folder)
|
222
235
|
expect { checker.find count: 1 }.to raise_error MailHandler::FileError
|
223
236
|
end
|
224
237
|
|
225
238
|
it 'archive folder' do
|
226
|
-
checker =
|
239
|
+
checker = described_class.new(data_folder, 'test')
|
227
240
|
expect { checker.find count: 1 }.to raise_error MailHandler::FileError
|
228
241
|
end
|
229
242
|
end
|
@@ -1,8 +1,7 @@
|
|
1
|
-
|
2
1
|
require 'spec_helper'
|
3
2
|
|
4
3
|
describe MailHandler::Receiving::IMAPChecker do
|
5
|
-
let(:checker) {
|
4
|
+
let(:checker) { described_class.new }
|
6
5
|
|
7
6
|
it '.create' do
|
8
7
|
expect(checker).to be_kind_of MailHandler::Receiving::Checker
|
@@ -13,9 +12,9 @@ describe MailHandler::Receiving::IMAPChecker do
|
|
13
12
|
end
|
14
13
|
|
15
14
|
context 'search options' do
|
16
|
-
before
|
17
|
-
allow(checker).to receive(:init_retriever)
|
18
|
-
allow(checker).to receive(:find_emails)
|
15
|
+
before do
|
16
|
+
allow(checker).to receive(:init_retriever).and_return(true)
|
17
|
+
allow(checker).to receive(:find_emails).and_return([])
|
19
18
|
end
|
20
19
|
|
21
20
|
it 'by multiple search options' do
|
@@ -1,19 +1,19 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe MailHandler::Receiving::Notification::Console do
|
4
|
-
subject {
|
4
|
+
subject(:notification_console) { described_class }
|
5
5
|
|
6
6
|
context 'notify of a delay' do
|
7
7
|
it '.notify' do
|
8
|
-
search =
|
9
|
-
expect {
|
8
|
+
search = instance_double('Search', started_at: Time.now - 10)
|
9
|
+
expect { notification_console.new.notify(search) }.to output(/.+email delay: 0(9|1)0 seconds/).to_stdout
|
10
10
|
end
|
11
11
|
end
|
12
12
|
|
13
13
|
context 'not notify of a delay' do
|
14
14
|
it '.notify' do
|
15
|
-
search =
|
16
|
-
expect {
|
15
|
+
search = instance_double('Search', started_at: Time.now + 5)
|
16
|
+
expect { notification_console.new.notify(search) }.to output('').to_stdout
|
17
17
|
end
|
18
18
|
end
|
19
19
|
end
|
@@ -1,7 +1,7 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe MailHandler::Receiving::Notification::EmailContent do
|
4
|
-
subject {
|
4
|
+
subject(:notification_email_content) { described_class.new }
|
5
5
|
|
6
6
|
let(:to) { 'john@example.com' }
|
7
7
|
let(:from) { 'igor@example.com' }
|
@@ -9,33 +9,35 @@ describe MailHandler::Receiving::Notification::EmailContent do
|
|
9
9
|
|
10
10
|
context '.email_received' do
|
11
11
|
it 'create email' do
|
12
|
-
expect(
|
12
|
+
expect(notification_email_content.retrieve(:received, options, 60, from, to)).to be_kind_of Mail::Message
|
13
13
|
end
|
14
14
|
|
15
15
|
context 'email content' do
|
16
16
|
it 'sender' do
|
17
|
-
expect(
|
17
|
+
expect(notification_email_content.retrieve(:received, options, 60, from, to)[:from].to_s).to eq from
|
18
18
|
end
|
19
19
|
|
20
20
|
it 'single recipient' do
|
21
|
-
expect(
|
21
|
+
expect(notification_email_content.retrieve(:received, options, 60, from, to)[:to].to_s).to eq to
|
22
22
|
end
|
23
23
|
|
24
24
|
it 'multiple recipients' do
|
25
25
|
to = 'john1@example.com, john2@example.com'
|
26
|
-
expect(
|
26
|
+
expect(notification_email_content.retrieve(:received, options, 60, from, to)[:to].to_s).to eq to
|
27
27
|
end
|
28
28
|
|
29
|
-
it '
|
30
|
-
expect(
|
29
|
+
it 'notification_email_content - 1 minute delay' do
|
30
|
+
expect(notification_email_content.retrieve(:received, options, 60, from, to).subject)
|
31
|
+
.to eq 'Received - delay was 1.0 minutes'
|
31
32
|
end
|
32
33
|
|
33
|
-
it '
|
34
|
-
expect(
|
34
|
+
it 'notification_email_content - 1.5 minute delay' do
|
35
|
+
expect(notification_email_content.retrieve(:received, options, 90, from, to).subject)
|
36
|
+
.to eq 'Received - delay was 1.5 minutes'
|
35
37
|
end
|
36
38
|
|
37
39
|
it 'body' do
|
38
|
-
expect(
|
40
|
+
expect(notification_email_content.retrieve(:received, options, 90, from, to).body.to_s)
|
39
41
|
.to eq "Received - delay was 1.5 minutes - search by #{options}"
|
40
42
|
end
|
41
43
|
end
|
@@ -43,28 +45,30 @@ describe MailHandler::Receiving::Notification::EmailContent do
|
|
43
45
|
|
44
46
|
context '.email_delayed' do
|
45
47
|
it 'sender' do
|
46
|
-
expect(
|
48
|
+
expect(notification_email_content.retrieve(:delayed, options, 60, from, to)[:from].to_s).to eq from
|
47
49
|
end
|
48
50
|
|
49
51
|
it 'single recipient' do
|
50
|
-
expect(
|
52
|
+
expect(notification_email_content.retrieve(:delayed, options, 60, from, to)[:to].to_s).to eq to
|
51
53
|
end
|
52
54
|
|
53
55
|
it 'multiple recipients' do
|
54
56
|
to = 'john1@example.com, john2@example.com'
|
55
|
-
expect(
|
57
|
+
expect(notification_email_content.retrieve(:delayed, options, 60, from, to)[:to].to_s).to eq to
|
56
58
|
end
|
57
59
|
|
58
|
-
it '
|
59
|
-
expect(
|
60
|
+
it 'notification_email_content - 1 minute delay' do
|
61
|
+
expect(notification_email_content.retrieve(:delayed, options, 60, from, to).subject)
|
62
|
+
.to eq 'Over 1.0 minutes delay'
|
60
63
|
end
|
61
64
|
|
62
|
-
it '
|
63
|
-
expect(
|
65
|
+
it 'notification_email_content - 1.5 minute delay' do
|
66
|
+
expect(notification_email_content.retrieve(:delayed, options, 90, from, to).subject)
|
67
|
+
.to eq 'Over 1.5 minutes delay'
|
64
68
|
end
|
65
69
|
|
66
70
|
it 'body' do
|
67
|
-
expect(
|
71
|
+
expect(notification_email_content.retrieve(:delayed, options, 90, from, to).body.to_s)
|
68
72
|
.to eq "Over 1.5 minutes delay - search by #{options}"
|
69
73
|
end
|
70
74
|
end
|
@@ -1,13 +1,13 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe MailHandler::Receiving::Notification::Email do
|
4
|
-
let(:search) {
|
5
|
-
let(:sender) {
|
6
|
-
let(:notification) {
|
4
|
+
let(:search) { instance_double('search') }
|
5
|
+
let(:sender) { instance_double('sender') }
|
6
|
+
let(:notification) { described_class.new(sender, 'from@example.com', 'igor@example.com', 1) }
|
7
7
|
|
8
|
-
before
|
9
|
-
allow(sender).to receive(:send_email)
|
10
|
-
allow(search).to receive(:max_duration)
|
8
|
+
before do
|
9
|
+
allow(sender).to receive(:send_email).and_return(true)
|
10
|
+
allow(search).to receive(:max_duration).and_return(5)
|
11
11
|
end
|
12
12
|
|
13
13
|
it '.create' do
|
@@ -34,24 +34,24 @@ describe MailHandler::Receiving::Notification::Email do
|
|
34
34
|
|
35
35
|
it 'delayed' do
|
36
36
|
allow(search).to receive(:started_at) { Time.now - 2 }
|
37
|
-
allow(search).to receive(:result)
|
38
|
-
allow(notification).to receive(:send_email)
|
37
|
+
allow(search).to receive(:result).and_return(false)
|
38
|
+
allow(notification).to receive(:send_email).and_return(nil)
|
39
39
|
notification.notify(search)
|
40
40
|
expect(notification.current_state).to be_kind_of MailHandler::Receiving::Notification::Delay
|
41
41
|
end
|
42
42
|
|
43
43
|
it 'received' do
|
44
44
|
allow(search).to receive(:started_at) { Time.now - 2 }
|
45
|
-
allow(search).to receive(:result)
|
46
|
-
allow(notification).to receive(:send_email)
|
45
|
+
allow(search).to receive(:result).and_return(true)
|
46
|
+
allow(notification).to receive(:send_email).and_return(nil)
|
47
47
|
notification.notify(search)
|
48
48
|
expect(notification.current_state).to be_kind_of MailHandler::Receiving::Notification::Received
|
49
49
|
end
|
50
50
|
|
51
51
|
it 'max delayed' do
|
52
52
|
allow(search).to receive(:started_at) { Time.now - 10 }
|
53
|
-
allow(search).to receive(:result)
|
54
|
-
allow(notification).to receive(:send_email)
|
53
|
+
allow(search).to receive(:result).and_return(false)
|
54
|
+
allow(notification).to receive(:send_email).and_return(nil)
|
55
55
|
notification.notify(search)
|
56
56
|
expect(notification.current_state).to be_kind_of MailHandler::Receiving::Notification::MaxDelay
|
57
57
|
end
|
@@ -1,13 +1,17 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe MailHandler::Sender do
|
4
|
-
subject {
|
4
|
+
subject { described_class }
|
5
5
|
|
6
6
|
let(:send_duration) { 3 }
|
7
7
|
let(:dispatcher) do
|
8
|
-
dispatcher =
|
8
|
+
dispatcher = instance_double('Dispatcher')
|
9
|
+
|
10
|
+
allow(dispatcher).to receive(:send) do
|
11
|
+
sleep send_duration
|
12
|
+
'Sent'
|
13
|
+
end
|
9
14
|
|
10
|
-
allow(dispatcher).to receive(:send) { sleep send_duration; 'Sent' }
|
11
15
|
dispatcher
|
12
16
|
end
|
13
17
|
let(:mail) do
|
@@ -1,12 +1,12 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe MailHandler::Sending::PostmarkBatchAPISender do
|
4
|
-
subject {
|
4
|
+
subject(:postmark_api_batch_sender) { described_class }
|
5
5
|
|
6
6
|
let(:api_token) { '122878782' }
|
7
7
|
|
8
8
|
it 'create' do
|
9
|
-
sender =
|
9
|
+
sender = postmark_api_batch_sender.new(api_token)
|
10
10
|
|
11
11
|
aggregate_failures 'init details' do
|
12
12
|
expect(sender.api_token).to eq api_token
|
@@ -17,21 +17,23 @@ describe MailHandler::Sending::PostmarkBatchAPISender do
|
|
17
17
|
end
|
18
18
|
|
19
19
|
it '.send - invalid auth' do
|
20
|
-
sender =
|
20
|
+
sender = postmark_api_batch_sender.new(api_token)
|
21
21
|
expect { sender.send([Mail.new]) }.to raise_error Postmark::InvalidApiKeyError
|
22
22
|
end
|
23
23
|
|
24
24
|
context 'invalid sending object' do
|
25
|
+
let(:error_message) { 'Invalid type error, only Array of Mail::Message object types for sending allowed' }
|
26
|
+
|
25
27
|
it '.send with string parameter' do
|
26
|
-
sender =
|
28
|
+
sender = postmark_api_batch_sender.new(api_token)
|
27
29
|
expect { sender.send('test') }
|
28
|
-
.to raise_error MailHandler::TypeError,
|
30
|
+
.to raise_error MailHandler::TypeError, error_message
|
29
31
|
end
|
30
32
|
|
31
33
|
it '.send with incorrect array parameter' do
|
32
|
-
sender =
|
34
|
+
sender = postmark_api_batch_sender.new(api_token)
|
33
35
|
expect { sender.send([1, 2, 2]) }
|
34
|
-
.to raise_error MailHandler::TypeError,
|
36
|
+
.to raise_error MailHandler::TypeError, error_message
|
35
37
|
end
|
36
38
|
end
|
37
39
|
end
|
@@ -1,12 +1,12 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe MailHandler::Sending::PostmarkAPISender do
|
4
|
-
subject {
|
4
|
+
subject(:postmark_api_sender) { described_class }
|
5
5
|
|
6
6
|
let(:api_token) { '122878782' }
|
7
7
|
|
8
8
|
it 'create' do
|
9
|
-
sender =
|
9
|
+
sender = postmark_api_sender.new(api_token)
|
10
10
|
|
11
11
|
aggregate_failures 'init details' do
|
12
12
|
expect(sender.api_token).to eq api_token
|
@@ -17,13 +17,13 @@ describe MailHandler::Sending::PostmarkAPISender do
|
|
17
17
|
end
|
18
18
|
|
19
19
|
it '.send - invalid auth' do
|
20
|
-
sender =
|
20
|
+
sender = postmark_api_sender.new(api_token)
|
21
21
|
expect { sender.send(Mail.new) }.to raise_error Postmark::InvalidApiKeyError
|
22
22
|
end
|
23
23
|
|
24
24
|
context 'invalid sending object' do
|
25
25
|
it '.send' do
|
26
|
-
sender =
|
26
|
+
sender = postmark_api_sender.new(api_token)
|
27
27
|
expect { sender.send('test') }.to raise_error StandardError
|
28
28
|
end
|
29
29
|
end
|
@@ -1,12 +1,12 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe MailHandler::Sending::SMTPSender do
|
4
|
-
subject {
|
4
|
+
subject(:smtp_sender) { described_class }
|
5
5
|
|
6
6
|
context '.send' do
|
7
7
|
context 'invalid' do
|
8
8
|
it 'incorrect mail type' do
|
9
|
-
sender =
|
9
|
+
sender = smtp_sender.new
|
10
10
|
expect { sender.send('Test') }.to raise_error MailHandler::TypeError
|
11
11
|
end
|
12
12
|
end
|
@@ -15,26 +15,26 @@ describe MailHandler::Sending::SMTPSender do
|
|
15
15
|
context '.new' do
|
16
16
|
context 'smtp timeouts' do
|
17
17
|
it 'open' do
|
18
|
-
sender =
|
18
|
+
sender = smtp_sender.new
|
19
19
|
expect(sender.open_timeout).to be > 0
|
20
20
|
end
|
21
21
|
|
22
22
|
it 'read' do
|
23
|
-
sender =
|
23
|
+
sender = smtp_sender.new
|
24
24
|
expect(sender.read_timeout).to be > 0
|
25
25
|
end
|
26
26
|
end
|
27
27
|
|
28
28
|
it 'save response' do
|
29
|
-
expect(
|
29
|
+
expect(smtp_sender.new.save_response).to be false
|
30
30
|
end
|
31
31
|
|
32
32
|
it 'use ssl' do
|
33
|
-
expect(
|
33
|
+
expect(smtp_sender.new.use_ssl).to be false
|
34
34
|
end
|
35
35
|
|
36
36
|
it 'authentication' do
|
37
|
-
expect(
|
37
|
+
expect(smtp_sender.new.authentication).to eq 'plain'
|
38
38
|
end
|
39
39
|
end
|
40
40
|
end
|