@@ -463,7 +463,7 @@ private function generateBody(): AbstractPart
463
463
464
464
$ this ->ensureValidity ();
465
465
466
- [$ htmlPart , $ attachmentParts , $ inlineParts ] = $ this ->prepareParts ();
466
+ [$ htmlPart , $ otherParts , $ relatedParts ] = $ this ->prepareParts ();
467
467
468
468
$ part = null === $ this ->text ? null : new TextPart ($ this ->text , $ this ->textCharset );
469
469
if (null !== $ htmlPart ) {
@@ -474,15 +474,15 @@ private function generateBody(): AbstractPart
474
474
}
475
475
}
476
476
477
- if ($ inlineParts ) {
478
- $ part = new RelatedPart ($ part , ...$ inlineParts );
477
+ if ($ relatedParts ) {
478
+ $ part = new RelatedPart ($ part , ...$ relatedParts );
479
479
}
480
480
481
- if ($ attachmentParts ) {
481
+ if ($ otherParts ) {
482
482
if ($ part ) {
483
- $ part = new MixedPart ($ part , ...$ attachmentParts );
483
+ $ part = new MixedPart ($ part , ...$ otherParts );
484
484
} else {
485
- $ part = new MixedPart (...$ attachmentParts );
485
+ $ part = new MixedPart (...$ otherParts );
486
486
}
487
487
}
488
488
@@ -508,42 +508,44 @@ private function prepareParts(): ?array
508
508
}
509
509
510
510
// usage of reflection is a temporary workaround for missing getters that will be added in 6.2
511
- $ dispositionRef = new \ReflectionProperty (TextPart::class, 'disposition ' );
512
- $ dispositionRef ->setAccessible (true );
513
511
$ nameRef = new \ReflectionProperty (TextPart::class, 'name ' );
514
512
$ nameRef ->setAccessible (true );
515
- $ attachmentParts = $ inlineParts = [];
513
+ $ otherParts = $ relatedParts = [];
516
514
foreach ($ this ->attachments as $ attachment ) {
517
515
$ part = $ this ->createDataPart ($ attachment );
518
516
if (isset ($ attachment ['part ' ])) {
519
517
$ attachment ['name ' ] = $ nameRef ->getValue ($ part );
520
518
}
521
519
520
+ $ related = false ;
522
521
foreach ($ names as $ name ) {
523
522
if ($ name !== $ attachment ['name ' ]) {
524
523
continue ;
525
524
}
526
- if (isset ($ inlineParts [$ name ])) {
525
+ if (isset ($ relatedParts [$ name ])) {
527
526
continue 2 ;
528
527
}
529
528
$ part ->setDisposition ('inline ' );
530
- $ html = str_replace ('cid: ' .$ name , 'cid: ' .$ part ->getContentId (), $ html );
529
+ $ html = str_replace ('cid: ' .$ name , 'cid: ' .$ part ->getContentId (), $ html , $ count );
530
+ if ($ count ) {
531
+ $ related = true ;
532
+ }
531
533
$ part ->setName ($ part ->getContentId ());
532
534
533
535
break ;
534
536
}
535
537
536
- if (' inline ' === $ dispositionRef -> getValue ( $ part ) ) {
537
- $ inlineParts [$ attachment ['name ' ]] = $ part ;
538
+ if ($ related ) {
539
+ $ relatedParts [$ attachment ['name ' ]] = $ part ;
538
540
} else {
539
- $ attachmentParts [] = $ part ;
541
+ $ otherParts [] = $ part ;
540
542
}
541
543
}
542
544
if (null !== $ htmlPart ) {
543
545
$ htmlPart = new TextPart ($ html , $ this ->htmlCharset , 'html ' );
544
546
}
545
547
546
- return [$ htmlPart , $ attachmentParts , array_values ($ inlineParts )];
548
+ return [$ htmlPart , $ otherParts , array_values ($ relatedParts )];
547
549
}
548
550
549
551
private function createDataPart (array $ attachment ): DataPart
0 commit comments