mailhandler 1.0.19 → 1.0.20
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: 6ad403b028e0aaa2b38fe06175974beff76015b8
|
4
|
+
data.tar.gz: d3c7387992cb45fdad2d4e2d8de4bbffb9f77edd
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 76bf22bb22a36ee53fd8a67356b9192f0e6ecb491816b55fbfaab48bbd4bbdbc1d85f4e0374852e6a65960badc025101cb17121995acdbf049c5cc5329bf2c31
|
7
|
+
data.tar.gz: 097b7e17cef92ecefdfd69b431efcb71ce3d76fc269bbac299c8d4ef370910119e0c3688b190ee891888ffde76ceebd22d91b46a20b73fbba4b8f6a1d7405efa
|
@@ -5,15 +5,45 @@ module MailHandler
|
|
5
5
|
|
6
6
|
module Receiving
|
7
7
|
|
8
|
+
module FileHandling
|
9
|
+
|
10
|
+
# if file exists, execute file operation, otherwise return default return value when it doesn't
|
11
|
+
def access_file(file, default_return = false, &block)
|
12
|
+
|
13
|
+
if File.exists? file
|
14
|
+
|
15
|
+
begin
|
16
|
+
|
17
|
+
block.call
|
18
|
+
|
19
|
+
rescue => e
|
20
|
+
|
21
|
+
raise e if File.exists? file
|
22
|
+
default_return
|
23
|
+
|
24
|
+
end
|
25
|
+
|
26
|
+
else
|
27
|
+
|
28
|
+
default_return
|
29
|
+
|
30
|
+
end
|
31
|
+
|
32
|
+
end
|
33
|
+
|
34
|
+
end
|
35
|
+
|
8
36
|
class FileList
|
9
37
|
|
10
|
-
|
38
|
+
include FileHandling
|
11
39
|
|
12
|
-
|
40
|
+
def get(pattern)
|
41
|
+
|
42
|
+
Dir.glob(pattern)
|
13
43
|
|
14
44
|
end
|
15
45
|
|
16
|
-
def
|
46
|
+
def sort(files)
|
17
47
|
|
18
48
|
swapped = true
|
19
49
|
j = 0
|
@@ -25,7 +55,10 @@ module MailHandler
|
|
25
55
|
|
26
56
|
(files.size - j).times do |i|
|
27
57
|
|
28
|
-
|
58
|
+
file1 = access_file(files[i], false) { File.new(files[i]).ctime }
|
59
|
+
file2 = access_file(files[i+1], false) { File.new(files[i+1]).ctime }
|
60
|
+
|
61
|
+
if file1 && file2 && file1 < file2
|
29
62
|
tmp = files[i]
|
30
63
|
files[i] = files[i + 1]
|
31
64
|
files[i + 1] = tmp
|
File without changes
|
@@ -1,7 +1,7 @@
|
|
1
1
|
require 'mail'
|
2
2
|
require_relative 'base.rb'
|
3
3
|
require_relative '../errors'
|
4
|
-
require_relative '
|
4
|
+
require_relative 'filelist/filter.rb'
|
5
5
|
|
6
6
|
module MailHandler
|
7
7
|
|
@@ -9,6 +9,8 @@ module MailHandler
|
|
9
9
|
|
10
10
|
class FolderChecker < Checker
|
11
11
|
|
12
|
+
include FileHandling
|
13
|
+
|
12
14
|
# folders in which emails will be searched for and managed
|
13
15
|
attr_accessor :inbox_folder,
|
14
16
|
:archive_folder
|
@@ -31,7 +33,7 @@ module MailHandler
|
|
31
33
|
|
32
34
|
unless email_files.empty?
|
33
35
|
|
34
|
-
@found_emails =
|
36
|
+
@found_emails = parse_email_from_files(email_files, search_options[:count])
|
35
37
|
move_files(email_files) if search_options[:archive]
|
36
38
|
|
37
39
|
end
|
@@ -57,17 +59,12 @@ module MailHandler
|
|
57
59
|
|
58
60
|
end
|
59
61
|
|
60
|
-
def read_found_emails(files, count)
|
61
|
-
|
62
|
-
files.first(count).map { |file| Mail.read(file ) }
|
63
|
-
|
64
|
-
end
|
65
|
-
|
66
62
|
# find files by FILE_SEARCH_CLASSES options
|
67
63
|
# this will ignore filter criteria options which can't be done on files directly
|
68
64
|
def find_files(options)
|
69
65
|
|
70
|
-
|
66
|
+
file_list = FileList.new
|
67
|
+
files = file_list.get(search_pattern)
|
71
68
|
|
72
69
|
options.each do |key, value|
|
73
70
|
|
@@ -75,30 +72,45 @@ module MailHandler
|
|
75
72
|
|
76
73
|
end
|
77
74
|
|
78
|
-
|
75
|
+
file_list.sort(files)
|
79
76
|
|
80
77
|
end
|
81
78
|
|
82
79
|
def move_files(files)
|
83
80
|
|
84
|
-
files.each
|
81
|
+
files.each { |file| (inbox_folder == archive_folder)? delete_file(file) : archive_file(file) }
|
82
|
+
|
83
|
+
end
|
84
|
+
|
85
|
+
def parse_email_from_files(files, count)
|
86
|
+
|
87
|
+
read_files(files, count).map { |email_string| Mail.read_from_string(email_string) }
|
88
|
+
|
89
|
+
end
|
85
90
|
|
86
|
-
|
87
|
-
|
91
|
+
def read_files(files, count)
|
92
|
+
|
93
|
+
file_contents = []
|
94
|
+
files.first(count).each do |file|
|
95
|
+
|
96
|
+
file_content = access_file(file, nil) { File.read(file ) }
|
97
|
+
file_contents << file_content unless file_content.nil?
|
88
98
|
|
89
99
|
end
|
90
100
|
|
101
|
+
file_contents
|
102
|
+
|
91
103
|
end
|
92
104
|
|
93
105
|
def archive_file(file)
|
94
106
|
|
95
|
-
FileUtils.mv("#{inbox_folder}/#{file}", "#{archive_folder}/#{file}")
|
107
|
+
access_file(file) { FileUtils.mv("#{inbox_folder}/#{File.basename(file)}", "#{archive_folder}/#{File.basename(file)}") }
|
96
108
|
|
97
109
|
end
|
98
110
|
|
99
111
|
def delete_file(file)
|
100
112
|
|
101
|
-
FileUtils.rm_r "#{inbox_folder}/#{file}", :force => false
|
113
|
+
access_file(file) { FileUtils.rm_r "#{inbox_folder}/#{File.basename(file)}", :force => false }
|
102
114
|
|
103
115
|
end
|
104
116
|
|
data/lib/mailhandler/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mailhandler
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.20
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Igor Balos
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-01
|
11
|
+
date: 2016-02-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: mail
|
@@ -62,8 +62,8 @@ files:
|
|
62
62
|
- lib/mailhandler/errors.rb
|
63
63
|
- lib/mailhandler/receiver.rb
|
64
64
|
- lib/mailhandler/receiving/base.rb
|
65
|
-
- lib/mailhandler/receiving/
|
66
|
-
- lib/mailhandler/receiving/
|
65
|
+
- lib/mailhandler/receiving/filelist/base.rb
|
66
|
+
- lib/mailhandler/receiving/filelist/filter.rb
|
67
67
|
- lib/mailhandler/receiving/folder.rb
|
68
68
|
- lib/mailhandler/receiving/imap.rb
|
69
69
|
- lib/mailhandler/receiving/notification/console.rb
|