Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[#6404] Update user email to be sent from the blackhole address #8261

Merged
merged 5 commits into from
May 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions app/helpers/config_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,8 @@
!AlaveteliConfiguration.exception_notifications_from.blank? &&
!AlaveteliConfiguration.exception_notifications_to.blank?
end

def blackhole_email
AlaveteliConfiguration.blackhole_prefix+"@"+AlaveteliConfiguration.incoming_email_domain

Check warning on line 16 in app/helpers/config_helper.rb

View workflow job for this annotation

GitHub Actions / build

[rubocop] reported by reviewdog 🐶 Surrounding space missing for operator `+`. (https://rubystyle.guide#spaces-operators) Raw Output: app/helpers/config_helper.rb:16:44: C: Layout/SpaceAroundOperators: Surrounding space missing for operator `+`. (https://rubystyle.guide#spaces-operators)

Check warning on line 16 in app/helpers/config_helper.rb

View workflow job for this annotation

GitHub Actions / build

[rubocop] reported by reviewdog 🐶 Surrounding space missing for operator `+`. (https://rubystyle.guide#spaces-operators) Raw Output: app/helpers/config_helper.rb:16:48: C: Layout/SpaceAroundOperators: Surrounding space missing for operator `+`. (https://rubystyle.guide#spaces-operators)

Check warning on line 16 in app/helpers/config_helper.rb

View workflow job for this annotation

GitHub Actions / build

[rubocop] reported by reviewdog 🐶 Line is too long. [92/80] (https://rubystyle.guide#max-line-length) Raw Output: app/helpers/config_helper.rb:16:81: C: Layout/LineLength: Line is too long. [92/80] (https://rubystyle.guide#max-line-length)
end
end
2 changes: 1 addition & 1 deletion app/mailers/alaveteli_pro/account_mailer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ module AlaveteliPro
class AccountMailer < ApplicationMailer
def account_request(account_request)
@account_request = account_request
set_reply_to_headers(nil, 'Reply-To' => @account_request.email)
set_reply_to_headers('Reply-To' => @account_request.email)

# From is an address we control so that strict DMARC senders don't get refused
mail(from: blackhole_email,
Expand Down
27 changes: 2 additions & 25 deletions app/mailers/alaveteli_pro/embargo_mailer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,7 @@ def expiring_alert(user, info_requests)
site_name: site_name.html_safe,
count: info_requests.count
)
auto_generated_headers
mail_user(@user, subject)
mail_user(@user, subject: subject)
end

def expired_alert(user, info_requests)
Expand All @@ -89,29 +88,7 @@ def expired_alert(user, info_requests)
site_name: site_name.html_safe,
count: info_requests.count
)
auto_generated_headers
mail_user(@user, subject)
end

private

# TODO: these are copied from request_mailer, but it seems like they should
# be something shared via application_mailer.
def auto_generated_headers
headers({
'Return-Path' => blackhole_email,
'Reply-To' => pro_contact_from_name_and_email, # not much we can do if the user's email is broken
'Auto-Submitted' => 'auto-generated', # http://tools.ietf.org/html/rfc3834
'X-Auto-Response-Suppress' => 'OOF'
})
end

def mail_user(user, subject)
mail({
from: pro_contact_from_name_and_email,
to: user.name_and_email,
subject: subject
})
mail_user(@user, subject: subject)
end
end
end
2 changes: 1 addition & 1 deletion app/mailers/alaveteli_pro/subscription_mailer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ def payment_failed(user)
@user_name = user.name
@pro_site_name = pro_site_name.html_safe
@subscriptions_url = subscriptions_url
mail_user(user, subject)
mail_user(user, subject: subject)
end

private
Expand Down
34 changes: 23 additions & 11 deletions app/mailers/application_mailer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,27 @@ class ApplicationMailer < ActionMailer::Base
# about the errors, and have to do error checking on return codes.
self.raise_delivery_errors = true

def blackhole_email
AlaveteliConfiguration.blackhole_prefix+"@"+AlaveteliConfiguration.incoming_email_domain
end
def mail_user(user, subject:, **opts)
if user.is_a?(User)
opts[:to] = user.name_and_email
else
opts[:to] = user
end

if opts[:from].is_a?(User)
set_reply_to_headers('Reply-To' => opts[:from].name_and_email)
opts[:from] = MailHandler.address_from_name_and_email(
opts[:from].name, blackhole_email
)

else
opts[:from] = blackhole_email
set_reply_to_headers
end

set_auto_generated_headers

def mail_user(user, subject, opts = {})
default_opts = {
from: contact_for_user(user),
to: user.name_and_email,
subject: subject
}
default_opts.merge!(opts)
Expand All @@ -49,10 +62,10 @@ def contact_for_user(user = nil)
# Set headers that mark an email as being auto-generated and suppress out of
# office responses to them
def set_auto_generated_headers(_opts = {})
headers({
headers(
'Auto-Submitted' => 'auto-generated', # http://tools.ietf.org/html/rfc3834
'X-Auto-Response-Suppress' => 'OOF'
})
)
end

# Set Return-Path and Reply-To headers
Expand All @@ -68,10 +81,9 @@ def set_auto_generated_headers(_opts = {})
# - When sending emails from one user to another, do not set envelope from
# address to the from_user, so they can't get someone's email addresses
# from transitory bounce messages.
def set_reply_to_headers(user = nil, opts = {})
def set_reply_to_headers(opts = {})
default_opts = {
'Return-Path' => blackhole_email,
'Reply-To' => contact_for_user(user)
'Return-Path' => blackhole_email
}
default_opts.merge!(opts)
headers(default_opts)
Expand Down
29 changes: 17 additions & 12 deletions app/mailers/contact_mailer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ def to_admin_message(name, email, subject, message, logged_in_user, last_request
@last_body = last_body

reply_to_address = MailHandler.address_from_name_and_email(name, email)
set_reply_to_headers(nil, 'Reply-To' => reply_to_address)
set_reply_to_headers('Reply-To' => reply_to_address)

# From is an address we control so that strict DMARC senders don't get refused
mail(from: MailHandler.address_from_name_and_email(name, blackhole_email),
Expand All @@ -30,12 +30,12 @@ def user_message(from_user, recipient_user, from_user_url, subject, message)
@recipient_user = recipient_user
@from_user_url = from_user_url

set_reply_to_headers(nil, 'Reply-To' => from_user.name_and_email)

# From is an address we control so that strict DMARC senders don't get refused
mail(from: MailHandler.address_from_name_and_email(from_user.name, blackhole_email),
to: recipient_user.name_and_email,
subject: subject)
mail_user(
recipient_user,
from: from_user,
subject: subject
)
end

# Send message to a user from the administrator
Expand All @@ -44,11 +44,16 @@ def from_admin_message(recipient_name, recipient_email, subject, message)
@recipient_name = recipient_name
@recipient_email = recipient_email

recipient_user = User.find_by_email(recipient_email)

mail(from: contact_for_user(recipient_user),
to: MailHandler.address_from_name_and_email(@recipient_name, @recipient_email),
bcc: AlaveteliConfiguration.contact_email,
subject: subject)
to_address = MailHandler.address_from_name_and_email(
@recipient_name, @recipient_email
)
from_address = contact_for_user(User.find_by_email(recipient_email))

mail_user(
to_address,
from: from_address,
bcc: AlaveteliConfiguration.contact_email,
subject: subject
)
end
end
6 changes: 2 additions & 4 deletions app/mailers/info_request_batch_mailer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,10 @@ def batch_sent(info_request_batch, unrequestable, user)
@unrequestable = unrequestable
@url = info_request_batch_url(@info_request_batch)

set_reply_to_headers(user)

mail_user(
user,
_("Your batch request \"{{title}}\" has been sent",
title: info_request_batch.title.html_safe)
subject: _("Your batch request \"{{title}}\" has been sent",
title: info_request_batch.title.html_safe)
)
end
end
62 changes: 27 additions & 35 deletions app/mailers/notification_mailer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -82,13 +82,10 @@ def daily_summary(user, notifications)
end
end

set_reply_to_headers(user)
set_auto_generated_headers

mail_user(
user,
_("Your daily request summary from {{pro_site_name}}",
pro_site_name: pro_site_name)
subject: _("Your daily request summary from {{pro_site_name}}",
pro_site_name: pro_site_name)
)
end

Expand All @@ -102,80 +99,75 @@ def response_notification(notification)
@info_request = notification.info_request_event.info_request
@incoming_message = notification.info_request_event.incoming_message

set_reply_to_headers(@info_request.user)
set_auto_generated_headers

subject = _("New response to your FOI request - {{request_title}}",
request_title: @info_request.title.html_safe)
mail_user(@info_request.user,
subject,
template_name: 'response_notification')
mail_user(
@info_request.user,
subject: subject,
template_name: 'response_notification'
)
end

def embargo_expiring_notification(notification)
@info_request = notification.info_request_event.info_request

set_reply_to_headers(@info_request.user)
set_auto_generated_headers

subject = _(
"Your FOI request - {{request_title}} will be made public on " \
"{{site_name}} this week",
request_title: @info_request.title.html_safe,
site_name: site_name.html_safe
)

mail_user(@info_request.user,
subject,
template_name: 'embargo_expiring_notification')
mail_user(
@info_request.user,
subject: subject,
template_name: 'embargo_expiring_notification'
)
end

def expire_embargo_notification(notification)
@info_request = notification.info_request_event.info_request

set_reply_to_headers(@info_request.user)
set_auto_generated_headers

subject = _(
"Your FOI request - {{request_title}} has been made public on " \
"{{site_name}}",
request_title: @info_request.title.html_safe,
site_name: site_name.html_safe
)

mail_user(@info_request.user,
subject,
template_name: 'expire_embargo_notification')
mail_user(
@info_request.user,
subject: subject,
template_name: 'expire_embargo_notification'
)
end

def overdue_notification(notification)
@info_request = notification.info_request_event.info_request
@url = signin_url(r: respond_to_last_path(@info_request))

set_reply_to_headers(@info_request.user)
set_auto_generated_headers

subject = _("Delayed response to your FOI request - {{request_title}}",
request_title: @info_request.title.html_safe)

mail_user(@info_request.user,
subject,
template_name: 'overdue_notification')
mail_user(
@info_request.user,
subject: subject,
template_name: 'overdue_notification'
)
end

def very_overdue_notification(notification)
@info_request = notification.info_request_event.info_request
@url = signin_url(r: respond_to_last_path(@info_request))

set_reply_to_headers(@info_request.user)
set_auto_generated_headers

subject = _("You're long overdue a response to your FOI request " \
"- {{request_title}}",
request_title: @info_request.title.html_safe)

mail_user(@info_request.user,
subject,
template_name: 'very_overdue_notification')
mail_user(
@info_request.user,
subject: subject,
template_name: 'very_overdue_notification'
)
end
end
2 changes: 1 addition & 1 deletion app/mailers/public_body_change_request_mailer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def change_request_message(change_request, template)
@change_request.get_user_name,
@change_request.get_user_email)

set_reply_to_headers(nil, 'Reply-To' => reply_to_address)
set_reply_to_headers('Reply-To' => reply_to_address)

mail(from: from_address,
to: contact_from_name_and_email,
Expand Down
Loading
Loading