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 +3 -0
- data/lib/tuktuk/package.rb +4 -4
- data/lib/tuktuk/tuktuk.rb +21 -12
- data/lib/tuktuk/version.rb +1 -1
- metadata +3 -3
data/.gitignore
CHANGED
data/lib/tuktuk/package.rb
CHANGED
@@ -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]
|
13
|
-
mail['List-Id'] = message[:list_id] if message[:list_id]
|
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']
|
18
|
-
mail['Errors-To']
|
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
|
-
|
18
|
+
options = opts
|
18
19
|
mail = Package.new(message)
|
19
|
-
mail['X-Mailer'] =
|
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
|
58
|
+
logger.info("#{destination} - Successfully sent!")
|
50
59
|
end
|
51
60
|
|
52
|
-
def error(mail,
|
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 "#{
|
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("#{
|
60
|
-
raise "Unable to send to #{
|
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
|
-
|
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(
|
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)
|
data/lib/tuktuk/version.rb
CHANGED
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:
|
4
|
+
hash: 29
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 1
|
9
|
-
-
|
10
|
-
version: 0.1.
|
9
|
+
- 3
|
10
|
+
version: 0.1.3
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- "Tom\xC3\xA1s Pollak"
|