tuktuk 0.1.2 → 0.1.3

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.
data/.gitignore CHANGED
@@ -1 +1,4 @@
1
1
  *~
2
+ test
3
+ log
4
+ pkg
@@ -9,13 +9,13 @@ module Package
9
9
  mail.charset = 'UTF-8'
10
10
 
11
11
  mail['In-Reply-To'] = message[:in_reply_to] if message[:in_reply_to]
12
- mail['List-Archive'] = message[:list_archive] if message[:list_archive] # https://github.com/tomas/prey
13
- mail['List-Id'] = message[:list_id] if message[:list_id] # <prey.tomas.github.com>
12
+ mail['List-Archive'] = message[:list_archive] if message[:list_archive]
13
+ mail['List-Id'] = message[:list_id] if message[:list_id]
14
14
 
15
15
  if message[:return_path]
16
16
  mail['Return-Path'] = message[:return_path]
17
- mail['Bounces-To'] = message[:return_path]
18
- mail['Errors-To'] = message[:return_path]
17
+ mail['Bounces-To'] = message[:return_path]
18
+ mail['Errors-To'] = message[:return_path]
19
19
  end
20
20
 
21
21
  mail
data/lib/tuktuk/tuktuk.rb CHANGED
@@ -6,7 +6,8 @@ require 'tuktuk/package'
6
6
 
7
7
  DEFAULTS = {
8
8
  :retry_sleep => 10,
9
- :max_attempts => 3
9
+ :max_attempts => 3,
10
+ :mailer => "Tuktuk SMTP #{VERSION}"
10
11
  }
11
12
 
12
13
  module Tuktuk
@@ -14,14 +15,22 @@ module Tuktuk
14
15
  class << self
15
16
 
16
17
  def deliver(message, opts = {})
17
- config.merge(opts)
18
+ options = opts
18
19
  mail = Package.new(message)
19
- mail['X-Mailer'] = opts[:smtp_server_name] || "Tuktuk SMTP #{VERSION}"
20
+ mail['X-Mailer'] = config[:mailer]
20
21
  lookup_and_deliver(mail)
21
22
  mail
22
23
  end
23
24
 
25
+ def options=(hash)
26
+ if dkim_opts = hash.delete(:dkim)
27
+ self.dkim = dkim_opts
28
+ end
29
+ config.merge!(hash)
30
+ end
31
+
24
32
  def dkim=(dkim_opts)
33
+ # logger.info "Enabling DKIM for domain #{dkim_opts[:domain]}..."
25
34
  Dkim::domain = dkim_opts[:domain]
26
35
  Dkim::selector = dkim_opts[:selector]
27
36
  Dkim::private_key = dkim_opts[:private_key]
@@ -42,22 +51,22 @@ module Tuktuk
42
51
  end
43
52
 
44
53
  def get_domain(email_address)
45
- email_address[/@([a-z0-9\._-]+)/i, 1]
54
+ email_address && email_address[/@([a-z0-9\._-]+)/i, 1]
46
55
  end
47
56
 
48
57
  def success(destination)
49
- logger.info("#{destination} - Successfully sent mail!")
58
+ logger.info("#{destination} - Successfully sent!")
50
59
  end
51
60
 
52
- def error(mail, destination, error, attempt = 1)
61
+ def error(mail, to, error, attempt = 1)
53
62
  if attempt <= config[:max_attempts] && (error.is_a?(Net::SMTPServerBusy) or error.is_a?(EOFError))
54
- logger.info "#{destination} - Got #{error.class.name} error. Retrying after #{config[:retry_sleep]} secs..."
63
+ logger.info "#{to} - Got #{error.class.name} error. Retrying after #{config[:retry_sleep]} secs..."
55
64
  sleep config[:retry_sleep]
56
65
  lookup_and_deliver(mail, attempt+1)
57
66
  else
58
67
  error_message = error.respond_to?(:message) ? "#{error.message} [#{error.class.name}]" : error
59
- logger.error("#{destination} - Unable to send: #{error_message}")
60
- raise "Unable to send to #{destination}: #{error_message}"
68
+ logger.error("#{to} - Error: #{error_message}")
69
+ raise "Unable to send to #{to}: #{error_message}"
61
70
  end
62
71
  end
63
72
 
@@ -101,13 +110,13 @@ module Tuktuk
101
110
  context = OpenSSL::SSL::SSLContext.new
102
111
  context.verify_mode = OpenSSL::SSL::VERIFY_NONE # OpenSSL::SSL::VERIFY_PEER
103
112
 
104
- domain = config[:domain] || get_domain(to)
113
+ helo_domain = config[:helo_domain] || Dkim::domain || get_domain(mail[:from])
105
114
 
106
115
  smtp = Net::SMTP.new(server, nil)
107
116
  smtp.enable_starttls_auto(context)
108
- smtp.start(domain, nil, nil, nil) do |smtp|
117
+ smtp.start(helo_domain, nil, nil, nil) do |smtp|
109
118
  result = smtp.send_message(raw_mail, from, to)
110
- logger.info result.string
119
+ logger.info "#{to} - #{result.string.strip}"
111
120
  end
112
121
 
113
122
  success(to)
@@ -1,7 +1,7 @@
1
1
  module Tuktuk
2
2
  MAJOR = 0
3
3
  MINOR = 1
4
- PATCH = 2
4
+ PATCH = 3
5
5
 
6
6
  VERSION = [MAJOR, MINOR, PATCH].join('.')
7
7
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tuktuk
3
3
  version: !ruby/object:Gem::Version
4
- hash: 31
4
+ hash: 29
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 1
9
- - 2
10
- version: 0.1.2
9
+ - 3
10
+ version: 0.1.3
11
11
  platform: ruby
12
12
  authors:
13
13
  - "Tom\xC3\xA1s Pollak"