jtrupiano-sanitize_email 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
data/README.rdoc ADDED
@@ -0,0 +1,107 @@
1
+ = sanitize_email
2
+
3
+ This gem allows you to globally override your mail delivery settings. It's particularly helpful when you want to omit the delivery of email (e.g. in development/test environments) or alter the to/cc/bcc (e.g. in staging or demo environments) of all email generated from your application.
4
+
5
+ It is a "configure it and forget it" type gem that requires very little setup. It includes some very innocuous monkey patching of ActionMailer::Base to work its magic.
6
+
7
+ Peter Boling wrote the plugin that this gem is derived from. It currently solves three common problems in ruby web applications that use ActionMailer:
8
+
9
+ === Working Locally with Production Data
10
+
11
+ Peter described this common problem in his original plugin implementation as such:
12
+
13
+ * I have a production site with live data.
14
+ * I dump the live data and securely transfer it to another machine (rync -e ssh), and import it using scripts that I will soon open source to.
15
+ * On this separate machine (staging, or development) I run tests, and test various features.
16
+ * I usually want the emails to get sent from these non-production environments so I can verify what they look like when sent, but I don't ever want to risk them getting sent to addresses that are not mine.
17
+
18
+ === Re-routing Email on a Staging or QA Server
19
+
20
+ Another very important use case for me is to transparently re-route email generated from a staging or QA server to an appropriate person. For example, it's common for us to set up a staging server for a client to use to view our progress and test out new features. It's important for any email that is generated from our web application be delivered to the client's inbox so that they can review the content and ensure that it's acceptable. Similarly, we set up QA instances for our own QA team and we use {rails-caddy}[http://github.com/jtrupiano/rails-caddy] to allow each QA person to configure it specifically for them.
21
+
22
+ === Testing Email from a Hot Production Server
23
+
24
+ If you install this gem on a production server (which I don't always do), you can load up script/console and override the to/cc/bcc on all emails for the duration of your console session. This allows you to poke and prod a live production instance, and route all email to your own inbox for inspection. The best part is that this can all be accomplished without changing a single line of your application code.
25
+
26
+ == Install
27
+
28
+ gem sources -a http://gems.github.com/
29
+ gem install jtrupiano-sanitize_email
30
+
31
+ == Setup
32
+
33
+ It only requires a few lines of configuration:
34
+
35
+ * Rails 1.x: Add to bottom of environment.rb
36
+
37
+ * Rails 2.x: Use an initializer, stick it in any initializer file, or create a new one for sanitize_email
38
+
39
+ Add this bit and customize for your app:
40
+
41
+ # Settings for sanitize_email gem. These can be overridden in individual config/%env%/environment.rb files.
42
+
43
+ require 'sanitize_email'
44
+ ActionMailer::Base.sanitized_recipients = "jtrupiano@gmail.com"
45
+ ActionMailer::Base.sanitized_bcc = nil
46
+ ActionMailer::Base.sanitized_cc = nil
47
+
48
+ # These are the environments whose outgoing email BCC, CC and recipients fields will be overridden!
49
+ # All environments not listed will be treated as normal.
50
+ ActionMailer::Base.local_environments = %w( development test staging )
51
+
52
+ Keep in mind, this is ruby (and possibly rails), so you can add conditionals or utilize different environment.rb files to customize these settings on a per-environment basis.
53
+
54
+ But wait there's more:
55
+
56
+ Let's say you have a method in your model that you can call to test the signup email.
57
+ You want to be able to test sending it to any user at any time... but you don't want
58
+ the user to ACTUALLY get the email, even in production. A dilemma, yes? Not anymore!
59
+
60
+ All your mailers get a force_sanitize class method which takes precedence over the environment override.
61
+
62
+ When force_sanitize is nil it will not be used by sanitize_email to determine if it should override the recipients, bcc, and cc.
63
+
64
+
65
+ == Example
66
+
67
+ So here's how you can use force_sanitize to override the override.
68
+
69
+ Even if you set:
70
+
71
+ ActionMailer::Base.local_environments = %w( development )
72
+
73
+ and are in the development environment, you can override the override anywhere in your code.
74
+
75
+ class User < ActiveRecord::Base
76
+ def test_signup_email_me_only
77
+ UserMailer.force_sanitize = true
78
+ UserMailer.deliver_signup_notification(self)
79
+ UserMailer.force_sanitize = nil
80
+ end
81
+
82
+ def test_signup_email_user_only
83
+ UserMailer.force_sanitize = false
84
+ UserMailer.deliver_signup_notification(self)
85
+ UserMailer.force_sanitize = nil
86
+ end
87
+
88
+ # this third method would conditionally use the overridden recipients based on current Rails environment
89
+ def test_signup_email_environment
90
+ UserMailer.deliver_signup_notification(self)
91
+ end
92
+ end
93
+
94
+ Load the console with ruby script/console and regardless of what environment you are in:
95
+
96
+ > User.find(4).test_signup_email_me_only
97
+
98
+ and the email will have it's recipients, bcc, and cc overridden to be whatever you set the sanitized values to be.
99
+ Then if you want to send it to the actual user, instead of yourself
100
+
101
+ > User.find(4).test_signup_email_user_only
102
+
103
+ That's it! Enjoy!
104
+
105
+ Copyright (c) 2009 {John Trupiano}[http://smartlogicsolutions.com/wiki/John_Trupiano] of {SmartLogic Solutions, LLC}[http://www.smartlogicsolutions.com]
106
+ Copyright (c) 2008 {Peter H. Boling}[http://www.peterboling.com/about.html] of {9thBit LLC}[http://www.peterboling.com/]
107
+ Released under the MIT license
data/VERSION.yml CHANGED
@@ -1,4 +1,4 @@
1
1
  ---
2
2
  :major: 0
3
3
  :minor: 1
4
- :patch: 0
4
+ :patch: 1
@@ -37,7 +37,7 @@ module NinthBit
37
37
 
38
38
  def recipients(*addresses)
39
39
  real_recipients *addresses
40
- puts "santize_email error: sanitized_recipients is not set" if self.class.sanitized_recipients.nil?
40
+ puts "sanitize_email error: sanitized_recipients is not set" if self.class.sanitized_recipients.nil?
41
41
  localish? ? self.class.sanitized_recipients : real_recipients
42
42
  end
43
43
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jtrupiano-sanitize_email
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - John Trupiano
@@ -10,7 +10,7 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2009-03-02 00:00:00 -08:00
13
+ date: 2009-04-25 00:00:00 -07:00
14
14
  default_executable:
15
15
  dependencies: []
16
16
 
@@ -20,10 +20,10 @@ executables: []
20
20
 
21
21
  extensions: []
22
22
 
23
- extra_rdoc_files: []
24
-
23
+ extra_rdoc_files:
24
+ - README.rdoc
25
25
  files:
26
- - README.textile
26
+ - README.rdoc
27
27
  - VERSION.yml
28
28
  - lib/sanitize_email
29
29
  - lib/sanitize_email/custom_environments.rb
@@ -53,10 +53,10 @@ required_rubygems_version: !ruby/object:Gem::Requirement
53
53
  version:
54
54
  requirements: []
55
55
 
56
- rubyforge_project:
56
+ rubyforge_project: johntrupiano
57
57
  rubygems_version: 1.2.0
58
58
  signing_key:
59
59
  specification_version: 2
60
- summary: "Gemified fork of pboling's sanitize_email plugin: allows you to play with your application's email abilities without worrying that emails will get sent to actual live addresses."
60
+ summary: Tool to aid in development, testing, qa, and production troubleshooting of email issues without worrying that emails will get sent to actual live addresses.
61
61
  test_files: []
62
62
 
data/README.textile DELETED
@@ -1,102 +0,0 @@
1
- h1. sanitize_email
2
-
3
- This gem allows you to quickly globally override your mail delivery settings in depending on the environment. It's particularly helpful when you want to omit the delivery of email (e.g. in development/test environments) or alter the to/cc/bcc (e.g. in staging or demo environments) of all email generated from your application.
4
-
5
- This is the problem I have with site after site:
6
-
7
- # I have a production site with live data.
8
- # I dump the live data and securely transfer it to another machine (rync -e ssh), and import it using scripts that I will soon open source to.
9
- # On this separate machine (staging, or development) I run tests, and test various features.
10
- # I usually want the emails to get sent from these non-production evnironments so I can verify what they look like when sent, but I don't ever want to risk them getting sent to addresses that are not mine.
11
-
12
- So Peter Boling wrote a plugin! And I've taken it and turned it into a gem!
13
-
14
- It is an "configure it and forget it" type gem that requires very little setup. It includes some very innocuous monkey patching of ActiveRecord::Base to work its magic.
15
-
16
-
17
- h2. Install
18
-
19
- gem sources -a http://gems.github.com/
20
- gem install jtrupiano-sanitize_email
21
-
22
- h2. Setup
23
-
24
- It only requires a few lines of configuration:
25
-
26
- * Rails 1.x: Add to bottom of environment.rb
27
-
28
- * Rails 2.x: Use an initializer, stick it in any initializer file, or create a new one for sanitize_email
29
-
30
- Add this bit and customize for your app:
31
-
32
- <pre>
33
- # Settings for sanitize_email gem. These can be overridden in individual config/%env%/environment.rb files.
34
-
35
- require 'sanitize_email'
36
- ActionMailer::Base.sanitized_recipients = "jtrupiano@gmail.com"
37
- ActionMailer::Base.sanitized_bcc = nil
38
- ActionMailer::Base.sanitized_cc = nil
39
-
40
- # These are the environments whose outgoing email BCC, CC and recipients fields will be overridden!
41
- # All environments not listed will be treated as normal.
42
- ActionMailer::Base.local_environments = %w( development test staging )
43
- </pre>
44
-
45
- Keep in mind, this is ruby (and possibly rails), so you can add conditionals or utilize different environment.rb files to customize these settings on a per-environment basis.
46
-
47
- But wait there's more:
48
-
49
- Let's say you have a method in your model that you can call to test the signup email.
50
- You want to be able to test sending it to any user at any time... but you don't want
51
- the user to ACTUALLY get the email, even in production. A dilemma, yes? Not anymore!
52
-
53
- All your mailers get a force_sanitize class method which takes precedence over the environment override.
54
-
55
- When force_sanitize is nil it will not be used by sanitize_email to determine if it should override the recipients, bcc, and cc.
56
-
57
-
58
- h2. Example
59
-
60
- So here's how you can use force_sanitize to override the override.
61
-
62
- Even if you set:
63
-
64
- ActionMailer::Base.local_environments = %w( development )
65
-
66
- and are in the development environment, you can override the override anywhere in your code.
67
-
68
- <pre>
69
- class User < ActiveRecord::Base
70
- def test_signup_email_me_only
71
- UserMailer.force_sanitize = true
72
- UserMailer.deliver_signup_notification(self)
73
- UserMailer.force_sanitize = nil
74
- end
75
-
76
- def test_signup_email_user_only
77
- UserMailer.force_sanitize = false
78
- UserMailer.deliver_signup_notification(self)
79
- UserMailer.force_sanitize = nil
80
- end
81
-
82
- # this third method would conditionally use the overridden recipients based on current Rails environment
83
- def test_signup_email_environment
84
- UserMailer.deliver_signup_notification(self)
85
- end
86
-
87
- end
88
- </pre>
89
-
90
- Load the console with ruby script/console and regardless of what environment you are in:
91
-
92
- > User.find(4).test_signup_email_me_only
93
-
94
- and the email will have it's recipients, bcc, and cc overridden to be whatever you set the sanitized values to be.
95
- Then if you want to send it to the actual user, instead of yourself
96
-
97
- > User.find(4).test_signup_email_user_only
98
-
99
- That's it! Enjoy!
100
-
101
- Copyright (c) 2008 Peter H. Boling of 9thBit LLC
102
- Released under the MIT license