mailhandler 1.0.10 → 1.0.11
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
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c27c5a6bcd4af8802a454e343c1e7978b655e237
|
4
|
+
data.tar.gz: eb4a2f4637c35f9b63c46727d190a0328eb9d210
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 166964ab0416a5c07492eb73ec3626f041f77712dda85c3807372ba1472ceb658120c42e7f41af9aa92d2b3e4829fc0d8b909aefc52ab107144e75461e8be932
|
7
|
+
data.tar.gz: 6982dcdf0315ede236c6118c5f4af5270b3c91c4305f4e212fbe7126ac95b592079c6823af912573b7a34a49d4da14e5506df4854aad3775e2dcde97922ac1bf
|
data/lib/mailhandler/errors.rb
CHANGED
@@ -26,6 +26,7 @@ module MailHandler
|
|
26
26
|
def find(options)
|
27
27
|
|
28
28
|
verify_and_set_search_options(options)
|
29
|
+
verify_mailbox_folders
|
29
30
|
email_files = find_files(search_options)
|
30
31
|
|
31
32
|
unless email_files.empty?
|
@@ -42,7 +43,7 @@ module MailHandler
|
|
42
43
|
private
|
43
44
|
|
44
45
|
# filter options which need to be done by searching files
|
45
|
-
|
46
|
+
FILE_SEARCH_CLASSES = {
|
46
47
|
|
47
48
|
:by_subject => Filter::ByContent,
|
48
49
|
:by_content => Filter::ByContent,
|
@@ -67,7 +68,7 @@ module MailHandler
|
|
67
68
|
|
68
69
|
end
|
69
70
|
|
70
|
-
# find files by
|
71
|
+
# find files by FILE_SEARCH_CLASSES options
|
71
72
|
# this will ignore filter criteria options which can't be done on files directly
|
72
73
|
def find_files(options)
|
73
74
|
|
@@ -75,7 +76,7 @@ module MailHandler
|
|
75
76
|
|
76
77
|
options.each do |key, value|
|
77
78
|
|
78
|
-
files = (files &
|
79
|
+
files = (files & FILE_SEARCH_CLASSES[key].new(value).get(search_pattern)) if FILE_SEARCH_CLASSES[key] != nil
|
79
80
|
|
80
81
|
end
|
81
82
|
|
@@ -85,33 +86,31 @@ module MailHandler
|
|
85
86
|
|
86
87
|
def move_files(files)
|
87
88
|
|
88
|
-
setup_inbox_folders
|
89
|
-
|
90
89
|
files.each do |file|
|
91
90
|
|
92
91
|
file = File.basename(file)
|
92
|
+
(inbox_folder == archive_folder)? delete_file(file) : archive_file(file)
|
93
93
|
|
94
|
-
|
94
|
+
end
|
95
95
|
|
96
|
-
|
96
|
+
end
|
97
97
|
|
98
|
-
|
98
|
+
def archive_file(file)
|
99
99
|
|
100
|
-
|
100
|
+
FileUtils.mv("#{inbox_folder}/#{file}", "#{archive_folder}/#{file}")
|
101
101
|
|
102
|
-
|
102
|
+
end
|
103
103
|
|
104
|
-
|
104
|
+
def delete_file(file)
|
105
105
|
|
106
|
-
|
106
|
+
FileUtils.rm_r "#{inbox_folder}/#{file}", :force => true
|
107
107
|
|
108
|
-
|
109
|
-
def setup_inbox_folders
|
108
|
+
end
|
110
109
|
|
111
|
-
|
110
|
+
def verify_mailbox_folders
|
112
111
|
|
113
|
-
|
114
|
-
|
112
|
+
raise MailHandler::Error, 'Folder variables are not set.' if inbox_folder.nil? or archive_folder.nil?
|
113
|
+
raise MailHandler::FileError, 'Mailbox folders do not exist.' unless File.directory? inbox_folder and File.directory? archive_folder
|
115
114
|
|
116
115
|
end
|
117
116
|
|
data/lib/mailhandler/version.rb
CHANGED
@@ -199,9 +199,15 @@ describe MailHandler::Receiving::FolderChecker do
|
|
199
199
|
|
200
200
|
context 'archiving emails' do
|
201
201
|
|
202
|
+
before(:each) {
|
203
|
+
|
204
|
+
FileUtils.mkdir "#{data_folder}/checked" unless Dir.exists? "#{data_folder}/checked"
|
205
|
+
|
206
|
+
}
|
207
|
+
|
202
208
|
after(:each) {
|
203
209
|
|
204
|
-
FileUtils.rm_r "#{data_folder}/checked", :force =>
|
210
|
+
FileUtils.rm_r "#{data_folder}/checked", :force => false if Dir.exists? "#{data_folder}"
|
205
211
|
|
206
212
|
}
|
207
213
|
|
@@ -235,7 +241,6 @@ describe MailHandler::Receiving::FolderChecker do
|
|
235
241
|
checker_archive.find({:by_subject => mail.subject, :archive => true})
|
236
242
|
expect(checker_archive.found_emails).to be_empty
|
237
243
|
|
238
|
-
|
239
244
|
end
|
240
245
|
|
241
246
|
end
|
@@ -246,4 +251,23 @@ describe MailHandler::Receiving::FolderChecker do
|
|
246
251
|
|
247
252
|
end
|
248
253
|
|
254
|
+
context 'invalid folders' do
|
255
|
+
|
256
|
+
it 'inbox folder' do
|
257
|
+
|
258
|
+
checker = MailHandler::Receiving::FolderChecker.new('test', data_folder)
|
259
|
+
expect { checker.find :count => 1 }.to raise_error MailHandler::FileError
|
260
|
+
|
261
|
+
end
|
262
|
+
|
263
|
+
it 'archive folder' do
|
264
|
+
|
265
|
+
checker = MailHandler::Receiving::FolderChecker.new(data_folder, 'test')
|
266
|
+
expect { checker.find :count => 1 }.to raise_error MailHandler::FileError
|
267
|
+
|
268
|
+
end
|
269
|
+
|
270
|
+
end
|
271
|
+
|
272
|
+
|
249
273
|
end
|