forked from PHPMailer/PHPMailer
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add flag for using copiedHeaderFields and config for using extra head…
…ers in DKIM signature (PHPMailer#1468) * Changed in DKIM signature - Add flag for using copiedHeaderFields - config for using extra headers in DKIM signature * Cleanups after Review - Don't use masked ampersands in url - Remove test related artifacts after run * Complete docs
- Loading branch information
1 parent
46869d4
commit 5c9d3c5
Showing
3 changed files
with
153 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1910,6 +1910,96 @@ public function testDKIMHeaderCanonicalization() | |
); | ||
} | ||
|
||
/** | ||
* DKIM copied header fields tests. | ||
* | ||
* @group dkim | ||
* | ||
* @see https://tools.ietf.org/html/rfc6376#section-3.5 | ||
*/ | ||
public function testDKIMOptionalHeaderFieldsCopy() | ||
{ | ||
$privatekeyfile = 'dkim_private.pem'; | ||
$pk = openssl_pkey_new( | ||
[ | ||
'private_key_bits' => 2048, | ||
'private_key_type' => OPENSSL_KEYTYPE_RSA, | ||
] | ||
); | ||
openssl_pkey_export_to_file($pk, $privatekeyfile); | ||
$this->Mail->DKIM_private = 'dkim_private.pem'; | ||
|
||
//Example from https://tools.ietf.org/html/rfc6376#section-3.5 | ||
$from = '[email protected]'; | ||
$to = '[email protected]'; | ||
$date = 'date'; | ||
$subject = 'example'; | ||
|
||
$headerLines = "From:$from\r\nTo:$to\r\nDate:$date\r\n"; | ||
$copyHeaderFields = "\tz=From:$from\r\n\t|To:$to\r\n\t|Date:$date\r\n\t|Subject:=20$subject;\r\n"; | ||
|
||
$this->Mail->DKIM_copyHeaderFields = true; | ||
$this->assertContains( | ||
$copyHeaderFields, | ||
$this->Mail->DKIM_Add($headerLines, $subject, ''), | ||
'DKIM header with copied header fields incorrect' | ||
); | ||
|
||
$this->Mail->DKIM_copyHeaderFields = false; | ||
$this->assertNotContains( | ||
$copyHeaderFields, | ||
$this->Mail->DKIM_Add($headerLines, $subject, ''), | ||
'DKIM header without copied header fields incorrect' | ||
); | ||
|
||
unlink($privatekeyfile); | ||
} | ||
|
||
/** | ||
* DKIM signing extra headers tests. | ||
* | ||
* @group dkim | ||
*/ | ||
public function testDKIMExtraHeaders() | ||
{ | ||
$privatekeyfile = 'dkim_private.pem'; | ||
$pk = openssl_pkey_new( | ||
[ | ||
'private_key_bits' => 2048, | ||
'private_key_type' => OPENSSL_KEYTYPE_RSA, | ||
] | ||
); | ||
openssl_pkey_export_to_file($pk, $privatekeyfile); | ||
$this->Mail->DKIM_private = 'dkim_private.pem'; | ||
|
||
//Example from https://tools.ietf.org/html/rfc6376#section-3.5 | ||
$from = '[email protected]'; | ||
$to = '[email protected]'; | ||
$date = 'date'; | ||
$subject = 'example'; | ||
$anyHeader = 'foo'; | ||
$unsubscribeUrl = '<https://www.example.com/unsubscribe/?newsletterId=anytoken&actionToken=anyToken' . | ||
'&otherParam=otherValue&anotherParam=anotherVeryVeryVeryLongValue>'; | ||
|
||
$this->Mail->addCustomHeader('X-AnyHeader', $anyHeader); | ||
$this->Mail->addCustomHeader('Baz', 'bar'); | ||
$this->Mail->addCustomHeader('List-Unsubscribe', $unsubscribeUrl); | ||
|
||
$this->Mail->DKIM_extraHeaders = ['Baz', 'List-Unsubscribe']; | ||
|
||
$headerLines = "From:$from\r\nTo:$to\r\nDate:$date\r\n"; | ||
$headerLines .= "X-AnyHeader:$anyHeader\r\nBaz:bar\r\n"; | ||
$headerLines .= 'List-Unsubscribe:' . $this->Mail->encodeHeader($unsubscribeUrl) . "\r\n"; | ||
|
||
$headerFields = 'h=From:To:Date:Subject:Baz:List-Unsubscribe'; | ||
|
||
$result = $this->Mail->DKIM_Add($headerLines, $subject, ''); | ||
|
||
$this->assertContains($headerFields, $result, 'DKIM header with extra headers incorrect'); | ||
|
||
unlink($privatekeyfile); | ||
} | ||
|
||
/** | ||
* DKIM Signing tests. | ||
* | ||
|