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