aws_email_bounce 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (72) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +13 -0
  3. data/CODE_OF_CONDUCT.md +49 -0
  4. data/Gemfile +53 -0
  5. data/Gemfile.lock +207 -0
  6. data/LICENSE.txt +21 -0
  7. data/README.md +41 -0
  8. data/README.rdoc +28 -0
  9. data/Rakefile +6 -0
  10. data/app/assets/images/.keep +0 -0
  11. data/app/assets/javascripts/application.js +16 -0
  12. data/app/assets/javascripts/email_responses.coffee +3 -0
  13. data/app/assets/stylesheets/application.css +15 -0
  14. data/app/assets/stylesheets/email_responses.scss +3 -0
  15. data/app/controllers/application_controller.rb +5 -0
  16. data/app/controllers/concerns/.keep +0 -0
  17. data/app/controllers/email_responses_controller.rb +78 -0
  18. data/app/helpers/application_helper.rb +2 -0
  19. data/app/helpers/email_responses_helper.rb +2 -0
  20. data/app/mailers/.keep +0 -0
  21. data/app/mailers/application_mailer.rb +4 -0
  22. data/app/mailers/user_mailer.rb +6 -0
  23. data/app/models/.keep +0 -0
  24. data/app/models/concerns/.keep +0 -0
  25. data/app/models/email_response.rb +3 -0
  26. data/app/views/layouts/application.html.erb +14 -0
  27. data/app/views/layouts/mailer.html.erb +5 -0
  28. data/app/views/layouts/mailer.text.erb +1 -0
  29. data/app/views/user_mailer/welcome.html.erb +0 -0
  30. data/aws_email_bounce.gemspec +32 -0
  31. data/bin/bundle +3 -0
  32. data/bin/console +14 -0
  33. data/bin/rails +9 -0
  34. data/bin/rake +9 -0
  35. data/bin/setup +29 -0
  36. data/bin/spring +15 -0
  37. data/config.ru +4 -0
  38. data/config/application.rb +36 -0
  39. data/config/boot.rb +3 -0
  40. data/config/database.yml +54 -0
  41. data/config/environment.rb +5 -0
  42. data/config/environments/development.rb +41 -0
  43. data/config/environments/production.rb +79 -0
  44. data/config/environments/test.rb +42 -0
  45. data/config/initializers/assets.rb +11 -0
  46. data/config/initializers/backtrace_silencers.rb +7 -0
  47. data/config/initializers/cookies_serializer.rb +3 -0
  48. data/config/initializers/filter_parameter_logging.rb +4 -0
  49. data/config/initializers/inflections.rb +16 -0
  50. data/config/initializers/invalid_email_interceptor.rb +9 -0
  51. data/config/initializers/mime_types.rb +4 -0
  52. data/config/initializers/session_store.rb +3 -0
  53. data/config/initializers/wrap_parameters.rb +14 -0
  54. data/config/locales/en.yml +23 -0
  55. data/config/routes.rb +58 -0
  56. data/config/secrets.yml +22 -0
  57. data/db/migrate/20160830102515_create_email_responses.rb +10 -0
  58. data/db/schema.rb +24 -0
  59. data/db/seeds.rb +7 -0
  60. data/lib/assets/.keep +0 -0
  61. data/lib/aws_email_bounce.rb +5 -0
  62. data/lib/aws_email_bounce/version.rb +3 -0
  63. data/lib/tasks/.keep +0 -0
  64. data/log/.keep +0 -0
  65. data/public/404.html +67 -0
  66. data/public/422.html +67 -0
  67. data/public/500.html +66 -0
  68. data/public/favicon.ico +0 -0
  69. data/public/robots.txt +5 -0
  70. data/vendor/assets/javascripts/.keep +0 -0
  71. data/vendor/assets/stylesheets/.keep +0 -0
  72. metadata +142 -0
