Break out setting MIME boundaries into a protected method, fixes #2511
This commit is contained in:
parent
12e5c0c6f6
commit
c033268049
|
|
@ -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.
|
||||
*
|
||||
|
|
|
|||
|
|
@ -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]);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue