gravity_mailbox 0.3.0 → 0.4.1

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 570d181cfe915276f4974ccfcf0d3e155201ab1b801ace546f8f3f492072640d
4
- data.tar.gz: 4bfa2c3ae452251cd56fd5cbcfb8da0dda6b3ec967df6310cb192881dc23c14f
3
+ metadata.gz: 5835a90d8c0976603d428e309d93cf986c01acdae1828a552a66c863cd313e80
4
+ data.tar.gz: 6827f99d05b9fab10df3622879f1afaabd1b1dbc25a7ed225413b16eb1b70b52
5
5
  SHA512:
6
- metadata.gz: 38e58ed90b91cd01fd22b4ce0d6643a1a747fc195681c83d43a8831ba73f956ff1fca06c60f197fa38443f6c4cbf0c40c6c2b2dd0de150c8eb9b60e3f9e22a85
7
- data.tar.gz: 3cb194679c08136d8ab6f4957a5651e346dff20c710b54f28649e9db3d82f4a0080ccd64eddfcc052d71783e49cd2e98b44ea8ec033d5839d28a1d659524279d
6
+ metadata.gz: ff917785d1ce22c4026d320d251b0c4430878105903fa18469901dbc6bfdfb6151a792b92b7b66a49d9cf177df5e069c098cdfe0aa6c733ec29edeb9da84ffed
7
+ data.tar.gz: 013eb6ca9e93c6d61e07fec711a07dda29de59af08402e6f48e94410f576b0af09986effc8051c44c003b6fc05f2d034436b16b341359ba2a86e1c05537975f6
data/README.md CHANGED
@@ -29,13 +29,28 @@ Or install it yourself as:
29
29
  * Config ActionMailer to use the RailsCacheDeliveryMethod.
30
30
 
31
31
  ```ruby
32
+ # config/environments/(development|staging).rb
32
33
  config.action_mailer.delivery_method = :gravity_mailbox_rails_cache
33
34
  config.action_mailer.perform_deliveries = true
34
35
  ```
35
36
 
37
+ * Mount the Engine
38
+
39
+ ```ruby
40
+ # config/routes.rb
41
+ mount GravityMailbox::Engine => "/gravity_mailbox"
42
+ ```
43
+
36
44
  * Send mails
37
45
  * Go to http://localhost:3000/gravity_mailbox to see the mails.
38
46
 
