Skip to content

Commit

Permalink
Ok, SendGrid, we'll do it your way.
Browse files Browse the repository at this point in the history
  • Loading branch information
the1banana committed Jul 26, 2023
1 parent 24cfe27 commit c0df234
Show file tree
Hide file tree
Showing 9 changed files with 133 additions and 3 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,5 @@

.env
private/

/config/master.key
3 changes: 3 additions & 0 deletions app/mailboxes/application_mailbox.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
class ApplicationMailbox < ActionMailbox::Base
routing :all => :incomings
end
15 changes: 15 additions & 0 deletions app/mailboxes/incomings_mailbox.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
class IncomingsMailbox < ApplicationMailbox
def process
mail_attachments
end

def mail_body
mail.body.decoded
end

def mail_attachments
mail.mail_attachments.each do |attachment|
# your logic here
end
end
end
1 change: 1 addition & 0 deletions config/credentials.yml.enc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
hlOhSyqh0KJoerA3ojBSyGK+uHvPMsisouAb9oRiX3GllB/R7F4gQjX0+Ipu/ixFRTMYdEl9biq+ZQt9y+4dUsfqzuMjfVkJp2aP8AjZO/3Rc7msUw67V3GLBLWFOdOgIk7to04Ta0OcJCDoqiNj/A1XHCLCdUCfe3E/UKp5XiStCocyvJexri/v4D3TmnvJVUjORdmIAI/8//vK9ElAxBvqLTWHKRWup2VUdqIHd+aelOtur2dHLJ6YO6LUMYSony5T4ubU2FUo1VnSeJU1jTiTPna8fegjhSUQPIrU2gQjdseljXiMhrlyL4y/42hLua/vVHydWACToj1rV3qYXZXg/Zh13rwyZSo2aip8nzJ9OTthihfx7aTsBTXPCxmPxImxSvHbYvBLqO5WIEIvLgf4yZUcFCBZ2cEZwgLn7ZnofRlkluzZxUkGqH0A--WeC7nRLgdXv4ar+D--HTpMvy6AYOiOGdTTfQNtTw==
3 changes: 3 additions & 0 deletions config/environments/production.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
# frozen_string_literal: true

Rails.application.configure do
# Prepare the ingress controller used to receive mail
config.action_mailbox.ingress = :sendgrid

# Settings specified here will take precedence over those in config/application.rb.

# Code is not reloaded between requests.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
# This migration comes from active_storage (originally 20170806125915)
class CreateActiveStorageTables < ActiveRecord::Migration[5.2]
def change
# Use Active Record's configured type for primary and foreign keys
primary_key_type, foreign_key_type = primary_and_foreign_key_types

create_table :active_storage_blobs, id: primary_key_type do |t|
t.string :key, null: false
t.string :filename, null: false
t.string :content_type
t.text :metadata
t.string :service_name, null: false
t.bigint :byte_size, null: false
t.string :checksum, null: false
t.datetime :created_at, null: false

t.index [ :key ], unique: true
end

create_table :active_storage_attachments, id: primary_key_type do |t|
t.string :name, null: false
t.references :record, null: false, polymorphic: true, index: false, type: foreign_key_type
t.references :blob, null: false, type: foreign_key_type

t.datetime :created_at, null: false

t.index [ :record_type, :record_id, :name, :blob_id ], name: "index_active_storage_attachments_uniqueness", unique: true
t.foreign_key :active_storage_blobs, column: :blob_id
end

create_table :active_storage_variant_records, id: primary_key_type do |t|
t.belongs_to :blob, null: false, index: false, type: foreign_key_type
t.string :variation_digest, null: false

t.index %i[ blob_id variation_digest ], name: "index_active_storage_variant_records_uniqueness", unique: true
t.foreign_key :active_storage_blobs, column: :blob_id
end
end

private
def primary_and_foreign_key_types
config = Rails.configuration.generators
setting = config.options[config.orm][:primary_key_type]
primary_key_type = setting || :primary_key
foreign_key_type = setting || :bigint
[primary_key_type, foreign_key_type]
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# This migration comes from action_mailbox (originally 20180917164000)
class CreateActionMailboxTables < ActiveRecord::Migration[6.0]
def change
create_table :action_mailbox_inbound_emails do |t|
t.integer :status, default: 0, null: false
t.string :message_id, null: false
t.string :message_checksum, null: false

t.timestamps

t.index [ :message_id, :message_checksum ], name: "index_action_mailbox_inbound_emails_uniqueness", unique: true
end
end
end
45 changes: 42 additions & 3 deletions db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,56 @@
# of editing this file, please use the migrations feature of Active Record to
# incrementally modify your database, and then regenerate this schema definition.
#
# This file is the source Rails uses to define your schema when running `rails
# db:schema:load`. When creating a new database, `rails db:schema:load` tends to
# This file is the source Rails uses to define your schema when running `bin/rails
# db:schema:load`. When creating a new database, `bin/rails db:schema:load` tends to
# be faster and is potentially less error prone than running all of your
# migrations from scratch. Old migrations may fail to apply correctly if those
# migrations use external dependencies or application code.
#
# It's strongly recommended that you check this file into your version control system.

ActiveRecord::Schema.define(version: 2021_12_05_074007) do
ActiveRecord::Schema.define(version: 2023_07_26_012826) do

# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"

create_table "action_mailbox_inbound_emails", force: :cascade do |t|
t.integer "status", default: 0, null: false
t.string "message_id", null: false
t.string "message_checksum", null: false
t.datetime "created_at", precision: 6, null: false
t.datetime "updated_at", precision: 6, null: false
t.index ["message_id", "message_checksum"], name: "index_action_mailbox_inbound_emails_uniqueness", unique: true
end

create_table "active_storage_attachments", force: :cascade do |t|
t.string "name", null: false
t.string "record_type", null: false
t.bigint "record_id", null: false
t.bigint "blob_id", null: false
t.datetime "created_at", null: false
t.index ["blob_id"], name: "index_active_storage_attachments_on_blob_id"
t.index ["record_type", "record_id", "name", "blob_id"], name: "index_active_storage_attachments_uniqueness", unique: true
end

create_table "active_storage_blobs", force: :cascade do |t|
t.string "key", null: false
t.string "filename", null: false
t.string "content_type"
t.text "metadata"
t.string "service_name", null: false
t.bigint "byte_size", null: false
t.string "checksum", null: false
t.datetime "created_at", null: false
t.index ["key"], name: "index_active_storage_blobs_on_key", unique: true
end

create_table "active_storage_variant_records", force: :cascade do |t|
t.bigint "blob_id", null: false
t.string "variation_digest", null: false
t.index ["blob_id", "variation_digest"], name: "index_active_storage_variant_records_uniqueness", unique: true
end

create_table "awards", id: :serial, force: :cascade do |t|
t.integer "badge_id"
t.integer "user_id"
Expand Down Expand Up @@ -291,6 +328,8 @@
t.index ["name"], name: "index_users_on_name", unique: true
end

add_foreign_key "active_storage_attachments", "active_storage_blobs", column: "blob_id"
add_foreign_key "active_storage_variant_records", "active_storage_blobs", column: "blob_id"
add_foreign_key "challenges", "users", column: "creator_id"
add_foreign_key "discussions", "boards"
add_foreign_key "discussions", "users"
Expand Down
5 changes: 5 additions & 0 deletions spec/mailboxes/incomings_mailbox_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
require 'rails_helper'

RSpec.describe IncomingsMailbox, type: :mailbox do
pending "add some examples to (or delete) #{__FILE__}"
end

0 comments on commit c0df234

Please sign in to comment.