mailhandler 1.0.20 → 1.0.21
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/lib/mailhandler/receiving/base.rb +2 -1
- data/lib/mailhandler/receiving/filelist/base.rb +2 -0
- data/lib/mailhandler/receiving/filelist/filter/base.rb +85 -0
- data/lib/mailhandler/receiving/filelist/filter/email.rb +130 -0
- data/lib/mailhandler/receiving/folder.rb +17 -4
- data/lib/mailhandler/version.rb +1 -1
- metadata +4 -3
- data/lib/mailhandler/receiving/filelist/filter.rb +0 -147
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: aed334966f4daa868a8533ea9e16b841b68f02b6
|
4
|
+
data.tar.gz: 69bc39be92c6408806830d8afead62ebd08080da
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 793f2480e28e3a8c9487cd7bdd3b5dade4d40d72306d5056438227711703a538635a11c72ff162578630d699d3ed4da51822ca30bfdd1f10b69e7024f52e2f5c
|
7
|
+
data.tar.gz: 60ea9caf4a6fe6be1efd66a1267cf05b54318a7a341f32aea1f23a0d8ea3971a443dbcc7d06aa4b6cd992f0acdba495ee53a7db65f11def31acdbeb68e044e3d
|
@@ -0,0 +1,85 @@
|
|
1
|
+
require_relative '../base'
|
2
|
+
require_relative '../../../errors'
|
3
|
+
|
4
|
+
module MailHandler
|
5
|
+
|
6
|
+
module Receiving
|
7
|
+
|
8
|
+
class FileList
|
9
|
+
|
10
|
+
module Filter
|
11
|
+
|
12
|
+
class Base
|
13
|
+
|
14
|
+
attr_accessor :files, :fast_check
|
15
|
+
|
16
|
+
def initialize(files)
|
17
|
+
|
18
|
+
@files=files
|
19
|
+
|
20
|
+
end
|
21
|
+
|
22
|
+
def get
|
23
|
+
|
24
|
+
files.select { |file| ignore_exception { meets_expectation?(file) } }
|
25
|
+
|
26
|
+
end
|
27
|
+
|
28
|
+
protected
|
29
|
+
|
30
|
+
def meet_expectation?(file)
|
31
|
+
|
32
|
+
raise MailHandler::InterfaceError, 'Interface not implemented.'
|
33
|
+
|
34
|
+
end
|
35
|
+
|
36
|
+
def read_file(file)
|
37
|
+
|
38
|
+
File.read(file)
|
39
|
+
|
40
|
+
end
|
41
|
+
|
42
|
+
private
|
43
|
+
|
44
|
+
def ignore_exception
|
45
|
+
|
46
|
+
begin
|
47
|
+
|
48
|
+
yield
|
49
|
+
|
50
|
+
rescue
|
51
|
+
|
52
|
+
false
|
53
|
+
|
54
|
+
end
|
55
|
+
|
56
|
+
end
|
57
|
+
|
58
|
+
end
|
59
|
+
|
60
|
+
class ByDate < Base
|
61
|
+
|
62
|
+
def initialize(files, date)
|
63
|
+
|
64
|
+
super(files)
|
65
|
+
@date = date
|
66
|
+
|
67
|
+
end
|
68
|
+
|
69
|
+
private
|
70
|
+
|
71
|
+
def meets_expectation?(file)
|
72
|
+
|
73
|
+
(File.exists? file)? (File.ctime file) > @date : false
|
74
|
+
|
75
|
+
end
|
76
|
+
|
77
|
+
end
|
78
|
+
|
79
|
+
end
|
80
|
+
|
81
|
+
end
|
82
|
+
|
83
|
+
end
|
84
|
+
|
85
|
+
end
|
@@ -0,0 +1,130 @@
|
|
1
|
+
require 'mail'
|
2
|
+
require_relative 'base'
|
3
|
+
|
4
|
+
module MailHandler
|
5
|
+
|
6
|
+
module Receiving
|
7
|
+
|
8
|
+
class FileList
|
9
|
+
|
10
|
+
module Filter
|
11
|
+
|
12
|
+
# filtering file content by its email properties
|
13
|
+
class Email < Base
|
14
|
+
|
15
|
+
def initialize(files)
|
16
|
+
|
17
|
+
@fast_check=true
|
18
|
+
super(files)
|
19
|
+
|
20
|
+
end
|
21
|
+
|
22
|
+
protected
|
23
|
+
|
24
|
+
def read_email_from_file(file)
|
25
|
+
|
26
|
+
Mail.read(file)
|
27
|
+
|
28
|
+
end
|
29
|
+
|
30
|
+
def meets_expectation?(file)
|
31
|
+
|
32
|
+
# fast content checks search for content by file reading
|
33
|
+
# slow content checks search for content by reconstructing email from file and then searching for content
|
34
|
+
(fast_check)? check_content_fast(file) : check_content_slow(file)
|
35
|
+
|
36
|
+
end
|
37
|
+
|
38
|
+
def check_content_fast(file)
|
39
|
+
|
40
|
+
raise MailHandler::InterfaceError, 'Interface not implemented.'
|
41
|
+
|
42
|
+
end
|
43
|
+
|
44
|
+
def check_content_slow(file)
|
45
|
+
|
46
|
+
raise MailHandler::InterfaceError, 'Interface not implemented.'
|
47
|
+
|
48
|
+
end
|
49
|
+
|
50
|
+
end
|
51
|
+
|
52
|
+
class ByEmailContent < Email
|
53
|
+
|
54
|
+
def initialize(files, content)
|
55
|
+
|
56
|
+
super(files)
|
57
|
+
@content = content
|
58
|
+
|
59
|
+
end
|
60
|
+
|
61
|
+
private
|
62
|
+
|
63
|
+
def check_content_fast(file)
|
64
|
+
|
65
|
+
read_file(file).include? @content
|
66
|
+
|
67
|
+
end
|
68
|
+
|
69
|
+
def check_content_slow(file)
|
70
|
+
|
71
|
+
email = read_email_from_file(file)
|
72
|
+
|
73
|
+
if email.multipart?
|
74
|
+
|
75
|
+
email.text_part.decoded.include?(@content) || email.html_part.decoded.include?(@content)
|
76
|
+
|
77
|
+
else
|
78
|
+
|
79
|
+
email.decoded.include? @content
|
80
|
+
|
81
|
+
end
|
82
|
+
|
83
|
+
end
|
84
|
+
|
85
|
+
end
|
86
|
+
|
87
|
+
class ByEmailSubject < ByEmailContent
|
88
|
+
|
89
|
+
private
|
90
|
+
|
91
|
+
def check_content_fast(file)
|
92
|
+
|
93
|
+
read_file(file).include? @content
|
94
|
+
|
95
|
+
end
|
96
|
+
|
97
|
+
def check_content_slow(file)
|
98
|
+
|
99
|
+
read_email_from_file(file).subject.to_s.include? @content
|
100
|
+
|
101
|
+
end
|
102
|
+
|
103
|
+
end
|
104
|
+
|
105
|
+
class ByEmailRecipient < Email
|
106
|
+
|
107
|
+
def initialize(files, recipient)
|
108
|
+
|
109
|
+
super(files)
|
110
|
+
@recipient = recipient
|
111
|
+
|
112
|
+
end
|
113
|
+
|
114
|
+
private
|
115
|
+
|
116
|
+
def meets_expectation?(file)
|
117
|
+
|
118
|
+
read_email_from_file(file)[@recipient.keys.first].to_s.include? @recipient.values.first
|
119
|
+
|
120
|
+
end
|
121
|
+
|
122
|
+
end
|
123
|
+
|
124
|
+
end
|
125
|
+
|
126
|
+
end
|
127
|
+
|
128
|
+
end
|
129
|
+
|
130
|
+
end
|
@@ -1,7 +1,9 @@
|
|
1
1
|
require 'mail'
|
2
2
|
require_relative 'base.rb'
|
3
3
|
require_relative '../errors'
|
4
|
-
require_relative 'filelist/
|
4
|
+
require_relative 'filelist/base.rb'
|
5
|
+
require_relative 'filelist/filter/base.rb'
|
6
|
+
require_relative 'filelist/filter/email.rb'
|
5
7
|
|
6
8
|
module MailHandler
|
7
9
|
|
@@ -64,15 +66,26 @@ module MailHandler
|
|
64
66
|
def find_files(options)
|
65
67
|
|
66
68
|
file_list = FileList.new
|
67
|
-
files = file_list.get(search_pattern)
|
69
|
+
files = filter_files(file_list.get(search_pattern), options)
|
70
|
+
file_list.sort(files)
|
71
|
+
|
72
|
+
end
|
73
|
+
|
74
|
+
def filter_files(files, options)
|
68
75
|
|
69
76
|
options.each do |key, value|
|
70
77
|
|
71
|
-
|
78
|
+
if FILE_SEARCH_CLASSES[key] != nil
|
79
|
+
|
80
|
+
filter = FILE_SEARCH_CLASSES[key].new(files, value)
|
81
|
+
filter.fast_check = options[:fast_check] unless options[:fast_check].nil?
|
82
|
+
files = filter.get
|
83
|
+
|
84
|
+
end
|
72
85
|
|
73
86
|
end
|
74
87
|
|
75
|
-
|
88
|
+
files
|
76
89
|
|
77
90
|
end
|
78
91
|
|
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.21
|
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-02-
|
11
|
+
date: 2016-02-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: mail
|
@@ -63,7 +63,8 @@ files:
|
|
63
63
|
- lib/mailhandler/receiver.rb
|
64
64
|
- lib/mailhandler/receiving/base.rb
|
65
65
|
- lib/mailhandler/receiving/filelist/base.rb
|
66
|
-
- lib/mailhandler/receiving/filelist/filter.rb
|
66
|
+
- lib/mailhandler/receiving/filelist/filter/base.rb
|
67
|
+
- lib/mailhandler/receiving/filelist/filter/email.rb
|
67
68
|
- lib/mailhandler/receiving/folder.rb
|
68
69
|
- lib/mailhandler/receiving/imap.rb
|
69
70
|
- lib/mailhandler/receiving/notification/console.rb
|
@@ -1,147 +0,0 @@
|
|
1
|
-
require 'fileutils'
|
2
|
-
require_relative 'base'
|
3
|
-
|
4
|
-
module MailHandler
|
5
|
-
|
6
|
-
module Receiving
|
7
|
-
|
8
|
-
class FileList
|
9
|
-
|
10
|
-
module Filter
|
11
|
-
|
12
|
-
class Base
|
13
|
-
|
14
|
-
attr_accessor :files
|
15
|
-
|
16
|
-
def initialize(files)
|
17
|
-
|
18
|
-
@files=files
|
19
|
-
|
20
|
-
end
|
21
|
-
|
22
|
-
def get
|
23
|
-
|
24
|
-
files.select { |file| ignore_exception { meets_expectation?(file) } }
|
25
|
-
|
26
|
-
end
|
27
|
-
|
28
|
-
protected
|
29
|
-
|
30
|
-
def meet_expectation?(file)
|
31
|
-
|
32
|
-
raise StandardError, 'Needs to be implemented.'
|
33
|
-
|
34
|
-
end
|
35
|
-
|
36
|
-
def read_file(file)
|
37
|
-
|
38
|
-
# TODO: add UTF support
|
39
|
-
# string need to be read and converted
|
40
|
-
# read_email(file_content).subject.include?(@content) - 10x slower, use something else for reading
|
41
|
-
# Mail::Encodings.unquote_and_convert_to(content, "UTF-8") - 6x slower
|
42
|
-
File.read(file)
|
43
|
-
|
44
|
-
end
|
45
|
-
|
46
|
-
private
|
47
|
-
|
48
|
-
def ignore_exception
|
49
|
-
|
50
|
-
begin
|
51
|
-
|
52
|
-
yield
|
53
|
-
|
54
|
-
rescue
|
55
|
-
|
56
|
-
false
|
57
|
-
|
58
|
-
end
|
59
|
-
|
60
|
-
end
|
61
|
-
|
62
|
-
end
|
63
|
-
|
64
|
-
class ByDate < Base
|
65
|
-
|
66
|
-
def initialize(files, date)
|
67
|
-
|
68
|
-
super(files)
|
69
|
-
@date = date
|
70
|
-
|
71
|
-
end
|
72
|
-
|
73
|
-
private
|
74
|
-
|
75
|
-
def meets_expectation?(file)
|
76
|
-
|
77
|
-
(File.exists? file)? (File.ctime file) > @date : false
|
78
|
-
|
79
|
-
end
|
80
|
-
|
81
|
-
end
|
82
|
-
|
83
|
-
class Email < Base
|
84
|
-
|
85
|
-
def initialize(files)
|
86
|
-
|
87
|
-
super(files)
|
88
|
-
|
89
|
-
end
|
90
|
-
|
91
|
-
protected
|
92
|
-
|
93
|
-
def read_email_from_file(file)
|
94
|
-
|
95
|
-
Mail.read(file)
|
96
|
-
|
97
|
-
end
|
98
|
-
|
99
|
-
end
|
100
|
-
|
101
|
-
class ByEmailContent < Email
|
102
|
-
|
103
|
-
def initialize(files, content)
|
104
|
-
|
105
|
-
super(files)
|
106
|
-
@content = content
|
107
|
-
|
108
|
-
end
|
109
|
-
|
110
|
-
protected
|
111
|
-
|
112
|
-
def meets_expectation?(file)
|
113
|
-
|
114
|
-
read_file(file).include? @content
|
115
|
-
|
116
|
-
end
|
117
|
-
|
118
|
-
end
|
119
|
-
|
120
|
-
class ByEmailSubject < ByEmailContent ; end
|
121
|
-
|
122
|
-
class ByEmailRecipient < Email
|
123
|
-
|
124
|
-
def initialize(files, recipient)
|
125
|
-
|
126
|
-
super(files)
|
127
|
-
@recipient = recipient
|
128
|
-
|
129
|
-
end
|
130
|
-
|
131
|
-
private
|
132
|
-
|
133
|
-
def meets_expectation?(file)
|
134
|
-
|
135
|
-
read_email_from_file(file)[@recipient.keys.first].to_s.include? @recipient.values.first
|
136
|
-
|
137
|
-
end
|
138
|
-
|
139
|
-
end
|
140
|
-
|
141
|
-
end
|
142
|
-
|
143
|
-
end
|
144
|
-
|
145
|
-
end
|
146
|
-
|
147
|
-
end
|