fusionary-mail_logger 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
data/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2006 - 2009 Fusionary Media
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/Manifest ADDED
@@ -0,0 +1,13 @@
1
+ generators/mail_logger/lib/rake_commands.rb
2
+ generators/mail_logger/mail_logger_generator.rb
3
+ generators/mail_logger/templates/app/models/mail_log.rb
4
+ generators/mail_logger/templates/db/migrate/create_mail_logs.rb
5
+ generators/mail_logger/USAGE
6
+ lib/mail_logger/app/models/mail_log.rb
7
+ lib/mail_logger/lib/extensions/action_mailer.rb
8
+ lib/mail_logger.rb
9
+ Manifest
10
+ MIT-LICENSE
11
+ rails/init.rb
12
+ Rakefile
13
+ README.textile
data/README.textile ADDED
@@ -0,0 +1,26 @@
1
+ h1. Mail Logger
2
+
3
+ Braindead-simple email logger for ActionMailer using ActiveRecord
4
+
5
+ h2. Gem Installation for Rails 2.1+
6
+
7
+ In config/environment.rb:
8
+
9
+ config.gem "fusionary-mail_logger",
10
+ :lib => "mail_logger",
11
+ :source => "http://gems.github.com"
12
+
13
+ h2. Generator
14
+
15
+ Ensure the environment's database is present and then run
16
+
17
+ script/generate mail_logger
18
+
19
+ This will generate the migration and generate the MailLog AR model.
20
+
21
+ h2. About
22
+
23
+ The purpose of this is to provide a simple audit trail, specific to ActionMailer, for Rails apps. Without much work, you could write a
24
+ controller and some views and then monitor the emails sent out; that's really beyond the scope of this project though.
25
+
26
+ Copyright (c) 2009 Fusionary Media, released under the MIT license
data/Rakefile ADDED
@@ -0,0 +1,13 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+ require 'rake/testtask'
4
+ require 'echoe'
5
+
6
+ Echoe.new("mail_logger", "0.1.1") do |p|
7
+ p.description = "Braindead-simple email logger for ActionMailer using ActiveRecord"
8
+ p.url = "http://github.com/fusionary/mail_logger"
9
+ p.author = ["Fusionary Media", "Josh Clayton"]
10
+ p.email = "joshua.clayton@gmail.com"
11
+ p.ignore_pattern = ["tmp/*"]
12
+ p.development_dependencies = ["actionmailer >= 2.1.0"]
13
+ end
@@ -0,0 +1 @@
1
+ script/generate mail_logger
@@ -0,0 +1,22 @@
1
+ Rails::Generator::Commands::Create.class_eval do
2
+ def rake_db_migrate
3
+ logger.rake "db:migrate"
4
+ unless system("rake db:migrate")
5
+ logger.rake "db:migrate failed. Rolling back"
6
+ command(:destroy).invoke!
7
+ end
8
+ end
9
+ end
10
+
11
+ Rails::Generator::Commands::Destroy.class_eval do
12
+ def rake_db_migrate
13
+ logger.rake "db:rollback"
14
+ system "rake db:rollback"
15
+ end
16
+ end
17
+
18
+ Rails::Generator::Commands::List.class_eval do
19
+ def rake_db_migrate
20
+ logger.rake "db:migrate"
21
+ end
22
+ end
@@ -0,0 +1,18 @@
1
+ require File.expand_path(File.dirname(__FILE__) + "/lib/rake_commands.rb")
2
+
3
+ class MailLoggerGenerator < Rails::Generator::Base
4
+ def manifest
5
+ record do |m|
6
+ m.directory File.join("app", "models")
7
+ ["app/models/mail_log.rb"].each do |file|
8
+ m.file file, file
9
+ end
10
+
11
+ unless ActiveRecord::Base.connection.table_exists?(:mail_logs)
12
+ m.migration_template 'db/migrate/create_mail_logs.rb', 'db/migrate', :migration_file_name => 'create_mail_logs'
13
+ end
14
+
15
+ m.rake_db_migrate
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,3 @@
1
+ class MailLog < ActiveRecord::Base
2
+ include MailLogger::App::Models::MailLog
3
+ end
@@ -0,0 +1,20 @@
1
+ class CreateMailLogs < ActiveRecord::Migration
2
+ def self.up
3
+ create_table :mail_logs do |t|
4
+ t.string :subject, :to, :from, :cc
5
+ t.text :body, :message
6
+ t.timestamps
7
+ end
8
+
9
+ change_table :mail_logs do |t|
10
+ t.index :subject
11
+ t.index :to
12
+ t.index :from
13
+ t.index :created_at
14
+ end
15
+ end
16
+
17
+ def self.down
18
+ drop_table :mail_logs
19
+ end
20
+ end
@@ -0,0 +1,4 @@
1
+ require "mail_logger/app/models/mail_log"
2
+ require "mail_logger/lib/extensions/action_mailer"
3
+
4
+ ActionMailer::Base.send :include, MailLogger::Lib::Extensions::ActionMailer
@@ -0,0 +1,21 @@
1
+ module MailLogger
2
+ module App
3
+ module Models
4
+ module MailLog
5
+ def self.included(base)
6
+ base.extend ClassMethods
7
+ end
8
+
9
+ module ClassMethods
10
+ def create_from_mail(email)
11
+ [:to, :from, :subject, :quoted_body, :encoded].each do |att|
12
+ return unless email.respond_to?(att)
13
+ end
14
+
15
+ self.create(:to => email.to.join(", "), :from => email.from.join(", "), :subject => email.subject, :body => email.quoted_body, :message => email.encoded)
16
+ end
17
+ end
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,27 @@
1
+ module MailLogger
2
+ module Lib
3
+ module Extensions
4
+ module ActionMailer
5
+ def self.included(base)
6
+ base.class_eval do
7
+ def deliver_with_hooks!(*args)
8
+ mail = args.first || @mail # depend on ActionMailer::Base's @mail ivar is pretty nasty but has to be done
9
+ if !mail.nil?
10
+ begin
11
+ logger.info "MailLogger logged #{mail.encoded}" unless logger.nil?
12
+ MailLog.create_from_mail(mail)
13
+ rescue
14
+ logger.info "MailLogger failed" unless logger.nil?
15
+ end
16
+ end
17
+
18
+ deliver_without_hooks!(*args)
19
+ end
20
+
21
+ alias_method_chain :deliver!, :hooks
22
+ end
23
+ end
24
+ end
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,34 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ Gem::Specification.new do |s|
4
+ s.name = %q{mail_logger}
5
+ s.version = "0.1.1"
6
+
7
+ s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
8
+ s.authors = ["Fusionary Media, Josh Clayton"]
9
+ s.date = %q{2009-04-14}
10
+ s.description = %q{Braindead-simple email logger for ActionMailer using ActiveRecord}
11
+ s.email = %q{joshua.clayton@gmail.com}
12
+ s.extra_rdoc_files = ["lib/mail_logger/app/models/mail_log.rb", "lib/mail_logger/lib/extensions/action_mailer.rb", "lib/mail_logger.rb", "README.textile"]
13
+ s.files = ["generators/mail_logger/lib/rake_commands.rb", "generators/mail_logger/mail_logger_generator.rb", "generators/mail_logger/templates/app/models/mail_log.rb", "generators/mail_logger/templates/db/migrate/create_mail_logs.rb", "generators/mail_logger/USAGE", "lib/mail_logger/app/models/mail_log.rb", "lib/mail_logger/lib/extensions/action_mailer.rb", "lib/mail_logger.rb", "Manifest", "MIT-LICENSE", "rails/init.rb", "Rakefile", "README.textile", "mail_logger.gemspec"]
14
+ s.has_rdoc = true
15
+ s.homepage = %q{http://github.com/fusionary/mail_logger}
16
+ s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "Mail_logger", "--main", "README.textile"]
17
+ s.require_paths = ["lib"]
18
+ s.rubyforge_project = %q{mail_logger}
19
+ s.rubygems_version = %q{1.3.1}
20
+ s.summary = %q{Braindead-simple email logger for ActionMailer using ActiveRecord}
21
+
22
+ if s.respond_to? :specification_version then
23
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
24
+ s.specification_version = 2
25
+
26
+ if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
27
+ s.add_development_dependency(%q<actionmailer>, [">= 0", "= 2.1.0"])
28
+ else
29
+ s.add_dependency(%q<actionmailer>, [">= 0", "= 2.1.0"])
30
+ end
31
+ else
32
+ s.add_dependency(%q<actionmailer>, [">= 0", "= 2.1.0"])
33
+ end
34
+ end
data/rails/init.rb ADDED
@@ -0,0 +1 @@
1
+ require "mail_logger"
metadata ADDED
@@ -0,0 +1,86 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: fusionary-mail_logger
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.1
5
+ platform: ruby
6
+ authors:
7
+ - Fusionary Media, Josh Clayton
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2009-04-14 00:00:00 -07:00
13
+ default_executable:
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: actionmailer
17
+ type: :development
18
+ version_requirement:
19
+ version_requirements: !ruby/object:Gem::Requirement
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: "0"
24
+ - - "="
25
+ - !ruby/object:Gem::Version
26
+ version: 2.1.0
27
+ version:
28
+ description: Braindead-simple email logger for ActionMailer using ActiveRecord
29
+ email: joshua.clayton@gmail.com
30
+ executables: []
31
+
32
+ extensions: []
33
+
34
+ extra_rdoc_files:
35
+ - lib/mail_logger/app/models/mail_log.rb
36
+ - lib/mail_logger/lib/extensions/action_mailer.rb
37
+ - lib/mail_logger.rb
38
+ - README.textile
39
+ files:
40
+ - generators/mail_logger/lib/rake_commands.rb
41
+ - generators/mail_logger/mail_logger_generator.rb
42
+ - generators/mail_logger/templates/app/models/mail_log.rb
43
+ - generators/mail_logger/templates/db/migrate/create_mail_logs.rb
44
+ - generators/mail_logger/USAGE
45
+ - lib/mail_logger/app/models/mail_log.rb
46
+ - lib/mail_logger/lib/extensions/action_mailer.rb
47
+ - lib/mail_logger.rb
48
+ - Manifest
49
+ - MIT-LICENSE
50
+ - rails/init.rb
51
+ - Rakefile
52
+ - README.textile
53
+ - mail_logger.gemspec
54
+ has_rdoc: true
55
+ homepage: http://github.com/fusionary/mail_logger
56
+ post_install_message:
57
+ rdoc_options:
58
+ - --line-numbers
59
+ - --inline-source
60
+ - --title
61
+ - Mail_logger
62
+ - --main
63
+ - README.textile
64
+ require_paths:
65
+ - lib
66
+ required_ruby_version: !ruby/object:Gem::Requirement
67
+ requirements:
68
+ - - ">="
69
+ - !ruby/object:Gem::Version
70
+ version: "0"
71
+ version:
72
+ required_rubygems_version: !ruby/object:Gem::Requirement
73
+ requirements:
74
+ - - ">="
75
+ - !ruby/object:Gem::Version
76
+ version: "1.2"
77
+ version:
78
+ requirements: []
79
+
80
+ rubyforge_project: mail_logger
81
+ rubygems_version: 1.2.0
82
+ signing_key:
83
+ specification_version: 2
84
+ summary: Braindead-simple email logger for ActionMailer using ActiveRecord
85
+ test_files: []
86
+