draft_box 0.0.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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: e3fefedd7a473d1101e01fc2577793271f1a31fc642e8487c3bc60816a982291
4
+ data.tar.gz: 8d3d685787454a383ad1184d763fe8c0546bce85b33c4aabdbae3570e90d500c
5
+ SHA512:
6
+ metadata.gz: 8995b11fd93e62153dde02c26d074671e9dee9c71fb9196f0ffe4c33067b3b6fa06c3e3fa8055e37a389171df83493135e1c29154452c777866314ff9673a19a
7
+ data.tar.gz: f86a3b3102af31ce86e356304c9ea9428d27bd2d258712a35bf5f90c1eaf6a81be3ec9aebf924f14e7ce2b4936d5caf2e64fad0480d056cd62cf1592f966cfd2
@@ -0,0 +1,57 @@
1
+ module DraftBox
2
+ class DeliveryMethod
3
+ attr_accessor :settings
4
+
5
+ def initialize(options = {})
6
+ self.settings = options
7
+ end
8
+
9
+ def deliver!(mail)
10
+ validate_mail!(mail)
11
+
12
+ # subject: mail.subject
13
+ # body: mail.body.to_s
14
+ # from: mail.from
15
+ # to: mail.to
16
+ # cc: mail.cc
17
+ # bcc: mail.bcc
18
+ # attachments: mail.attachments
19
+
20
+ # Attachment:
21
+ # filename: attachment.filename
22
+ # content_type: attachment.content_type
23
+ # content: attachment.body.to_s
24
+
25
+ ActiveRecord::Base.transaction do
26
+ email = DraftBox::Email.create!(
27
+ subject: mail.subject,
28
+ body: mail.parts.empty? ? mail.body.to_s : mail.parts.find { |p| p.content_type.start_with?('text/html', 'text/plain') }&.body.to_s,
29
+ from: mail.from.first,
30
+ to: mail.to,
31
+ cc: mail.cc,
32
+ bcc: mail.bcc
33
+ )
34
+
35
+ mail.attachments.each do |attachment|
36
+ email.attachments.create!(
37
+ filename: attachment.filename,
38
+ content_type: attachment.content_type,
39
+ data: attachment.body.to_s
40
+ )
41
+ end
42
+ end
43
+ end
44
+
45
+ private
46
+
47
+ def validate_mail!(mail)
48
+ if !mail.smtp_envelope_from || mail.smtp_envelope_from.empty?
49
+ raise ArgumentError, "SMTP From address may not be blank"
50
+ end
51
+
52
+ if !mail.smtp_envelope_to || mail.smtp_envelope_to.empty?
53
+ raise ArgumentError, "SMTP To address may not be blank"
54
+ end
55
+ end
56
+ end
57
+ end
@@ -0,0 +1,17 @@
1
+ require 'draft_box/delivery_method'
2
+
3
+ module DraftBox
4
+ class Engine < ::Rails::Engine
5
+ isolate_namespace DraftBox
6
+
7
+ initializer 'draft_box.add_delivery_method' do
8
+ ActiveSupport.on_load :action_mailer do
9
+ ActionMailer::Base.add_delivery_method(
10
+ :draft_box,
11
+ DraftBox::DeliveryMethod,
12
+ location: ''
13
+ )
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,9 @@
1
+ module DraftBox
2
+ module Version
3
+ module_function
4
+
5
+ def to_s
6
+ '0.0.1'
7
+ end
8
+ end
9
+ end
data/lib/draft_box.rb ADDED
@@ -0,0 +1 @@
1
+ require 'draft_box/engine'
@@ -0,0 +1,35 @@
1
+ require "rails/generators"
2
+
3
+ module Generators
4
+ module DraftBox
5
+ class InstallGenerator < ::Rails::Generators::Base
6
+ source_root File.expand_path("templates", __dir__)
7
+
8
+ namespace "draft_box:install"
9
+ desc "Creates a DraftBox migration files."
10
+
11
+ def create
12
+ timestamp = Time.zone.now.to_s.tr('^0-9', '')[0..13]
13
+ template "emails_migration.rb", "db/migrate/#{timestamp}_create_draft_box_emails.rb"
14
+
15
+ timestamp = (Time.zone.now + 1).to_s.tr('^0-9', '')[0..13]
16
+ template "attachments_migration.rb", "db/migrate/#{timestamp}_create_draft_box_attachments.rb"
17
+ end
18
+
19
+ private
20
+
21
+ def migration_version
22
+ "[#{Rails::VERSION::MAJOR}.#{Rails::VERSION::MINOR}]"
23
+ end
24
+
25
+ def primary_key_type
26
+ primary_key_string
27
+ end
28
+
29
+ def primary_key_string
30
+ key_string = options[:primary_key_type]
31
+ ", id: :#{key_string}" if key_string
32
+ end
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,11 @@
1
+ class CreateDraftBoxAttachments < ActiveRecord::Migration<%= migration_version %>
2
+ def change
3
+ create_table :draft_box_attachments<%= primary_key_type %> do |t|
4
+ t.references :draft_box_email, null: false, foreign_key: true
5
+ t.string :filename
6
+ t.string :content_type
7
+ t.binary :data
8
+ end
9
+ end
10
+ end
11
+
@@ -0,0 +1,14 @@
1
+ class CreateDraftBoxEmails < ActiveRecord::Migration<%= migration_version %>
2
+ def change
3
+ create_table :draft_box_emails<%= primary_key_type %> do |t|
4
+ t.string :subject
5
+ t.text :body
6
+ t.string :from
7
+ t.string :to, array: true, default: []
8
+ t.string :cc, array: true, default: []
9
+ t.string :bcc, array: true, default: []
10
+
11
+ t.timestamps
12
+ end
13
+ end
14
+ end
metadata ADDED
@@ -0,0 +1,50 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: draft_box
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Paweł Dąbrowski
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2024-12-26 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: A web interface for browsing Ruby on Rails sent emails with support for
14
+ distributed environments
15
+ email: contact@paweldabrowski.com
16
+ executables: []
17
+ extensions: []
18
+ extra_rdoc_files: []
19
+ files:
20
+ - lib/draft_box.rb
21
+ - lib/draft_box/delivery_method.rb
22
+ - lib/draft_box/engine.rb
23
+ - lib/draft_box/version.rb
24
+ - lib/generators/draft_box/install_generator.rb
25
+ - lib/generators/draft_box/templates/attachments_migration.rb
26
+ - lib/generators/draft_box/templates/emails_migration.rb
27
+ homepage:
28
+ licenses: []
29
+ metadata: {}
30
+ post_install_message:
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: '0'
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.4.10
46
+ signing_key:
47
+ specification_version: 4
48
+ summary: A web interface for browsing Ruby on Rails sent emails with support for distributed
49
+ environments
50
+ test_files: []