mailhandler 1.0.42 → 1.0.51

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 99f1d39aad0dedeab9bdac5972470471bd199bb4b5fc1a99e6c4d518c6bdda4f
4
- data.tar.gz: 9601b811111067f81d85fd139a9eb51c83a4741336f503d8356dde26cace3e57
3
+ metadata.gz: 7d42c93426c484996cc604a260820c1db617cf9d3e17d3441ac07038f31df9b0
4
+ data.tar.gz: afb801fe33b1b317aeb036ec0a9722fccd0a2524ec8ce58333659552ae947ad3
5
5
  SHA512:
6
- metadata.gz: d11f02d93e90fa805968be45194277dfbd6e8584b043a953e383a5b5cc8406da0285271491c79c4d8ab6ddebabbdb78eba2fb4f6d55d3c13e0a3f37abb2be85a
7
- data.tar.gz: 0bc30ecfdbbb5490be43e4c241a354a83206da0475173c8706b57a0526c3de7b1c9c9014083537f09b2c4297c32e18f9a213450aad19fa72996cea2ef7ba9147
6
+ metadata.gz: 32410e9dfca936b1638ed6f4eff71800ce41f50193d8926dd2d9c5c62620856231c337a05acc9ca0299e5fad8cb1d442d0aae2bd9bba93bb18544c1db1d93f26
7
+ data.tar.gz: 2f84617e07cf1ba803bb958c65b5ede2e46ded12bb8f514a219b0366bd8efb2f5051a1e38c324b31cb1b478014d45543f931fcc9abfc6432d0c1e7da8c0e64dd
@@ -2,8 +2,8 @@
2
2
 
3
3
  require_relative 'receiving/folder'
4
4
  require_relative 'receiving/imap'
5
+ require_relative 'extensions/mail/imap'
5
6
  require_relative 'receiving/observer'
6
- require_relative 'receiving/mail.rb'
7
7
 
8
8
  module MailHandler
9
9
  # handling receiving email
@@ -44,6 +44,7 @@ module MailHandler
44
44
 
45
45
  until search_time_expired?
46
46
  break if single_search(options)
47
+
47
48
  sleep search_frequency
48
49
  end
49
50
 
@@ -90,7 +90,7 @@ module MailHandler
90
90
 
91
91
  count = options[:count]
92
92
  error_message = "Incorrect option options[:count]=#{options[:count]}."
93
- raise MailHandler::Error, error_message if (count < 0) || (count > 2000)
93
+ raise MailHandler::Error, error_message if (count <0) || (count > 2000)
94
94
  end
95
95
 
96
96
  def validate_used_options(options)
@@ -31,6 +31,10 @@ module MailHandler
31
31
  response
32
32
  end
33
33
 
34
+ def dispatcher_client
35
+ dispatcher.client if dispatcher.respond_to?(:client)
36
+ end
37
+
34
38
  private
35
39
 
36
40
  def init_sending_details(email)
@@ -1,6 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'mail'
4
3
  require 'postmark'
5
4
  require_relative 'base.rb'
6
5
 
@@ -11,18 +10,19 @@ module MailHandler
11
10
  attr_accessor :host,
12
11
  :api_token,
13
12
  :use_ssl,
14
- :client,
15
13
  :http_open_timeout,
16
- :http_read_timeout
14
+ :http_read_timeout,
15
+ :client
17
16
 
18
17
  def initialize(api_token = nil)
19
18
  @type = :postmark_api
20
- @host = DEFAULT_HOST
19
+ @host = DEFAULTS[:host]
21
20
  @api_token = api_token
22
21
  @use_ssl = false
23
22
 
24
- @http_open_timeout = 15
25
- @http_read_timeout = 15
23
+ @http_open_timeout = DEFAULTS[:open_timeout]
24
+ @http_read_timeout = DEFAULTS[:read_timeout]
25
+ init_client
26
26
  end
27
27
 
28
28
  def send(email)
@@ -42,7 +42,11 @@ module MailHandler
42
42
  host: host, secure: @use_ssl)
43
43
  end
44
44
 
45
- DEFAULT_HOST = 'api.postmarkapp.com'.freeze
45
+ DEFAULTS = {
46
+ host: 'api.postmarkapp.com',
47
+ read_timeout: 15,
48
+ open_timeout: 15
49
+ }.freeze
46
50
  end
47
51
  end
48
52
  end
@@ -1,5 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require 'mail'
3
4
  require_relative '../errors'
4
5
 
5
6
  module MailHandler
@@ -1,6 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'net/imap'
4
3
  require_relative 'base'
5
4
 
6
5
  module MailHandler
@@ -23,7 +22,7 @@ module MailHandler
23
22
  @type = :smtp
24
23
  @authentication = 'plain'
25
24
  @use_ssl = false
26
- @save_response = false
25
+ @save_response = true
27
26
 
28
27
  @open_timeout = 60
29
28
  @read_timeout = 60
@@ -35,10 +34,31 @@ module MailHandler
35
34
  save_response ? email.deliver! : email.deliver
36
35
  end
37
36
 
37
+ def send_raw_email(text_email, smtp_from, smtp_to)
38
+ response = init_net_smtp.start(domain, username, password, authentication) do |smtp|
39
+ smtp.send_message(text_email, smtp_from, smtp_to)
40
+ end
41
+
42
+ save_response ? response : nil
43
+ end
44
+
38
45
  private
39
46
 
47
+ def init_net_smtp
48
+ sending = Net::SMTP.new(address, port)
49
+ sending.read_timeout = read_timeout
50
+ sending.open_timeout = open_timeout
51
+ sending.enable_starttls_auto if use_ssl
52
+ sending
53
+ end
54
+
40
55
  def configure_sending(email)
41
- options = {
56
+ email.delivery_method :smtp, delivery_options
57
+ email
58
+ end
59
+
60
+ def delivery_options
61
+ {
42
62
  address: address,
43
63
  port: port,
44
64
  domain: domain,
@@ -51,9 +71,6 @@ module MailHandler
51
71
  open_timeout: open_timeout,
52
72
  read_timeout: read_timeout
53
73
  }
54
-
55
- email.delivery_method :smtp, options
56
- email
57
74
  end
58
75
  end
59
76
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module MailHandler
4
- VERSION = '1.0.42'.freeze
4
+ VERSION = '1.0.51'
5
5
  end
@@ -28,7 +28,7 @@ describe MailHandler::Sending::SMTPSender do
28
28
  end
29
29
 
30
30
  it 'save response' do
31
- expect(smtp_sender.new.save_response).to be false
31
+ expect(smtp_sender.new.save_response).to be true
32
32
  end
33
33
 
34
34
  it 'use ssl' do
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.42
4
+ version: 1.0.51
5
5
  platform: ruby
6
6
  authors:
7
7
  - Igor Balos
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-01-09 00:00:00.000000000 Z
11
+ date: 2020-03-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: mail
@@ -55,6 +55,7 @@ files:
55
55
  - Rakefile
56
56
  - lib/mailhandler.rb
57
57
  - lib/mailhandler/errors.rb
58
+ - lib/mailhandler/extensions/mail/imap.rb
58
59
  - lib/mailhandler/receiver.rb
59
60
  - lib/mailhandler/receiving/base.rb
60
61
  - lib/mailhandler/receiving/filelist/base.rb
@@ -62,7 +63,6 @@ files:
62
63
  - lib/mailhandler/receiving/filelist/filter/email.rb
63
64
  - lib/mailhandler/receiving/folder.rb
64
65
  - lib/mailhandler/receiving/imap.rb
65
- - lib/mailhandler/receiving/mail.rb
66
66
  - lib/mailhandler/receiving/notification/console.rb
67
67
  - lib/mailhandler/receiving/notification/email.rb
68
68
  - lib/mailhandler/receiving/notification/email/content.rb