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];
//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') {
return $link;
}
@ -229,11 +229,17 @@ class PHPMailerEnhanced extends PHPMailer {
return $link;
}
}
$path = realpath($path);
//endregion
//region Associate a cid to the file
if (array_key_exists($path, $embeddedImages)) {
$cid = $embeddedImages[$path];
}
else {
$cid = $this->cidGenerate();
$embeddedImages[$cid] = $path;
$embeddedImages[$path] = $cid;
}
//endregion
return 'cid:' . $cid;
@ -251,7 +257,7 @@ class PHPMailerEnhanced extends PHPMailer {
$this->$bodyProperty = $body;
//endregion
//region Embed the files in the mail
foreach ($embeddedImages as $cid => $path) {
foreach ($embeddedImages as $path => $cid) {
$this->addEmbeddedImage($path, $cid);
}
//endregion

Loading…
Cancel
Save