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

[Pro] Site email handling for pro users #3706

Merged
merged 17 commits into from
Feb 6, 2017

Conversation

stevenday
Copy link

@stevenday stevenday commented Jan 31, 2017

This combines mysociety/alaveteli-professional#75 mysociety/alaveteli-professional#138 and
mysociety/alaveteli-professional#140 into a single branch, since they're all related
and need each other to really work correctly.

This PR:

  • Refactors bounce handling so that non-bounce replies to emails are sent to
    two different addresses, one for replies from pro users and one for
    everything else
  • Adds a new contact address for pro user support
  • Refactors all of the mailers to:
    • Share Return-Path, Reply-To and other related header setting wherever
      possible
    • Be aware of the new pro contact address and use it when emailing pros

Closes mysociety/alaveteli-professional#75
Closes mysociety/alaveteli-professional#138
Closes mysociety/alaveteli-professional#140

@stevenday stevenday force-pushed the alaveteli-pro-site-email-handling branch from 925dcf8 to fb7e6f5 Compare January 31, 2017 13:17
@coveralls

This comment has been minimized.

@stevenday
Copy link
Author

@crowbot - I think the only spec failures here are the ones occurring everywhere in pro regarding month arithmetic, so this should be ready for a review when you have a moment.

@coveralls

This comment has been minimized.

Copy link
Member

@crowbot crowbot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this PR is making an unintended change which adds the headers that indicate that the message was autogenerated and that out of office replies should be suppressed to lots of messages that didn't previously have them. A couple of other less significant style/naming comments inline.

headers('Return-Path' => blackhole_email,
'Reply-To' => MailHandler.address_from_name_and_email(name, email))
reply_to_address = MailHandler.address_from_name_and_email(name, email)
auto_generated_headers('Reply-To' => reply_to_address)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is going to set the 'Auto-Submitted' => 'auto-generated' and 'X-Auto-Response-Suppress' => 'OOF' headers here, I don't think the 'Auto-Submitted' => 'auto-generated' one is appropriate as it shouldn't be used on manually generated messages, only on messages that are automatically created.

# Do not set envelope from address to the from_user, so they can't get
# someone's email addresses from transitory bounce messages.
headers('Return-Path' => blackhole_email, 'Reply-To' => from_user.name_and_email)
auto_generated_headers('Reply-To' => from_user.name_and_email)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Again, I don't think the autogenerated headers for 'Auto-Submitted' and 'X-Auto-Response-Suppress' are right for this email

:to => user.name_and_email,
:subject => _("Your batch request \"{{title}}\" has been sent",
:title => info_request_batch.title.html_safe))
mail_user(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is going to use the headers that we don't want.

# Return path is an address we control so that SPF checks are done on it.
headers('Return-Path' => blackhole_email,
'Reply-To' => user.name_and_email)
auto_generated_headers(:reply_to => user.name_and_email)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same issue, some of these headers aren't appropriate.

:to => info_request.user.name_and_email,
:subject => _("New response to your FOI request - {{request_title}}",
:request_title => info_request.title.html_safe),
:charset => "UTF-8",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like we've lost the charset here?

mail(:from => contact_from_name_and_email,
:to => user.name_and_email,
:subject => reasons[:email_subject])
mail_user(user, reasons[:email_subject])
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Again, we don't want the `auto-submitted' and 'auto-reply-suppress' headers here.

end

def already_registered(user, reasons, url)
@reasons, @name, @url = reasons, user.name, url
headers('Return-Path' => blackhole_email, 'Reply-To' => contact_from_name_and_email) # we don't care about bounces when people are fiddling with their account
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same issue here

end

def changeemail_confirm(user, new_email, url)
@name, @url, @old_email, @new_email = user.name, url, user.email, new_email
headers('Return-Path' => blackhole_email, 'Reply-To' => contact_from_name_and_email) # we don't care about bounces when people are fiddling with their account
auto_generated_headers('Reply-To' => contact_for_user(user))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't want some of these headers, as in previous cases.

:to => new_email,
:subject => _("Confirm your new email address on {{site_name}}", :site_name => site_name))
end

def changeemail_already_used(old_email, new_email)
@old_email, @new_email = old_email, new_email
headers('Return-Path' => blackhole_email, 'Reply-To' => contact_from_name_and_email) # we don't care about bounces when people are fiddling with their account
user = User.find_by_email(@old_email)
auto_generated_headers('Reply-To' => contact_for_user(user))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same again.

@@ -0,0 +1,125 @@
# -*- encoding : utf-8 -*-
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe this ought to be a submodule of `mail_handler?

@coveralls

This comment has been minimized.

@stevenday
Copy link
Author

@crowbot - sorry, I hadn't really thought through the impact of setting those headers everywhere.

I've made some changes to application_mailer.rb to separate setting reply_to headers and auto_generated headers, and then updated all the mailers so that they only call the appropriate things. I think there are now no unexpected changes to any of the mail headers.

I've also put ReplyHandler into MailHandler::ReplyHandler as suggested, though I'm not sure if there's a convention for where the file should live? (It seems a bit odd being alongside mail_handler.rb)

@coveralls

This comment has been minimized.

@stevenday stevenday removed their assignment Feb 3, 2017
Copy link
Member

@crowbot crowbot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One comment inline, but other than that, looks great!

mail(:from => contact_from_name_and_email,

recipient_user = User.find_by_email(recipient_email)
set_reply_to_headers(recipient_user)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We're adding new reply-to and return-path headers here. I don't think it should make any substantial difference, but maybe better to leave it as it is, as it's not the focus of this PR?

@coveralls

This comment has been minimized.

@coveralls

This comment has been minimized.

@coveralls

This comment has been minimized.

@stevenday stevenday force-pushed the alaveteli-pro-site-email-handling branch from 75bef5e to 8bb6946 Compare February 6, 2017 15:13
@stevenday stevenday merged commit 8bb6946 into alaveteli-pro-develop Feb 6, 2017
@coveralls
Copy link

coveralls commented Feb 6, 2017

Coverage Status

Coverage decreased (-0.5%) to 92.934% when pulling 8bb6946 on alaveteli-pro-site-email-handling into 71e0672 on alaveteli-pro-develop.

@stevenday stevenday deleted the alaveteli-pro-site-email-handling branch February 6, 2017 15:37
@mysociety mysociety deleted a comment from coveralls Jul 6, 2021
@mysociety mysociety deleted a comment from coveralls Jul 6, 2021
@mysociety mysociety deleted a comment from coveralls Jul 6, 2021
@mysociety mysociety deleted a comment from coveralls Jul 6, 2021
@mysociety mysociety deleted a comment from coveralls Jul 6, 2021
@mysociety mysociety deleted a comment from coveralls Jul 6, 2021
@mysociety mysociety deleted a comment from coveralls Jul 6, 2021
@mysociety mysociety deleted a comment from coveralls Jul 6, 2021
@mysociety mysociety deleted a comment from coveralls Jul 6, 2021
@mysociety mysociety deleted a comment from coveralls Jul 6, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants