rails-mailer-sandbox 0.2.1 → 0.2.2
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/.yardopts +8 -0
- data/CHANGELOG.md +9 -0
- data/README.md +1 -0
- data/lib/rails_mailer_sandbox/setup.rb +4 -0
- data/lib/rails_mailer_sandbox.rb +62 -4
- metadata +6 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: bf80512fe3b9cd60f5842611ee2a68be8b1f5da0f7198872f5aaf0e62fc9c46a
|
|
4
|
+
data.tar.gz: 8436ff5fa82cf18b5dcb6ea7a905264fcf4bcb638aa711a2f0808528c0aee986
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 755b5e8a9368bd55e3c3221494a95aedef5604da4378c32ec62baa84a9754318c5a586a7dc4dd28a4b7a6fb6e1e27409613ed8059d3affba7398f4c6b511d234
|
|
7
|
+
data.tar.gz: b2a089a3a3b475457052833aac2ba039cd76a7ff39fd25d2bf4aac0c573ebd82cd3e6d7440ec2ae18e77bcd4848964092c604fbb1794bdf4ad88a582cd0b70d2
|
data/.yardopts
ADDED
data/CHANGELOG.md
CHANGED
|
@@ -5,6 +5,14 @@ All notable changes to Rails Mailer Sandbox are documented here.
|
|
|
5
5
|
Format follows [Keep a Changelog](https://keepachangelog.com/en/1.1.0/), and versions
|
|
6
6
|
follow [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
7
7
|
|
|
8
|
+
## [0.2.2] - 2026-09-21
|
|
9
|
+
|
|
10
|
+
### Added
|
|
11
|
+
|
|
12
|
+
- Rubydoc.info documentation metadata and YARD annotations
|
|
13
|
+
- Documentation status badge in README
|
|
14
|
+
- `.yardopts` configuration file
|
|
15
|
+
|
|
8
16
|
## [0.2.1] - 2026-09-13
|
|
9
17
|
|
|
10
18
|
### Added
|
|
@@ -42,5 +50,6 @@ follow [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
|
42
50
|
attachments, automatic refresh, and message deletion
|
|
43
51
|
- `rails_mailer_sandbox:setup` Rake task
|
|
44
52
|
|
|
53
|
+
[0.2.2]: https://github.com/azmi2409/rails-mailer-sandbox/compare/v0.2.1...v0.2.2
|
|
45
54
|
[0.2.1]: https://github.com/azmi2409/rails-mailer-sandbox/compare/v0.2.0...v0.2.1
|
|
46
55
|
[0.2.0]: https://github.com/azmi2409/rails-mailer-sandbox/releases/tag/v0.2.0
|
data/README.md
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
[](https://github.com/azmi2409/rails-mailer-sandbox/actions/workflows/ci.yml)
|
|
4
4
|
[](https://rubygems.org/gems/rails-mailer-sandbox)
|
|
5
|
+
[](https://rubydoc.info/gems/rails-mailer-sandbox)
|
|
5
6
|
[](MIT-LICENSE)
|
|
6
7
|
|
|
7
8
|
Catch Rails emails locally before they escape into the wild. Rails Mailer Sandbox stores
|
|
@@ -3,7 +3,11 @@
|
|
|
3
3
|
require "fileutils"
|
|
4
4
|
|
|
5
5
|
module RailsMailerSandbox
|
|
6
|
+
# Generator for sandbox initializer.
|
|
6
7
|
module Setup
|
|
8
|
+
# Generates initializer and configures routes.
|
|
9
|
+
# @param root [String, Pathname] Rails application root path
|
|
10
|
+
# @return [void]
|
|
7
11
|
def self.run(root)
|
|
8
12
|
root = File.expand_path(root)
|
|
9
13
|
raise "Not a Rails application: #{root}" unless File.file?(File.join(root, "config/application.rb"))
|
data/lib/rails_mailer_sandbox.rb
CHANGED
|
@@ -11,21 +11,48 @@ require "mail"
|
|
|
11
11
|
require "base64"
|
|
12
12
|
require "uri"
|
|
13
13
|
|
|
14
|
+
# Module for local Action Mailer email preview and storage sandbox.
|
|
14
15
|
module RailsMailerSandbox
|
|
15
|
-
VERSION = "0.2.
|
|
16
|
+
VERSION = "0.2.2"
|
|
16
17
|
|
|
17
18
|
class << self
|
|
19
|
+
# @return [String, nil]
|
|
18
20
|
attr_writer :storage_path
|
|
19
21
|
|
|
22
|
+
# Directory where captured emails are stored.
|
|
23
|
+
# @return [String]
|
|
20
24
|
def storage_path
|
|
21
25
|
@storage_path || File.join(defined?(Rails) && Rails.respond_to?(:root) && Rails.root ? Rails.root.to_s : Dir.pwd, "tmp", "rails_mailer_sandbox")
|
|
22
26
|
end
|
|
23
27
|
end
|
|
24
28
|
|
|
29
|
+
# Represents a captured email message.
|
|
25
30
|
class Message
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
31
|
+
# @return [String] Unique message identifier
|
|
32
|
+
attr_reader :id
|
|
33
|
+
# @return [Array<String>] Sender email addresses
|
|
34
|
+
attr_reader :from
|
|
35
|
+
# @return [Array<String>] Recipient email addresses
|
|
36
|
+
attr_reader :to
|
|
37
|
+
# @return [Array<String>] CC recipient email addresses
|
|
38
|
+
attr_reader :cc
|
|
39
|
+
# @return [Array<String>] BCC recipient email addresses
|
|
40
|
+
attr_reader :bcc
|
|
41
|
+
# @return [String] Email subject line
|
|
42
|
+
attr_reader :subject
|
|
43
|
+
# @return [Time, DateTime] Message timestamp
|
|
44
|
+
attr_reader :date
|
|
45
|
+
# @return [String, nil] Plain text body
|
|
46
|
+
attr_reader :text_part
|
|
47
|
+
# @return [String, nil] HTML body
|
|
48
|
+
attr_reader :html_part
|
|
49
|
+
# @return [String] Raw MIME message source
|
|
50
|
+
attr_reader :raw_source
|
|
51
|
+
# @return [Array<Hash{Symbol => Object}>] Parsed attachments
|
|
52
|
+
attr_reader :attachments
|
|
53
|
+
|
|
54
|
+
# @param mail [Mail::Message]
|
|
55
|
+
# @param id [String]
|
|
29
56
|
def initialize(mail, id: SecureRandom.uuid)
|
|
30
57
|
@id = id
|
|
31
58
|
@date = mail.date || Time.now
|
|
@@ -40,18 +67,23 @@ module RailsMailerSandbox
|
|
|
40
67
|
@raw_source = "Bcc: #{@bcc.join(', ').gsub(/[\r\n]/, '')}\r\n#{@raw_source}" unless @bcc.empty? || @raw_source.match?(/^Bcc:/i)
|
|
41
68
|
end
|
|
42
69
|
|
|
70
|
+
# @return [Array<String>]
|
|
43
71
|
def recipients
|
|
44
72
|
to + cc + bcc
|
|
45
73
|
end
|
|
46
74
|
|
|
75
|
+
# @return [String]
|
|
47
76
|
def preview
|
|
48
77
|
text_part.to_s.gsub(/\s+/, " ").strip[0, 140]
|
|
49
78
|
end
|
|
50
79
|
|
|
80
|
+
# @return [Integer]
|
|
51
81
|
def size
|
|
52
82
|
raw_source.bytesize
|
|
53
83
|
end
|
|
54
84
|
|
|
85
|
+
# @param query [String]
|
|
86
|
+
# @return [Boolean]
|
|
55
87
|
def matches?(query)
|
|
56
88
|
query.empty? || [subject, *from, *recipients, text_part.to_s].any? { |value| value.downcase.include?(query) }
|
|
57
89
|
end
|
|
@@ -97,8 +129,12 @@ module RailsMailerSandbox
|
|
|
97
129
|
end
|
|
98
130
|
end
|
|
99
131
|
|
|
132
|
+
# Thread-safe filesystem storage for captured emails.
|
|
100
133
|
class Storage
|
|
101
134
|
class << self
|
|
135
|
+
# Stores an email message.
|
|
136
|
+
# @param mail [Mail::Message]
|
|
137
|
+
# @return [Message]
|
|
102
138
|
def add(mail)
|
|
103
139
|
message = Message.new(mail)
|
|
104
140
|
locked do |directory|
|
|
@@ -117,6 +153,8 @@ module RailsMailerSandbox
|
|
|
117
153
|
message
|
|
118
154
|
end
|
|
119
155
|
|
|
156
|
+
# Returns all stored messages, ordered newest first.
|
|
157
|
+
# @return [Array<Message>]
|
|
120
158
|
def all
|
|
121
159
|
locked do |directory|
|
|
122
160
|
Dir.glob(File.join(directory, "*.eml")).sort_by { |path| [File.mtime(path), path] }.reverse.map do |path|
|
|
@@ -125,6 +163,9 @@ module RailsMailerSandbox
|
|
|
125
163
|
end
|
|
126
164
|
end
|
|
127
165
|
|
|
166
|
+
# Finds message by UUID.
|
|
167
|
+
# @param id [String]
|
|
168
|
+
# @return [Message, nil]
|
|
128
169
|
def find(id)
|
|
129
170
|
return unless valid_id?(id)
|
|
130
171
|
locked do |directory|
|
|
@@ -133,6 +174,9 @@ module RailsMailerSandbox
|
|
|
133
174
|
end
|
|
134
175
|
end
|
|
135
176
|
|
|
177
|
+
# Deletes message by UUID.
|
|
178
|
+
# @param id [String]
|
|
179
|
+
# @return [Boolean, nil]
|
|
136
180
|
def delete(id)
|
|
137
181
|
return unless valid_id?(id)
|
|
138
182
|
locked do |directory|
|
|
@@ -141,10 +185,14 @@ module RailsMailerSandbox
|
|
|
141
185
|
end
|
|
142
186
|
end
|
|
143
187
|
|
|
188
|
+
# Clears all stored messages.
|
|
189
|
+
# @return [Array<String>]
|
|
144
190
|
def clear
|
|
145
191
|
locked { |directory| Dir.glob(File.join(directory, "*.eml")).each { |path| File.delete(path) } }
|
|
146
192
|
end
|
|
147
193
|
|
|
194
|
+
# Returns count of stored messages.
|
|
195
|
+
# @return [Integer]
|
|
148
196
|
def count
|
|
149
197
|
locked { |directory| Dir.glob(File.join(directory, "*.eml")).size }
|
|
150
198
|
end
|
|
@@ -169,18 +217,25 @@ module RailsMailerSandbox
|
|
|
169
217
|
end
|
|
170
218
|
end
|
|
171
219
|
|
|
220
|
+
# Action Mailer delivery method for sandbox storage.
|
|
172
221
|
class DeliveryMethod
|
|
222
|
+
# @return [Hash]
|
|
173
223
|
attr_accessor :settings
|
|
174
224
|
|
|
225
|
+
# @param values [Hash]
|
|
175
226
|
def initialize(values = {})
|
|
176
227
|
@settings = values
|
|
177
228
|
end
|
|
178
229
|
|
|
230
|
+
# Stores incoming email.
|
|
231
|
+
# @param mail [Mail::Message]
|
|
232
|
+
# @return [Message]
|
|
179
233
|
def deliver!(mail)
|
|
180
234
|
Storage.add(mail)
|
|
181
235
|
end
|
|
182
236
|
end
|
|
183
237
|
|
|
238
|
+
# Rack application providing Web UI to inspect captured emails.
|
|
184
239
|
class Server
|
|
185
240
|
SECURITY_HEADERS = {
|
|
186
241
|
"content-security-policy" => "default-src 'self'; style-src 'unsafe-inline'; script-src 'unsafe-inline'; frame-src 'self'; img-src 'self' data:; object-src 'none'; base-uri 'none'; frame-ancestors 'self'",
|
|
@@ -189,6 +244,9 @@ module RailsMailerSandbox
|
|
|
189
244
|
"x-frame-options" => "SAMEORIGIN"
|
|
190
245
|
}.freeze
|
|
191
246
|
|
|
247
|
+
# Rack call entrypoint.
|
|
248
|
+
# @param env [Hash]
|
|
249
|
+
# @return [Array]
|
|
192
250
|
def call(env)
|
|
193
251
|
request = Rack::Request.new(env)
|
|
194
252
|
response = route(request)
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: rails-mailer-sandbox
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.2.
|
|
4
|
+
version: 0.2.2
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- azmimuwahid
|
|
@@ -73,6 +73,7 @@ executables: []
|
|
|
73
73
|
extensions: []
|
|
74
74
|
extra_rdoc_files: []
|
|
75
75
|
files:
|
|
76
|
+
- ".yardopts"
|
|
76
77
|
- CHANGELOG.md
|
|
77
78
|
- CONTRIBUTING.md
|
|
78
79
|
- MIT-LICENSE
|
|
@@ -84,7 +85,10 @@ files:
|
|
|
84
85
|
homepage: https://github.com/azmi2409/rails-mailer-sandbox
|
|
85
86
|
licenses:
|
|
86
87
|
- MIT
|
|
87
|
-
metadata:
|
|
88
|
+
metadata:
|
|
89
|
+
documentation_uri: https://rubydoc.info/gems/rails-mailer-sandbox
|
|
90
|
+
source_code_uri: https://github.com/azmi2409/rails-mailer-sandbox
|
|
91
|
+
changelog_uri: https://github.com/azmi2409/rails-mailer-sandbox/blob/main/CHANGELOG.md
|
|
88
92
|
rdoc_options: []
|
|
89
93
|
require_paths:
|
|
90
94
|
- lib
|