for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
declare(strict_types=1);
namespace Genkgo\Mail\Header\Dkim;
final class RelaxedCanonicalizeBody implements CanonicalizeBodyInterface
getName
{
/**
* @param string $string
* @return string
*/
public function canonicalize(string $string): string
$length = strlen($string);
$canon = '';
$lastChar = null;
$space = false;
$line = '';
$emptyCounter = 0;
for ($i = 0; $i < $length; ++$i) {
switch ($string[$i]) {
case "\r":
$lastChar = "\r";
break;
case "\n":
if ($lastChar === "\r") {
if ($line === '') {
++$emptyCounter;
} else {
$canon .= "\r\n";
}
throw new \RuntimeException('This should never happen');
case ' ':
case "\t":
$space = true;
default:
if ($emptyCounter > 0) {
$canon .= str_repeat("\r\n", $emptyCounter);
if ($space) {
$line .= ' ';
$canon .= ' ';
$line .= $string[$i];
$canon .= $string[$i];
return $canon;