New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix DKIM's error when there is S/MIME-sign #2340
base: master
Are you sure you want to change the base?
Conversation
Thanks for this – I don't think anyone has actually used this combination before, so I'm happy to receive fixes like this! |
@Synchro Openssl uses \n\n to separate headers and content. This is what everyone knows. I'm not sure if openssl uses the unique \n to split the lines of headers. Maybe \r\n too? But \n is present in all cases. That's why I split the lines with \n, then use the function TRIM for those lines. This way, if \r is present, it will be removed as well. |
Thanks for clarifying. Do you have tests to cover this? |
@Synchro Yes, I've tested it many times already. And this solves the problem of incorrectly displaying the message with this configuration: PHP 8.x, PHPmail, S/MIME without DKIM (the same reason: MIME-Version and Content-Type not found) |
No, I mean could you add tests to the PHPMailer test suite to ensure it works and prevent regression in future. |
@Synchro Same test (environment: Linux/windows, php 8.x, PHP mail, S/MIME) : |
I mean the automated unit tests in here. What you pointed at is example code which has to be adapted and run manually. Ideally there would be something similar that generates a message, but then verifies it as part of the test suite, which is run and checked every time a commit it made to the repo. Unfortunately there is no PHP-based test suite for DKIM (though I'm working on it), but S/MIME should be easier to write a test for – generate a signed message, then check if its signature matches the key. |
$subparts = array_map('trim', explode("\n", $parts[0])); | ||
foreach($subparts as $subpart) { | ||
$this->MIMEHeader .= $subpart . static::$LE; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, this is great here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is already a function to normalise breaks in static::normalizeBreaks()
which would make for a cleaner implementation here.
In $parts[0] there is MIME-Version and Content-Type delimited by "\n".
Need to separate them, otherwise error with DKIM: "dkim=neutral (body hash did not verify)" (The reason is in "h=Date:To:From:Reply-To:Subject:Message-ID:X-Mailer;" without MIME-Version and Content-Type)
Test environment : PHP 8.0.6, PHPmail, isSMTP, DKIM-sign, S/MIME