Module: SanitizeEmail

Extended by:
Deprecation
Defined in:
lib/sanitize_email/bleach.rb,
lib/sanitize_email.rb,
lib/sanitize_email/config.rb,
lib/sanitize_email/engine.rb,
lib/sanitize_email/railtie.rb,
lib/sanitize_email/version.rb,
lib/sanitize_email/deprecation.rb,
lib/sanitize_email/test_helpers.rb,
lib/sanitize_email/rspec_matchers.rb,
lib/sanitize_email/mail_header_tools.rb,
lib/sanitize_email/overridden_addresses.rb

Overview

Copyright © 2008-16 Peter H. Boling of RailsBling.com Released under the MIT license

Defined Under Namespace

Modules: Deprecation, MailExt, MailHeaderTools, RspecMatchers, TestHelpers Classes: Bleach, Config, Engine, MissingBlockParameter, OverriddenAddresses, Railtie

Constant Summary collapse

VERSION =
'2.0.3'

Class Attribute Summary collapse

Class Method Summary collapse

Methods included from Deprecation

deprecated, deprecated_alias, deprecation, deprecation_warning_message

Class Attribute Details

.force_sanitizeObject

Returns the value of attribute force_sanitize



66
67
68
# File 'lib/sanitize_email.rb', line 66

def force_sanitize
  @force_sanitize
end

Class Method Details

.[](key) ⇒ Object



39
40
41
42
# File 'lib/sanitize_email.rb', line 39

def self.[](key)
  return nil unless key.respond_to?(:to_sym)
  SanitizeEmail::Config.config[key.to_sym]
end

.activate?(message) ⇒ Boolean

Returns:

  • (Boolean)


60
61
62
63
# File 'lib/sanitize_email.rb', line 60

def self.activate?(message)
  proc = SanitizeEmail::Config.config[:activation_proc]
  proc.call(message) if proc.respond_to?(:call)
end

.janitor(options) ⇒ Object



114
115
116
117
118
119
120
# File 'lib/sanitize_email.rb', line 114

def self.janitor(options)
  raise MissingBlockParameter, 'SanitizeEmail.janitor must be called with a block' unless block_given?
  original = SanitizeEmail.force_sanitize
  SanitizeEmail.force_sanitize = options[:forcing]
  yield
  SanitizeEmail.force_sanitize = original
end

.local_environmentsObject

NOTE: Deprecated method We have to actually define because we can't deprecate methods that are hooked up via method_missing



56
57
58
# File 'lib/sanitize_email.rb', line 56

def self.local_environments
  SanitizeEmail::Config.config[:local_environments]
end

.method_missing(name, *_args) ⇒ Object



44
45
46
# File 'lib/sanitize_email.rb', line 44

def self.method_missing(name, *_args)
  SanitizeEmail[name]
end

.sanitary(config_options = {}) ⇒ Object

Regardless of the Config settings of SanitizeEmail you can do a local override to send sanitary email in any environment. You have access to all the same configuration options in the parameter hash as you can set in the actual SanitizeEmail.configure block.

SanitizeEmail.sanitary(=> “boo@example.com”) do

Mail.deliver do
  from      "from@example.org"
  # Will actually be sent to the override addresses, not this one:
  to        "to@example.org"
  reply_to  "reply_to@example.org"
  subject   "subject"
end

end



85
86
87
88
89
90
91
92
93
# File 'lib/sanitize_email.rb', line 85

def self.sanitary(config_options = {})
  raise MissingBlockParameter, 'SanitizeEmail.sanitary must be called with a block' unless block_given?
  janitor(:forcing => true) do
    original = SanitizeEmail::Config.config.dup
    SanitizeEmail::Config.config.merge!(config_options)
    yield
    SanitizeEmail::Config.config = original
  end
end

.sanitized_recipientsObject

NOTE: Deprecated method We have to actually define because we can't deprecate methods that are hooked up via method_missing



50
51
52
# File 'lib/sanitize_email.rb', line 50

def self.sanitized_recipients
  SanitizeEmail::Config.config[:sanitized_recipients]
end

.unsanitaryObject

Regardless of the Config settings of SanitizeEmail you can do a local override to force unsanitary email in any environment.

SanitizeEmail.unsanitary do

Mail.deliver do
  from      "from@example.org"
  to        "to@example.org"
  reply_to  "reply_to@example.org"
  subject   "subject"
end

end



107
108
109
110
111
112
# File 'lib/sanitize_email.rb', line 107

def self.unsanitary
  raise MissingBlockParameter, 'SanitizeEmail.unsanitary must be called with a block' unless block_given?
  janitor(:forcing => false) do
    yield
  end
end