47
+ **Note**
48
+
49
+ You can use routing constraints to restrict access to GravityMailbox. More details and example in the [Rails Guides](https://guides.rubyonrails.org/routing.html#advanced-constraints).
50
+
51
+
52
+ ## Screenshots
53
+
39
54
  <p align="center">
40
55
  <img width="520" alt="image" src="https://user-images.githubusercontent.com/7858787/213796119-a22ac9da-3943-4cd0-95e6-2fb724de999a.png">
41
56
  </p>
@@ -46,6 +61,11 @@ After checking out the repo, run `bin/setup` to install dependencies. Then, run
46
61
 
47
62
  To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
48
63
 
64
+ ### Standalone app
65
+
66
+ Use `bundle exec rackup` to test locally the gem. Go to [http://localhost:9292](http://localhost:9292)
67
+ Use the button to send a test mail and to see those mail into GravityMailbox.
68
+
49
69
  ## Contributing
50
70
 
51
71
  Bug reports and pull requests are welcome on GitHub at https://github.com/petalmd/gravity_mailbox.
@@ -1,19 +1,19 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require 'action_controller'
4
+
3
5
  module GravityMailbox
4
6
  class MailboxController < ActionController::Base
5
- self.view_paths = File.expand_path('templates', __dir__)
6
-
7
- layout 'application'
7
+ layout 'gravity_mailbox'
8
8
 
9
9
  before_action :set_mails, only: %i[index]
10
10
 
11
11
  def index
12
- @part = find_preferred_part(request.format, Mime[:html], Mime[:text]) if @mail
12
+ @part = find_preferred_part(*[request.format, Mime[:html], Mime[:text]].uniq) if @mail
13
13
  return unless params[:part]
14
14
 
15
15
  response.content_type = 'text/html'
16
- render plain: email_body
16
+ render plain: @part&.decoded
17
17
  end
18
18
 
19
19
  def download_eml
@@ -34,18 +34,14 @@ module GravityMailbox
34
34
  private
35
35
 
36
36
  def find_preferred_part(*formats)
37
- formats.each do |format|
38
- part = @mail.find_first_mime_type(format)
39
- return part if part
37
+ if @mail.multipart?
38
+ formats.each do |format|
39
+ part = @mail.find_first_mime_type(format)
40
+ return part if part
41
+ end
42
+ elsif formats.include?(@mail.mime_type)
43
+ @mail.body
40
44
  end
41
-
42
- return unless formats.any? { |f| @mail.mime_type == f }
43
-
44
- @mail
45
- end
46
-
47
- def email_body
48
- @mail.part[1].body.decoded
49
45
  end
50
46
 
51
47
  def set_mails
@@ -0,0 +1,18 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <meta name="viewport" content="width=device-width"/>
5
+ <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bulma@0.9.4/css/bulma.min.css">
6
+ <link rel="preconnect" href="https://fonts.googleapis.com">
7
+ <link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
8
+ <link href="https://fonts.googleapis.com/css2?family=Righteous&display=swap" rel="stylesheet">
9
+ <style>
10
+ <%= yield :style %>
11
+ </style>
12
+ </head>
13
+ <body>
14
+ <%= yield %>
15
+ <script type="module" src="https://unpkg.com/ionicons@5.5.2/dist/ionicons/ionicons.esm.js"></script>
16
+ <script nomodule src="https://unpkg.com/ionicons@5.5.2/dist/ionicons/ionicons.js"></script>
17
+ </body>
18
+ </html>
data/config/routes.rb ADDED
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ GravityMailbox::Engine.routes.draw do
4
+ get '/' => 'mailbox#index', as: :index
5
+ get 'download_eml' => 'mailbox#download_eml'
6
+ post 'delete' => 'mailbox#delete'
7
+ post 'delete_all' => 'mailbox#delete_all'
8
+ end
@@ -0,0 +1,19 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'rails'
4
+ require_relative 'rails_cache_delivery_method'
5
+
6
+ module GravityMailbox
7
+ class Engine < ::Rails::Engine # :nodoc:
8
+ isolate_namespace(GravityMailbox)
9
+
10
+ initializer 'gravity_mailbox.add_delivery_method' do
11
+ ActiveSupport.on_load :action_mailer do
12
+ ActionMailer::Base.add_delivery_method(
13
+ :gravity_mailbox_rails_cache,
14
+ RailsCacheDeliveryMethod
15
+ )
16
+ end
17
+ end
18
+ end
19
+ end
@@ -1,12 +1,16 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require 'mail'
4
+
3
5
  module GravityMailbox
4
6
  class RailsCacheDeliveryMethod
5
7
  KEY_PREFIX = 'gravity_mailbox/'
6
8
  MAILS_LIST_KEY = "#{KEY_PREFIX}list"
7
9
 
8
- def initialize(options)
9
- @options = options
10
+ attr_accessor :settings
11
+
12
+ def initialize(settings)
13
+ @settings = settings
10
14
  end
11
15
 
12
16
  def deliver!(mail)
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module GravityMailbox
4
- VERSION = '0.3.0'
4
+ VERSION = '0.4.1'
5
5
  end
@@ -1,8 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require_relative 'gravity_mailbox/version'
4
- require_relative 'gravity_mailbox/rails_cache_delivery_method'
5
- require_relative 'gravity_mailbox/railtie' if defined?(Rails)
4
+ require_relative 'gravity_mailbox/engine'
6
5
 
7
6
  module GravityMailbox
8
7
  end
metadata CHANGED
@@ -1,43 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gravity_mailbox
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.4.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jean-Francis Bastien
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-01-20 00:00:00.000000000 Z
11
+ date: 2023-06-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
- name: actionmailer
14
+ name: rails
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
17
  - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: '5.2'
19
+ version: '6.0'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - ">="
25
25
  - !ruby/object:Gem::Version
26
- version: '5.2'
27
- - !ruby/object:Gem::Dependency
28
- name: railties
29
- requirement: !ruby/object:Gem::Requirement
30
- requirements:
31
- - - ">="
32
- - !ruby/object:Gem::Version
33
- version: '5.2'
34
- type: :runtime
35
- prerelease: false
36
- version_requirements: !ruby/object:Gem::Requirement
37
- requirements:
38
- - - ">="
39
- - !ruby/object:Gem::Version
40
- version: '5.2'
26
+ version: '6.0'
41
27
  description: Development tools that aim to make it simple to visualize mail sent by
42
28
  your Rails app directly through your Rails app.
43
29
  email:
@@ -50,13 +36,14 @@ extra_rdoc_files:
50
36
  files:
51
37
  - LICENSE.txt
52
38
  - README.md
39
+ - app/controllers/gravity_mailbox/mailbox_controller.rb
40
+ - app/views/gravity_mailbox/mailbox/_mail.html.erb
41
+ - app/views/gravity_mailbox/mailbox/index.html.erb
42
+ - app/views/layouts/gravity_mailbox.html.erb
43
+ - config/routes.rb
53
44
  - lib/gravity_mailbox.rb
54
- - lib/gravity_mailbox/mailbox_controller.rb
45
+ - lib/gravity_mailbox/engine.rb
55
46
  - lib/gravity_mailbox/rails_cache_delivery_method.rb
56
- - lib/gravity_mailbox/railtie.rb
57
- - lib/gravity_mailbox/templates/gravity_mailbox/mailbox/_mail.html.erb
58
- - lib/gravity_mailbox/templates/gravity_mailbox/mailbox/index.html.erb
59
- - lib/gravity_mailbox/templates/layouts/application.html.erb
60
47
  - lib/gravity_mailbox/version.rb
61
48
  homepage: https://github.com/petalmd/gravity_mailbox
62
49
  licenses:
@@ -82,7 +69,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
82
69
  - !ruby/object:Gem::Version
83
70
  version: '0'
84
71
  requirements: []
85
- rubygems_version: 3.0.3
72
+ rubygems_version: 3.2.3
86
73
  signing_key:
87
74
  specification_version: 4
88
75
  summary: Visualize mail sent by your Rails app directly through your Rails app.
@@ -1,25 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require_relative 'mailbox_controller'
4
-
5
- module GravityMailbox
6
- class Railtie < ::Rails::Railtie # :nodoc:
7
- initializer 'gravity_mailbox.add_delivery_method' do
8
- ActiveSupport.on_load :action_mailer do
9
- ActionMailer::Base.add_delivery_method(
10
- :gravity_mailbox_rails_cache,
11
- RailsCacheDeliveryMethod
12
- )
13
- end
14
- end
15
-
16
- config.after_initialize do |app|
17
- app.routes.prepend do
18
- get '/gravity_mailbox' => 'gravity_mailbox/mailbox#index', internal: true
19
- post '/gravity_mailbox/delete_all' => 'gravity_mailbox/mailbox#delete_all', internal: true
20
- get '/gravity_mailbox/download_eml' => 'gravity_mailbox/mailbox#download_eml', internal: true
21
- post '/gravity_mailbox/delete' => 'gravity_mailbox/mailbox#delete', internal: true
22
- end
23
- end
24
- end
25
- end
@@ -1,18 +0,0 @@
1
- <!DOCTYPE html>
2
- <html>
3
- <head>
4
- <meta name="viewport" content="width=device-width" />
5
- <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bulma@0.9.4/css/bulma.min.css">
6
- <link rel="preconnect" href="https://fonts.googleapis.com">
7
- <link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
8
- <link href="https://fonts.googleapis.com/css2?family=Righteous&display=swap" rel="stylesheet">
9
- <style>
10
- <%= yield :style %>
11
- </style>
12
- </head>
13
- <body>
14
- <%= yield %>
15
- <script type="module" src="https://unpkg.com/ionicons@5.5.2/dist/ionicons/ionicons.esm.js"></script>
16
- <script nomodule src="https://unpkg.com/ionicons@5.5.2/dist/ionicons/ionicons.js"></script>
17
- </body>
18
- </html>