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

Provide additional information to Mail class (original values) #31842

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

eileenmcnaughton
Copy link
Contributor

@eileenmcnaughton eileenmcnaughton commented Jan 21, 2025

Overview

I'm working through replacing the mail library in an extension - https://github.com/eileenmcnaughton/symfony_mailer - although I think I'd like to see it changed in core - at the moment its hard to do that because our code interprets the html into body before it gets to the library - which wants to do it itself

We do have VARIOUS hooks = but so far changing it out in hook_civicrm_alterMailer seems to intervene in the most places / most reliably & other extensions seem to use it

Before

It is possible to entirely swap out the REALLY OLD Pear mail libraries - but if you do so the library does not receive adequate information about the bcc or the attachments

After

These extra parameters are passed

Technical Details

I think we should consider migrating to symfony_mailer in core given it seems to be winning the mailer adoption battle and move the old mail classes to an extension. But out of scope here

Comments

Copy link

civibot bot commented Jan 21, 2025

🤖 Thank you for contributing to CiviCRM! ❤️ We will need to test and review this PR. 👷

Introduction for new contributors...
  • If this is your first PR, an admin will greenlight automated testing with the command ok to test or add to whitelist.
  • A series of tests will automatically run. You can see the results at the bottom of this page (if there are any problems, it will include a link to see what went wrong).
  • A demo site will be built where anyone can try out a version of CiviCRM that includes your changes.
  • If this process needs to be repeated, an admin will issue the command test this please to rerun tests and build a new demo site.
  • Before this PR can be merged, it needs to be reviewed. Please keep in mind that reviewers are volunteers, and their response time can vary from a few hours to a few weeks depending on their availability and their knowledge of this particular part of CiviCRM.
  • A great way to speed up this process is to "trade reviews" with someone - find an open PR that you feel able to review, and leave a comment like "I'm reviewing this now, could you please review mine?" (include a link to yours). You don't have to wait for a response to get started (and you don't have to stop at one!) the more you review, the faster this process goes for everyone 😄
  • To ensure that you are credited properly in the final release notes, please add yourself to contributor-key.yml
  • For more information about contributing, see CONTRIBUTING.md.
Quick links for reviewers...

➡️ Online demo of this PR 🔗

@civibot civibot bot added the master label Jan 21, 2025
eileenmcnaughton added a commit to eileenmcnaughton/symfony_mailer that referenced this pull request Jan 21, 2025
@mattwire
Copy link
Contributor

@eileenmcnaughton This looks fine. Have you tried extracting the BCC recipients yet... that's a whole other mess and would be really nice to see them separated out in the call to send()

$originalValues = [
'html' => $params['html'] ?? NULL,
'text' => $params['text'] ?? NULL,
'attachments' => $params['attachments'] ?? [],
Copy link
Contributor

Choose a reason for hiding this comment

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

@eileenmcnaughton Please can we add in 'Bcc' => $headers['Bcc'] ?? NULL or similar here because of this crazyness: https://github.com/civicrm/civicrm-core/blob/master/CRM/Utils/Mail.php#L202 which makes it really annoying to get the Bcc recipients back into the headers if they are required. You have to parse the headers, extract the email addresses and compare against the $to array! The missing ones then have to be added back in as Bcc.
At least that's the case for eg. Amazon SES via API.

Copy link
Contributor

Choose a reason for hiding this comment

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

Note, we'd need to store the value before unsetting it as well.

Copy link
Contributor

Choose a reason for hiding this comment

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

Oh, it might make sense to just add in Cc array keys here as well for completeness though we don't necessarily need it because we can find it in the headers. Would make it easier for anyone wanting to work with this in the future though.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@mattwire I feel like if we add in Bcc we should add in to, cc & bcc (maybe from too) - but then the format becomes the question - from context it looks like we have already formatted the emails so an array like this probably makes sense (& invites the addition of 'from' too) - ie it's an array of strings where name & email are already formatted into a single string, if both exist

'to' => [
  '[email protected]',
  "Matt Wire <[email protected]">,
],
'cc' =>  ['[email protected]', "Matt Wire <[email protected]">],
'bcc' =>  ['[email protected]', "Matt Wire <[email protected]">],

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hmm - I guess what you are saying is that ^^ would be no different to what is currently in 'headers'

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@mattwire I've added in 'bcc' - I'm on the fence about cc cos I feel like that would be cc, to and from once we get into the completeness question - which might make sense but I'm not sure.

Also, my read of the code is that Bcc would currently be a single email address so converting to an array through casting works - is that your take?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oh dang - it comes in as

"Adams, Clint" <[email protected]>,"[email protected]" <[email protected]>

I kinda hate not converting it to an array - but I don't think I can safely explode it

Copy link
Contributor

Choose a reason for hiding this comment

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

@mattwire
Copy link
Contributor

@eileenmcnaughton I think this is a great idea. But I've added a "feature request" that would help me too :-)

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

@eileenmcnaughton I've made a suggested change. If you are happy with those I suggest you flag merge-ready

@mattwire
Copy link
Contributor

mattwire commented Feb 3, 2025

@eileenmcnaughton I've hit a little spanner... see https://github.com/civicrm/civicrm-core/blob/master/ext/flexmailer/src/Listener/DefaultSender.php#L65

Ideally we'd add the extra data there two so we call mail() with the same signature. Also to make things more messy that one passes the first argument as a string (To) instead of array

eileenmcnaughton and others added 2 commits February 4, 2025 09:17
Co-authored-by: Matthew Wire <[email protected]>
Co-authored-by: Matthew Wire <[email protected]>
@eileenmcnaughton
Copy link
Contributor Author

@mattwire I've merged your changes but I kinda hate passing bcc as a string - It feels gross.

Re the flexmailing calling mail directly ... ug - thinking.

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.

2 participants