mailhandler 1.0.1 → 1.0.2

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: ad4de21ce6ad278dd2916e5cb898691c10961b87
4
- data.tar.gz: caedb45d153cbfa44d41b13328a9afb20c81b2fa
3
+ metadata.gz: 9d007dfe2c9742d1099adc9d58f156bb147c9350
4
+ data.tar.gz: 5d6a258c2706b9718379cf5ec101723f686010bd
5
5
  SHA512:
6
- metadata.gz: a0da923ce9b696ca05ce4cc1b322678bd272b44227ca25a330239375fac65c3bdddbe3fbc08b6b425a27b89c24907b4a48fd259a5a99cec88f5e4ac6f165f8c4
7
- data.tar.gz: 7667ee7a964c55262104b954abd8289f7855b4107056041587702d76dbecab016425b139d49a3989ddcc53d7a905d781c029f39ca339cb122278d75542c46eae
6
+ metadata.gz: ec4bee8fcdbcbc9444e9b12a0cc328128971836e6ec435f4309784d3c619afac4b250b9e9d71772a7cecef69993d2c0163be61f515a0d9de53f089831f3596ff
7
+ data.tar.gz: 4b61c6b691b1c016ffd64c0411a91480f3fe5fa82744e6a6fd4a6d79ebea19c5cda1b2caa3ecff8b43bb04bc678926a6d41d0b08e052de4343d4420c6105e9ba
data/Gemfile ADDED
@@ -0,0 +1,7 @@
1
+ # A sample Gemfile
2
+ source 'https://rubygems.org'
3
+
4
+ gem 'rspec'
5
+ gem 'mail'
6
+ gem 'postmark'
7
+ gem 'pry'
data/Gemfile.lock ADDED
@@ -0,0 +1,44 @@
1
+ GEM
2
+ remote: https://rubygems.org/
3
+ specs:
4
+ coderay (1.1.0)
5
+ diff-lcs (1.2.5)
6
+ json (1.8.3)
7
+ mail (2.6.3)
8
+ mime-types (>= 1.16, < 3)
9
+ method_source (0.8.2)
10
+ mime-types (2.6.2)
11
+ postmark (1.7.0)
12
+ json
13
+ rake
14
+ pry (0.10.2)
15
+ coderay (~> 1.1.0)
16
+ method_source (~> 0.8.1)
17
+ slop (~> 3.4)
18
+ rake (10.4.2)
19
+ rspec (3.3.0)
20
+ rspec-core (~> 3.3.0)
21
+ rspec-expectations (~> 3.3.0)
22
+ rspec-mocks (~> 3.3.0)
23
+ rspec-core (3.3.2)
24
+ rspec-support (~> 3.3.0)
25
+ rspec-expectations (3.3.1)
26
+ diff-lcs (>= 1.2.0, < 2.0)
27
+ rspec-support (~> 3.3.0)
28
+ rspec-mocks (3.3.2)
29
+ diff-lcs (>= 1.2.0, < 2.0)
30
+ rspec-support (~> 3.3.0)
31
+ rspec-support (3.3.0)
32
+ slop (3.6.0)
33
+
34
+ PLATFORMS
35
+ ruby
36
+
37
+ DEPENDENCIES
38
+ mail
39
+ postmark
40
+ pry
41
+ rspec
42
+
43
+ BUNDLED WITH
44
+ 1.10.6
data/Rakefile ADDED
@@ -0,0 +1,3 @@
1
+ require "bundler/gem_tasks"
2
+ require 'rspec/core/rake_task'
3
+ RSpec::Core::RakeTask.new(:default)
@@ -27,7 +27,7 @@ module MailHandler
27
27
  def initialize
28
28
 
29
29
  # Default number of email results to return, and whether to archive emails.
30
- @search_options = {:count => 10, :archive => false}
30
+ @search_options = {:count => 50, :archive => false}
31
31
 
32
32
  end
33
33
 
@@ -12,12 +12,12 @@ module MailHandler
12
12
  :api_token,
13
13
  :use_ssl
14
14
 
15
- def initialize(host = nil, api_token = nil, use_ssl = false)
15
+ def initialize(api_token = nil)
16
16
 
17
17
  @type = :postmark_api
18
- @host = host
18
+ @host = DEFAULT_HOST
19
19
  @api_token = api_token
20
- @use_ssl = use_ssl
20
+ @use_ssl = false
21
21
 
22
22
  end
23
23
 
@@ -30,6 +30,8 @@ module MailHandler
30
30
 
31
31
  protected
32
32
 
33
+ DEFAULT_HOST = 'api.postmarkapp.com'
34
+
33
35
  def setup_sending_client
34
36
 
35
37
  # clearing cache so valid host is accepted, and not the cached one
@@ -1,5 +1,5 @@
1
1
  module MailHandler
2
2
 
3
- VERSION = '1.0.1'
3
+ VERSION = '1.0.2'
4
4
 
5
5
  end
data/mailhandler.gemspec CHANGED
@@ -18,8 +18,17 @@ Gem::Specification.new do |s|
18
18
 
19
19
 
20
20
  s.files = `git ls-files`.split($/)
21
+ s.test_files = `git ls-files -- {spec}/*`.split("\n")
21
22
  s.homepage = 'https://github.com/ibalosh'
22
23
  s.require_paths = ["lib"]
24
+
25
+ s.post_install_message = %q{
26
+ ==================
27
+ Thanks for installing the mailhandler gem.
28
+ Review the README.md for implementation details and examples.
29
+ ==================
30
+ }
31
+
23
32
  s.required_rubygems_version = ">= 1.8.7"
24
33
 
25
34
  s.add_dependency "mail"
data/readme.md CHANGED
@@ -1,8 +1,11 @@
1
1
  # MailHandler Gem
2
2
 
3
- This gem represents a simple library which allows you to send email and check email delivery.
4
- The library supports sending SMTP, Postmark API or Postmark Batch API, checking email delivery by IMAP, or by folder,
5
- if you have a local mailbox.
3
+ [![Build Status](https://travis-ci.org/ibalosh/MailHandler.svg?branch=master)](https://travis-ci.org/ibalosh/MailHandler)
4
+
5
+ MailHandler is a simple wrapper for [mail](https://github.com/mikel/mail) and [postmark](https://github.com/wildbit/postmark-gem) libraries which allows you to send and retrieve emails,
6
+ and get more details about email sending and delivery. Main purpose of the gem is easier email sending/delivery testing.
7
+
8
+ The library supports sending by SMTP, Postmark API and checking email delivery by IMAP protocol, or by folder, if you have a local mailbox.
6
9
 
7
10
  # Install the gem
8
11
 
@@ -22,6 +25,9 @@ gem install mailhandler
22
25
 
23
26
  ## Configure local mailbox email to check
24
27
 
28
+ Checking emails locally option can be used when you have emails stored in certain local path. In order to search for email, all you need to do is setup inbox and archive folder.
29
+ They can be the same if you don't plan to archive checked files.
30
+
25
31
  ``` ruby
26
32
  email_receiver = MailHandler::Handler.receiver(:folder) do |checker|
27
33
  checker.inbox_folder = folder_of_your_inbox
@@ -30,6 +36,8 @@ end
30
36
  ```
31
37
 
32
38
  ## Configure imap mailbox email to check
39
+
40
+ If you plan to check for an email in your inbox which support IMAP, you can use mailhandler with provided IMAP settings.
33
41
 
34
42
  ``` ruby
35
43
  email_receiver = MailHandler::Handler.receiver(:imap) do |checker|
@@ -79,7 +87,7 @@ Once email searching is finished, you can check search result by looking at: `em
79
87
  # Email search notifications
80
88
 
81
89
  While searching for an email, there is a possibility to get notification if emails sending is taking too long.
82
- You can get an notification in console, by email or both.
90
+ You can get an notification in console, by email or both. Console output is good if you are testing email delivery, and want to see how long its taking for email to arrive in console.
83
91
 
84
92
  To add notifications to email searching all you need to do is:
85
93
 
@@ -88,7 +96,7 @@ email_receiver.add_observer(MailHandler::Receiving::Notification::Email.new(emai
88
96
  email_receiver.add_observer(MailHandler::Receiving::Notification::Console.new)
89
97
  ```
90
98
 
91
- the parameters you need are:
99
+ For email notifications, the parameters you need are:
92
100
 
93
101
  * `email_sender` - email sender you will use for sending an email (it should be one of senders described below)
94
102
  * `contacts` - list of contacts to receive the notification (for example: `john@example.com, igor@example.com`
@@ -103,20 +111,16 @@ To send email you can use SMTP protocol or Postmark.
103
111
 
104
112
  ### Send by Postmark API
105
113
 
106
- To send email with Postmark, you need to choose type of sending, host, api token, and ssl options.
114
+ To send email with Postmark, you need to choose type of sending, api token options.
107
115
 
108
116
  ``` ruby
109
117
  email_sender = MailHandler::Handler.sender(type) do |dispatcher|
110
- dispatcher.host = host
111
118
  dispatcher.api_token = api_token
112
- dispatcher.use_ssl = use_ssl
113
119
  end
114
120
  ```
115
121
 
116
122
  * `:type` - type can be `:postmark_api` or `postmark_batch_api`
117
- * `:host` - host is `api.postmarkapp.com`
118
123
  * `:api_token` - api token of one of your Postmark sending servers
119
- * `:use_ssl` - can be true/false
120
124
 
121
125
  ### Sending email by SMTP
122
126
 
@@ -131,7 +135,17 @@ email_sender = MailHandler::Handler.sender(:smtp) do |dispatcher|
131
135
  dispatcher.password = password
132
136
  dispatcher.use_ssl = use_ssl
133
137
  end
134
- ```
138
+ ```
139
+
140
+ ### Sending email
141
+
142
+ Once you have setup your email sender, all you need to do is to send an email:
143
+
144
+ ``` ruby
145
+ email_sender.send_email(email)
146
+ ```
147
+
148
+ email has to be an email created with Mail gem. In order to send emails by Postmark batch, you will need to provide an Array of emails.
135
149
 
136
150
  ## Sending results
137
151
 
@@ -0,0 +1,16 @@
1
+ require 'rspec'
2
+ require 'mail'
3
+ require 'postmark'
4
+ require 'pry'
5
+ require 'mailhandler'
6
+
7
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
8
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
9
+
10
+ RSpec.configure do |c|
11
+
12
+ # Use the specified formatter, options are: # :documentation, :progress, :html, :textmate
13
+ c.formatter = :documentation
14
+ c.color = true
15
+
16
+ end
@@ -0,0 +1,41 @@
1
+ require 'spec_helper'
2
+
3
+ describe MailHandler::Receiver do
4
+
5
+ subject { MailHandler::Receiver }
6
+ let(:default_search_option) { {:by_subject => 'test'} }
7
+ let(:receiving_duration) { 5 }
8
+ let(:checker) {
9
+ checker = double('Checker')
10
+
11
+ allow(checker).to receive(:find) { sleep receiving_duration ; true }
12
+ allow(checker).to receive(:search_result) { true }
13
+ allow(checker).to receive(:found_emails) { [] }
14
+ checker
15
+
16
+ }
17
+
18
+ it '.find_email' do
19
+
20
+ receiver = subject.new(checker)
21
+ expect(receiver.find_email(default_search_option)).to be true
22
+
23
+ end
24
+
25
+ it '.search object' do
26
+
27
+ receiver = subject.new(checker)
28
+ receiver.find_email(default_search_option)
29
+
30
+ aggregate_failures "search details" do
31
+ expect(receiver.search.options).to eq default_search_option
32
+ expect(receiver.search.started_at).to be_within(1).of(Time.now - receiving_duration)
33
+ expect(receiver.search.finished_at).to be_within(1).of(Time.now)
34
+ expect(receiver.search.duration).to be_within(0.5).of(receiving_duration)
35
+ expect(receiver.search.result).to be true
36
+ expect(receiver.search.emails).to eq []
37
+ end
38
+
39
+ end
40
+
41
+ end
@@ -0,0 +1,29 @@
1
+ require 'spec_helper'
2
+
3
+ describe MailHandler::Receiving::Notification::Console do
4
+
5
+ subject { MailHandler::Receiving::Notification::Console }
6
+
7
+ context 'notify of a delay' do
8
+
9
+ it '.notify' do
10
+
11
+ search = double('Search', :started_at => Time.now - 10)
12
+ expect{ subject.new.notify(search) }.to output(/.+email delay: 0(9|1)0 seconds/).to_stdout
13
+
14
+ end
15
+
16
+ end
17
+
18
+ context 'not notify of a delay' do
19
+
20
+ it '.notify' do
21
+
22
+ search = double('Search', :started_at => Time.now + 5)
23
+ expect{ subject.new.notify(search) }.to output('').to_stdout
24
+
25
+ end
26
+
27
+ end
28
+
29
+ end
@@ -0,0 +1,105 @@
1
+ require 'spec_helper'
2
+
3
+ describe MailHandler::Receiving::Notification::EmailContent do
4
+
5
+ subject { MailHandler::Receiving::Notification::EmailContent }
6
+
7
+ let(:to) { 'john@example.com' }
8
+ let(:from) { 'igor@example.com' }
9
+ let(:options) {{ :test => 'test' } }
10
+
11
+ context '.email_received' do
12
+
13
+ it 'create email' do
14
+
15
+ expect(subject.email_received(options, 60, from, to)).to be_kind_of Mail::Message
16
+
17
+ end
18
+
19
+ context 'email content' do
20
+
21
+ it 'sender' do
22
+
23
+ expect(subject.email_received(options, 60, from, to)[:from].to_s).to eq from
24
+
25
+ end
26
+
27
+ it 'single recipient' do
28
+
29
+ expect(subject.email_received(options, 60, from, to)[:to].to_s).to eq to
30
+
31
+ end
32
+
33
+ it 'multiple recipients' do
34
+
35
+ to = 'john1@example.com, john2@example.com'
36
+ expect(subject.email_received(options, 60, from, to)[:to].to_s).to eq to
37
+
38
+ end
39
+
40
+ it 'subject - 1 minute delay' do
41
+
42
+ expect(subject.email_received(options, 60, from, to).subject).to eq "Received - delay was 1.0 minutes"
43
+
44
+ end
45
+
46
+ it 'subject - 1.5 minute delay' do
47
+
48
+ expect(subject.email_received(options, 90, from, to).subject).to eq "Received - delay was 1.5 minutes"
49
+
50
+ end
51
+
52
+ it 'body' do
53
+
54
+ expect(subject.email_received(options, 90, from, to).body.to_s).
55
+ to eq "Received - delay was 1.5 minutes - search by #{options}"
56
+
57
+ end
58
+
59
+ end
60
+
61
+ end
62
+
63
+ context '.email_delayed' do
64
+
65
+ it 'sender' do
66
+
67
+ expect(subject.email_delayed(options, 60, from, to)[:from].to_s).to eq from
68
+
69
+ end
70
+
71
+ it 'single recipient' do
72
+
73
+ expect(subject.email_delayed(options, 60, from, to)[:to].to_s).to eq to
74
+
75
+ end
76
+
77
+ it 'multiple recipients' do
78
+
79
+ to = 'john1@example.com, john2@example.com'
80
+ expect(subject.email_delayed(options, 60, from, to)[:to].to_s).to eq to
81
+
82
+ end
83
+
84
+ it 'subject - 1 minute delay' do
85
+
86
+ expect(subject.email_delayed(options, 60, from, to).subject).to eq "Over 1.0 minutes delay"
87
+
88
+ end
89
+
90
+ it 'subject - 1.5 minute delay' do
91
+
92
+ expect(subject.email_delayed(options, 90, from, to).subject).to eq "Over 1.5 minutes delay"
93
+
94
+ end
95
+
96
+ it 'body' do
97
+
98
+ expect(subject.email_delayed(options, 90, from, to).body.to_s).
99
+ to eq "Over 1.5 minutes delay - search by #{options}"
100
+
101
+ end
102
+
103
+ end
104
+
105
+ end
@@ -0,0 +1,7 @@
1
+ require 'spec_helper'
2
+
3
+ describe MailHandler::Receiving::Notification::Email do
4
+
5
+
6
+
7
+ end
@@ -0,0 +1,61 @@
1
+ require 'spec_helper'
2
+
3
+ describe MailHandler::Sender do
4
+
5
+ subject { MailHandler::Sender }
6
+
7
+ let(:send_duration) { 3 }
8
+ let(:dispatcher) {
9
+ dispatcher = double('Dispatcher')
10
+
11
+ allow(dispatcher).to receive(:send) { sleep send_duration ; 'Sent' }
12
+ dispatcher
13
+
14
+ }
15
+ let(:mail) {
16
+
17
+ Mail.new do
18
+ from "sheldon@bigbangtheory.com"
19
+ to "lenard@bigbangtheory.com"
20
+ subject "Hello!"
21
+ body "Hello Sheldon!"
22
+ end
23
+
24
+ }
25
+
26
+ it '.sending' do
27
+
28
+ expect(subject.new(dispatcher)).not_to be nil
29
+
30
+ end
31
+
32
+ it '.sending init' do
33
+
34
+ sender = subject.new(dispatcher)
35
+
36
+ aggregate_failures "sending details" do
37
+ expect(sender.sending.started_at).to be nil
38
+ expect(sender.sending.finished_at).to be nil
39
+ expect(sender.sending.duration).to be nil
40
+ expect(sender.sending.response).to be nil
41
+ expect(sender.sending.email).to be nil
42
+ end
43
+
44
+ end
45
+
46
+ it '.send_email' do
47
+
48
+ sender = subject.new(dispatcher)
49
+ sender.send_email(mail)
50
+
51
+ aggregate_failures "sending details" do
52
+ expect(sender.sending.started_at).to be_within(1).of(Time.now - send_duration)
53
+ expect(sender.sending.finished_at).to be_within(1).of(Time.now)
54
+ expect(sender.sending.duration).to be_within(0.5).of(send_duration)
55
+ expect(sender.sending.response).to eq 'Sent'
56
+ expect(sender.sending.email).to be mail
57
+ end
58
+
59
+ end
60
+
61
+ end
@@ -0,0 +1,64 @@
1
+ require 'spec_helper'
2
+
3
+ describe MailHandler::Handler do
4
+
5
+ subject { MailHandler::Handler }
6
+
7
+ context 'receiver' do
8
+
9
+ let(:receiver_folder) {
10
+
11
+ subject.receiver(:folder)
12
+
13
+ }
14
+
15
+ it 'invalid type' do
16
+
17
+ expect{subject.receiver(:test)}.
18
+ to raise_error(StandardError, 'Unknown type - test, possible options: [:folder, :imap]')
19
+
20
+ end
21
+
22
+ context 'folder check' do
23
+
24
+ it 'object type' do
25
+
26
+ expect(receiver_folder).to match MailHandler::Receiver
27
+
28
+ end
29
+
30
+ end
31
+
32
+
33
+ end
34
+
35
+ context 'sender' do
36
+
37
+ it 'invalid type' do
38
+
39
+ expect{subject.sender(:test)}.
40
+ to raise_error(StandardError, 'Unknown type - test, possible options: [:postmark_api, :postmark_batch_api, :smtp]')
41
+
42
+ end
43
+
44
+ it 'create sender - postmark api' do
45
+
46
+ expect(subject.sender(:postmark_api)).to match MailHandler::Sender
47
+
48
+ end
49
+
50
+ it 'create sender - postmark batch api' do
51
+
52
+ expect(subject.sender(:postmark_batch_api)).to match MailHandler::Sender
53
+
54
+ end
55
+
56
+ it 'create sender - smtp' do
57
+
58
+ expect(subject.sender(:smtp)).to match MailHandler::Sender
59
+
60
+ end
61
+
62
+ end
63
+
64
+ end
data/travis.yml ADDED
@@ -0,0 +1,9 @@
1
+ language: ruby
2
+ rvm:
3
+ - 1.8.7
4
+ - 1.9.3
5
+ - 2.0.0
6
+ - 2.1.6
7
+ - 2.2.2
8
+
9
+ script: bundle exec rake spec
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.1
4
+ version: 1.0.2
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-10-02 00:00:00.000000000 Z
11
+ date: 2015-10-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: mail
@@ -52,6 +52,9 @@ extensions: []
52
52
  extra_rdoc_files: []
53
53
  files:
54
54
  - ".gitignore"
55
+ - Gemfile
56
+ - Gemfile.lock
57
+ - Rakefile
55
58
  - lib/mailhandler.rb
56
59
  - lib/mailhandler/receiver.rb
57
60
  - lib/mailhandler/receiving/checker.rb
@@ -71,11 +74,21 @@ files:
71
74
  - lib/mailhandler/version.rb
72
75
  - mailhandler.gemspec
73
76
  - readme.md
77
+ - spec/spec_helper.rb
78
+ - spec/unit/mailhandler/receiver_spec.rb
79
+ - spec/unit/mailhandler/receiving/notification/console_spec.rb
80
+ - spec/unit/mailhandler/receiving/notification/email/content_spec.rb
81
+ - spec/unit/mailhandler/receiving/notification/email_spec.rb
82
+ - spec/unit/mailhandler/sender_spec.rb
83
+ - spec/unit/mailhandler_spec.rb
84
+ - travis.yml
74
85
  homepage: https://github.com/ibalosh
75
86
  licenses:
76
87
  - MIT
77
88
  metadata: {}
78
- post_install_message:
89
+ post_install_message: "\n ==================\n Thanks for installing the mailhandler
90
+ gem.\n Review the README.md for implementation details and examples.\n ==================\n
91
+ \ "
79
92
  rdoc_options: []
80
93
  require_paths:
81
94
  - lib