Skip to content

Commit

Permalink
Fix email address check
Browse files Browse the repository at this point in the history
  • Loading branch information
JohnDuprey committed Mar 30, 2024
1 parent a57afd0 commit 93d3b6e
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions Modules/CIPPCore/Public/Entrypoints/Invoke-ExecMailTest.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ Function Invoke-ExecMailTest {
'CheckConfig' {
$GraphToken = Get-GraphToken -returnRefresh $true -SkipCache $true
$AccessTokenDetails = Read-JwtAccessDetails -Token $GraphToken.access_token
$Me = New-GraphGetRequest -uri 'https://graph.microsoft.com/beta/me?$select=displayName,proxyAddresses' -NoAuthCheck $true
$Me = New-GraphGetRequest -uri 'https://graph.microsoft.com/beta/me?$select=displayName,userPrincipalName,proxyAddresses' -NoAuthCheck $true
if ($AccessTokenDetails.Scope -contains 'Mail.Read') {
$Message = 'Mail.Read - Delegated was found in the token scope.'
$HasMailRead = $true
Expand All @@ -27,11 +27,17 @@ Function Invoke-ExecMailTest {
$HasMailRead = $false
}

if ($Me.proxyAddresses) {
$Emails = $Me.proxyAddresses | Select-Object @{n = 'Address'; exp = { ($_ -split ':')[1] } }, @{n = 'IsPrimary'; exp = { $_ -cmatch 'SMTP' } }
} else {
$Emails = @(@{ Address = $Me.userPrincipalName; IsPrimary = $true })
}

$Body = [PSCustomObject]@{
Message = $Message
HasMailRead = $HasMailRead
MailUser = $Me.displayName
MailAddresses = $Me.proxyAddresses | Select-Object @{n = 'Address'; exp = { ($_ -split ':')[1] } }, @{n = 'IsPrimary'; exp = { $_ -cmatch 'SMTP' } }
MailAddresses = $Emails
}
}
default {
Expand All @@ -54,7 +60,7 @@ Function Invoke-ExecMailTest {
Sender = $Message.sender.emailAddress.name
From = $Message.sender.emailAddress.address
Link = $Message.webLink
Headers = $Message.internetMessageHeaders
Headers = $Message.internetMessageHeaders
AuthResult = $AuthResult
}
}
Expand Down

0 comments on commit 93d3b6e

Please sign in to comment.