rails_email 0.1.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 +7 -0
- data/README.md +159 -0
- data/app/views/rails/mailers/_scripts.html.erb +344 -0
- data/app/views/rails/mailers/_sidebar.html.erb +26 -0
- data/app/views/rails/mailers/_styles.html.erb +299 -0
- data/app/views/rails/mailers/email.html.erb +257 -0
- data/app/views/rails/mailers/index.html.erb +73 -0
- data/app/views/rails/mailers/mailer.html.erb +49 -0
- data/lib/rails_email/engine.rb +60 -0
- data/lib/rails_email/version.rb +3 -0
- data/lib/rails_email.rb +2 -0
- metadata +48 -0
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
<% if @preview.emails.any? %>
|
|
2
|
+
<script>
|
|
3
|
+
window.location.replace("<%= url_for(controller: 'rails/mailers', action: 'preview', path: "#{@preview.preview_name}/#{@preview.emails.first}") %>");
|
|
4
|
+
</script>
|
|
5
|
+
<% else %>
|
|
6
|
+
<!DOCTYPE html>
|
|
7
|
+
<html data-theme="dark">
|
|
8
|
+
<head>
|
|
9
|
+
<meta charset="utf-8">
|
|
10
|
+
<meta name="viewport" content="width=device-width">
|
|
11
|
+
<title><%= @preview.preview_name %> — rails mail</title>
|
|
12
|
+
<%= render "rails/mailers/styles" %>
|
|
13
|
+
</head>
|
|
14
|
+
<body>
|
|
15
|
+
<div class="rm-app">
|
|
16
|
+
<nav class="rm-nav">
|
|
17
|
+
<div class="rm-nav-left">
|
|
18
|
+
<a class="rm-logo" href="<%= url_for(controller: 'rails/mailers', action: 'index') %>">
|
|
19
|
+
<svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round">
|
|
20
|
+
<rect x="2" y="4" width="20" height="16" rx="2"/>
|
|
21
|
+
<path d="m22 7-8.97 5.7a1.94 1.94 0 0 1-2.06 0L2 7"/>
|
|
22
|
+
</svg>
|
|
23
|
+
rails mail
|
|
24
|
+
</a>
|
|
25
|
+
</div>
|
|
26
|
+
<div class="rm-nav-center">
|
|
27
|
+
<span class="rm-breadcrumb"><%= @preview.preview_name %></span>
|
|
28
|
+
</div>
|
|
29
|
+
<div class="rm-nav-right">
|
|
30
|
+
<button class="rm-icon-btn" onclick="rmToggleTheme()" title="Toggle theme">
|
|
31
|
+
<svg id="rm-icon-moon" width="15" height="15" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"><path d="M12 3a6 6 0 0 0 9 9 9 9 0 1 1-9-9Z"/></svg>
|
|
32
|
+
<svg id="rm-icon-sun" class="hidden" width="15" height="15" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"><circle cx="12" cy="12" r="4"/><path d="M12 2v2M12 20v2M4.93 4.93l1.41 1.41M17.66 17.66l1.41 1.41M2 12h2M20 12h2M6.34 17.66l-1.41 1.41M19.07 4.93l-1.41 1.41"/></svg>
|
|
33
|
+
</button>
|
|
34
|
+
</div>
|
|
35
|
+
</nav>
|
|
36
|
+
<div class="rm-body">
|
|
37
|
+
<%= render "rails/mailers/sidebar", active_preview: @preview, active_action: nil %>
|
|
38
|
+
<main class="rm-main">
|
|
39
|
+
<div class="rm-empty">
|
|
40
|
+
<h2>No preview methods defined</h2>
|
|
41
|
+
<p>Add methods to <code style="font-family: monospace; font-size: 11px;"><%= @preview.name %></code></p>
|
|
42
|
+
</div>
|
|
43
|
+
</main>
|
|
44
|
+
</div>
|
|
45
|
+
</div>
|
|
46
|
+
<%= render "rails/mailers/scripts" %>
|
|
47
|
+
</body>
|
|
48
|
+
</html>
|
|
49
|
+
<% end %>
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
module RailsEmail
|
|
2
|
+
# Isolated module so the method survives Rails code reloading
|
|
3
|
+
module MailersControllerExtension
|
|
4
|
+
def spam_check
|
|
5
|
+
require "net/http"
|
|
6
|
+
require "json"
|
|
7
|
+
|
|
8
|
+
find_preview
|
|
9
|
+
email_action = File.basename(params[:path])
|
|
10
|
+
|
|
11
|
+
unless @preview.email_exists?(email_action)
|
|
12
|
+
render json: { error: "Email '#{email_action}' not found" }, status: :not_found
|
|
13
|
+
return
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
email = @preview.call(email_action, params)
|
|
17
|
+
raw = email.to_s
|
|
18
|
+
|
|
19
|
+
uri = URI("https://spamcheck.postmarkapp.com/filter")
|
|
20
|
+
http = Net::HTTP.new(uri.host, uri.port)
|
|
21
|
+
http.use_ssl = true
|
|
22
|
+
http.verify_mode = OpenSSL::SSL::VERIFY_PEER
|
|
23
|
+
|
|
24
|
+
# OpenSSL 3.x tries to fetch the CRL for intermediate certs and fails
|
|
25
|
+
# when the distribution point is unreachable (error code 3 =
|
|
26
|
+
# V_ERR_UNABLE_TO_GET_CRL). Skip only that error; enforce everything else.
|
|
27
|
+
crl_err = OpenSSL::X509::V_ERR_UNABLE_TO_GET_CRL rescue 3
|
|
28
|
+
http.verify_callback = proc do |ok, ctx|
|
|
29
|
+
ok || ctx.error == crl_err
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
req = Net::HTTP::Post.new(uri, "Content-Type" => "application/json")
|
|
33
|
+
req.body = { email: raw, options: "long" }.to_json
|
|
34
|
+
res = http.request(req)
|
|
35
|
+
render json: JSON.parse(res.body)
|
|
36
|
+
rescue => e
|
|
37
|
+
render json: { error: e.message }, status: :unprocessable_entity
|
|
38
|
+
end
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
class Engine < ::Rails::Engine
|
|
42
|
+
# Must be prepended so it wins over ActionMailer's wildcard /*path
|
|
43
|
+
initializer "rails_email.routes" do
|
|
44
|
+
Rails.application.routes.prepend do
|
|
45
|
+
get "/rails/mailers/spam_check/*path", to: "rails/mailers#spam_check"
|
|
46
|
+
end
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
# to_prepare runs after all initializers + after each code reload in development
|
|
50
|
+
config.to_prepare do
|
|
51
|
+
require "rails/mailers_controller"
|
|
52
|
+
|
|
53
|
+
Rails::MailersController.prepend_view_path(
|
|
54
|
+
RailsEmail::Engine.root.join("app/views")
|
|
55
|
+
)
|
|
56
|
+
Rails::MailersController.layout(false)
|
|
57
|
+
Rails::MailersController.include(RailsEmail::MailersControllerExtension)
|
|
58
|
+
end
|
|
59
|
+
end
|
|
60
|
+
end
|
data/lib/rails_email.rb
ADDED
metadata
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: rails_email
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.1.0
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- Facundo
|
|
8
|
+
bindir: bin
|
|
9
|
+
cert_chain: []
|
|
10
|
+
date: 1980-01-02 00:00:00.000000000 Z
|
|
11
|
+
dependencies: []
|
|
12
|
+
description: Replaces the /rails/mailers preview UI with a polished React Email-inspired
|
|
13
|
+
interface, while keeping ActionMailer::Preview classes and routes unchanged.
|
|
14
|
+
executables: []
|
|
15
|
+
extensions: []
|
|
16
|
+
extra_rdoc_files: []
|
|
17
|
+
files:
|
|
18
|
+
- README.md
|
|
19
|
+
- app/views/rails/mailers/_scripts.html.erb
|
|
20
|
+
- app/views/rails/mailers/_sidebar.html.erb
|
|
21
|
+
- app/views/rails/mailers/_styles.html.erb
|
|
22
|
+
- app/views/rails/mailers/email.html.erb
|
|
23
|
+
- app/views/rails/mailers/index.html.erb
|
|
24
|
+
- app/views/rails/mailers/mailer.html.erb
|
|
25
|
+
- lib/rails_email.rb
|
|
26
|
+
- lib/rails_email/engine.rb
|
|
27
|
+
- lib/rails_email/version.rb
|
|
28
|
+
licenses:
|
|
29
|
+
- MIT
|
|
30
|
+
metadata: {}
|
|
31
|
+
rdoc_options: []
|
|
32
|
+
require_paths:
|
|
33
|
+
- lib
|
|
34
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
35
|
+
requirements:
|
|
36
|
+
- - ">="
|
|
37
|
+
- !ruby/object:Gem::Version
|
|
38
|
+
version: '3.1'
|
|
39
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
40
|
+
requirements:
|
|
41
|
+
- - ">="
|
|
42
|
+
- !ruby/object:Gem::Version
|
|
43
|
+
version: '0'
|
|
44
|
+
requirements: []
|
|
45
|
+
rubygems_version: 3.6.9
|
|
46
|
+
specification_version: 4
|
|
47
|
+
summary: React Email-style mailer preview UI for Rails
|
|
48
|
+
test_files: []
|