diff --git a/CHANGELOG.md b/CHANGELOG.md index 5384918..a9a8b71 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,7 @@ - **FIX** `Test-DaneRecords` now correctly checks DANE records for domains without MX records. - **FIX** The DMARC `fo` token is now parsed correctly when multiple values are present. - **FIX** The DMARC `rf` token is now parsed correctly. +- **FIX** The MTA-STS policy file test returns a better error message when the file does not have the correct CRLF line endings. - **FIX** The SPF `exists` and `mx` token parsers no longer generate a spurious error when *not* counting DNS lookups. - **FIX** IntelliSense's handling of `Test-SpfRecord` has been improved by hiding some internal-use-only parameters. - **FIX** Cleaned up `Test-DaneRecords`' output. diff --git a/MailPolicyExplainer.psd1 b/MailPolicyExplainer.psd1 index 2f89da0..2be47d5 100644 --- a/MailPolicyExplainer.psd1 +++ b/MailPolicyExplainer.psd1 @@ -174,6 +174,7 @@ Many bugs were fixed, too: - The DMARC `fo` token is now parsed correctly when multiple values are present. - The DMARC `rf` token is now parsed correctly. - The IntelliSense handling of `Test-SpfRecord` has been improved by hiding some internal-use-only parameters. +- The MTA-STS policy file test returns a better error message when the file does not have the correct CRLF line endings. - The SPF `exists` and `mx` token parsers no longer generate a spurious error when not counting DNS lookups. - Cleaned up the output of `Test-DaneRecords` a little. - Miscellaneous code cleanup. diff --git a/src/MailPolicyExplainer.psm1 b/src/MailPolicyExplainer.psm1 index 213f1c1..92f6596 100644 --- a/src/MailPolicyExplainer.psm1 +++ b/src/MailPolicyExplainer.psm1 @@ -867,7 +867,21 @@ Function Test-MtaStsPolicy Write-BadNews "MTA-STS Policy: It was found, but was returned with the wrong content type ($($policy.Headers.'Content-Type'))." } Else { - $policy.Content.Split("`r`n") | ForEach-Object { + #region Make sure the file has the correct line endings. + # The MTA-STS RFC says that they should end with CRLF (i.e., "`r`n"). + # Split it up two different ways and see if we get the same results. + # If not, then someone probably saved the file with UNIX ("`r") endings. + # We're going to be strict and refuse to parse the file in this case. + $lines = $policy.Content.Split("`r`n") + $LFlines = $policy.Content -Split "`r?`n" + + If ($lines -ne $LFLines) { + Write-BadNews "MTA-STS Policy: The policy file does not have the correct CRLF line endings!" + Return + } + #endregion + + $lines | ForEach-Object { $line = $_.Trim() If ($line -CLike 'version: *') { If (($line -Split ':')[1].Trim() -Eq 'STSv1') { @@ -1279,7 +1293,7 @@ Function Test-SpfRecord If ($CountDnsLookups) { $DnsLookups.Value++ } - + If ($token -Match "^\+?exists:.*") { Write-GoodNews "${RecordType}: Accept mail if $($token -Replace '\+' -Replace 'exists:') resolves to an A record.$(Write-DnsLookups $DnsLookups -Enabled:$CountDnsLookups)" }