diff --git a/src/PHPMailer.php b/src/PHPMailer.php index 26bc6cce..5e8bbe6f 100644 --- a/src/PHPMailer.php +++ b/src/PHPMailer.php @@ -1124,6 +1124,22 @@ class PHPMailer return call_user_func_array([$this, 'addAnAddress'], $params); } + /** + * Set the boundaries to use for delimiting MIME parts. + * If you override this, ensure you set all 3 boundaries to unique values. + * The default boundaries include a "=_" sequence which cannot occur in quoted-printable bodies, + * as suggested by https://www.rfc-editor.org/rfc/rfc2045#section-6.7 + * + * @return void + */ + public function setBoundaries() + { + $this->uniqueid = $this->generateId(); + $this->boundary[1] = 'b1=_' . $this->uniqueid; + $this->boundary[2] = 'b2=_' . $this->uniqueid; + $this->boundary[3] = 'b3=_' . $this->uniqueid; + } + /** * Add an address to one of the recipient arrays or to the ReplyTo array. * Addresses that have been added already return false, but do not throw exceptions. @@ -2794,10 +2810,7 @@ class PHPMailer { $body = ''; //Create unique IDs and preset boundaries - $this->uniqueid = $this->generateId(); - $this->boundary[1] = 'b1_' . $this->uniqueid; - $this->boundary[2] = 'b2_' . $this->uniqueid; - $this->boundary[3] = 'b3_' . $this->uniqueid; + $this->setBoundaries(); if ($this->sign_key_file) { $body .= $this->getMailMIME() . static::$LE; @@ -3069,6 +3082,18 @@ class PHPMailer return $body; } + /** + * Get the boundaries that this message will use + * @return array + */ + public function getBoundaries() + { + if (empty($this->boundary)) { + $this->setBoundaries(); + } + return $this->boundary; + } + /** * Return the start of a message boundary. * diff --git a/test/PHPMailer/GenerateIdTest.php b/test/PHPMailer/GenerateIdTest.php index 5230b4ce..c9dcf257 100644 --- a/test/PHPMailer/GenerateIdTest.php +++ b/test/PHPMailer/GenerateIdTest.php @@ -49,7 +49,7 @@ final class GenerateIdTest extends PreSendTestCase self::assertSame( 1, preg_match( - '`Content-Type: multipart/alternative;\s+boundary="(b[1-3]_[A-Za-z0-9]{32,})"`', + '`Content-Type: multipart/alternative;\s+boundary="(b[1-3]=_[A-Za-z0-9]{32,})"`', $message, $matches ), @@ -64,4 +64,12 @@ final class GenerateIdTest extends PreSendTestCase 'No boundaries using the generated ID found in message' ); } + + public function testBoundaries() + { + $boundaries = $this->Mail->getBoundaries(); + self::assertMatchesRegularExpression('/b[1-3]=_[A-Za-z0-9]{32,}/', $boundaries[1]); + self::assertMatchesRegularExpression('/b[1-3]=_[A-Za-z0-9]{32,}/', $boundaries[2]); + self::assertMatchesRegularExpression('/b[1-3]=_[A-Za-z0-9]{32,}/', $boundaries[3]); + } }