@@ -0,0 +1,3 @@
1
+ # Place all the behaviors and hooks related to the matching controller here.
2
+ # All this logic will automatically be available in application.js.
3
+ # You can use CoffeeScript in this file: http://coffeescript.org/
@@ -0,0 +1,15 @@
1
+ /*
2
+ * This is a manifest file that'll be compiled into application.css, which will include all the files
3
+ * listed below.
4
+ *
5
+ * Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets,
6
+ * or any plugin's vendor/assets/stylesheets directory can be referenced here using a relative path.
7
+ *
8
+ * You're free to add application-wide styles to this file and they'll appear at the bottom of the
9
+ * compiled file so the styles you add here take precedence over styles defined in any styles
10
+ * defined in the other CSS/SCSS files in this directory. It is generally better to create a new
11
+ * file per style scope.
12
+ *
13
+ *= require_tree .
14
+ *= require_self
15
+ */
@@ -0,0 +1,3 @@
1
+ // Place all the styles related to the EmailResponses controller here.
2
+ // They will automatically be included in application.css.
3
+ // You can use Sass (SCSS) here: http://sass-lang.com/
@@ -0,0 +1,5 @@
1
+ class ApplicationController < ActionController::Base
2
+ # Prevent CSRF attacks by raising an exception.
3
+ # For APIs, you may want to use :null_session instead.
4
+ # protect_from_forgery with: :exception
5
+ end
File without changes
@@ -0,0 +1,78 @@
1
+ # class EmailResponsesController < ApplicationController
2
+
3
+ # end
4
+
5
+ require 'json'
6
+ require 'aws-sdk'
7
+
8
+ class EmailResponsesController < ApplicationController
9
+
10
+ # skip_authorization_check
11
+ # skip_before_action :verify_authenticity_token
12
+
13
+ before_action :log_incoming_message
14
+
15
+ def bounce
16
+ # return render json: {} unless aws_message.authentic?
17
+ if type != 'Bounce'
18
+ Rails.logger.info "Not a bounce - exiting"
19
+ return render json: {}
20
+ end
21
+
22
+
23
+ bounce = message['bounce']
24
+
25
+ bouncerecps = bounce['bouncedRecipients']
26
+ bouncerecps.each do |recp|
27
+ email = recp['emailAddress']
28
+ extra_info = "status: #{recp['status']}, action: #{recp['action']}, diagnosticCode: #{recp['diagnosticCode']}"
29
+ Rails.logger.info "Creating a bounce record for #{email}"
30
+
31
+ EmailResponse.create ({ email: email, response_type: 'bounce', extra_info: extra_info})
32
+ end
33
+
34
+ render json: {}
35
+ end
36
+
37
+ def complaint
38
+
39
+ # return render json: {} unless aws_message.authentic?
40
+
41
+ if type != 'Complaint'
42
+ Rails.logger.info "Not a complaint - exiting"
43
+ return render json: {}
44
+ end
45
+
46
+ complaint = message['complaint']
47
+ recipients = complaint['complainedRecipients']
48
+ recipients.each do |recp|
49
+ email = recp['emailAddress']
50
+ extra_info = "complaintFeedbackType: #{complaint['complaintFeedbackType']}"
51
+ EmailResponse.create ( { email: email, response_type: 'complaint', extra_info: extra_info } )
52
+ end
53
+
54
+ render json: {}
55
+ end
56
+
57
+ protected
58
+
59
+ def aws_message
60
+
61
+ # @aws_message ||= AWS::SNS::Message.new request.raw_post
62
+ end
63
+
64
+ def log_incoming_message
65
+ print "----------"
66
+ Rails.logger.info request.raw_post
67
+ end
68
+
69
+ # Weirdly, AWS double encodes the JSON.
70
+ def message
71
+
72
+ @message ||= JSON.parse JSON.parse(request.raw_post)['Message']
73
+ end
74
+
75
+ def type
76
+ message['notificationType']
77
+ end
78
+ end
@@ -0,0 +1,2 @@
1
+ module ApplicationHelper
2
+ end
@@ -0,0 +1,2 @@
1
+ module EmailResponsesHelper
2
+ end
File without changes
@@ -0,0 +1,4 @@
1
+ class ApplicationMailer < ActionMailer::Base
2
+ default from: "from@example.com"
3
+ layout 'mailer'
4
+ end
@@ -0,0 +1,6 @@
1
+ class UserMailer < ApplicationMailer
2
+
3
+ def welcome(email)
4
+ mail(:to => email, :from => "Info <info@dummy.com>")
5
+ end
6
+ end
File without changes
File without changes
@@ -0,0 +1,3 @@
1
+ class EmailResponse < ActiveRecord::Base
2
+ enum response_type: [ :bounce, :complaint ]
3
+ end
@@ -0,0 +1,14 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>AwsEmailBounce</title>
5
+ <%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track' => true %>
6
+ <%= javascript_include_tag 'application', 'data-turbolinks-track' => true %>
7
+ <%= csrf_meta_tags %>
8
+ </head>
9
+ <body>
10
+
11
+ <%= yield %>
12
+
13
+ </body>
14
+ </html>
@@ -0,0 +1,5 @@
1
+ <html>
2
+ <body>
3
+ <%= yield %>
4
+ </body>
5
+ </html>
@@ -0,0 +1 @@
1
+ <%= yield %>
File without changes
@@ -0,0 +1,32 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'aws_email_bounce/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "aws_email_bounce"
8
+ spec.version = AwsEmailBounce::VERSION
9
+ spec.authors = ["Sunil Kumar"]
10
+ spec.email = ["sunilkumar199198@gmail.com"]
11
+
12
+ spec.summary = %q{It will help you to get bounce_email list from aws}
13
+ spec.description = %q{get Bounce email list}
14
+ spec.homepage = "https://gitlab.com/sunilascratech/aws_email_bounce"
15
+ spec.license = "MIT"
16
+
17
+ # Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
18
+ # to allow pushing to a single host or delete this section to allow pushing to any host.
19
+ if spec.respond_to?(:metadata)
20
+ # spec.metadata['allowed_push_host'] = "TODO: Set to 'http://mygemserver.com'"
21
+ else
22
+ raise "RubyGems 2.0 or newer is required to protect against public gem pushes."
23
+ end
24
+
25
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
26
+ spec.bindir = "exe"
27
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
28
+ spec.require_paths = ["lib"]
29
+
30
+ spec.add_development_dependency "bundler", "~> 1.12"
31
+ spec.add_development_dependency "rake", "~> 10.0"
32
+ end
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env ruby
2
+ ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__)
3
+ load Gem.bin_path('bundler', 'bundle')
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "aws_email_bounce"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
@@ -0,0 +1,9 @@
1
+ #!/usr/bin/env ruby
2
+ begin
3
+ load File.expand_path('../spring', __FILE__)
4
+ rescue LoadError => e
5
+ raise unless e.message.include?('spring')
6
+ end
7
+ APP_PATH = File.expand_path('../../config/application', __FILE__)
8
+ require_relative '../config/boot'
9
+ require 'rails/commands'
@@ -0,0 +1,9 @@
1
+ #!/usr/bin/env ruby
2
+ begin
3
+ load File.expand_path('../spring', __FILE__)
4
+ rescue LoadError => e
5
+ raise unless e.message.include?('spring')
6
+ end
7
+ require_relative '../config/boot'
8
+ require 'rake'
9
+ Rake.application.run
@@ -0,0 +1,29 @@
1
+ #!/usr/bin/env ruby
2
+ require 'pathname'
3
+
4
+ # path to your application root.
5
+ APP_ROOT = Pathname.new File.expand_path('../../', __FILE__)
6
+
7
+ Dir.chdir APP_ROOT do
8
+ # This script is a starting point to setup your application.
9
+ # Add necessary setup steps to this file:
10
+
11
+ puts "== Installing dependencies =="
12
+ system "gem install bundler --conservative"
13
+ system "bundle check || bundle install"
14
+
15
+ # puts "\n== Copying sample files =="
16
+ # unless File.exist?("config/database.yml")
17
+ # system "cp config/database.yml.sample config/database.yml"
18
+ # end
19
+
20
+ puts "\n== Preparing database =="
21
+ system "bin/rake db:setup"
22
+
23
+ puts "\n== Removing old logs and tempfiles =="
24
+ system "rm -f log/*"
25
+ system "rm -rf tmp/cache"
26
+
27
+ puts "\n== Restarting application server =="
28
+ system "touch tmp/restart.txt"
29
+ end
@@ -0,0 +1,15 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ # This file loads spring without using Bundler, in order to be fast.
4
+ # It gets overwritten when you run the `spring binstub` command.
5
+
6
+ unless defined?(Spring)
7
+ require 'rubygems'
8
+ require 'bundler'
9
+
10
+ if (match = Bundler.default_lockfile.read.match(/^GEM$.*?^ (?: )*spring \((.*?)\)$.*?^$/m))
11
+ Gem.paths = { 'GEM_PATH' => [Bundler.bundle_path.to_s, *Gem.path].uniq.join(Gem.path_separator) }
12
+ gem 'spring', match[1]
13
+ require 'spring/binstub'
14
+ end
15
+ end
@@ -0,0 +1,4 @@
1
+ # This file is used by Rack-based servers to start the application.
2
+
3
+ require ::File.expand_path('../config/environment', __FILE__)
4
+ run Rails.application
@@ -0,0 +1,36 @@
1
+ require File.expand_path('../boot', __FILE__)
2
+
3
+ require 'rails/all'
4
+
5
+ # Require the gems listed in Gemfile, including any gems
6
+ # you've limited to :test, :development, or :production.
7
+ Bundler.require(*Rails.groups)
8
+
9
+ module AwsEmailBounce
10
+ class Application < Rails::Application
11
+ # Settings in config/environments/* take precedence over those specified here.
12
+ # Application configuration should go into files in config/initializers
13
+ # -- all .rb files in that directory are automatically loaded.
14
+
15
+ # Set Time.zone default to the specified zone and make Active Record auto-convert to this zone.
16
+ # Run "rake -D time" for a list of tasks for finding time zone names. Default is UTC.
17
+ # config.time_zone = 'Central Time (US & Canada)'
18
+
19
+ # The default locale is :en and all translations from config/locales/*.rb,yml are auto loaded.
20
+ # config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}').to_s]
21
+ # config.i18n.default_locale = :de
22
+
23
+ # Do not swallow errors in after_commit/after_rollback callbacks.
24
+ config.active_record.raise_in_transactional_callbacks = true
25
+
26
+ config.action_mailer.smtp_settings = {
27
+ :user_name => "AKIAJOSHKBK7KGFMPJYA",
28
+ :password => "AqbKSiVThhZkdY+BZQ+LbP6SCNxIBosOugSnIB0UEcdo",
29
+ :domain => "localhost",
30
+ :address => "email-smtp.us-west-2.amazonaws.com",
31
+ :port => 587,
32
+ :authentication => :plain,
33
+ :enable_starttls_auto => true
34
+ }
35
+ end
36
+ end
@@ -0,0 +1,3 @@
1
+ ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__)
2
+
3
+ require 'bundler/setup' # Set up gems listed in the Gemfile.
@@ -0,0 +1,54 @@
1
+ # MySQL. Versions 5.0+ are recommended.
2
+ #
3
+ # Install the MYSQL driver
4
+ # gem install mysql2
5
+ #
6
+ # Ensure the MySQL gem is defined in your Gemfile
7
+ # gem 'mysql2'
8
+ #
9
+ # And be sure to use new-style password hashing:
10
+ # http://dev.mysql.com/doc/refman/5.0/en/old-client.html
11
+ #
12
+ default: &default
13
+ adapter: mysql2
14
+ encoding: utf8
15
+ pool: 5
16
+ username: root
17
+ password: password
18
+ socket: /var/run/mysqld/mysqld.sock
19
+
20
+ development:
21
+ <<: *default
22
+ database: aws_email_bounce_development
23
+
24
+ # Warning: The database defined as "test" will be erased and
25
+ # re-generated from your development database when you run "rake".
26
+ # Do not set this db to the same as development or production.
27
+ test:
28
+ <<: *default
29
+ database: aws_email_bounce_test
30
+
31
+ # As with config/secrets.yml, you never want to store sensitive information,
32
+ # like your database password, in your source code. If your source code is
33
+ # ever seen by anyone, they now have access to your database.
34
+ #
35
+ # Instead, provide the password as a unix environment variable when you boot
36
+ # the app. Read http://guides.rubyonrails.org/configuring.html#configuring-a-database
37
+ # for a full rundown on how to provide these environment variables in a
38
+ # production deployment.
39
+ #
40
+ # On Heroku and other platform providers, you may have a full connection URL
41
+ # available as an environment variable. For example:
42
+ #
43
+ # DATABASE_URL="mysql2://myuser:mypass@localhost/somedatabase"
44
+ #
45
+ # You can use this database configuration with:
46
+ #
47
+ # production:
48
+ # url: <%= ENV['DATABASE_URL'] %>
49
+ #
50
+ production:
51
+ <<: *default
52
+ database: aws_email_bounce_production
53
+ username: aws_email_bounce
54
+ password: <%= ENV['AWS_EMAIL_BOUNCE_DATABASE_PASSWORD'] %>
@@ -0,0 +1,5 @@
1
+ # Load the Rails application.
2
+ require File.expand_path('../application', __FILE__)
3
+
4
+ # Initialize the Rails application.
5
+ Rails.application.initialize!
@@ -0,0 +1,41 @@
1
+ Rails.application.configure do
2
+ # Settings specified here will take precedence over those in config/application.rb.
3
+
4
+ # In the development environment your application's code is reloaded on
5
+ # every request. This slows down response time but is perfect for development
6
+ # since you don't have to restart the web server when you make code changes.
7
+ config.cache_classes = false
8
+
9
+ # Do not eager load code on boot.
10
+ config.eager_load = false
11
+
12
+ # Show full error reports and disable caching.
13
+ config.consider_all_requests_local = true
14
+ config.action_controller.perform_caching = false
15
+
16
+ # Don't care if the mailer can't send.
17
+ config.action_mailer.raise_delivery_errors = false
18
+
19
+ # Print deprecation notices to the Rails logger.
20
+ config.active_support.deprecation = :log
21
+
22
+ # Raise an error on page load if there are pending migrations.
23
+ config.active_record.migration_error = :page_load
24
+
25
+ # Debug mode disables concatenation and preprocessing of assets.
26
+ # This option may cause significant delays in view rendering with a large
27
+ # number of complex assets.
28
+ config.assets.debug = true
29
+
30
+ # Asset digests allow you to set far-future HTTP expiration dates on all assets,
31
+ # yet still be able to expire them through the digest params.
32
+ config.assets.digest = true
33
+
34
+ # Adds additional error checking when serving assets at runtime.
35
+ # Checks for improperly declared sprockets dependencies.
36
+ # Raises helpful error messages.
37
+ config.assets.raise_runtime_errors = true
38
+
39
+ # Raises error for missing translations
40
+ # config.action_view.raise_on_missing_translations = true
41
+ end