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

[5.1] Fix attachment handling in libraries Mail class #43828

Merged
merged 3 commits into from
Jul 23, 2024

Conversation

LadySolveig
Copy link
Contributor

Pull Request for Issue # .

Summary of Changes

It is currently not possible to attach a single attachment with the disposition 'inline' to a mail via the Mail library class.

Above all, this means that it is also not possible to send an image as an inline attachment via the Mail class and then simply refer to it via cid.

This means that in the e-mails that are sent when they are received on different clients, the download of the images must first be approved by the user before they are visible.

The changes in the Mail class address issues with attachment handling. Specifically:

  • Ensured the addAttachment method includes the $disposition parameter in all cases.
  • Simplified the logic for adding attachments by removing redundant checks.
  • Added a check to ensure $name is an array before comparing its count with $path.

Testing Instructions

Set the option Mail Format -> HTML in Global Configuration -> Mail Templates

grafik

Add the following lines of code (only!) for testing into the file 'libraries/src/Mail/MailTemplate.php' line 277

$logo = Path::clean(JPATH_ROOT . '/images/banners/white.png');
# Attach the logo as inline attachement
$this->mailer->addAttachment($logo, basename($logo), 'base64', mime_content_type($logo), 'inline');
// We need only the cid for attached logo file inline
$htmlBody .= '<img src="cid:' . htmlspecialchars(basename($logo), ENT_QUOTES) . '" alt="Test inline attachment" style="max-width:80%;height:auto;border:none;text-decoration:none;color:#ffffff;">';

grafik

Send a test mail under Global Configuration -> Server tab at the bottom of the page using the Send Test Mail button

grafik

Actual result BEFORE applying this Pull Request

Attachment is inserted but not as an inline attachment and thus the assignment to the image fails.

grafik

grafik

Expected result AFTER applying this Pull Request

Attachment is inserted as an inline attachment and thus the assignment to the image works.
grafik
grafik

Link to documentations

Please select:

  • Documentation link for docs.joomla.org:

  • No documentation changes for docs.joomla.org needed

  • Pull Request link for manual.joomla.org:

  • No documentation changes for manual.joomla.org needed

@brianteeman
Copy link
Contributor

I have tested this item ✅ successfully on 574d39d


This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/43828.

1 similar comment
@bembelimen
Copy link
Contributor

I have tested this item ✅ successfully on 574d39d


This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/43828.

@Quy
Copy link
Contributor

Quy commented Jul 23, 2024

RTC


This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/43828.

@joomla-cms-bot joomla-cms-bot added the RTC This Pull Request is Ready To Commit label Jul 23, 2024
@bembelimen bembelimen merged commit dabf3fe into joomla:5.1-dev Jul 23, 2024
4 checks passed
@bembelimen
Copy link
Contributor

Thx

@joomla-cms-bot joomla-cms-bot removed the RTC This Pull Request is Ready To Commit label Jul 23, 2024
@bembelimen bembelimen added this to the Joomla! 5.1.3 milestone Jul 23, 2024
dgrammatiko pushed a commit to dgrammatiko/joomla-cms that referenced this pull request Aug 11, 2024
dgrammatiko pushed a commit to dgrammatiko/joomla-cms that referenced this pull request Aug 11, 2024
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.

5 participants