leanweb 0.5.1 → 0.5.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/contrib/lib/lean_mail.rb +44 -22
- data/lib/leanweb/route.rb +1 -3
- data/lib/leanweb/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d558c8dc51eb0ded4ae4ca0c73bed085cbc9f807df31f615ec697f2555c59492
|
4
|
+
data.tar.gz: f45c4c2df3cbdfd6dcc1b56c37e6a79d36b24497b8a62faad2ee2c7d0d47027d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d7e428e0f47aea5c20e8bf59a8bc93e4bfec30488c9e84a2e9d3d26901fcd6ae5b96710fd7cfc4346c028781879cf343bc479069aec58b0e3f41ef1ec43a8a42
|
7
|
+
data.tar.gz: 87a6f8b615112c8525a9241b6fc0d4b02b305334abc064072b6c4babe80a775af138fa935161211c9af547acbdef9f9ab808aa1f2455f221357b17904fd4a498
|
data/contrib/lib/lean_mail.rb
CHANGED
@@ -12,6 +12,7 @@ require 'net/smtp'
|
|
12
12
|
require 'securerandom'
|
13
13
|
require 'socket'
|
14
14
|
require 'time'
|
15
|
+
require 'uri/mailto'
|
15
16
|
|
16
17
|
# Send an email with SMTP easily.
|
17
18
|
#
|
@@ -25,27 +26,32 @@ require 'time'
|
|
25
26
|
# - SMTP_FROM: In the format `Name <user@mail>` or `user@mail`.
|
26
27
|
#
|
27
28
|
# @example Single address
|
28
|
-
# LeanMail.deliver('to@mail', 'subject', 'body')
|
29
|
+
# LeanMail.deliver('to@mail', 'subject', 'body', reply_to: 'to@other.host')
|
29
30
|
#
|
30
31
|
# @example Multiple addresses
|
31
32
|
# LeanMail.deliver(['to@mail', 'to2@mail'], 'subject', 'body')
|
32
33
|
module LeanMail
|
33
34
|
# RFC 2821 message data representation.
|
34
35
|
class Data
|
35
|
-
attr_reader :from, :to, :subject, :message
|
36
|
+
attr_reader :from, :to, :subject, :message, :reply_to
|
37
|
+
|
38
|
+
def initialize(from, to, subject, message, reply_to: nil)
|
39
|
+
self.class.validate_recipients(to)
|
40
|
+
self.class.validate_recipients(reply_to) if reply_to
|
36
41
|
|
37
|
-
def initialize(from, to, subject, message)
|
38
42
|
@from = from
|
39
43
|
@to = to
|
40
44
|
@subject = subject
|
41
45
|
@message = message
|
46
|
+
@reply_to = reply_to
|
42
47
|
end
|
43
48
|
|
44
49
|
def to_s
|
45
50
|
<<~MAIL
|
46
51
|
Content-type: text/plain; charset=UTF-8
|
47
52
|
From: #{@from}
|
48
|
-
To: #{to.instance_of?(Array) ? to.join(', ') : to}
|
53
|
+
To: #{@to.instance_of?(Array) ? @to.join(', ') : @to}
|
54
|
+
Reply-To: #{@reply_to || @from}
|
49
55
|
Subject: =?UTF-8?B?#{Base64.strict_encode64(subject)}?=
|
50
56
|
Date: #{Time.new.rfc2822}
|
51
57
|
Message-Id: <#{SecureRandom.uuid}@#{Socket.gethostname}>
|
@@ -53,6 +59,29 @@ module LeanMail
|
|
53
59
|
#{@message}
|
54
60
|
MAIL
|
55
61
|
end
|
62
|
+
|
63
|
+
class << self
|
64
|
+
def validate_recipients(recipients)
|
65
|
+
return recipients.each{ |recipient| validate_recipients(recipient) } if
|
66
|
+
recipients.instance_of?(Array)
|
67
|
+
|
68
|
+
raise(ArgumentError, "#{recipients} is not a valid recipient") unless
|
69
|
+
URI::MailTo::EMAIL_REGEXP.match?(extract_addr(recipients))
|
70
|
+
end
|
71
|
+
|
72
|
+
def extract_addr(str)
|
73
|
+
match = str.match(/\A[^\n\r<]+<([^\n\r>]+)>\z/)
|
74
|
+
return match[1] if match
|
75
|
+
|
76
|
+
str
|
77
|
+
end
|
78
|
+
|
79
|
+
def extract_addrs(to)
|
80
|
+
return to.map{ |addr| extract_addr(addr) } if to.instance_of?(Array)
|
81
|
+
|
82
|
+
extract_addr(to)
|
83
|
+
end
|
84
|
+
end
|
56
85
|
end
|
57
86
|
|
58
87
|
# Email deliverer.
|
@@ -76,12 +105,17 @@ module LeanMail
|
|
76
105
|
# @param to [Array, String] In the format `Name <user@mail>` or `user@mail`.
|
77
106
|
# @param subject [String]
|
78
107
|
# @param body [String]
|
108
|
+
# @param reply_to [Array, String] In the same format as `to`.
|
79
109
|
# @return [Deliver]
|
80
|
-
def call(to, subject, body)
|
81
|
-
@data = Data.new(@from, to, subject, body)
|
110
|
+
def call(to, subject, body, reply_to: nil)
|
111
|
+
@data = Data.new(@from, to, subject, body, reply_to: reply_to)
|
82
112
|
|
83
113
|
@smtp.start(Socket.gethostname, @user, @password, :plain) do |smtp|
|
84
|
-
smtp.send_message(
|
114
|
+
smtp.send_message(
|
115
|
+
@data.to_s,
|
116
|
+
Data.extract_addr(@from),
|
117
|
+
Data.extract_addrs(to)
|
118
|
+
)
|
85
119
|
end
|
86
120
|
|
87
121
|
self
|
@@ -100,19 +134,6 @@ module LeanMail
|
|
100
134
|
when 'starttls' then @smtp.enable_starttls
|
101
135
|
end
|
102
136
|
end
|
103
|
-
|
104
|
-
def extract_addr(str)
|
105
|
-
match = str.match(%r{<([^/]+)>})
|
106
|
-
return match[1] if match
|
107
|
-
|
108
|
-
str
|
109
|
-
end
|
110
|
-
|
111
|
-
def extract_addrs(to)
|
112
|
-
return to.map{ |addr| extract_addr(addr) } if to.instance_of?(Array)
|
113
|
-
|
114
|
-
extract_addr(to)
|
115
|
-
end
|
116
137
|
end
|
117
138
|
|
118
139
|
# Deliver email.
|
@@ -120,8 +141,9 @@ module LeanMail
|
|
120
141
|
# @param to [Array, String] In the format `Name <user@mail>` or `user@mail`.
|
121
142
|
# @param subject [String]
|
122
143
|
# @param body [String]
|
144
|
+
# @param reply_to [Array, String] In the same format as `to`.
|
123
145
|
# @return [Deliver]
|
124
|
-
def self.deliver(to, subject, body)
|
125
|
-
LeanMail::Deliver.new.call(to, subject, body)
|
146
|
+
def self.deliver(to, subject, body, reply_to: nil)
|
147
|
+
LeanMail::Deliver.new.call(to, subject, body, reply_to: reply_to)
|
126
148
|
end
|
127
149
|
end
|
data/lib/leanweb/route.rb
CHANGED
@@ -73,10 +73,8 @@ module LeanWeb
|
|
73
73
|
|
74
74
|
respond_method(request)
|
75
75
|
rescue NoMethodError
|
76
|
-
raise unless @static == true && (view_path = guess_view_path)
|
77
|
-
|
78
76
|
controller = default_controller_class.new(self)
|
79
|
-
controller.default_static_action(
|
77
|
+
controller.default_static_action(guess_view_path)
|
80
78
|
end
|
81
79
|
|
82
80
|
# String path, independent if {#path} is Regexp or String.
|
data/lib/leanweb/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: leanweb
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.5.
|
4
|
+
version: 0.5.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Felix Freeman
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-05-
|
11
|
+
date: 2023-05-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rack
|