File attachments don't get correct filename or mimetype when set explicitly

Created on 31 January 2025, 2 months ago

Problem/Motivation

When preparing an email with an attachment using mimemail, we may want to send the file as a different filename from that on the server. And since the filename is used in the guessing of the mimetime, it should allow the mimetype to be set as well.

Currently the filename isn't set correctly because the code is using the wrong array key, and the filemime is not overriddable at all.

Steps to reproduce

When preparing an emali using mime mail and mail manager:

        $result = $this->mailManager->mail(
          'mymodule',
          'mymodule_mailtemplate',
          $pdf_recipient,
          $pdf_language,
          [
            'attachments' => [
              [
                'filename' => 'history.pdf',
                'filepath' => $pdfFileRealPath,
                'filemime' => 'application/pdf',
              ],
            ],
            'requester_email' => $data['email'],
            'request_hash' => $request_hash,
          ],
          FALSE
        );

And we set the filemime and filename we want (which are different than the file that was generated on the server).

Proposed resolution

  • Use the filename key correctly
  • Allow the filemime to be set as well
🐛 Bug report
Status

Active

Version

2.0

Component

Code

Created by

🇨🇦Canada minoroffense Ottawa, Canada

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

Production build 0.71.5 2024