Closed GUI closed 2 weeks ago
Interesting. Thanks for the report. I'll get it fixed ASAP.
Turns out part of the Rails documentation was bad. https://github.com/rails/rails/issues/42170
Fixing.
Fix released in 2.0.7. Please give it a try @GUI
We're still experiencing this issue in version 2.0.7 & rails 7.1.3.4
Changing the code in engine_v6.rb
to
ActiveSupport.on_load(:action_mailer) do
ActionMailer::Base.register_interceptor(SanitizeEmail::Bleach)
end
as suggested here appears to solve the problem
Fix is released in v2.0.8 @anthonyklue @GUI
After upgrading from sanitize_email 2.0.4 to 2.0.6, it looks like e-mails have stopped being intercepted in a Rails 7.1 app by default. If I manually call
Mail.register_interceptor(SanitizeEmail::Bleach)
, this does seem to fix the interception in the app, but I think something is maybe amiss with the new Engine integration for Rails 6+ in 2.0.6:https://github.com/pboling/sanitize_email/compare/v2.0.4...v2.0.6#diff-c6ad5f4fb841393b5d4fee8dac9a3be490baf334851b4cae3adcb90c1096a4e2 https://github.com/pboling/sanitize_email/compare/v2.0.4...v2.0.6#diff-6b14c6f0901cbec9229126c0ae73f28b72421a354fc0aead148fa406f5f665ca
I think the issue is maybe related to the new
EngineV6
calling: https://github.com/pboling/sanitize_email/blob/2ee17b815d7bff4dcba975ea2410d7cbbc48b1c2/lib/sanitize_email/engine_v6.rb#L13I believe the issue is that
register_interceptor
may not actually be doing anything in this case. At least in the Rails 7.1 app I'm testing,Rails.application.config.action_mailer
is actually an instance ofActiveSupport::OrderedOptions
, so this is more like a hash that responds to method calls as hash lookups too. But that means that I don't thinkregister_interceptor()
is actually calling any type of underlying method. Instead, I think it's just looking for a:register_interceptor
attribute on the hash of mailer config data, and returningnil
since it doesn't exist.So I think this means that calling
Rails.application.config.action_mailer.register_interceptor(SanitizeEmail::Bleach)
doesn't actually seem to ever call the underlyingActionMailer::Base.register_interceptor
orMail.register_interceptor
methods. You can see how any method passed toaction_mailer
will not raise an exception, but I don't believe it's actually calling anything (I think it's just acting more like a hash accessor). This differs from how a real call toActionMailer::Base.register_interceptor
will react:So I think this might mean that this Engine for Rails 6+ isn't actually setting the interceptor by default in version 2.0.6. It sounds like maybe a deprecation warning is the reason for the new approach in Rails 6+, but for whatever it's worth I don't actually see any deprecation warnings when using sanitize_email 2.0.4 under Rails 7.1 (but I realize I might not be exercising the right thing, since there's probably a lot of different possible app setups).
Thanks!