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
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 3 additions & 11 deletions libraries/src/Mail/Mail.php
Original file line number Diff line number Diff line change
Expand Up @@ -401,28 +401,20 @@ public function addAttachment($path, $name = '', $encoding = 'base64', $type = '
$result = true;

if (\is_array($path)) {
if (!empty($name) && \count($path) != \count($name)) {
if (!empty($name) && \is_array($name) && \count($path) != \count($name)) {
throw new \InvalidArgumentException('The number of attachments must be equal with the number of name');
}

foreach ($path as $key => $file) {
if (!empty($name)) {
$result = parent::addAttachment($file, $name[$key], $encoding, $type);
} else {
if (!empty($name)) {
$result = parent::addAttachment($file, $name[$key], $encoding, $type, $disposition);
} else {
$result = parent::addAttachment($file, $name, $encoding, $type, $disposition);
}
}
$result = parent::addAttachment($file, isset($name[$key]) ? $name[$key] : '', $encoding, $type, $disposition);
}

// Check for boolean false return if exception handling is disabled
if ($result === false) {
return false;
}
} else {
$result = parent::addAttachment($path, $name, $encoding, $type);
$result = parent::addAttachment($path, $name, $encoding, $type, $disposition);
}

// Check for boolean false return if exception handling is disabled
Expand Down