Fix file processing and optimize when the same file if multiple times

master 1.2.1
Julien Rosset 5 days ago
parent b79dfdbb2b
commit a77612bad1

@ -209,7 +209,7 @@ class PHPMailerEnhanced extends PHPMailer {
$link = $match[0]; $link = $match[0];
//region Check the link has no protocol (http, cid, etc.) or it's “file” //region Check the link has no protocol (http, cid, etc.) or it's “file”
if (preg_match('#^(?<protocol>[a-z][a-z\d+.-]*):(?<path>.+)$#i', $link, $match) === 1) { if (preg_match('#^(?:(?<protocol>[a-z][a-z\d+.-]*):)?(?<path>.+)$#i', $link, $match) === 1) {
if (($match['protocol'] ?? '') !== 'file') { if (($match['protocol'] ?? '') !== 'file') {
return $link; return $link;
} }
@ -229,11 +229,17 @@ class PHPMailerEnhanced extends PHPMailer {
return $link; return $link;
} }
} }
$path = realpath($path);
//endregion //endregion
//region Associate a cid to the file //region Associate a cid to the file
$cid = $this->cidGenerate(); if (array_key_exists($path, $embeddedImages)) {
$embeddedImages[$cid] = $path; $cid = $embeddedImages[$path];
}
else {
$cid = $this->cidGenerate();
$embeddedImages[$path] = $cid;
}
//endregion //endregion
return 'cid:' . $cid; return 'cid:' . $cid;
@ -251,7 +257,7 @@ class PHPMailerEnhanced extends PHPMailer {
$this->$bodyProperty = $body; $this->$bodyProperty = $body;
//endregion //endregion
//region Embed the files in the mail //region Embed the files in the mail
foreach ($embeddedImages as $cid => $path) { foreach ($embeddedImages as $path => $cid) {
$this->addEmbeddedImage($path, $cid); $this->addEmbeddedImage($path, $cid);
} }
//endregion //endregion

Loading…
Cancel
Save