Skip to content

Commit

Permalink
Merge pull request #13 from JohnDuprey/dev
Browse files Browse the repository at this point in the history
Dev to main
  • Loading branch information
JohnDuprey authored Feb 2, 2024
2 parents fb1a841 + 64d1b9a commit 9023e85
Showing 1 changed file with 22 additions and 12 deletions.
34 changes: 22 additions & 12 deletions DNSHealth/Public/Records/Read-DkimRecord.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,10 @@ function Read-DkimRecord {
[string]$Domain,

[Parameter()]
[System.Collections.Generic.List[string]]$Selectors = @()
[System.Collections.Generic.List[string]]$Selectors = @(),

[Parameter()]
[switch]$FallbackToMicrosoftSelectors
)

$MXRecord = $null
Expand All @@ -49,21 +52,28 @@ function Read-DkimRecord {
# MX lookup, check for defined selectors
try {
$MXRecord = Read-MXRecord -Domain $Domain
foreach ($Selector in $MXRecord.Selectors) {
try {
$Selectors.Add($Selector) | Out-Null
if ($MXRecord.Selectors) {
foreach ($Selector in $MXRecord.Selectors) {
try {
$Selectors.Add($Selector) | Out-Null
} catch { Write-Verbose $_.Exception.Message }
}

catch { Write-Verbose $_.Exception.Message }
}
$DkimAnalysis.MailProvider = $MXRecord.MailProvider
if ($MXRecord.MailProvider.PSObject.Properties.Name -contains 'MinimumSelectorPass') {
$MinimumSelectorPass = $MXRecord.MailProvider.MinimumSelectorPass
if ($MXRecord.MailProvider) {
$DkimAnalysis.MailProvider = $MXRecord.MailProvider
if ($MXRecord.MailProvider.PSObject.Properties.Name -contains 'MinimumSelectorPass') {
$MinimumSelectorPass = $MXRecord.MailProvider.MinimumSelectorPass
}
$DkimAnalysis.Selectors = $Selectors
}
$DkimAnalysis.Selectors = $Selectors
}
} catch { Write-Verbose $_.Exception.Message }

catch { Write-Verbose $_.Exception.Message }
# Fallback to Microsoft DKIM selectors
if ($FallbackToMicrosoftSelectors.IsPresent -and ($Selectors | Measure-Object | Select-Object -ExpandProperty Count) -eq 0) {
$MinimumSelectorPass = 1
$Selectors.Add('selector1')
$Selectors.Add('selector2')
}

# Get unique selectors
$Selectors = $Selectors | Sort-Object -Unique
Expand Down

0 comments on commit 9023e85

Please sign in to comment.