mailhandler 1.0.33 → 1.0.34
Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2b329d4b975268c0863e22ca7bdd1c6b0b68749d
|
4
|
+
data.tar.gz: 8f0a8df3543fb535647995c00d3f7a41fa96c5e2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ae8c4663433e1ba91a603168f90f18b041619559b2e8019d5de1662b72e0670f3d3d1eb04b82a4765953d1afdc00dea0fc55dc7acd7ce50ec0bed0417621d908
|
7
|
+
data.tar.gz: 1db0cc12950ec81b530da34560536fe834aaac86c606e5f1696ca65ccf30d58c87a829acc762ae4c176142a73609403e5266544b203fd76d4965d9ab0f29ab0e
|
@@ -23,6 +23,7 @@ module MailHandler
|
|
23
23
|
@sender = sender
|
24
24
|
@contacts = contacts
|
25
25
|
init_state
|
26
|
+
set_content_handler(EmailContent.new)
|
26
27
|
|
27
28
|
end
|
28
29
|
|
@@ -43,11 +44,19 @@ module MailHandler
|
|
43
44
|
def send_email(type, search)
|
44
45
|
|
45
46
|
verify_email_type(type)
|
46
|
-
content =
|
47
|
+
content = @content_handler.retrieve(type, search.options, Time.now - search.started_at,
|
48
|
+
sender.dispatcher.username, contacts)
|
47
49
|
sender.send_email content
|
48
50
|
|
49
51
|
end
|
50
52
|
|
53
|
+
# Allow users to specify their own content classes.
|
54
|
+
# Class must match by methods to the interface of MailHandler::Receiving::Notification::EmailContent
|
55
|
+
def set_content_handler(content_handler)
|
56
|
+
@content_handler = content_handler
|
57
|
+
end
|
58
|
+
|
59
|
+
|
51
60
|
private
|
52
61
|
|
53
62
|
def init_state
|
@@ -8,40 +8,41 @@ module MailHandler
|
|
8
8
|
|
9
9
|
class EmailContent
|
10
10
|
|
11
|
+
# @param [Symbol] type - notification type
|
11
12
|
# @param [Hash] options - search options used for searching for an email
|
12
13
|
# @param [Int] delay - delay in seconds
|
13
14
|
# @param [String] from - email address
|
14
15
|
# @param [String] to - email address
|
15
|
-
def
|
16
|
+
def retrieve(type, options, delay, from, to)
|
16
17
|
|
17
|
-
Mail.new
|
18
|
+
mail = Mail.new
|
19
|
+
mail.from = from
|
20
|
+
mail.to = to
|
21
|
+
delay = (delay.to_f/60).round(2)
|
18
22
|
|
19
|
-
|
20
|
-
subject "Received - delay was #{(delay.to_f/60).round(2)} minutes"
|
21
|
-
body "Received - delay was #{(delay.to_f/60).round(2)} minutes - search by #{options}"
|
22
|
-
to to
|
23
|
+
case type
|
23
24
|
|
24
|
-
|
25
|
+
when :received
|
25
26
|
|
26
|
-
|
27
|
+
mail.subject = "Received - delay was #{delay} minutes"
|
28
|
+
mail.body = "Received - delay was #{delay} minutes - search by #{options}"
|
27
29
|
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
def self.email_delayed(options, delay, from, to)
|
30
|
+
when :delayed
|
31
|
+
|
32
|
+
mail.subject = "Over #{delay} minutes delay"
|
33
|
+
mail.body = "Over #{delay} minutes delay - search by #{options}"
|
33
34
|
|
34
|
-
|
35
|
+
else
|
35
36
|
|
36
|
-
|
37
|
-
subject "Over #{(delay.to_f/60).round(2)} minutes delay"
|
38
|
-
body "Over #{(delay.to_f/60).round(2)} minutes delay - search by #{options}"
|
39
|
-
to to
|
37
|
+
raise StandardError, "Incorrect type: #{type}"
|
40
38
|
|
41
39
|
end
|
42
40
|
|
41
|
+
mail
|
42
|
+
|
43
43
|
end
|
44
44
|
|
45
|
+
|
45
46
|
end
|
46
47
|
|
47
48
|
end
|
data/lib/mailhandler/version.rb
CHANGED
@@ -2,7 +2,7 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
describe MailHandler::Receiving::Notification::EmailContent do
|
4
4
|
|
5
|
-
subject { MailHandler::Receiving::Notification::EmailContent }
|
5
|
+
subject { MailHandler::Receiving::Notification::EmailContent.new }
|
6
6
|
|
7
7
|
let(:to) { 'john@example.com' }
|
8
8
|
let(:from) { 'igor@example.com' }
|
@@ -12,7 +12,7 @@ describe MailHandler::Receiving::Notification::EmailContent do
|
|
12
12
|
|
13
13
|
it 'create email' do
|
14
14
|
|
15
|
-
expect(subject.
|
15
|
+
expect(subject.retrieve(:received, options, 60, from, to)).to be_kind_of Mail::Message
|
16
16
|
|
17
17
|
end
|
18
18
|
|
@@ -20,38 +20,38 @@ describe MailHandler::Receiving::Notification::EmailContent do
|
|
20
20
|
|
21
21
|
it 'sender' do
|
22
22
|
|
23
|
-
expect(subject.
|
23
|
+
expect(subject.retrieve(:received, options, 60, from, to)[:from].to_s).to eq from
|
24
24
|
|
25
25
|
end
|
26
26
|
|
27
27
|
it 'single recipient' do
|
28
28
|
|
29
|
-
expect(subject.
|
29
|
+
expect(subject.retrieve(:received, options, 60, from, to)[:to].to_s).to eq to
|
30
30
|
|
31
31
|
end
|
32
32
|
|
33
33
|
it 'multiple recipients' do
|
34
34
|
|
35
35
|
to = 'john1@example.com, john2@example.com'
|
36
|
-
expect(subject.
|
36
|
+
expect(subject.retrieve(:received, options, 60, from, to)[:to].to_s).to eq to
|
37
37
|
|
38
38
|
end
|
39
39
|
|
40
40
|
it 'subject - 1 minute delay' do
|
41
41
|
|
42
|
-
expect(subject.
|
42
|
+
expect(subject.retrieve(:received, options, 60, from, to).subject).to eq "Received - delay was 1.0 minutes"
|
43
43
|
|
44
44
|
end
|
45
45
|
|
46
46
|
it 'subject - 1.5 minute delay' do
|
47
47
|
|
48
|
-
expect(subject.
|
48
|
+
expect(subject.retrieve(:received, options, 90, from, to).subject).to eq "Received - delay was 1.5 minutes"
|
49
49
|
|
50
50
|
end
|
51
51
|
|
52
52
|
it 'body' do
|
53
53
|
|
54
|
-
expect(subject.
|
54
|
+
expect(subject.retrieve(:received, options, 90, from, to).body.to_s).
|
55
55
|
to eq "Received - delay was 1.5 minutes - search by #{options}"
|
56
56
|
|
57
57
|
end
|
@@ -64,38 +64,38 @@ describe MailHandler::Receiving::Notification::EmailContent do
|
|
64
64
|
|
65
65
|
it 'sender' do
|
66
66
|
|
67
|
-
expect(subject.
|
67
|
+
expect(subject.retrieve(:delayed, options, 60, from, to)[:from].to_s).to eq from
|
68
68
|
|
69
69
|
end
|
70
70
|
|
71
71
|
it 'single recipient' do
|
72
72
|
|
73
|
-
expect(subject.
|
73
|
+
expect(subject.retrieve(:delayed, options, 60, from, to)[:to].to_s).to eq to
|
74
74
|
|
75
75
|
end
|
76
76
|
|
77
77
|
it 'multiple recipients' do
|
78
78
|
|
79
79
|
to = 'john1@example.com, john2@example.com'
|
80
|
-
expect(subject.
|
80
|
+
expect(subject.retrieve(:delayed, options, 60, from, to)[:to].to_s).to eq to
|
81
81
|
|
82
82
|
end
|
83
83
|
|
84
84
|
it 'subject - 1 minute delay' do
|
85
85
|
|
86
|
-
expect(subject.
|
86
|
+
expect(subject.retrieve(:delayed, options, 60, from, to).subject).to eq "Over 1.0 minutes delay"
|
87
87
|
|
88
88
|
end
|
89
89
|
|
90
90
|
it 'subject - 1.5 minute delay' do
|
91
91
|
|
92
|
-
expect(subject.
|
92
|
+
expect(subject.retrieve(:delayed, options, 90, from, to).subject).to eq "Over 1.5 minutes delay"
|
93
93
|
|
94
94
|
end
|
95
95
|
|
96
96
|
it 'body' do
|
97
97
|
|
98
|
-
expect(subject.
|
98
|
+
expect(subject.retrieve(:delayed, options, 90, from, to).body.to_s).
|
99
99
|
to eq "Over 1.5 minutes delay - search by #{options}"
|
100
100
|
|
101
101
|
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.34
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Igor Balos
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-
|
11
|
+
date: 2017-06-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: mail
|
@@ -115,7 +115,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
115
115
|
version: 1.9.3
|
116
116
|
requirements: []
|
117
117
|
rubyforge_project:
|
118
|
-
rubygems_version: 2.
|
118
|
+
rubygems_version: 2.5.1
|
119
119
|
signing_key:
|
120
120
|
specification_version: 4
|
121
121
|
summary: Postmark email receiving and sending handler.
|