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: b888851bd9c92766c8abb3399b4bc7115dfd54ff
4
- data.tar.gz: 39d2842b2fe5be561a99d6a77bf9c2b99cc8f49f
3
+ metadata.gz: 2b329d4b975268c0863e22ca7bdd1c6b0b68749d
4
+ data.tar.gz: 8f0a8df3543fb535647995c00d3f7a41fa96c5e2
5
5
  SHA512:
6
- metadata.gz: b285a314daaa40d85d5133888b21c7a2340df5906c24f98a6165b38d2b3525fc666f54020a6e79aa9989719474ab9bfc6688f5aad753f1e18010a2c63183fb2d
7
- data.tar.gz: e55151fa11ab16befe97d21e43463bcdb3e356676c98932b2ec810b5a8d0d3bc6602d2582faff96896f50ddc5f7301d00573ce8f8967bfaaba0928ccce5e476d
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 = EmailContent.send("email_#{type}",search.options, Time.now - search.started_at, sender.dispatcher.username, contacts)
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 self.email_received(options, delay, from, to)
16
+ def retrieve(type, options, delay, from, to)
16
17
 
17
- Mail.new do
18
+ mail = Mail.new
19
+ mail.from = from
20
+ mail.to = to
21
+ delay = (delay.to_f/60).round(2)
18
22
 
19
- from from
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
- end
25
+ when :received
25
26
 
26
- end
27
+ mail.subject = "Received - delay was #{delay} minutes"
28
+ mail.body = "Received - delay was #{delay} minutes - search by #{options}"
27
29
 
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
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
- Mail.new do
35
+ else
35
36
 
36
- from from
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
@@ -1,5 +1,5 @@
1
1
  module MailHandler
2
2
 
3
- VERSION = '1.0.33'
3
+ VERSION = '1.0.34'
4
4
 
5
5
  end
@@ -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.email_received(options, 60, from, to)).to be_kind_of Mail::Message
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.email_received(options, 60, from, to)[:from].to_s).to eq from
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.email_received(options, 60, from, to)[:to].to_s).to eq to
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.email_received(options, 60, from, to)[:to].to_s).to eq to
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.email_received(options, 60, from, to).subject).to eq "Received - delay was 1.0 minutes"
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.email_received(options, 90, from, to).subject).to eq "Received - delay was 1.5 minutes"
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.email_received(options, 90, from, to).body.to_s).
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.email_delayed(options, 60, from, to)[:from].to_s).to eq from
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.email_delayed(options, 60, from, to)[:to].to_s).to eq to
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.email_delayed(options, 60, from, to)[:to].to_s).to eq to
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.email_delayed(options, 60, from, to).subject).to eq "Over 1.0 minutes delay"
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.email_delayed(options, 90, from, to).subject).to eq "Over 1.5 minutes delay"
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.email_delayed(options, 90, from, to).body.to_s).
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.33
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-05-01 00:00:00.000000000 Z
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.6.11
118
+ rubygems_version: 2.5.1
119
119
  signing_key:
120
120
  specification_version: 4
121
121
  summary: Postmark email receiving and sending handler.