uri-smtp 0.2.0 → 0.4.0
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 +4 -4
- data/CHANGELOG.md +10 -2
- data/README.md +115 -1
- data/lib/uri/smtp/version.rb +1 -1
- data/lib/uri/smtp.rb +13 -3
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 70ec42fc77da96a4bf7e8766406f110edbbd0de008148a7b62ad64b90137515e
|
4
|
+
data.tar.gz: def1342386b5d4ef7599f09750fd2dea8a709f06c452459c4f174374de4f48de
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1eeb8f2e3f8debbc08271ae35c9a55cadbd2b2d7380a86d174cfa91461012b4986e1e9489c6fde38eedf018d1e5e8601807e6ba23fb6ed1aab3d0a755d82e628
|
7
|
+
data.tar.gz: d450be99efefaa24c20c2c6315a4d7b0a406d9ba043b558e6742a9bbe510670e0b6d076c5a1584ace1270ce650d73b9fd7549d93dd0853365b938b97713affe4
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,13 @@
|
|
1
1
|
## [Unreleased]
|
2
2
|
|
3
|
-
## [0.
|
3
|
+
## [0.4.0] - 2025-07-23
|
4
4
|
|
5
|
-
-
|
5
|
+
- FIX: correct settings for action_mailer using mail v2.8.1
|
6
|
+
|
7
|
+
## [0.3.0] - 2025-07-23
|
8
|
+
|
9
|
+
- FIX: Kernel.URI should accept URI's
|
10
|
+
|
11
|
+
## [0.2.0] - 2025-07-18
|
12
|
+
|
13
|
+
- Feature complete
|
data/README.md
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# URI::SMTP
|
2
2
|
|
3
|
-
|
3
|
+
This library allows for parsing SMTP-URIs.
|
4
4
|
|
5
5
|
## Installation
|
6
6
|
|
@@ -18,6 +18,120 @@ gem install uri-smtp
|
|
18
18
|
|
19
19
|
## Usage
|
20
20
|
|
21
|
+
### parse
|
22
|
+
|
23
|
+
```ruby
|
24
|
+
u = URI("smtps+login://user%40gmail.com:p%40ss@smtp.gmail.com?domain=sender.org")
|
25
|
+
|
26
|
+
url.scheme #=> "smtps+login"
|
27
|
+
url.auth #=> "login"
|
28
|
+
url.starttls #=> false
|
29
|
+
url.tls? #=> true
|
30
|
+
url.userinfo #=> "user%40gmail.com:p%40ss"
|
31
|
+
url.decoded_user #=> "user@gmail.com"
|
32
|
+
url.user #=> "user%40gmail.com"
|
33
|
+
url.decoded_password #=> "p@ss"
|
34
|
+
url.password #=> "p%40ss"
|
35
|
+
url.host #=> "smtp.gmail.com"
|
36
|
+
url.port #=> 465
|
37
|
+
url.domain #=> s"ender.org"
|
38
|
+
url.query #=> "domain=sender.org"
|
39
|
+
```
|
40
|
+
|
41
|
+
### to_h
|
42
|
+
|
43
|
+
```ruby
|
44
|
+
URI("smtps+login://user%40gmail.com:p%40ss@smtp.gmail.com?domain=sender.org").to_h
|
45
|
+
{auth: "login",
|
46
|
+
domain: "sender.org",
|
47
|
+
host: "smtp.gmail.com",
|
48
|
+
port: 587,
|
49
|
+
scheme: "smtps+login",
|
50
|
+
starttls: :always,
|
51
|
+
tls: false,
|
52
|
+
user: "user@gmail.com",
|
53
|
+
password: "p@ss"}
|
54
|
+
```
|
55
|
+
|
56
|
+
Formatting for action_mailer configuration, use `to_h(format: :am)`:
|
57
|
+
```ruby
|
58
|
+
URI("smtps+login://user%40gmail.com:p%40ss@smtp.gmail.com?domain=sender.org").to_h(format: :am)
|
59
|
+
{address: "smtp.gmail.com",
|
60
|
+
authentication: "login",
|
61
|
+
domain: "sender.org",
|
62
|
+
enable_starttls: :always,
|
63
|
+
port: 587,
|
64
|
+
user_name: "user@gmail.com",
|
65
|
+
password: "p@ss"}
|
66
|
+
```
|
67
|
+
|
68
|
+
|
69
|
+
Full Rails config:
|
70
|
+
```ruby
|
71
|
+
config.action_mailer.delivery_method = :smtp
|
72
|
+
# [mailcatcher](https://github.com/sj26/mailcatcher) fallback:
|
73
|
+
config.action_mailer.smtp_settings = URI(ENV.fetch("SMTP_URL", "smtp://127.0.0.1:1025")).to_h(format: :am)
|
74
|
+
```
|
75
|
+
|
76
|
+
## SMTP-URI
|
77
|
+
|
78
|
+
There's no official specification for SMTP-URIs. There's some prior work though. This implementation is heavily inspired by [aerc](https://git.sr.ht/~rjarry/aerc/tree/master/item/doc/aerc-smtp.5.scd).
|
79
|
+
|
80
|
+
`<scheme>[+<auth>]://[<user>[:<password>]@]<host>[:<port>][?<query>][#<fragment>]`
|
81
|
+
|
82
|
+
### scheme
|
83
|
+
|
84
|
+
- `smtp`
|
85
|
+
SMTP with STARTTLS (i.e. `url.starttls #=> :always`).
|
86
|
+
- `smtp+insecure`
|
87
|
+
SMTP without STARTTLS (i.e. `url.starttls #=> false`)..
|
88
|
+
- `smtps`
|
89
|
+
SMTP with TLS.
|
90
|
+
|
91
|
+
> [!NOTE]
|
92
|
+
> to get `url.starttls #=> :auto`, provide it in the query: `smtp://foo?auth=auto`. In that case `net-smtp` uses STARTTLS when the server supports it (but won't halt like when using `:always`).
|
93
|
+
|
94
|
+
|
95
|
+
### auth
|
96
|
+
|
97
|
+
There's no restriction to the value of auth. Though the following values have special meaning:
|
98
|
+
|
99
|
+
- `none`
|
100
|
+
No authentication is required.
|
101
|
+
- `plain`
|
102
|
+
Authenticate with a username and password using AUTH PLAIN. This is the default behavior.
|
103
|
+
|
104
|
+
> [!NOTE]
|
105
|
+
> any query's value for `auth` takes precedence.
|
106
|
+
|
107
|
+
### Examples
|
108
|
+
|
109
|
+
| SMTP URI | TLS? | Port | STARTTLS | Auth Method | Notes |
|
110
|
+
|----------|---------|------|----------|-------------|-------|
|
111
|
+
| `smtp://smtp.example.com` | ❌ | 587 | ⚡ | none | Standard submission with STARTTLS `:always` |
|
112
|
+
| `smtp+insecure://smtp.example.com` | ❌ | 587 | ❌ | none | Standard submission without STARTTLS |
|
113
|
+
| `smtp+insecure+login://user:pass@smtp.example.com` | ❌ | 587 | ❌ | login | Authenticate insecurely using LOGIN auth |
|
114
|
+
| `smtp://smtp.example.com?starttls=auto` | ❌ | 587 | 🔄 | none | Standard submission with STARTTLS `:auto` |
|
115
|
+
| `smtp://smtp.example.com:1025` | ❌ | 1025 | ⚡ | none | Standard submission with STARTTLS `:always` on custom port |
|
116
|
+
| `smtp://user:pass@mail.example.com` | ❌ | 587 | ⚡ | plain | STARTTLS `:always` with (default) PLAIN auth |
|
117
|
+
| `smtp+login://user:pass@mail.example.com` | ❌ | 587 | ⚡ | login | STARTTLS `:always` with LOGIN auth |
|
118
|
+
| `smtp+none://mail.example.com` | ❌ | 587 | 🔄 | none | Explicit no authentication |
|
119
|
+
| `smtps://mail.example.com` | ✅ | 465 | ❌ | none | Direct TLS connection |
|
120
|
+
| `smtps://mail.example.com?domain=sender.org&read_timeout=5&open_timeout=5` | ✅ | 465 | ❌ | none | `domain`, `read_timeout` and `open_timeout` set |
|
121
|
+
| `smtps+login://user@imap.gmail.com` | ✅ | 465 | ❌ | login | Direct TLS with LOGIN auth |
|
122
|
+
| `smtps://user%40gmail.com:p%40ss@imap.gmail.com` | ✅ | 465 | ❌ | login | Direct TLS with encoded userinfo `user@gmail.com:p@ss` |
|
123
|
+
| `smtp://localhost` | ❌ | 25 | ❌ | none | Local delivery (no encryption) |
|
124
|
+
| `smtp://127.0.0.1` | ❌ | 25 | ❌ | none | Local delivery (no encryption) |
|
125
|
+
|
126
|
+
**Legend**
|
127
|
+
|
128
|
+
`STARTTLS`
|
129
|
+
- ⚡ = `:always`
|
130
|
+
Require STARTTLS (i.e. `net-smtp` aborts when server doesn't support STARTTLS).
|
131
|
+
- 🔄 = `:auto`
|
132
|
+
Use STARTTLS if supported by server.
|
133
|
+
- ❌ = `false`
|
134
|
+
No STARTTLS. This is always the case when using TLS.
|
21
135
|
|
22
136
|
## Development
|
23
137
|
|
data/lib/uri/smtp/version.rb
CHANGED
data/lib/uri/smtp.rb
CHANGED
@@ -81,13 +81,23 @@ module URI
|
|
81
81
|
address: host,
|
82
82
|
authentication: auth,
|
83
83
|
domain:,
|
84
|
-
enable_starttls: starttls,
|
85
|
-
|
84
|
+
enable_starttls: starttls == :always,
|
85
|
+
enable_starttls_auto: starttls == :auto,
|
86
|
+
port:,
|
87
|
+
tls:
|
86
88
|
}.tap do
|
87
89
|
unless _1[:authentication].nil?
|
88
90
|
_1[:user_name] = decoded_user
|
89
91
|
_1[:password] = decoded_password
|
90
92
|
end
|
93
|
+
# mail 2.8.1 logic is faulty in that it shortcuts
|
94
|
+
# (start)tls-settings when they are false.
|
95
|
+
# So we delete these flags.
|
96
|
+
_1.delete(:tls) unless _1[:tls]
|
97
|
+
_1.delete(:enable_starttls) unless _1[:enable_starttls]
|
98
|
+
_1.delete(:enable_starttls) if _1[:tls]
|
99
|
+
_1.delete(:enable_starttls_auto) unless _1[:enable_starttls_auto]
|
100
|
+
_1.delete(:enable_starttls_auto) if _1[:tls]
|
91
101
|
end.delete_if { |_k, v| v.nil? }
|
92
102
|
else
|
93
103
|
{
|
@@ -118,7 +128,7 @@ end
|
|
118
128
|
|
119
129
|
module UriSmtpExtensions
|
120
130
|
def parse(uri)
|
121
|
-
if uri.start_with?("smtp")
|
131
|
+
if uri.is_a?(String) && uri.start_with?("smtp")
|
122
132
|
return URI::SMTP.parse(uri)
|
123
133
|
end
|
124
134
|
|