mail-logger 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.
- data/.gitignore +18 -0
- data/.travis.yml +10 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/MIT-LICENSE +21 -0
- data/README.md +46 -0
- data/Rakefile +11 -0
- data/lib/mail/logger/callback.rb +8 -0
- data/lib/mail/logger/configuration.rb +20 -0
- data/lib/mail/logger/logfile.rb +8 -0
- data/lib/mail/logger/version.rb +5 -0
- data/lib/mail_logger.rb +25 -0
- data/mail_logger.gemspec +26 -0
- data/test/mail/logger/callback_test.rb +44 -0
- data/test/mail/logger/configuration_test.rb +47 -0
- data/test/mail/logger/logfile_test.rb +22 -0
- data/test/test_helper.rb +18 -0
- metadata +156 -0
data/.gitignore
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 Josh McArthur
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/MIT-LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
Copyright 2013 Josh McArthur
|
2
|
+
|
3
|
+
|
4
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
5
|
+
a copy of this software and associated documentation files (the
|
6
|
+
"Software"), to deal in the Software without restriction, including
|
7
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
8
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
9
|
+
permit persons to whom the Software is furnished to do so, subject to
|
10
|
+
the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be
|
13
|
+
included in all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
16
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
17
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
18
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
19
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
20
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
21
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,46 @@
|
|
1
|
+
# MailLogger
|
2
|
+
|
3
|
+
[](https://travis-ci.org/joshmcarthur/mail_logger)
|
4
|
+
|
5
|
+
> Please note: There's another project around called [**mail_logger**](https://rubygems.org/gems/mail_logger), which records details of mail to the database via ActiveRecord, instead of a log file (which is what this project does). While I certainly didn't intend to infringe, the other project hasn't been updated in a few years, so I'm sticking with this name.
|
6
|
+
|
7
|
+
You know how you're looking through your logs to see how your mailing is doing, and after all that request rubbish, you just can't see that **Sent mail** stuff? Annoying, right?
|
8
|
+
|
9
|
+
MailLogger to the rescue! It lodges a callback with `Mail`, capturing all of the mail being sent, and logging it to it's own file, so you can simply look back through that file to see what's up. Easy peasy!
|
10
|
+
|
11
|
+
I could be a pain and require Rails here, but I don't. If you are using Rails, then this gem should put things in the right place: `#{Rails.root}/log/mail_{development,etc}.log` - no extra work necessary. If you are not using Rails, then the gem will place the log file in `./log` - wherever that may be.
|
12
|
+
|
13
|
+
Default paths getting you down? Not to worry, this gem is configurable!
|
14
|
+
|
15
|
+
``` ruby
|
16
|
+
Mail::Logger.configure do |config|
|
17
|
+
config.log_path = "Whatever you want"
|
18
|
+
config.log_file_name = "all my emails.log"
|
19
|
+
end
|
20
|
+
```
|
21
|
+
|
22
|
+
(If you're using Rails, this belongs in `config/initializers/mail_logger.rb`)
|
23
|
+
|
24
|
+
## Installation
|
25
|
+
|
26
|
+
Add this line to your application's Gemfile:
|
27
|
+
|
28
|
+
gem 'mail-logger'
|
29
|
+
|
30
|
+
And then execute:
|
31
|
+
|
32
|
+
$ bundle
|
33
|
+
|
34
|
+
Or install it yourself as:
|
35
|
+
|
36
|
+
$ gem install mail-logger
|
37
|
+
|
38
|
+
|
39
|
+
|
40
|
+
## Contributing
|
41
|
+
|
42
|
+
1. Fork it
|
43
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
44
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
45
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
46
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
class Mail::Logger::Configuration
|
2
|
+
attr_accessor :log_path, :log_file_name
|
3
|
+
|
4
|
+
def initialize
|
5
|
+
self.log_path = rails_log_path || File.expand_path("./log")
|
6
|
+
self.log_file_name = rails_log_file_name || "mail.log"
|
7
|
+
end
|
8
|
+
|
9
|
+
def rails_log_path
|
10
|
+
return nil unless defined? Rails
|
11
|
+
|
12
|
+
Rails.root
|
13
|
+
end
|
14
|
+
|
15
|
+
def rails_log_file_name
|
16
|
+
return nil unless defined? Rails
|
17
|
+
|
18
|
+
"mail_#{Rails.env}.log"
|
19
|
+
end
|
20
|
+
end
|
data/lib/mail_logger.rb
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
require "mail"
|
2
|
+
require "logger"
|
3
|
+
require "mail/logger/version"
|
4
|
+
require "mail/logger/configuration"
|
5
|
+
require "mail/logger/logfile"
|
6
|
+
require "mail/logger/callback"
|
7
|
+
|
8
|
+
module Mail::Logger
|
9
|
+
|
10
|
+
class << self
|
11
|
+
attr_accessor :configuration
|
12
|
+
end
|
13
|
+
|
14
|
+
def self.configuration
|
15
|
+
@configuration ||= Configuration.new
|
16
|
+
end
|
17
|
+
|
18
|
+
def self.configure
|
19
|
+
yield(configuration) if block_given?
|
20
|
+
end
|
21
|
+
|
22
|
+
def self.logger
|
23
|
+
@logger ||= Mail::Logger::Logfile.new
|
24
|
+
end
|
25
|
+
end
|
data/mail_logger.gemspec
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'mail/logger/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "mail-logger"
|
8
|
+
spec.version = Mail::Logger::VERSION
|
9
|
+
spec.authors = ["Josh McArthur"]
|
10
|
+
spec.email = ["joshua.mcarthur@gmail.com"]
|
11
|
+
spec.description = %q{Lodges a callback with `Mail`, capturing all of the mail being sent, and logging it to it's own file, so you can simply look back through that file to see what's up. }
|
12
|
+
spec.summary = %q{A Rubygem to capture information about sent emails, and log them to a file all to their own!}
|
13
|
+
spec.homepage = "https://github.com/joshmcarthur/mail_logger"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files`.split($/)
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_development_dependency "bundler"
|
22
|
+
spec.add_development_dependency 'mocha', '~> 0.13.3'
|
23
|
+
spec.add_development_dependency 'minitest'
|
24
|
+
spec.add_development_dependency "rake"
|
25
|
+
spec.add_dependency "mail"
|
26
|
+
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
require_relative "../../test_helper"
|
2
|
+
|
3
|
+
describe Mail::Logger::Callback do
|
4
|
+
before do
|
5
|
+
|
6
|
+
end
|
7
|
+
|
8
|
+
describe "#delivered_email" do
|
9
|
+
subject do
|
10
|
+
mail_object
|
11
|
+
end
|
12
|
+
|
13
|
+
it "Logs the email" do
|
14
|
+
Mail::Logger.logger.expects(:info).with(subject.inspect).returns(true)
|
15
|
+
Mail::Logger::Callback.delivered_email(subject)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
describe "Callback registration" do
|
20
|
+
before do
|
21
|
+
Mail.defaults do
|
22
|
+
delivery_method :test
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
it "Calls our callback method from Mail" do
|
27
|
+
Mail::Logger::Callback.stubs(:delivered_email).returns(true)
|
28
|
+
deliver_email
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
def deliver_email
|
33
|
+
Mail.new do
|
34
|
+
from "tester@example.com"
|
35
|
+
to "tester@example.com"
|
36
|
+
subject "Test"
|
37
|
+
body "Test"
|
38
|
+
end.deliver
|
39
|
+
end
|
40
|
+
|
41
|
+
def mail_object
|
42
|
+
Mail.new
|
43
|
+
end
|
44
|
+
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
require_relative '../../test_helper'
|
2
|
+
|
3
|
+
describe Mail::Logger::Configuration do
|
4
|
+
describe "with Rails" do
|
5
|
+
before do
|
6
|
+
module ::Rails
|
7
|
+
def self.env
|
8
|
+
"development"
|
9
|
+
end
|
10
|
+
|
11
|
+
def self.root
|
12
|
+
"log"
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
after do
|
18
|
+
Object.send(:remove_const, :Rails)
|
19
|
+
end
|
20
|
+
|
21
|
+
subject do
|
22
|
+
Mail::Logger::Configuration.new
|
23
|
+
end
|
24
|
+
|
25
|
+
it "Uses the Rails log folder as its path" do
|
26
|
+
subject.log_path.must_equal "log"
|
27
|
+
end
|
28
|
+
|
29
|
+
it "Uses the Rails environment to name the file" do
|
30
|
+
subject.log_file_name.must_equal "mail_development.log"
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
describe "without Rails" do
|
35
|
+
subject do
|
36
|
+
Mail::Logger::Configuration.new
|
37
|
+
end
|
38
|
+
|
39
|
+
it "Uses the log folder relative to the current directory" do
|
40
|
+
subject.log_path.must_equal File.expand_path("./log")
|
41
|
+
end
|
42
|
+
|
43
|
+
it "Uses a default string to name the file" do
|
44
|
+
subject.log_file_name.must_equal "mail.log"
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
require_relative '../../test_helper'
|
2
|
+
|
3
|
+
describe Mail::Logger::Logfile do
|
4
|
+
subject do
|
5
|
+
Mail::Logger::Logfile.new
|
6
|
+
end
|
7
|
+
|
8
|
+
it "Inherits from Logger" do
|
9
|
+
subject.class.superclass.must_equal ::Logger
|
10
|
+
end
|
11
|
+
|
12
|
+
it "derives its path from the config" do
|
13
|
+
Mail::Logger.configuration.expects(:log_path).returns(File.expand_path("./test/log"))
|
14
|
+
Mail::Logger::Logfile.new
|
15
|
+
end
|
16
|
+
|
17
|
+
it "Derives its filename from the config" do
|
18
|
+
Mail::Logger.configuration.expects(:log_file_name).returns("mail.log")
|
19
|
+
Mail::Logger::Logfile.new
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
data/test/test_helper.rb
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'bundler/setup'
|
3
|
+
require 'minitest/autorun'
|
4
|
+
require 'test/unit'
|
5
|
+
require 'mocha/setup'
|
6
|
+
require 'mail_logger'
|
7
|
+
|
8
|
+
Mail::Logger.configure do |config|
|
9
|
+
config.log_path = File.expand_path("./test/log")
|
10
|
+
end
|
11
|
+
|
12
|
+
unless File.directory?("./test/log")
|
13
|
+
require 'fileutils'
|
14
|
+
FileUtils.mkdir("./test/log")
|
15
|
+
end
|
16
|
+
|
17
|
+
Bundler.require(:default)
|
18
|
+
|
metadata
ADDED
@@ -0,0 +1,156 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: mail-logger
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Josh McArthur
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2013-04-29 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: bundler
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :development
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ! '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '0'
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: mocha
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ~>
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: 0.13.3
|
38
|
+
type: :development
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ~>
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: 0.13.3
|
46
|
+
- !ruby/object:Gem::Dependency
|
47
|
+
name: minitest
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - ! '>='
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '0'
|
54
|
+
type: :development
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ! '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
- !ruby/object:Gem::Dependency
|
63
|
+
name: rake
|
64
|
+
requirement: !ruby/object:Gem::Requirement
|
65
|
+
none: false
|
66
|
+
requirements:
|
67
|
+
- - ! '>='
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '0'
|
70
|
+
type: :development
|
71
|
+
prerelease: false
|
72
|
+
version_requirements: !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
74
|
+
requirements:
|
75
|
+
- - ! '>='
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: '0'
|
78
|
+
- !ruby/object:Gem::Dependency
|
79
|
+
name: mail
|
80
|
+
requirement: !ruby/object:Gem::Requirement
|
81
|
+
none: false
|
82
|
+
requirements:
|
83
|
+
- - ! '>='
|
84
|
+
- !ruby/object:Gem::Version
|
85
|
+
version: '0'
|
86
|
+
type: :runtime
|
87
|
+
prerelease: false
|
88
|
+
version_requirements: !ruby/object:Gem::Requirement
|
89
|
+
none: false
|
90
|
+
requirements:
|
91
|
+
- - ! '>='
|
92
|
+
- !ruby/object:Gem::Version
|
93
|
+
version: '0'
|
94
|
+
description: ! 'Lodges a callback with `Mail`, capturing all of the mail being sent,
|
95
|
+
and logging it to it''s own file, so you can simply look back through that file
|
96
|
+
to see what''s up. '
|
97
|
+
email:
|
98
|
+
- joshua.mcarthur@gmail.com
|
99
|
+
executables: []
|
100
|
+
extensions: []
|
101
|
+
extra_rdoc_files: []
|
102
|
+
files:
|
103
|
+
- .gitignore
|
104
|
+
- .travis.yml
|
105
|
+
- Gemfile
|
106
|
+
- LICENSE.txt
|
107
|
+
- MIT-LICENSE
|
108
|
+
- README.md
|
109
|
+
- Rakefile
|
110
|
+
- lib/mail/logger/callback.rb
|
111
|
+
- lib/mail/logger/configuration.rb
|
112
|
+
- lib/mail/logger/logfile.rb
|
113
|
+
- lib/mail/logger/version.rb
|
114
|
+
- lib/mail_logger.rb
|
115
|
+
- mail_logger.gemspec
|
116
|
+
- test/mail/logger/callback_test.rb
|
117
|
+
- test/mail/logger/configuration_test.rb
|
118
|
+
- test/mail/logger/logfile_test.rb
|
119
|
+
- test/test_helper.rb
|
120
|
+
homepage: https://github.com/joshmcarthur/mail_logger
|
121
|
+
licenses:
|
122
|
+
- MIT
|
123
|
+
post_install_message:
|
124
|
+
rdoc_options: []
|
125
|
+
require_paths:
|
126
|
+
- lib
|
127
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
128
|
+
none: false
|
129
|
+
requirements:
|
130
|
+
- - ! '>='
|
131
|
+
- !ruby/object:Gem::Version
|
132
|
+
version: '0'
|
133
|
+
segments:
|
134
|
+
- 0
|
135
|
+
hash: 3950467139491618074
|
136
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
137
|
+
none: false
|
138
|
+
requirements:
|
139
|
+
- - ! '>='
|
140
|
+
- !ruby/object:Gem::Version
|
141
|
+
version: '0'
|
142
|
+
segments:
|
143
|
+
- 0
|
144
|
+
hash: 3950467139491618074
|
145
|
+
requirements: []
|
146
|
+
rubyforge_project:
|
147
|
+
rubygems_version: 1.8.23
|
148
|
+
signing_key:
|
149
|
+
specification_version: 3
|
150
|
+
summary: A Rubygem to capture information about sent emails, and log them to a file
|
151
|
+
all to their own!
|
152
|
+
test_files:
|
153
|
+
- test/mail/logger/callback_test.rb
|
154
|
+
- test/mail/logger/configuration_test.rb
|
155
|
+
- test/mail/logger/logfile_test.rb
|
156
|
+
- test/test_helper.rb
|