mailhandler 1.0.15 → 1.0.16
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: c1ff94639607a5154fcff77dff88d700ced42619
|
4
|
+
data.tar.gz: a70576db7d202c837ba06c107c4c6f30fb7c08e3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7b1d05dc3c67f179772ce9419da3062be58f278b5bade09197b0c869cf209f7e302e6ed26008d2e1d0d30ebb2713dd94e30a9a4c07b420ae5397c0ddf21bde66
|
7
|
+
data.tar.gz: 2272b930094f1513a57af5fc5d4d7062d4d1e4efc651030d1c7a951ccc983e7c106f29f661f3f9c750be38e8842a2b418f3134f463c845123917da8a2a085fa2
|
@@ -0,0 +1,62 @@
|
|
1
|
+
# Base filtering class, which is used for reading list of all files based on passed pattern.
|
2
|
+
# Patterns to be used can be checked here: http://ruby-doc.org/core-1.9.3/Dir.html
|
3
|
+
|
4
|
+
module MailHandler
|
5
|
+
|
6
|
+
module Receiving
|
7
|
+
|
8
|
+
module Filter
|
9
|
+
|
10
|
+
class Base
|
11
|
+
|
12
|
+
def Base.sort(files)
|
13
|
+
|
14
|
+
swapped = true
|
15
|
+
j = 0
|
16
|
+
|
17
|
+
while swapped do
|
18
|
+
|
19
|
+
swapped = false
|
20
|
+
j+=1
|
21
|
+
|
22
|
+
(files.size - j).times do |i|
|
23
|
+
|
24
|
+
if File.new(files[i]).ctime < File.new(files[i + 1]).ctime
|
25
|
+
tmp = files[i]
|
26
|
+
files[i] = files[i + 1]
|
27
|
+
files[i + 1] = tmp
|
28
|
+
swapped = true
|
29
|
+
|
30
|
+
end
|
31
|
+
|
32
|
+
end
|
33
|
+
|
34
|
+
end
|
35
|
+
|
36
|
+
files
|
37
|
+
|
38
|
+
end
|
39
|
+
|
40
|
+
def get(pattern)
|
41
|
+
|
42
|
+
files = []
|
43
|
+
Dir.glob(pattern).each { |file| files << File.absolute_path(file) }
|
44
|
+
files
|
45
|
+
|
46
|
+
end
|
47
|
+
|
48
|
+
protected
|
49
|
+
|
50
|
+
def read_email(content)
|
51
|
+
|
52
|
+
Mail.read_from_string(content)
|
53
|
+
|
54
|
+
end
|
55
|
+
|
56
|
+
end
|
57
|
+
|
58
|
+
end
|
59
|
+
|
60
|
+
end
|
61
|
+
|
62
|
+
end
|
@@ -1,211 +1,170 @@
|
|
1
1
|
require 'fileutils'
|
2
|
+
require_relative 'base'
|
2
3
|
|
3
|
-
module
|
4
|
+
module MailHandler
|
4
5
|
|
5
|
-
|
6
|
-
# Patterns to be used can be checked here: http://ruby-doc.org/core-1.9.3/Dir.html
|
7
|
-
class Base
|
6
|
+
module Receiving
|
8
7
|
|
9
|
-
|
8
|
+
module Filter
|
10
9
|
|
11
|
-
|
12
|
-
j = 0
|
10
|
+
class ByFilename < Base
|
13
11
|
|
14
|
-
|
12
|
+
def get(pattern)
|
15
13
|
|
16
|
-
|
17
|
-
j+=1
|
18
|
-
|
19
|
-
(files.size - j).times do |i|
|
20
|
-
|
21
|
-
if File.new(files[i]).ctime < File.new(files[i + 1]).ctime
|
22
|
-
tmp = files[i]
|
23
|
-
files[i] = files[i + 1]
|
24
|
-
files[i + 1] = tmp
|
25
|
-
swapped = true
|
26
|
-
|
27
|
-
end
|
14
|
+
super(pattern)
|
28
15
|
|
29
16
|
end
|
30
17
|
|
31
18
|
end
|
32
19
|
|
33
|
-
|
34
|
-
|
35
|
-
end
|
36
|
-
|
37
|
-
def get(pattern)
|
38
|
-
|
39
|
-
files = []
|
40
|
-
Dir.glob(pattern).each { |file| files << File.absolute_path(file) }
|
41
|
-
files
|
42
|
-
|
43
|
-
end
|
44
|
-
|
45
|
-
protected
|
46
|
-
|
47
|
-
def read_email(content)
|
48
|
-
|
49
|
-
Mail.read_from_string(content)
|
50
|
-
|
51
|
-
end
|
52
|
-
|
53
|
-
end
|
54
|
-
|
55
|
-
class ByFilename < Base
|
20
|
+
class ContentBase < Base
|
56
21
|
|
57
|
-
|
22
|
+
def initialize(content)
|
58
23
|
|
59
|
-
|
24
|
+
@content = content.to_s
|
60
25
|
|
61
|
-
|
26
|
+
end
|
62
27
|
|
63
|
-
|
28
|
+
protected
|
64
29
|
|
65
|
-
|
30
|
+
def filter_files(files)
|
66
31
|
|
67
|
-
|
32
|
+
files.select do |file|
|
68
33
|
|
69
|
-
|
34
|
+
begin
|
70
35
|
|
71
|
-
|
36
|
+
file_match_filter?(file)
|
72
37
|
|
73
|
-
|
38
|
+
rescue
|
74
39
|
|
75
|
-
|
40
|
+
# return false if error occurred or content was not found
|
41
|
+
false
|
76
42
|
|
77
|
-
|
43
|
+
end
|
78
44
|
|
79
|
-
|
45
|
+
end
|
80
46
|
|
81
|
-
|
47
|
+
end
|
82
48
|
|
83
|
-
|
49
|
+
def file_match_filter?(file)
|
84
50
|
|
85
|
-
|
86
|
-
false
|
51
|
+
raise StandardError, 'Not implemented'
|
87
52
|
|
88
53
|
end
|
89
54
|
|
90
55
|
end
|
91
56
|
|
92
|
-
|
93
|
-
|
94
|
-
def file_match_filter?(file)
|
95
|
-
|
96
|
-
raise StandardError, 'Not implemented'
|
57
|
+
class BySubject < ContentBase
|
97
58
|
|
98
|
-
|
99
|
-
|
100
|
-
end
|
59
|
+
def initialize(content)
|
101
60
|
|
102
|
-
|
61
|
+
super(content)
|
103
62
|
|
104
|
-
|
63
|
+
end
|
105
64
|
|
106
|
-
|
65
|
+
def get(pattern)
|
107
66
|
|
108
|
-
|
67
|
+
files = super(pattern)
|
68
|
+
filter_files(files)
|
109
69
|
|
110
|
-
|
70
|
+
end
|
111
71
|
|
112
|
-
|
113
|
-
filter_files(files)
|
72
|
+
private
|
114
73
|
|
115
|
-
|
74
|
+
def file_match_filter?(file)
|
116
75
|
|
117
|
-
|
76
|
+
read_email(File.read(file)).subject.include? @content
|
118
77
|
|
119
|
-
|
78
|
+
end
|
120
79
|
|
121
|
-
|
80
|
+
end
|
122
81
|
|
123
|
-
|
82
|
+
class ByContent < ContentBase
|
124
83
|
|
125
|
-
|
84
|
+
def initialize(content)
|
126
85
|
|
127
|
-
|
86
|
+
super(content)
|
128
87
|
|
129
|
-
|
88
|
+
end
|
130
89
|
|
131
|
-
|
90
|
+
def get(pattern)
|
132
91
|
|
133
|
-
|
92
|
+
files = super(pattern)
|
93
|
+
filter_files(files)
|
134
94
|
|
135
|
-
|
95
|
+
end
|
136
96
|
|
137
|
-
|
138
|
-
filter_files(files)
|
97
|
+
private
|
139
98
|
|
140
|
-
|
99
|
+
def file_match_filter?(file)
|
141
100
|
|
142
|
-
|
101
|
+
File.read(file).include? @content
|
143
102
|
|
144
|
-
|
103
|
+
end
|
145
104
|
|
146
|
-
|
105
|
+
end
|
147
106
|
|
148
|
-
|
107
|
+
class ByDate < ContentBase
|
149
108
|
|
150
|
-
|
109
|
+
def initialize(date)
|
151
110
|
|
152
|
-
|
111
|
+
@date = date
|
153
112
|
|
154
|
-
|
113
|
+
end
|
155
114
|
|
156
|
-
|
115
|
+
def get(pattern)
|
157
116
|
|
158
|
-
|
117
|
+
files = super(pattern)
|
118
|
+
filter_files(files)
|
159
119
|
|
160
|
-
|
120
|
+
end
|
161
121
|
|
162
|
-
|
163
|
-
filter_files(files)
|
122
|
+
private
|
164
123
|
|
165
|
-
|
124
|
+
def file_match_filter?(file)
|
166
125
|
|
167
|
-
|
126
|
+
file = File.new(file)
|
127
|
+
if file != nil
|
168
128
|
|
169
|
-
|
129
|
+
file.ctime > @date
|
170
130
|
|
171
|
-
|
172
|
-
if file != nil
|
131
|
+
else
|
173
132
|
|
174
|
-
|
133
|
+
false
|
175
134
|
|
176
|
-
|
135
|
+
end
|
177
136
|
|
178
|
-
|
137
|
+
end
|
179
138
|
|
180
139
|
end
|
181
140
|
|
182
|
-
|
141
|
+
module Email
|
183
142
|
|
184
|
-
|
143
|
+
class ByRecipient < ContentBase
|
185
144
|
|
186
|
-
|
145
|
+
def initialize(recipient)
|
187
146
|
|
188
|
-
|
147
|
+
@recipient = recipient
|
189
148
|
|
190
|
-
|
149
|
+
end
|
191
150
|
|
192
|
-
|
151
|
+
def get(pattern)
|
193
152
|
|
194
|
-
|
153
|
+
files = super(pattern)
|
154
|
+
filter_files(files)
|
195
155
|
|
196
|
-
|
156
|
+
end
|
197
157
|
|
198
|
-
|
199
|
-
filter_files(files)
|
158
|
+
private
|
200
159
|
|
201
|
-
|
160
|
+
def file_match_filter?(file)
|
202
161
|
|
203
|
-
|
162
|
+
email = read_email(File.read(file))
|
163
|
+
email[@recipient.keys.first].to_s.include? @recipient.values.first
|
204
164
|
|
205
|
-
|
165
|
+
end
|
206
166
|
|
207
|
-
|
208
|
-
email[@recipient.keys.first].to_s.include? @recipient.values.first
|
167
|
+
end
|
209
168
|
|
210
169
|
end
|
211
170
|
|
@@ -213,4 +172,4 @@ module Filter
|
|
213
172
|
|
214
173
|
end
|
215
174
|
|
216
|
-
end
|
175
|
+
end
|
data/lib/mailhandler/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
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.16
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Igor Balos
|
@@ -62,6 +62,7 @@ files:
|
|
62
62
|
- lib/mailhandler/errors.rb
|
63
63
|
- lib/mailhandler/receiver.rb
|
64
64
|
- lib/mailhandler/receiving/base.rb
|
65
|
+
- lib/mailhandler/receiving/file_filter/base.rb
|
65
66
|
- lib/mailhandler/receiving/file_filter/filter.rb
|
66
67
|
- lib/mailhandler/receiving/folder.rb
|
67
68
|
- lib/mailhandler/receiving/imap.rb
|