From 9f4a1e9a0c669657248da328efaa36cecfea2aa6 Mon Sep 17 00:00:00 2001 From: David Russell Date: Tue, 9 Jul 2019 13:18:56 -0400 Subject: [PATCH 1/6] added import-gsgmailmessage --- .../Public/Gmail/Import-GSGmailMessage.ps1 | 125 ++++++++++++++++++ 1 file changed, 125 insertions(+) create mode 100644 PSGSuite/Public/Gmail/Import-GSGmailMessage.ps1 diff --git a/PSGSuite/Public/Gmail/Import-GSGmailMessage.ps1 b/PSGSuite/Public/Gmail/Import-GSGmailMessage.ps1 new file mode 100644 index 00000000..dc5a2dba --- /dev/null +++ b/PSGSuite/Public/Gmail/Import-GSGmailMessage.ps1 @@ -0,0 +1,125 @@ +function Get-GSGmailMessage { + <# + .SYNOPSIS + Gets Gmail message details + + .DESCRIPTION + Gets Gmail message details + + .PARAMETER User + The primary email of the user who owns the message + + Defaults to the AdminEmail user + + .PARAMETER Id + The Id of the message to retrieve info for + + .PARAMETER ParseMessage + If $true, returns the parsed raw message + + .PARAMETER SaveAttachmentsTo + If the message has attachments, the path to save the attachments to. If excluded, attachments are not saved locally + + .PARAMETER Format + The format of the message metadata to retrieve + + Available values are: + * "Full" + * "Metadata" + * "Minimal" + * "Raw" + + Defaults to "Full", but forces -Format as "Raw" if -ParseMessage or -SaveAttachmentsTo are used + + .EXAMPLE + Get-GSGmailMessage -Id 1615f9a6ee36cb5b -ParseMessage + + Gets the full message details for the provided Id and parses out the raw MIME message content + #> + [OutputType('Google.Apis.Gmail.v1.Data.Message')] + [cmdletbinding(DefaultParameterSetName = "Format")] + Param + ( + [parameter(Mandatory = $false,ValueFromPipelineByPropertyName = $true)] + [Alias("PrimaryEmail","UserKey","Mail")] + [string] + $User = $Script:PSGSuite.AdminEmail, + [parameter(Mandatory = $true,ValueFromPipelineByPropertyName = $true)] + [Alias('MessageId')] + [String[]] + $Id, + [parameter(Mandatory = $false,ParameterSetName = "ParseMessage")] + [switch] + $ParseMessage, + [parameter(Mandatory = $false,ParameterSetName = "ParseMessage")] + [Alias('AttachmentOutputPath','OutFilePath')] + [ValidateScript({(Get-Item $_).PSIsContainer})] + [string] + $SaveAttachmentsTo, + [parameter(Mandatory = $false,ParameterSetName = "Format")] + [ValidateSet("Full","Metadata","Minimal","Raw")] + [string] + $Format = "Full" + ) + Process { + if ($User -ceq 'me') { + $User = $Script:PSGSuite.AdminEmail + } + elseif ($User -notlike "*@*.*") { + $User = "$($User)@$($Script:PSGSuite.Domain)" + } + if ($ParseMessage) { + $Format = "Raw" + } + $serviceParams = @{ + Scope = 'https://mail.google.com' + ServiceType = 'Google.Apis.Gmail.v1.GmailService' + User = $User + } + $service = New-GoogleService @serviceParams + try { + foreach ($mId in $Id) { + $request = $service.Users.Messages.Get($User,$mId) + $request.Format = $Format + foreach ($key in $PSBoundParameters.Keys | Where-Object {$_ -ne "Id"}) { + switch ($key) { + Default { + if ($request.PSObject.Properties.Name -contains $key) { + $request.$key = $PSBoundParameters[$key] + } + } + } + } + Write-Verbose "Getting Message Id '$mId' for user '$User'" + $result = $request.Execute() | Add-Member -MemberType NoteProperty -Name 'User' -Value $User -PassThru + if ($ParseMessage) { + $parsed = Read-MimeMessage -String $(Convert-Base64 -From WebSafeBase64String -To NormalString -String $result.Raw) | Select-Object @{N = 'User';E = {$User}},@{N = "Id";E = {$result.Id}},@{N = "ThreadId";E = {$result.ThreadId}},@{N = "LabelIds";E = {$result.LabelIds}},@{N = "Snippet";E = {$result.Snippet}},@{N = "HistoryId";E = {$result.HistoryId}},@{N = "InternalDate";E = {$result.InternalDate}},@{N = "InternalDateConverted";E = {Convert-EpochToDate -EpochString $result.internalDate}},@{N = "SizeEstimate";E = {$result.SizeEstimate}},* + if ($SaveAttachmentsTo) { + $resPath = Resolve-Path $SaveAttachmentsTo + $attachments = $parsed.Attachments + foreach ($att in $attachments) { + $cleanedName = $att.FileName -replace "[$(([System.IO.Path]::GetInvalidFileNameChars() + [System.IO.Path]::GetInvalidPathChars()) -join '')]","_" + $fileName = Join-Path $resPath $cleanedName + Write-Verbose "Saving attachment to path '$fileName'" + $stream = [System.IO.File]::Create($fileName) + $att.ContentObject.DecodeTo($stream) + $stream.Close() + } + } + $parsed + } + else { + $result + } + } + } + catch { + if ($ErrorActionPreference -eq 'Stop') { + $PSCmdlet.ThrowTerminatingError($_) + } + else { + Write-Error $_ + } + } + } +} From 0c306fbc61118a9cb9cc27f4e4dfb6b27b2ef0ea Mon Sep 17 00:00:00 2001 From: David Russell Date: Fri, 18 Mar 2022 07:44:33 -0400 Subject: [PATCH 2/6] added move-gscalendarevent function --- .../Public/Calendar/Move-GSCalendarEvent.ps1 | 92 +++++++++++++++++++ 1 file changed, 92 insertions(+) create mode 100644 PSGSuite/Public/Calendar/Move-GSCalendarEvent.ps1 diff --git a/PSGSuite/Public/Calendar/Move-GSCalendarEvent.ps1 b/PSGSuite/Public/Calendar/Move-GSCalendarEvent.ps1 new file mode 100644 index 00000000..0cbec5a7 --- /dev/null +++ b/PSGSuite/Public/Calendar/Move-GSCalendarEvent.ps1 @@ -0,0 +1,92 @@ +function Move-GSCalendarEvent { + <# + .SYNOPSIS + Moves an event to a new calendar (updates the Organizer). + + .DESCRIPTION + Moves an event to a new calendar (updates the Organizer). + + .PARAMETER CalendarID + The Id of the source calendar. + + Defaults to the user's primary calendar. + + .PARAMETER EventID + The unique Id of the event to update + + .PARAMETER NewCalendarId + The Id of the target calendar. + + .PARAMETER User + The primary email or UserID of the user. You can exclude the '@domain.com' to insert the Domain in the config or use the special 'me' to indicate the AdminEmail in the config. + + Defaults to the AdminEmail in the config. + + User must have access to both calendars. Recommend using admin. + + .PARAMETER SendUpdates + Whether to send update notifications to the attendees. + + Possible values are: + * "none" - No notifications are sent. + * "externalOnly" - Notifications are sent to non-Google Calendar guests only. + * "all" - Notifications are sent to all guests. + + .EXAMPLE + Move-GSCalendarEvent -CalendarId source.calendar@domain.com -EventId bcfgr7j83oqpv8174bnamv63pj -NewCalendarId target.calendar@domain.com + + Moves the event with eventId "bcfgr7j83oqpv8174bnamv63pj" from calendar "source.calendar@domain.com" to calendar "target.calendar@domain.com" + #> + [OutputType('Google.Apis.Calendar.v3.Data.Event')] + [cmdletbinding(DefaultParameterSetName = "AttendeeEmails")] + Param + ( + [parameter(Mandatory = $true, Position = 0, ValueFromPipelineByPropertyName = $true)] + [Alias('Id')] + [String] + $EventId, + [parameter(Mandatory = $false, ValueFromPipelineByPropertyName = $true)] + [String] + $CalendarId = "primary", + [parameter(Mandatory = $false, ValueFromPipelineByPropertyName = $true)] + [Alias("PrimaryEmail", "UserKey", "Mail")] + [ValidateNotNullOrEmpty()] + [String] + $User = $Script:PSGSuite.AdminEmail, + [parameter(Mandatory = $true, ValueFromPipelineByPropertyName = $false)] + [String] + $NewCalendarId, + [parameter(Mandatory = $false, ValueFromPipelineByPropertyName = $false)] + [ValidateSet("none", "all", "externalOnly")] + [String] + $SendUpdates = "none" + ) + Process { + try { + if ($Uuser -ceq 'me') { + $User = $Script:PSGSuite.AdminEmail + } + elseif ($User -notlike "*@*.*") { + $User = "$($User)@$($Script:PSGSuite.Domain)" + } + $serviceParams = @{ + Scope = 'https://www.googleapis.com/auth/calendar' + ServiceType = 'Google.Apis.Calendar.v3.CalendarService' + User = $User + } + $service = New-GoogleService @serviceParams + Write-Verbose "Moving Calendar Event '$EventId' on calendar '$CalendarId' for user '$User' to calendar '$NewCalendarId'" + $request = $service.Events.Move($CalendarId, $EventId, $NewCalendarId) + $request.SendUpdates = $SendUpdates + $request.Execute() | Add-Member -MemberType NoteProperty -Name 'User' -Value $User -PassThru | Add-Member -MemberType NoteProperty -Name 'CalendarId' -Value $NewCalendarId -PassThru + } + catch { + if ($ErrorActionPreference -eq 'Stop') { + $PSCmdlet.ThrowTerminatingError($_) + } + else { + Write-Error $_ + } + } + } +} From 9c8057b33d9c00bdee8fe49fbf30c936398b4b9c Mon Sep 17 00:00:00 2001 From: David Russell Date: Fri, 18 Mar 2022 07:48:03 -0400 Subject: [PATCH 3/6] updated parameter name to DestinationCalendarId --- PSGSuite/Public/Calendar/Move-GSCalendarEvent.ps1 | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/PSGSuite/Public/Calendar/Move-GSCalendarEvent.ps1 b/PSGSuite/Public/Calendar/Move-GSCalendarEvent.ps1 index 0cbec5a7..abb39228 100644 --- a/PSGSuite/Public/Calendar/Move-GSCalendarEvent.ps1 +++ b/PSGSuite/Public/Calendar/Move-GSCalendarEvent.ps1 @@ -14,8 +14,8 @@ function Move-GSCalendarEvent { .PARAMETER EventID The unique Id of the event to update - .PARAMETER NewCalendarId - The Id of the target calendar. + .PARAMETER DestinationCalendarId + The Id of the destination calendar. .PARAMETER User The primary email or UserID of the user. You can exclude the '@domain.com' to insert the Domain in the config or use the special 'me' to indicate the AdminEmail in the config. @@ -33,7 +33,7 @@ function Move-GSCalendarEvent { * "all" - Notifications are sent to all guests. .EXAMPLE - Move-GSCalendarEvent -CalendarId source.calendar@domain.com -EventId bcfgr7j83oqpv8174bnamv63pj -NewCalendarId target.calendar@domain.com + Move-GSCalendarEvent -CalendarId source.calendar@domain.com -EventId bcfgr7j83oqpv8174bnamv63pj -DestinationCalendarId target.calendar@domain.com Moves the event with eventId "bcfgr7j83oqpv8174bnamv63pj" from calendar "source.calendar@domain.com" to calendar "target.calendar@domain.com" #> @@ -55,7 +55,7 @@ function Move-GSCalendarEvent { $User = $Script:PSGSuite.AdminEmail, [parameter(Mandatory = $true, ValueFromPipelineByPropertyName = $false)] [String] - $NewCalendarId, + $DestinationCalendarId, [parameter(Mandatory = $false, ValueFromPipelineByPropertyName = $false)] [ValidateSet("none", "all", "externalOnly")] [String] @@ -75,10 +75,10 @@ function Move-GSCalendarEvent { User = $User } $service = New-GoogleService @serviceParams - Write-Verbose "Moving Calendar Event '$EventId' on calendar '$CalendarId' for user '$User' to calendar '$NewCalendarId'" - $request = $service.Events.Move($CalendarId, $EventId, $NewCalendarId) + Write-Verbose "Moving Calendar Event '$EventId' on calendar '$CalendarId' for user '$User' to calendar '$DestinationCalendarId'" + $request = $service.Events.Move($CalendarId, $EventId, $DestinationCalendarId) $request.SendUpdates = $SendUpdates - $request.Execute() | Add-Member -MemberType NoteProperty -Name 'User' -Value $User -PassThru | Add-Member -MemberType NoteProperty -Name 'CalendarId' -Value $NewCalendarId -PassThru + $request.Execute() | Add-Member -MemberType NoteProperty -Name 'User' -Value $User -PassThru | Add-Member -MemberType NoteProperty -Name 'CalendarId' -Value $DestinationCalendarId -PassThru } catch { if ($ErrorActionPreference -eq 'Stop') { From 7af98ef2d09d56dbbfa4679f95fd80c6e1385d56 Mon Sep 17 00:00:00 2001 From: David Russell Date: Fri, 18 Mar 2022 07:55:37 -0400 Subject: [PATCH 4/6] updated version number --- CHANGELOG.md | 223 ++++++++++++++++++++++++++------------------------- README.md | 4 + 2 files changed, 118 insertions(+), 109 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 435e7097..0897da46 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,117 +1,122 @@ -* [PSGSuite - ChangeLog](#psgsuite---changelog) - * [2.36.5 - 2020-11-01](#2365---2020-11-01) - * [2.36.4 - 2020-03-20](#2364---2020-03-20) - * [2.36.3 - 2020-03-20](#2363---2020-03-20) - * [2.36.2 - 2020-03-02](#2362---2020-03-02) - * [2.36.1 - 2020-03-02](#2361---2020-03-02) - * [2.36.0 - 2020-02-28](#2360---2020-02-28) - * [2.35.1 - 2019-12-29](#2351---2019-12-29) - * [2.35.0 - 2019-12-29](#2350---2019-12-29) - * [2.34.0 - 2019-11-02](#2340---2019-11-02) - * [2.33.2 - 2019-10-06](#2332---2019-10-06) - * [2.33.1 - 2019-10-06](#2331---2019-10-06) - * [2.33.0 - 2019-09-26](#2330---2019-09-26) - * [2.32.3 - 2019-09-18](#2323---2019-09-18) - * [2.32.2 - 2019-09-15](#2322---2019-09-15) - * [2.32.1 - 2019-09-14](#2321---2019-09-14) - * [2.32.0 - 2019-09-12](#2320---2019-09-12) - * [2.31.1 - 2019-08-30](#2311---2019-08-30) - * [2.31.0](#2310) - * [2.30.2](#2302) - * [2.30.1](#2301) - * [2.30.0](#2300) - * [2.29.0](#2290) - * [2.28.2](#2282) - * [2.28.1](#2281) - * [2.28.0](#2280) - * [2.27.0](#2270) - * [2.26.4](#2264) - * [2.26.3](#2263) - * [2.26.2](#2262) - * [2.26.1](#2261) - * [2.26.0](#2260) - * [2.25.3](#2253) - * [2.25.2](#2252) - * [2.25.1](#2251) - * [2.25.0](#2250) - * [2.24.0](#2240) - * [2.23.2](#2232) - * [2.23.1](#2231) - * [2.23.0](#2230) - * [2.22.4](#2224) - * [2.22.3](#2223) - * [2.22.2](#2222) - * [2.22.1](#2221) - * [2.22.0](#2220) - * [2.21.3](#2213) - * [2.21.2](#2212) - * [2.21.1](#2211) - * [2.21.0](#2210) - * [2.20.2](#2202) - * [2.20.1](#2201) - * [2.20.0](#2200) - * [2.19.0](#2190) - * [2.18.1](#2181) - * [2.18.0](#2180) - * [2.17.2](#2172) - * [2.17.1](#2171) - * [2.17.0](#2170) - * [2.16.1](#2161) - * [2.16.0](#2160) - * [2.15.4](#2154) - * [2.15.3](#2153) - * [2.15.2](#2152) - * [2.15.1](#2151) - * [2.15.0](#2150) - * [2.14.1](#2141) - * [2.14.0](#2140) - * [2.13.2](#2132) - * [2.13.1](#2131) - * [2.13.0](#2130) - * [2.12.1](#2121) - * [2.12.0](#2120) - * [2.11.0](#2110) - * [2.10.2](#2102) - * [2.10.1](#2101) - * [2.10.0](#2100) - * [2.9.0](#290) - * [2.8.1](#281) - * [2.8.0](#280) - * [2.7.2](#272) - * [2.7.1](#271) - * [2.7.0](#270) - * [2.6.3](#263) - * [2.6.2](#262) - * [2.6.1](#261) - * [2.6.0](#260) - * [2.5.4](#254) - * [2.5.3](#253) - * [2.5.2](#252) - * [2.5.1](#251) - * [2.5.0](#250) - * [2.4.0](#240) - * [2.3.0](#230) - * [2.2.1](#221) - * [2.2.0](#220) - * [2.1.5](#215) - * [2.1.3 / 2.1.4](#213--214) - * [2.1.2](#212) - * [2.1.1](#211) - * [2.1.0](#210) - * [2.0.3](#203) - * [2.0.2](#202) - * [2.0.1](#201) - * [2.0.0](#200) - * [New Functionality](#new-functionality) - * [Breaking Changes in 2.0.0](#breaking-changes-in-200) - * [Gmail Delegation Management Removed](#gmail-delegation-management-removed) - * [Functions Removed](#functions-removed) - * [Functions Aliased](#functions-aliased) +- [PSGSuite - ChangeLog](#psgsuite---changelog) + - [2.36.6 - 2022-03-18](#2366---2022-03-18) + - [2.36.5 - 2020-11-01](#2365---2020-11-01) + - [2.36.4 - 2020-03-20](#2364---2020-03-20) + - [2.36.3 - 2020-03-20](#2363---2020-03-20) + - [2.36.2 - 2020-03-02](#2362---2020-03-02) + - [2.36.1 - 2020-03-02](#2361---2020-03-02) + - [2.36.0 - 2020-02-28](#2360---2020-02-28) + - [2.35.1 - 2019-12-29](#2351---2019-12-29) + - [2.35.0 - 2019-12-29](#2350---2019-12-29) + - [2.34.0 - 2019-11-02](#2340---2019-11-02) + - [2.33.2 - 2019-10-06](#2332---2019-10-06) + - [2.33.1 - 2019-10-06](#2331---2019-10-06) + - [2.33.0 - 2019-09-26](#2330---2019-09-26) + - [2.32.3 - 2019-09-18](#2323---2019-09-18) + - [2.32.2 - 2019-09-15](#2322---2019-09-15) + - [2.32.1 - 2019-09-14](#2321---2019-09-14) + - [2.32.0 - 2019-09-12](#2320---2019-09-12) + - [2.31.1 - 2019-08-30](#2311---2019-08-30) + - [2.31.0](#2310) + - [2.30.2](#2302) + - [2.30.1](#2301) + - [2.30.0](#2300) + - [2.29.0](#2290) + - [2.28.2](#2282) + - [2.28.1](#2281) + - [2.28.0](#2280) + - [2.27.0](#2270) + - [2.26.4](#2264) + - [2.26.3](#2263) + - [2.26.2](#2262) + - [2.26.1](#2261) + - [2.26.0](#2260) + - [2.25.3](#2253) + - [2.25.2](#2252) + - [2.25.1](#2251) + - [2.25.0](#2250) + - [2.24.0](#2240) + - [2.23.2](#2232) + - [2.23.1](#2231) + - [2.23.0](#2230) + - [2.22.4](#2224) + - [2.22.3](#2223) + - [2.22.2](#2222) + - [2.22.1](#2221) + - [2.22.0](#2220) + - [2.21.3](#2213) + - [2.21.2](#2212) + - [2.21.1](#2211) + - [2.21.0](#2210) + - [2.20.2](#2202) + - [2.20.1](#2201) + - [2.20.0](#2200) + - [2.19.0](#2190) + - [2.18.1](#2181) + - [2.18.0](#2180) + - [2.17.2](#2172) + - [2.17.1](#2171) + - [2.17.0](#2170) + - [2.16.1](#2161) + - [2.16.0](#2160) + - [2.15.4](#2154) + - [2.15.3](#2153) + - [2.15.2](#2152) + - [2.15.1](#2151) + - [2.15.0](#2150) + - [2.14.1](#2141) + - [2.14.0](#2140) + - [2.13.2](#2132) + - [2.13.1](#2131) + - [2.13.0](#2130) + - [2.12.1](#2121) + - [2.12.0](#2120) + - [2.11.0](#2110) + - [2.10.2](#2102) + - [2.10.1](#2101) + - [2.10.0](#2100) + - [2.9.0](#290) + - [2.8.1](#281) + - [2.8.0](#280) + - [2.7.2](#272) + - [2.7.1](#271) + - [2.7.0](#270) + - [2.6.3](#263) + - [2.6.2](#262) + - [2.6.1](#261) + - [2.6.0](#260) + - [2.5.4](#254) + - [2.5.3](#253) + - [2.5.2](#252) + - [2.5.1](#251) + - [2.5.0](#250) + - [2.4.0](#240) + - [2.3.0](#230) + - [2.2.1](#221) + - [2.2.0](#220) + - [2.1.5](#215) + - [2.1.3 / 2.1.4](#213--214) + - [2.1.2](#212) + - [2.1.1](#211) + - [2.1.0](#210) + - [2.0.3](#203) + - [2.0.2](#202) + - [2.0.1](#201) + - [2.0.0](#200) + - [New Functionality](#new-functionality) + - [Breaking Changes in 2.0.0](#breaking-changes-in-200) + - [Gmail Delegation Management Removed](#gmail-delegation-management-removed) + - [Functions Removed](#functions-removed) + - [Functions Aliased](#functions-aliased) *** # PSGSuite - ChangeLog +## 2.36.6 - 2022-03-18 + +* Added `Move-GSCalendarEvent` function for changing event ownership/organizer. + ## 2.36.5 - 2020-11-01 * [Issue #331](https://github.com/scrthq/PSGSuite/issues/331) diff --git a/README.md b/README.md index 243017a3..35e78098 100644 --- a/README.md +++ b/README.md @@ -158,6 +158,10 @@ All other functions are either intact or have an alias included to support backw [Full CHANGELOG here](https://github.com/scrthq/PSGSuite/blob/master/CHANGELOG.md) +#### 2.36.6 - 2022-03-18 + +* Added `Move-GSCalendarEvent` function for changing event ownership/organizer. + #### 2.36.4 - 2020-03-20 * [Issue #270](https://github.com/scrthq/PSGSuite/issues/270) From 450c3bce6cdea7f1fbd5ebdd67b42beba34bbfde Mon Sep 17 00:00:00 2001 From: David Russell Date: Fri, 18 Mar 2022 07:57:00 -0400 Subject: [PATCH 5/6] corrected version numbers --- CHANGELOG.md | 4 ++-- README.md | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0897da46..283f6c91 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,5 @@ - [PSGSuite - ChangeLog](#psgsuite---changelog) - - [2.36.6 - 2022-03-18](#2366---2022-03-18) + - [2.37.0 - 2022-03-18](#2370---2022-03-18) - [2.36.5 - 2020-11-01](#2365---2020-11-01) - [2.36.4 - 2020-03-20](#2364---2020-03-20) - [2.36.3 - 2020-03-20](#2363---2020-03-20) @@ -113,7 +113,7 @@ # PSGSuite - ChangeLog -## 2.36.6 - 2022-03-18 +## 2.37.0 - 2022-03-18 * Added `Move-GSCalendarEvent` function for changing event ownership/organizer. diff --git a/README.md b/README.md index 35e78098..406e597b 100644 --- a/README.md +++ b/README.md @@ -158,7 +158,7 @@ All other functions are either intact or have an alias included to support backw [Full CHANGELOG here](https://github.com/scrthq/PSGSuite/blob/master/CHANGELOG.md) -#### 2.36.6 - 2022-03-18 +#### 2.37.0 - 2022-03-18 * Added `Move-GSCalendarEvent` function for changing event ownership/organizer. From 304ea95c194004a759ad7b06eb33d52beb989f44 Mon Sep 17 00:00:00 2001 From: David Russell <31140715+dwrusse@users.noreply.github.com> Date: Fri, 18 Mar 2022 08:03:39 -0400 Subject: [PATCH 6/6] Delete Import-GSGmailMessage.ps1 --- .../Public/Gmail/Import-GSGmailMessage.ps1 | 125 ------------------ 1 file changed, 125 deletions(-) delete mode 100644 PSGSuite/Public/Gmail/Import-GSGmailMessage.ps1 diff --git a/PSGSuite/Public/Gmail/Import-GSGmailMessage.ps1 b/PSGSuite/Public/Gmail/Import-GSGmailMessage.ps1 deleted file mode 100644 index dc5a2dba..00000000 --- a/PSGSuite/Public/Gmail/Import-GSGmailMessage.ps1 +++ /dev/null @@ -1,125 +0,0 @@ -function Get-GSGmailMessage { - <# - .SYNOPSIS - Gets Gmail message details - - .DESCRIPTION - Gets Gmail message details - - .PARAMETER User - The primary email of the user who owns the message - - Defaults to the AdminEmail user - - .PARAMETER Id - The Id of the message to retrieve info for - - .PARAMETER ParseMessage - If $true, returns the parsed raw message - - .PARAMETER SaveAttachmentsTo - If the message has attachments, the path to save the attachments to. If excluded, attachments are not saved locally - - .PARAMETER Format - The format of the message metadata to retrieve - - Available values are: - * "Full" - * "Metadata" - * "Minimal" - * "Raw" - - Defaults to "Full", but forces -Format as "Raw" if -ParseMessage or -SaveAttachmentsTo are used - - .EXAMPLE - Get-GSGmailMessage -Id 1615f9a6ee36cb5b -ParseMessage - - Gets the full message details for the provided Id and parses out the raw MIME message content - #> - [OutputType('Google.Apis.Gmail.v1.Data.Message')] - [cmdletbinding(DefaultParameterSetName = "Format")] - Param - ( - [parameter(Mandatory = $false,ValueFromPipelineByPropertyName = $true)] - [Alias("PrimaryEmail","UserKey","Mail")] - [string] - $User = $Script:PSGSuite.AdminEmail, - [parameter(Mandatory = $true,ValueFromPipelineByPropertyName = $true)] - [Alias('MessageId')] - [String[]] - $Id, - [parameter(Mandatory = $false,ParameterSetName = "ParseMessage")] - [switch] - $ParseMessage, - [parameter(Mandatory = $false,ParameterSetName = "ParseMessage")] - [Alias('AttachmentOutputPath','OutFilePath')] - [ValidateScript({(Get-Item $_).PSIsContainer})] - [string] - $SaveAttachmentsTo, - [parameter(Mandatory = $false,ParameterSetName = "Format")] - [ValidateSet("Full","Metadata","Minimal","Raw")] - [string] - $Format = "Full" - ) - Process { - if ($User -ceq 'me') { - $User = $Script:PSGSuite.AdminEmail - } - elseif ($User -notlike "*@*.*") { - $User = "$($User)@$($Script:PSGSuite.Domain)" - } - if ($ParseMessage) { - $Format = "Raw" - } - $serviceParams = @{ - Scope = 'https://mail.google.com' - ServiceType = 'Google.Apis.Gmail.v1.GmailService' - User = $User - } - $service = New-GoogleService @serviceParams - try { - foreach ($mId in $Id) { - $request = $service.Users.Messages.Get($User,$mId) - $request.Format = $Format - foreach ($key in $PSBoundParameters.Keys | Where-Object {$_ -ne "Id"}) { - switch ($key) { - Default { - if ($request.PSObject.Properties.Name -contains $key) { - $request.$key = $PSBoundParameters[$key] - } - } - } - } - Write-Verbose "Getting Message Id '$mId' for user '$User'" - $result = $request.Execute() | Add-Member -MemberType NoteProperty -Name 'User' -Value $User -PassThru - if ($ParseMessage) { - $parsed = Read-MimeMessage -String $(Convert-Base64 -From WebSafeBase64String -To NormalString -String $result.Raw) | Select-Object @{N = 'User';E = {$User}},@{N = "Id";E = {$result.Id}},@{N = "ThreadId";E = {$result.ThreadId}},@{N = "LabelIds";E = {$result.LabelIds}},@{N = "Snippet";E = {$result.Snippet}},@{N = "HistoryId";E = {$result.HistoryId}},@{N = "InternalDate";E = {$result.InternalDate}},@{N = "InternalDateConverted";E = {Convert-EpochToDate -EpochString $result.internalDate}},@{N = "SizeEstimate";E = {$result.SizeEstimate}},* - if ($SaveAttachmentsTo) { - $resPath = Resolve-Path $SaveAttachmentsTo - $attachments = $parsed.Attachments - foreach ($att in $attachments) { - $cleanedName = $att.FileName -replace "[$(([System.IO.Path]::GetInvalidFileNameChars() + [System.IO.Path]::GetInvalidPathChars()) -join '')]","_" - $fileName = Join-Path $resPath $cleanedName - Write-Verbose "Saving attachment to path '$fileName'" - $stream = [System.IO.File]::Create($fileName) - $att.ContentObject.DecodeTo($stream) - $stream.Close() - } - } - $parsed - } - else { - $result - } - } - } - catch { - if ($ErrorActionPreference -eq 'Stop') { - $PSCmdlet.ThrowTerminatingError($_) - } - else { - Write-Error $_ - } - } - } -}