You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: src/Symfony/Component/Mime/Email.php
+14Lines changed: 14 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -43,6 +43,7 @@ class Email extends Message
43
43
private$html;
44
44
private$htmlCharset;
45
45
private$attachments = [];
46
+
private ?AbstractPart$cachedBody = null; // Used to avoid wrong body hash in DKIM signatures with multiple parts (e.g. HTML + TEXT) due to multiple boundaries.
46
47
47
48
/**
48
49
* @return $this
@@ -282,6 +283,7 @@ public function text($body, string $charset = 'utf-8')
282
283
thrownew \TypeError(sprintf('The body must be a string, a resource or null (got "%s").', get_debug_type($body)));
283
284
}
284
285
286
+
$this->cachedBody = null;
285
287
$this->text = $body;
286
288
$this->textCharset = $charset;
287
289
@@ -312,6 +314,7 @@ public function html($body, string $charset = 'utf-8')
312
314
thrownew \TypeError(sprintf('The body must be a string, a resource or null (got "%s").', get_debug_type($body)));
313
315
}
314
316
317
+
$this->cachedBody = null;
315
318
$this->html = $body;
316
319
$this->htmlCharset = $charset;
317
320
@@ -342,6 +345,7 @@ public function attach($body, string $name = null, string $contentType = null)
342
345
thrownew \TypeError(sprintf('The body must be a string or a resource (got "%s").', get_debug_type($body)));
$this->assertSame($body1, $body2, 'The two bodies must reference the same object, so the body cache ensures that the hash for the DKIM signature is unique.');
471
+
472
+
$email = newEmail();
473
+
$email->from('fabien@symfony.com');
474
+
$email->to('fabien@symfony.com');
475
+
$email->text('foo');
476
+
$body1 = $email->getBody();
477
+
$email->html('<b>bar</b>'); // We change a part to reset the body cache.
478
+
$body2 = $email->getBody();
479
+
$this->assertNotSame($body1, $body2, 'The two bodies must not reference the same object, so the body cache does not ensure that the hash for the DKIM signature is unique.');
0 commit comments