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

core#644 - extract function to return correct mailbox header #13407

Merged
merged 2 commits into from
Jan 7, 2019

Conversation

MegaphoneJon
Copy link
Contributor

Overview

Core#357 identified an issue where emails sent with a "From" address of the logged-in user send the contact ID as the "From" address instead of the correct "From" address. This PR extracts the fix to CRM_Utils_Mail, cleans it up a bit for readability, and applies it to membership renewal notifications.

Before

Membership renewal notifications sent a "From" address that's the contact ID of the logged-in user.

After

Membership renewal notifications send the logged-in user's actual name/email.

@civibot
Copy link

civibot bot commented Jan 5, 2019

(Standard links)

@civibot civibot bot added the master label Jan 5, 2019
@seamuslee001
Copy link
Contributor

@MegaphoneJon question do we need to apply similar fixes in CRM/Member/Form/Membership.php and CRM/Contribute/Form/AdditionalInfo.php and similar or maybe CRM/Contribute/Form/Task/Invoice.php ?

@seamuslee001
Copy link
Contributor

ping @mattwire

'id' => $header,
'return' => ['contact_id.display_name', 'email'],
'sequential' => 1,
])['values'][0];
Copy link
Contributor

Choose a reason for hiding this comment

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

This will give a PHP notice if the id is not found

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That's probably a good thing though, right? The only legitimate use case in which this code path executes would require the id to be found. Or are you suggesting I should use getsingle so it throws an error rather than a notice?

Copy link
Member

@monishdeb monishdeb Jan 7, 2019

Choose a reason for hiding this comment

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

The old and this new code pretends that is_numeric($from) will always be a valid email ID, so it doesn't need any additional handling for empty result. Or I could have suggested:

$result = CRM_Utils_Array::value(0, civicrm_api3('Email', 'get', [
        'id' => $from,
        'return' => ['contact_id.display_name', 'email'],
        'sequential' => 1,
      ])['values']);

if (empty($result)) {
  Civi::log()->warning(ts('Invalid From email ID - ' . $from);
}
...

I think we can ignore this.

CRM/Utils/Mail.php Outdated Show resolved Hide resolved
CRM/Utils/Mail.php Outdated Show resolved Hide resolved
@mattwire
Copy link
Contributor

mattwire commented Jan 6, 2019

do we need to apply similar fixes in CRM/Member/Form/Membership.php and CRM/Contribute/Form/AdditionalInfo.php and similar or maybe CRM/Contribute/Form/Task/Invoice.php ?

I think so, also looks like it would be an issue in CRM_Pledge_BAO_Pledge.php

@ghost
Copy link

ghost commented Jan 6, 2019

I have attached the patches and the e-mail addresses are correct now.

@MegaphoneJon
Copy link
Contributor Author

do we need to apply similar fixes in CRM/Member/Form/Membership.php and CRM/Contribute/Form/AdditionalInfo.php and similar or maybe CRM/Contribute/Form/Task/Invoice.php ?

I think so, also looks like it would be an issue in CRM_Pledge_BAO_Pledge.php

I'll patch these files too - but I'm curious how you two found these functions? And whether there are other places I should check?

@seamuslee001
Copy link
Contributor

@MegaphoneJon knowing that you can send receipts from the backend contrib forms (membership renewal membership signup contribution forms etc) I just started looking for similar places that might also be susceptible

@MegaphoneJon
Copy link
Contributor Author

Thanks @seamuslee001. These all call CRM_Core_BAO_MessageTemplate::sendTemplate so I'm moving my fix there to reduce code redundancy.

@seamuslee001
Copy link
Contributor

Jenkins re test this please

@seamuslee001
Copy link
Contributor

@MegaphoneJon @mattwire I managed to replicate the issue in a unit test so posted it here #13408 and was able to confirm this fixes the problem and outputs a sensible from email address.

@monishdeb
Copy link
Member

I have confirmed that this PR fixes the issue. @seamuslee001 isn't #13408 is supposed to fail without this patch?

@monishdeb
Copy link
Member

Cool. Based on @mattwire @seamuslee001 and my review I am going to merge this PR. Also it has UT in PR #13408 (I will trigger the test build again to ensure that the patch fixes the test failure and thus this bug).

Thanks!

@monishdeb monishdeb merged commit b0aa1e0 into civicrm:master Jan 7, 2019
@monishdeb
Copy link
Member

#13408 test build passed now :)

kenwest added a commit to kenwest/cbf-drupal that referenced this pull request Feb 28, 2019
Reverse commit e28a209
Add a patch for civicrm/civicrm-core#13407
This is CiviCRM's proposal to fix dev/core#758
@eileenmcnaughton
Copy link
Contributor

@aydun has asked if we can put the in tomorrow's 5.11.0 release -it looks like it's not already in?

@@ -389,6 +389,11 @@ public static function sendTemplate($params) {

CRM_Utils_Hook::alterMailParams($params, 'messageTemplate');

// Core#644 - handle contact ID passed as "From".
Copy link
Contributor

Choose a reason for hiding this comment

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

I know this commit has already been merged, but I feel like this block where the FROM address is "fixed" should be before the alterMailParams hook is called. otherwise we're sending bad data to that hook and then fixing it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@lcdservices That makes sense. If you submit a PR I'll review it?

Copy link
Contributor

Choose a reason for hiding this comment

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

@MegaphoneJon here you go: #13776

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants