mailhandler 1.0.36 → 1.0.37
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/Gemfile +2 -2
- data/Rakefile +2 -2
- data/lib/mailhandler.rb +13 -37
- data/lib/mailhandler/errors.rb +1 -5
- data/lib/mailhandler/receiver.rb +4 -22
- data/lib/mailhandler/receiving/base.rb +16 -45
- data/lib/mailhandler/receiving/filelist/base.rb +25 -49
- data/lib/mailhandler/receiving/filelist/filter/base.rb +10 -52
- data/lib/mailhandler/receiving/filelist/filter/email.rb +4 -44
- data/lib/mailhandler/receiving/folder.rb +16 -54
- data/lib/mailhandler/receiving/imap.rb +34 -78
- data/lib/mailhandler/receiving/mail.rb +5 -19
- data/lib/mailhandler/receiving/notification/console.rb +2 -18
- data/lib/mailhandler/receiving/notification/email.rb +5 -28
- data/lib/mailhandler/receiving/notification/email/content.rb +9 -20
- data/lib/mailhandler/receiving/notification/email/states.rb +1 -36
- data/lib/mailhandler/receiving/observer.rb +5 -16
- data/lib/mailhandler/sender.rb +2 -14
- data/lib/mailhandler/sending/api.rb +1 -7
- data/lib/mailhandler/sending/api_batch.rb +1 -13
- data/lib/mailhandler/sending/base.rb +1 -13
- data/lib/mailhandler/sending/smtp.rb +20 -22
- data/lib/mailhandler/version.rb +2 -2
- data/mailhandler.gemspec +14 -17
- data/readme.md +33 -8
- data/spec/spec_helper.rb +1 -5
- data/spec/unit/mailhandler/receiver_spec.rb +8 -30
- data/spec/unit/mailhandler/receiving/base_spec.rb +4 -14
- data/spec/unit/mailhandler/receiving/folder_spec.rb +61 -155
- data/spec/unit/mailhandler/receiving/imap_spec.rb +18 -42
- data/spec/unit/mailhandler/receiving/notification/console_spec.rb +6 -16
- data/spec/unit/mailhandler/receiving/notification/email/content_spec.rb +10 -44
- data/spec/unit/mailhandler/receiving/notification/email_spec.rb +9 -15
- data/spec/unit/mailhandler/sender_spec.rb +12 -23
- data/spec/unit/mailhandler/sending/sender_api_batch_spec.rb +7 -19
- data/spec/unit/mailhandler/sending/sender_api_spec.rb +4 -14
- data/spec/unit/mailhandler/sending/sender_smtp_spec.rb +24 -6
- data/spec/unit/mailhandler_spec.rb +33 -25
- metadata +2 -2
@@ -1,324 +1,230 @@
|
|
1
|
-
|
1
|
+
|
2
2
|
require 'spec_helper'
|
3
3
|
|
4
4
|
describe MailHandler::Receiving::FolderChecker do
|
5
|
-
|
6
5
|
subject { MailHandler::Receiving::FolderChecker.new }
|
7
6
|
|
8
7
|
it '.create' do
|
9
|
-
|
10
8
|
is_expected.to be_kind_of MailHandler::Receiving::Checker
|
11
|
-
|
12
9
|
end
|
13
10
|
|
14
11
|
context 'search emails' do
|
15
|
-
|
16
12
|
let(:checker) { MailHandler::Receiving::FolderChecker.new(data_folder, data_folder) }
|
17
13
|
|
18
14
|
context '.find email' do
|
19
|
-
|
20
15
|
context 'search options' do
|
21
|
-
|
22
16
|
it 'by multiple search options' do
|
23
|
-
|
24
17
|
time = Time.now
|
25
|
-
checker.find(
|
18
|
+
checker.find(by_subject: 'test', by_content: 'test', since: time, by_recipient: { to: 'igor@example.com' })
|
26
19
|
expect(checker.search_options).to eq(
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
20
|
+
count: 50,
|
21
|
+
archive: false,
|
22
|
+
by_subject: 'test',
|
23
|
+
by_content: 'test',
|
24
|
+
since: time,
|
25
|
+
by_recipient: { to: 'igor@example.com' }
|
26
|
+
)
|
34
27
|
end
|
35
28
|
|
36
29
|
it 'by_subject' do
|
37
|
-
|
38
|
-
checker.
|
39
|
-
expect(checker.search_options).to eq({:count=>50, :archive=>false, :by_subject=>'test'})
|
40
|
-
|
30
|
+
checker.find(by_subject: 'test')
|
31
|
+
expect(checker.search_options).to eq(count: 50, archive: false, by_subject: 'test')
|
41
32
|
end
|
42
33
|
|
43
34
|
it 'by_content' do
|
44
|
-
|
45
|
-
checker.
|
46
|
-
expect(checker.search_options).to eq({:count=>50, :archive=>false, :by_content => 'test'})
|
47
|
-
|
35
|
+
checker.find(by_content: 'test')
|
36
|
+
expect(checker.search_options).to eq(count: 50, archive: false, by_content: 'test')
|
48
37
|
end
|
49
38
|
|
50
39
|
context 'archive' do
|
51
|
-
|
52
40
|
it 'invalid' do
|
53
|
-
|
54
|
-
expect { checker.find({:archive => 'test'}) }.to raise_error MailHandler::Error
|
55
|
-
|
41
|
+
expect { checker.find(archive: 'test') }.to raise_error MailHandler::Error
|
56
42
|
end
|
57
|
-
|
58
43
|
end
|
59
44
|
|
60
45
|
context 'since' do
|
61
|
-
|
62
46
|
it 'valid' do
|
63
|
-
|
64
47
|
time = Time.now
|
65
|
-
checker.find(
|
66
|
-
expect(checker.search_options).to eq(
|
67
|
-
|
48
|
+
checker.find(since: time)
|
49
|
+
expect(checker.search_options).to eq(count: 50, archive: false, since: time)
|
68
50
|
end
|
69
51
|
|
70
52
|
it 'invalid' do
|
71
|
-
|
72
53
|
time = Time.now.to_s
|
73
|
-
expect { checker.find(
|
74
|
-
|
54
|
+
expect { checker.find(since: time) }.to raise_error MailHandler::Error
|
75
55
|
end
|
76
|
-
|
77
56
|
end
|
78
57
|
|
79
58
|
it 'by_recipient' do
|
80
|
-
|
81
|
-
checker.
|
82
|
-
expect(checker.search_options).to eq({:count=>50, :archive=>false, :by_recipient => {:to => 'igor@example.com' }})
|
83
|
-
|
59
|
+
checker.find(by_recipient: { to: 'igor@example.com' })
|
60
|
+
expect(checker.search_options).to eq(count: 50, archive: false, by_recipient: { to: 'igor@example.com' })
|
84
61
|
end
|
85
62
|
|
86
63
|
context 'count' do
|
87
|
-
|
88
64
|
it 'valid' do
|
89
|
-
|
90
|
-
checker.
|
91
|
-
expect(checker.search_options).to eq({:count=>1, :archive=>false})
|
92
|
-
|
65
|
+
checker.find(count: 1)
|
66
|
+
expect(checker.search_options).to eq(count: 1, archive: false)
|
93
67
|
end
|
94
68
|
|
95
69
|
it 'invalid - below limit' do
|
96
|
-
|
97
|
-
expect { checker.find({:count => -1}) }.to raise_error MailHandler::Error
|
98
|
-
|
70
|
+
expect { checker.find(count: -1) }.to raise_error MailHandler::Error
|
99
71
|
end
|
100
72
|
|
101
73
|
it 'invalid - above limit' do
|
102
|
-
|
103
|
-
expect { checker.find({:count => 3000 }) }.to raise_error MailHandler::Error
|
104
|
-
|
74
|
+
expect { checker.find(count: 3000) }.to raise_error MailHandler::Error
|
105
75
|
end
|
106
|
-
|
107
76
|
end
|
108
|
-
|
109
77
|
end
|
110
78
|
|
111
79
|
context 'not found' do
|
112
|
-
|
113
80
|
it 'result' do
|
114
|
-
|
115
|
-
expect(checker.find({:by_subject => 'test123'})).to be false
|
116
|
-
|
81
|
+
expect(checker.find(by_subject: 'test123')).to be false
|
117
82
|
end
|
118
83
|
|
119
84
|
it 'by subject' do
|
120
|
-
|
121
|
-
checker.find({:by_subject => 'test123'})
|
85
|
+
checker.find(by_subject: 'test123')
|
122
86
|
expect(checker.found_emails).to be_empty
|
123
|
-
|
124
87
|
end
|
125
88
|
|
126
89
|
it 'by date' do
|
127
|
-
|
128
|
-
checker.find({:since => Time.now + 86400})
|
90
|
+
checker.find(since: Time.now + 86_400)
|
129
91
|
expect(checker.found_emails).to be_empty
|
130
|
-
|
131
92
|
end
|
132
93
|
|
133
94
|
it 'by recipient' do
|
134
|
-
|
135
|
-
checker.find({:by_recipient => { to: 'igor+nonexisting@example.com'} })
|
95
|
+
checker.find(by_recipient: { to: 'igor+nonexisting@example.com' })
|
136
96
|
expect(checker.found_emails).to be_empty
|
137
|
-
|
138
97
|
end
|
139
|
-
|
140
98
|
end
|
141
99
|
|
142
100
|
context 'found' do
|
143
|
-
|
144
|
-
let(:
|
145
|
-
let(:mail2) { Mail.read_from_string(File.read "#{data_folder}/email2.txt")}
|
101
|
+
let(:mail1) { Mail.read_from_string(File.read("#{data_folder}/email1.txt")) }
|
102
|
+
let(:mail2) { Mail.read_from_string(File.read("#{data_folder}/email2.txt")) }
|
146
103
|
|
147
104
|
context 'search results' do
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
checker.find({:by_subject => mail1.subject})
|
105
|
+
let(:search) do
|
106
|
+
checker.find(by_subject: mail1.subject)
|
152
107
|
checker
|
153
|
-
|
154
|
-
}
|
108
|
+
end
|
155
109
|
|
156
110
|
it '.search_result' do
|
157
|
-
|
158
111
|
expect(search.search_result).to be true
|
159
|
-
|
160
112
|
end
|
161
113
|
|
162
114
|
it '.reset_found_emails' do
|
163
|
-
|
164
115
|
search.reset_found_emails
|
165
116
|
expect(search.search_result).to be false
|
166
|
-
|
167
117
|
end
|
168
|
-
|
169
118
|
end
|
170
119
|
|
171
120
|
it 'result' do
|
172
|
-
|
173
|
-
expect(checker.find({:by_subject => mail1.subject})).to be true
|
174
|
-
|
121
|
+
expect(checker.find(by_subject: mail1.subject)).to be true
|
175
122
|
end
|
176
123
|
|
177
124
|
it 'by subject - single' do
|
125
|
+
checker.find(by_subject: mail1.subject)
|
178
126
|
|
179
|
-
|
180
|
-
|
181
|
-
aggregate_failures "found mail details" do
|
127
|
+
aggregate_failures 'found mail details' do
|
182
128
|
expect(checker.found_emails.size).to be 1
|
183
129
|
expect(checker.found_emails.first).to eq mail1
|
184
130
|
expect(checker.found_emails).not_to include mail2
|
185
131
|
end
|
186
|
-
|
187
132
|
end
|
188
133
|
|
189
134
|
it 'by content' do
|
190
|
-
|
191
|
-
checker.find({:by_content => '1878271'})
|
135
|
+
checker.find(by_content: '1878271')
|
192
136
|
expect(checker.found_emails.size).to be 1
|
193
|
-
|
194
137
|
end
|
195
138
|
|
196
139
|
it 'by subject - multiple' do
|
140
|
+
checker.find(by_subject: 'test')
|
197
141
|
|
198
|
-
|
199
|
-
|
200
|
-
aggregate_failures "found mail details" do
|
142
|
+
aggregate_failures 'found mail details' do
|
201
143
|
expect(checker.found_emails.size).to be 2
|
202
144
|
expect(checker.found_emails).to include mail1
|
203
145
|
expect(checker.found_emails).to include mail2
|
204
146
|
end
|
205
|
-
|
206
147
|
end
|
207
148
|
|
208
149
|
it 'by count' do
|
209
|
-
|
210
|
-
checker.find({:by_subject => 'test', :count => 1})
|
150
|
+
checker.find(by_subject: 'test', count: 1)
|
211
151
|
expect(checker.found_emails.size).to be 1
|
212
|
-
|
213
152
|
end
|
214
153
|
|
215
154
|
it 'by date' do
|
216
|
-
|
217
|
-
checker.find({:since => Time.new(2015,10,12,13,30,0, "+02:00")})
|
155
|
+
checker.find(since: Time.new(2015, 10, 12, 13, 30, 0, '+02:00'))
|
218
156
|
expect(checker.found_emails.size).to be 4
|
219
|
-
|
220
157
|
end
|
221
158
|
|
222
159
|
it 'by recipient' do
|
223
|
-
|
224
|
-
checker.find({:by_recipient => { to: 'igor1@example.com'} })
|
160
|
+
checker.find(by_recipient: { to: 'igor1@example.com' })
|
225
161
|
expect(checker.found_emails.size).to be 1
|
226
162
|
|
227
|
-
checker.find(
|
163
|
+
checker.find(by_recipient: { to: 'igor2@example.com' })
|
228
164
|
expect(checker.found_emails.size).to be 1
|
229
|
-
|
230
165
|
end
|
231
166
|
|
232
167
|
context 'unicode' do
|
233
|
-
|
234
168
|
it 'by subject - cyrillic' do
|
235
|
-
|
236
169
|
skip
|
237
|
-
checker.find(
|
170
|
+
checker.find(by_subject: 'Е-маил пример')
|
238
171
|
expect(checker.found_emails.size).to be 1
|
239
|
-
|
240
172
|
end
|
241
173
|
|
242
174
|
it 'by subject - german' do
|
243
|
-
|
244
175
|
skip
|
245
|
-
checker.find(
|
176
|
+
checker.find(by_subject: 'möglich')
|
246
177
|
expect(checker.found_emails.size).to be 1
|
247
|
-
|
248
178
|
end
|
249
|
-
|
250
179
|
end
|
251
180
|
|
252
181
|
context 'archiving emails' do
|
182
|
+
before(:each) do
|
183
|
+
FileUtils.mkdir "#{data_folder}/checked" unless Dir.exist? "#{data_folder}/checked"
|
184
|
+
end
|
253
185
|
|
254
|
-
|
255
|
-
|
256
|
-
|
257
|
-
|
258
|
-
}
|
259
|
-
|
260
|
-
after(:each) {
|
261
|
-
|
262
|
-
FileUtils.rm_r "#{data_folder}/checked", :force => false if Dir.exists? "#{data_folder}"
|
263
|
-
|
264
|
-
}
|
265
|
-
|
266
|
-
let(:mail) {
|
186
|
+
after(:each) do
|
187
|
+
FileUtils.rm_r "#{data_folder}/checked", force: false if Dir.exist? data_folder.to_s
|
188
|
+
end
|
267
189
|
|
268
|
-
|
190
|
+
let(:mail) do
|
191
|
+
mail = Mail.read_from_string(File.read("#{data_folder}/email2.txt"))
|
269
192
|
mail.subject = 'test 872878278'
|
270
|
-
File.open("#{data_folder}/email3.txt",
|
193
|
+
File.open("#{data_folder}/email3.txt", 'w') { |file| file.write(mail) }
|
271
194
|
mail
|
272
|
-
|
273
|
-
}
|
195
|
+
end
|
274
196
|
|
275
197
|
let(:checker_archive) { MailHandler::Receiving::FolderChecker.new(data_folder, "#{data_folder}/checked") }
|
276
198
|
|
277
199
|
it 'to same folder - delete' do
|
278
|
-
|
279
|
-
checker.find({:by_subject => mail.subject, :archive => true})
|
200
|
+
checker.find(by_subject: mail.subject, archive: true)
|
280
201
|
expect(checker.found_emails.size).to be 1
|
281
202
|
|
282
|
-
checker.find(
|
203
|
+
checker.find(by_subject: mail.subject, archive: true)
|
283
204
|
expect(checker.found_emails).to be_empty
|
284
|
-
|
285
|
-
|
286
205
|
end
|
287
206
|
|
288
207
|
it 'to separate folder' do
|
289
|
-
|
290
|
-
checker_archive.find({:by_subject => mail.subject, :archive => true})
|
208
|
+
checker_archive.find(by_subject: mail.subject, archive: true)
|
291
209
|
expect(checker_archive.found_emails.size).to be 1
|
292
210
|
|
293
|
-
checker_archive.find(
|
211
|
+
checker_archive.find(by_subject: mail.subject, archive: true)
|
294
212
|
expect(checker_archive.found_emails).to be_empty
|
295
|
-
|
296
213
|
end
|
297
|
-
|
298
214
|
end
|
299
|
-
|
300
215
|
end
|
301
|
-
|
302
216
|
end
|
303
|
-
|
304
217
|
end
|
305
218
|
|
306
219
|
context 'invalid folders' do
|
307
|
-
|
308
220
|
it 'inbox folder' do
|
309
|
-
|
310
221
|
checker = MailHandler::Receiving::FolderChecker.new('test', data_folder)
|
311
|
-
expect { checker.find :
|
312
|
-
|
222
|
+
expect { checker.find count: 1 }.to raise_error MailHandler::FileError
|
313
223
|
end
|
314
224
|
|
315
225
|
it 'archive folder' do
|
316
|
-
|
317
226
|
checker = MailHandler::Receiving::FolderChecker.new(data_folder, 'test')
|
318
|
-
expect { checker.find :
|
319
|
-
|
227
|
+
expect { checker.find count: 1 }.to raise_error MailHandler::FileError
|
320
228
|
end
|
321
|
-
|
322
229
|
end
|
323
|
-
|
324
|
-
end
|
230
|
+
end
|
@@ -1,78 +1,54 @@
|
|
1
|
-
|
1
|
+
|
2
2
|
require 'spec_helper'
|
3
3
|
|
4
4
|
describe MailHandler::Receiving::IMAPChecker do
|
5
|
-
|
6
5
|
let(:checker) { MailHandler::Receiving::IMAPChecker.new }
|
7
6
|
|
8
7
|
it '.create' do
|
9
|
-
|
10
8
|
expect(checker).to be_kind_of MailHandler::Receiving::Checker
|
11
|
-
|
12
9
|
end
|
13
10
|
|
14
11
|
it 'options' do
|
15
|
-
|
16
|
-
expect(checker.search_options).to eq({:count=>50, :archive=>false})
|
17
|
-
|
12
|
+
expect(checker.search_options).to eq(count: 50, archive: false)
|
18
13
|
end
|
19
14
|
|
20
15
|
context 'search options' do
|
21
|
-
|
22
16
|
before(:each) do
|
23
|
-
|
24
|
-
|
25
|
-
allow(checker).to receive(:find_emails) { []}
|
26
|
-
|
17
|
+
allow(checker).to receive(:init_retriever) { true }
|
18
|
+
allow(checker).to receive(:find_emails) { [] }
|
27
19
|
end
|
28
20
|
|
29
21
|
it 'by multiple search options' do
|
30
|
-
|
31
|
-
checker.find({:by_subject => 'test', :by_content => 'test', :by_recipient => {:to => 'igor@example.com'}})
|
22
|
+
checker.find(by_subject: 'test', by_content: 'test', by_recipient: { to: 'igor@example.com' })
|
32
23
|
expect(checker.search_options).to eq(
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
24
|
+
count: 50,
|
25
|
+
archive: false,
|
26
|
+
by_subject: 'test',
|
27
|
+
by_content: 'test',
|
28
|
+
by_recipient: { to: 'igor@example.com' }
|
29
|
+
)
|
39
30
|
end
|
40
31
|
|
41
32
|
it 'by_subject' do
|
42
|
-
|
43
|
-
checker.
|
44
|
-
expect(checker.search_options).to eq({:count=>50, :archive=>false, :by_subject=>'test'})
|
45
|
-
|
33
|
+
checker.find(by_subject: 'test')
|
34
|
+
expect(checker.search_options).to eq(count: 50, archive: false, by_subject: 'test')
|
46
35
|
end
|
47
36
|
|
48
37
|
it 'by_content' do
|
49
|
-
|
50
|
-
checker.
|
51
|
-
expect(checker.search_options).to eq({:count=>50, :archive=>false, :by_content => 'test'})
|
52
|
-
|
38
|
+
checker.find(by_content: 'test')
|
39
|
+
expect(checker.search_options).to eq(count: 50, archive: false, by_content: 'test')
|
53
40
|
end
|
54
41
|
|
55
42
|
context 'invalid' do
|
56
|
-
|
57
43
|
it 'by_test' do
|
58
|
-
|
59
|
-
expect { checker.find({:by_test => 'test'}) }.to raise_error MailHandler::Error
|
60
|
-
|
44
|
+
expect { checker.find(by_test: 'test') }.to raise_error MailHandler::Error
|
61
45
|
end
|
62
|
-
|
63
|
-
|
64
46
|
end
|
65
47
|
|
66
48
|
context 'archive' do
|
67
|
-
|
68
49
|
it 'invalid' do
|
69
|
-
|
70
|
-
expect { checker.find({:archive => 'test'}) }.to raise_error MailHandler::Error
|
71
|
-
|
50
|
+
expect { checker.find(archive: 'test') }.to raise_error MailHandler::Error
|
72
51
|
end
|
73
|
-
|
74
52
|
end
|
75
|
-
|
76
53
|
end
|
77
|
-
|
78
|
-
end
|
54
|
+
end
|