mailhandler 1.0.17 → 1.0.18
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/mailhandler/receiving/base.rb +20 -16
- data/lib/mailhandler/receiving/file_filter/filter.rb +4 -1
- data/lib/mailhandler/receiving/folder.rb +1 -1
- data/lib/mailhandler/receiving/imap.rb +17 -16
- data/lib/mailhandler/receiving/notification/email.rb +2 -1
- data/lib/mailhandler/receiving/notification/email/content.rb +9 -1
- data/lib/mailhandler/version.rb +1 -1
- data/readme.md +3 -1
- data/spec/unit/mailhandler/receiving/base_spec.rb +6 -0
- data/spec/unit/mailhandler/receiving/folder_spec.rb +32 -8
- data/spec/unit/mailhandler/receiving/imap_spec.rb +84 -0
- data/spec/unit/mailhandler/receiving/notification/email_spec.rb +73 -0
- data/spec/unit/mailhandler/sending/sender_api_batch_spec.rb +1 -1
- data/spec/unit/mailhandler/sending/sender_api_spec.rb +1 -1
- data/spec/unit/mailhandler/sending/sender_smtp_spec.rb +22 -0
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 083df235cda02401f6ed87e997e235def311840e
|
4
|
+
data.tar.gz: bbc739fa0de274bb0d87733a418346d796526c3f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a067e385d21369f0eef498fc2c6f3843fe40ccb134f917e0b32b5e344660b8c7812f834b5cdba0e73e6c8c7f5760e21edc8e0d827496f8057f8160e9cc6d2c8c
|
7
|
+
data.tar.gz: 3b5f4dac54ef936fd3976dc847bfe82691c5656032bf243e57c5f9186ec37d294f256f69bf5e1aaf77a562bf5d0537e2f17385dca406f9d3ba08eb116f719186
|
@@ -11,21 +11,12 @@ module MailHandler
|
|
11
11
|
class Checker
|
12
12
|
|
13
13
|
attr_accessor :search_options,
|
14
|
-
:found_emails
|
15
|
-
|
16
|
-
AVAILABLE_SEARCH_OPTIONS = [
|
17
|
-
|
18
|
-
:by_subject,
|
19
|
-
:by_content,
|
20
|
-
:by_date,
|
21
|
-
:by_recipient,
|
22
|
-
:count,
|
23
|
-
:archive
|
24
|
-
|
25
|
-
]
|
14
|
+
:found_emails,
|
15
|
+
:available_search_options
|
26
16
|
|
27
17
|
def initialize
|
28
18
|
|
19
|
+
@available_search_options = AVAILABLE_SEARCH_OPTIONS
|
29
20
|
set_base_search_options
|
30
21
|
reset_found_emails
|
31
22
|
|
@@ -49,6 +40,19 @@ module MailHandler
|
|
49
40
|
|
50
41
|
end
|
51
42
|
|
43
|
+
private
|
44
|
+
|
45
|
+
AVAILABLE_SEARCH_OPTIONS = [
|
46
|
+
|
47
|
+
:by_subject,
|
48
|
+
:by_content,
|
49
|
+
:since,
|
50
|
+
:by_recipient,
|
51
|
+
:count,
|
52
|
+
:archive
|
53
|
+
|
54
|
+
]
|
55
|
+
|
52
56
|
protected
|
53
57
|
|
54
58
|
def verify_and_set_search_options(options)
|
@@ -64,9 +68,9 @@ module MailHandler
|
|
64
68
|
|
65
69
|
def validate_option_values(options)
|
66
70
|
|
67
|
-
if options[:
|
71
|
+
if options[:since]
|
68
72
|
|
69
|
-
raise MailHandler::Error, "Incorrect option options[:
|
73
|
+
raise MailHandler::Error, "Incorrect option options[:since]=#{options[:since]}." unless options[:since].is_a? Time
|
70
74
|
|
71
75
|
end
|
72
76
|
|
@@ -87,8 +91,8 @@ module MailHandler
|
|
87
91
|
|
88
92
|
def validate_used_options(options)
|
89
93
|
|
90
|
-
unless (options.keys -
|
91
|
-
raise MailHandler::Error, "#{(options.keys -
|
94
|
+
unless (options.keys - available_search_options).empty?
|
95
|
+
raise MailHandler::Error, "#{(options.keys - available_search_options)} - Incorrect search option values, options are #{available_search_options}."
|
92
96
|
end
|
93
97
|
|
94
98
|
end
|
@@ -73,8 +73,11 @@ module MailHandler
|
|
73
73
|
|
74
74
|
def file_match_filter?(file)
|
75
75
|
|
76
|
+
# TODO: add UTF support
|
77
|
+
# string need to be read and converted
|
78
|
+
# read_email(file_content).subject.include?(@content) - 10x slower, use something else for reading
|
79
|
+
# Mail::Encodings.unquote_and_convert_to(content, "UTF-8") - 6x slower
|
76
80
|
File.read(file).include? @content
|
77
|
-
#read_email(file_content).subject.include?(@content) slow, use something else for reading
|
78
81
|
|
79
82
|
end
|
80
83
|
|
@@ -17,25 +17,10 @@ module MailHandler
|
|
17
17
|
:authentication,
|
18
18
|
:use_ssl
|
19
19
|
|
20
|
-
# search options:
|
21
|
-
# by_subject - String, search by a whole string as part of the subject of the email
|
22
|
-
# by_content - String, search by a whole string as part of the content of the email
|
23
|
-
# count - Int, number of found emails to return
|
24
|
-
# archive - Boolean
|
25
|
-
# by_recipient - Hash, accepts a hash like: :to => 'igor@example.com'
|
26
|
-
AVAILABLE_SEARCH_OPTIONS = [
|
27
|
-
|
28
|
-
:by_subject,
|
29
|
-
:by_content,
|
30
|
-
:count,
|
31
|
-
:archive,
|
32
|
-
:by_recipient
|
33
|
-
|
34
|
-
]
|
35
|
-
|
36
20
|
def initialize
|
37
21
|
|
38
22
|
super
|
23
|
+
@available_search_options = AVAILABLE_SEARCH_OPTIONS
|
39
24
|
|
40
25
|
end
|
41
26
|
|
@@ -51,6 +36,22 @@ module MailHandler
|
|
51
36
|
|
52
37
|
private
|
53
38
|
|
39
|
+
# search options:
|
40
|
+
# by_subject - String, search by a whole string as part of the subject of the email
|
41
|
+
# by_content - String, search by a whole string as part of the content of the email
|
42
|
+
# count - Int, number of found emails to return
|
43
|
+
# archive - Boolean
|
44
|
+
# by_recipient - Hash, accepts a hash like: :to => 'igor@example.com'
|
45
|
+
AVAILABLE_SEARCH_OPTIONS = [
|
46
|
+
|
47
|
+
:by_subject,
|
48
|
+
:by_content,
|
49
|
+
:count,
|
50
|
+
:archive,
|
51
|
+
:by_recipient
|
52
|
+
|
53
|
+
]
|
54
|
+
|
54
55
|
# delegate retrieval details to Mail library
|
55
56
|
def init_retriever
|
56
57
|
|
@@ -8,6 +8,10 @@ module MailHandler
|
|
8
8
|
|
9
9
|
class EmailContent
|
10
10
|
|
11
|
+
# @param [Hash] options - search options used for searching for an email
|
12
|
+
# @param [Int] delay - delay in seconds
|
13
|
+
# @param [String] from - email address
|
14
|
+
# @param [String] to - email address
|
11
15
|
def self.email_received(options, delay, from, to)
|
12
16
|
|
13
17
|
Mail.new do
|
@@ -21,6 +25,10 @@ module MailHandler
|
|
21
25
|
|
22
26
|
end
|
23
27
|
|
28
|
+
# @param [Hash] options - search options used for searching for an email
|
29
|
+
# @param [Int] delay - delay in seconds
|
30
|
+
# @param [String] from - email address
|
31
|
+
# @param [String] to - email address
|
24
32
|
def self.email_delayed(options, delay, from, to)
|
25
33
|
|
26
34
|
Mail.new do
|
@@ -28,7 +36,7 @@ module MailHandler
|
|
28
36
|
from from
|
29
37
|
subject "Over #{(delay.to_f/60).round(2)} minutes delay"
|
30
38
|
body "Over #{(delay.to_f/60).round(2)} minutes delay - search by #{options}"
|
31
|
-
to
|
39
|
+
to to
|
32
40
|
|
33
41
|
end
|
34
42
|
|
data/lib/mailhandler/version.rb
CHANGED
data/readme.md
CHANGED
@@ -76,7 +76,9 @@ You can search local mailbox by following options:
|
|
76
76
|
Recipient to search by needs to by added in the following form: `by_recipient => { :to => 'igor@example.com' }`.
|
77
77
|
Library supports searching by :to, :cc recipients. At the moment, only searching by a single recipient email address is supported.
|
78
78
|
|
79
|
-
If you would like email to be archived after its read, use `:archive => true` option (recommended)
|
79
|
+
If you would like email to be archived after its read, use `:archive => true` option (recommended).
|
80
|
+
|
81
|
+
**For now, Unicode is not supported for search by local mailbox, only ASCII.**
|
80
82
|
|
81
83
|
## Search results
|
82
84
|
|
@@ -22,13 +22,13 @@ describe MailHandler::Receiving::FolderChecker do
|
|
22
22
|
it 'by multiple search options' do
|
23
23
|
|
24
24
|
time = Time.now
|
25
|
-
checker.find({:by_subject => 'test', :by_content => 'test', :
|
25
|
+
checker.find({:by_subject => 'test', :by_content => 'test', :since => time, :by_recipient => 'igor@example.com'})
|
26
26
|
expect(checker.search_options).to eq(
|
27
27
|
{:count=>50,
|
28
28
|
:archive=>false,
|
29
29
|
:by_subject => 'test',
|
30
30
|
:by_content => 'test',
|
31
|
-
:
|
31
|
+
:since => time,
|
32
32
|
:by_recipient => 'igor@example.com'})
|
33
33
|
|
34
34
|
end
|
@@ -57,20 +57,20 @@ describe MailHandler::Receiving::FolderChecker do
|
|
57
57
|
|
58
58
|
end
|
59
59
|
|
60
|
-
context '
|
60
|
+
context 'since' do
|
61
61
|
|
62
62
|
it 'valid' do
|
63
63
|
|
64
64
|
time = Time.now
|
65
|
-
checker.find({:
|
66
|
-
expect(checker.search_options).to eq({:count=>50, :archive=>false, :
|
65
|
+
checker.find({:since => time})
|
66
|
+
expect(checker.search_options).to eq({:count=>50, :archive=>false, :since => time })
|
67
67
|
|
68
68
|
end
|
69
69
|
|
70
70
|
it 'invalid' do
|
71
71
|
|
72
72
|
time = Time.now.to_s
|
73
|
-
expect { checker.find({:
|
73
|
+
expect { checker.find({:since => time}) }.to raise_error MailHandler::Error
|
74
74
|
|
75
75
|
end
|
76
76
|
|
@@ -125,7 +125,7 @@ describe MailHandler::Receiving::FolderChecker do
|
|
125
125
|
|
126
126
|
it 'by date' do
|
127
127
|
|
128
|
-
checker.find({:
|
128
|
+
checker.find({:since => Time.now + 86400})
|
129
129
|
expect(checker.found_emails).to be_empty
|
130
130
|
|
131
131
|
end
|
@@ -144,6 +144,30 @@ describe MailHandler::Receiving::FolderChecker do
|
|
144
144
|
let(:mail1) { Mail.read_from_string(File.read "#{data_folder}/email1.txt")}
|
145
145
|
let(:mail2) { Mail.read_from_string(File.read "#{data_folder}/email2.txt")}
|
146
146
|
|
147
|
+
context 'search results' do
|
148
|
+
|
149
|
+
let(:search) {
|
150
|
+
|
151
|
+
checker.find({:by_subject => mail1.subject})
|
152
|
+
checker
|
153
|
+
|
154
|
+
}
|
155
|
+
|
156
|
+
it '.search_result' do
|
157
|
+
|
158
|
+
expect(search.search_result).to be true
|
159
|
+
|
160
|
+
end
|
161
|
+
|
162
|
+
it '.reset_found_emails' do
|
163
|
+
|
164
|
+
search.reset_found_emails
|
165
|
+
expect(search.search_result).to be false
|
166
|
+
|
167
|
+
end
|
168
|
+
|
169
|
+
end
|
170
|
+
|
147
171
|
it 'result' do
|
148
172
|
|
149
173
|
expect(checker.find({:by_subject => mail1.subject})).to be true
|
@@ -190,7 +214,7 @@ describe MailHandler::Receiving::FolderChecker do
|
|
190
214
|
|
191
215
|
it 'by date' do
|
192
216
|
|
193
|
-
checker.find({:
|
217
|
+
checker.find({:since => Time.new(2015,10,12,13,30,0, "+02:00")})
|
194
218
|
expect(checker.found_emails.size).to be 4
|
195
219
|
|
196
220
|
end
|
@@ -0,0 +1,84 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require 'spec_helper'
|
3
|
+
|
4
|
+
describe MailHandler::Receiving::IMAPChecker do
|
5
|
+
|
6
|
+
let(:checker) { MailHandler::Receiving::IMAPChecker.new }
|
7
|
+
|
8
|
+
it '.create' do
|
9
|
+
|
10
|
+
expect(checker).to be_kind_of MailHandler::Receiving::Checker
|
11
|
+
|
12
|
+
end
|
13
|
+
|
14
|
+
it 'options' do
|
15
|
+
|
16
|
+
expect(checker.search_options).to eq({:count=>50, :archive=>false})
|
17
|
+
|
18
|
+
end
|
19
|
+
|
20
|
+
context 'search options' do
|
21
|
+
|
22
|
+
before(:each) do
|
23
|
+
|
24
|
+
allow(checker).to receive(:init_retriever) { true }
|
25
|
+
allow(checker).to receive(:find_emails) { []}
|
26
|
+
|
27
|
+
end
|
28
|
+
|
29
|
+
it 'by multiple search options' do
|
30
|
+
|
31
|
+
checker.find({:by_subject => 'test', :by_content => 'test', :by_recipient => 'igor@example.com'})
|
32
|
+
expect(checker.search_options).to eq(
|
33
|
+
{:count=>50,
|
34
|
+
:archive=>false,
|
35
|
+
:by_subject => 'test',
|
36
|
+
:by_content => 'test',
|
37
|
+
:by_recipient => 'igor@example.com'})
|
38
|
+
|
39
|
+
end
|
40
|
+
|
41
|
+
it 'by_subject' do
|
42
|
+
|
43
|
+
checker.find({:by_subject => 'test'})
|
44
|
+
expect(checker.search_options).to eq({:count=>50, :archive=>false, :by_subject=>'test'})
|
45
|
+
|
46
|
+
end
|
47
|
+
|
48
|
+
it 'by_content' do
|
49
|
+
|
50
|
+
checker.find({:by_content => 'test'})
|
51
|
+
expect(checker.search_options).to eq({:count=>50, :archive=>false, :by_content => 'test'})
|
52
|
+
|
53
|
+
end
|
54
|
+
|
55
|
+
context 'invalid' do
|
56
|
+
|
57
|
+
it 'by date' do
|
58
|
+
|
59
|
+
expect { checker.find({:since => Time.now}) }.to raise_error MailHandler::Error
|
60
|
+
|
61
|
+
end
|
62
|
+
|
63
|
+
it 'by_test' do
|
64
|
+
|
65
|
+
expect { checker.find({:by_test => 'test'}) }.to raise_error MailHandler::Error
|
66
|
+
|
67
|
+
end
|
68
|
+
|
69
|
+
|
70
|
+
end
|
71
|
+
|
72
|
+
context 'archive' do
|
73
|
+
|
74
|
+
it 'invalid' do
|
75
|
+
|
76
|
+
expect { checker.find({:archive => 'test'}) }.to raise_error MailHandler::Error
|
77
|
+
|
78
|
+
end
|
79
|
+
|
80
|
+
end
|
81
|
+
|
82
|
+
end
|
83
|
+
|
84
|
+
end
|
@@ -2,5 +2,78 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
describe MailHandler::Receiving::Notification::Email do
|
4
4
|
|
5
|
+
let(:search) { double('search') }
|
6
|
+
let(:sender) { double('sender') }
|
7
|
+
let(:notification) { MailHandler::Receiving::Notification::Email.new(sender, 'igor@example.com',1) }
|
8
|
+
|
9
|
+
before(:each) do
|
10
|
+
|
11
|
+
allow(sender).to receive(:send_email) { true }
|
12
|
+
allow(search).to receive(:max_duration) { 5 }
|
13
|
+
|
14
|
+
end
|
15
|
+
|
16
|
+
it '.create' do
|
17
|
+
|
18
|
+
aggregate_failures "init details" do
|
19
|
+
|
20
|
+
expect(notification.min_time_to_notify).to eq 1
|
21
|
+
expect(notification.max_time_to_notify).to eq nil
|
22
|
+
expect(notification.contacts).to eq 'igor@example.com'
|
23
|
+
expect(notification.sender).to eq sender
|
24
|
+
|
25
|
+
end
|
26
|
+
|
27
|
+
end
|
28
|
+
|
29
|
+
it '.notify' do
|
30
|
+
|
31
|
+
allow(search).to receive(:started_at) { Time.now }
|
32
|
+
notification.notify(search)
|
33
|
+
expect(notification.max_time_to_notify).to eq search.max_duration
|
34
|
+
|
35
|
+
end
|
36
|
+
|
37
|
+
context 'states' do
|
38
|
+
|
39
|
+
it 'no delay' do
|
40
|
+
|
41
|
+
allow(search).to receive(:started_at) { Time.now }
|
42
|
+
notification.notify(search)
|
43
|
+
expect(notification.current_state).to be_kind_of MailHandler::Receiving::Notification::NoDelay
|
44
|
+
|
45
|
+
end
|
46
|
+
|
47
|
+
it 'delayed' do
|
48
|
+
|
49
|
+
allow(search).to receive(:started_at) { Time.now - 2}
|
50
|
+
allow(search).to receive(:result) { false }
|
51
|
+
allow(notification).to receive(:send_email) { }
|
52
|
+
notification.notify(search)
|
53
|
+
expect(notification.current_state).to be_kind_of MailHandler::Receiving::Notification::Delay
|
54
|
+
|
55
|
+
end
|
56
|
+
|
57
|
+
it 'received' do
|
58
|
+
|
59
|
+
allow(search).to receive(:started_at) { Time.now - 2}
|
60
|
+
allow(search).to receive(:result) { true }
|
61
|
+
allow(notification).to receive(:send_email) { }
|
62
|
+
notification.notify(search)
|
63
|
+
expect(notification.current_state).to be_kind_of MailHandler::Receiving::Notification::Received
|
64
|
+
|
65
|
+
end
|
66
|
+
|
67
|
+
it 'max delayed' do
|
68
|
+
|
69
|
+
allow(search).to receive(:started_at) { Time.now - 10}
|
70
|
+
allow(search).to receive(:result) { false }
|
71
|
+
allow(notification).to receive(:send_email) { }
|
72
|
+
notification.notify(search)
|
73
|
+
expect(notification.current_state).to be_kind_of MailHandler::Receiving::Notification::MaxDelay
|
74
|
+
|
75
|
+
end
|
76
|
+
|
77
|
+
end
|
5
78
|
|
6
79
|
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe MailHandler::Sending::SMTPSender do
|
4
|
+
|
5
|
+
subject { MailHandler::Sending::SMTPSender }
|
6
|
+
|
7
|
+
context '.send' do
|
8
|
+
|
9
|
+
context 'invalid' do
|
10
|
+
|
11
|
+
it 'incorrect mail type' do
|
12
|
+
|
13
|
+
sender = subject.new
|
14
|
+
expect { sender.send('Test') }.to raise_error MailHandler::TypeError
|
15
|
+
|
16
|
+
end
|
17
|
+
|
18
|
+
end
|
19
|
+
|
20
|
+
end
|
21
|
+
|
22
|
+
end
|
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.18
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Igor Balos
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-12-
|
11
|
+
date: 2015-12-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: mail
|
@@ -87,12 +87,14 @@ files:
|
|
87
87
|
- spec/unit/mailhandler/receiver_spec.rb
|
88
88
|
- spec/unit/mailhandler/receiving/base_spec.rb
|
89
89
|
- spec/unit/mailhandler/receiving/folder_spec.rb
|
90
|
+
- spec/unit/mailhandler/receiving/imap_spec.rb
|
90
91
|
- spec/unit/mailhandler/receiving/notification/console_spec.rb
|
91
92
|
- spec/unit/mailhandler/receiving/notification/email/content_spec.rb
|
92
93
|
- spec/unit/mailhandler/receiving/notification/email_spec.rb
|
93
94
|
- spec/unit/mailhandler/sender_spec.rb
|
94
95
|
- spec/unit/mailhandler/sending/sender_api_batch_spec.rb
|
95
96
|
- spec/unit/mailhandler/sending/sender_api_spec.rb
|
97
|
+
- spec/unit/mailhandler/sending/sender_smtp_spec.rb
|
96
98
|
- spec/unit/mailhandler_spec.rb
|
97
99
|
homepage: https://github.com/wildbit/mailhandler
|
98
100
|
licenses:
|