diff --git a/CHANGELOG.md b/CHANGELOG.md index 6e3e34ad..b562e031 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,56 +1,61 @@ -# Changelog - - - -- [Changelog](#changelog) - - [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) - - +# Changelog + +* [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) + +## 2.15.2 + +* [Pull Request #94](https://github.com/scrthq/PSGSuite/pull/94) **Thanks, [@dwrusse](https://github.com/dwrusse)!** + * Added `Update-GSGmailLabel` to enable updating of Gmail label properties + * Added `Update-GSGmailMessageLabel` enable updating of labels attached to Gmail messages +* [Issue #93](https://github.com/scrthq/PSGSuite/issues/93) + * Updated `Remove-GSGmailMessage` to include a `-Filter` parameter to allow removal of messages matching a filter in a single command + * Improved pipeline support for `Remove-GSGmailMessage` ## 2.15.1 @@ -62,10 +67,10 @@ ## 2.15.0 -- Updated Gmail Delegation functions to use the .NET SDK after Google announced delegation support for the Gmail API -- Cleaned up `Get-GSGmailDelegates` by removing the trailing `s` (now `Get-GSGmailDelegate`). Added the original function as an alias to the new function for backwards compatibility with scripts. -- Removed the `Raw` parameter from `Get-GSGmailDelegate` since it's no longer applicable. -- Enabled `Get-GSGmailDelegate` to perform both Get and List requests (previously only performed List requests) +* Updated Gmail Delegation functions to use the .NET SDK after Google announced delegation support for the Gmail API +* Cleaned up `Get-GSGmailDelegates` by removing the trailing `s` (now `Get-GSGmailDelegate`). Added the original function as an alias to the new function for backwards compatibility with scripts. +* Removed the `Raw` parameter from `Get-GSGmailDelegate` since it's no longer applicable. +* Enabled `Get-GSGmailDelegate` to perform both Get and List requests (previously only performed List requests) ## 2.14.1 diff --git a/PSGSuite/PSGSuite.psd1 b/PSGSuite/PSGSuite.psd1 index 8ec120a1..02e5c039 100644 --- a/PSGSuite/PSGSuite.psd1 +++ b/PSGSuite/PSGSuite.psd1 @@ -12,7 +12,7 @@ RootModule = 'PSGSuite.psm1' # Version number of this module. - ModuleVersion = '2.15.1' + ModuleVersion = '2.15.2' # ID used to uniquely identify this module GUID = '9d751152-e83e-40bb-a6db-4c329092aaec' diff --git a/PSGSuite/Public/Gmail/Remove-GSGmailMessage.ps1 b/PSGSuite/Public/Gmail/Remove-GSGmailMessage.ps1 index 4c46069c..a0e5aee7 100644 --- a/PSGSuite/Public/Gmail/Remove-GSGmailMessage.ps1 +++ b/PSGSuite/Public/Gmail/Remove-GSGmailMessage.ps1 @@ -2,18 +2,16 @@ function Remove-GSGmailMessage { <# .SYNOPSIS Removes a Gmail message from the user - + .DESCRIPTION Removes a Gmail message from the user - - .PARAMETER User - The primary email of the user to remove the message from - Defaults to the AdminEmail user - .PARAMETER Id The Id of the message to remove - + + .PARAMETER Filter + The Gmail query to pull the list of messages to remove instead of passing the MessageId directly + .PARAMETER Method The method used to delete the message @@ -22,29 +20,38 @@ function Remove-GSGmailMessage { * "Delete": permanently deletes the message (NON-RECOVERABLE!) Default value is 'Trash' - + + .PARAMETER User + The primary email of the user to remove the message from + + Defaults to the AdminEmail user + .EXAMPLE Remove-GSGmailMessage -User joe -Id 161622d7b76b7e1e,1616227c34d435f2 Moves the 2 message Id's from Joe's inbox into their TRASH after confirmation #> - [cmdletbinding(SupportsShouldProcess = $true,ConfirmImpact = "High")] + [cmdletbinding(SupportsShouldProcess = $true,ConfirmImpact = "High",DefaultParameterSetName = "MessageId")] Param ( - [parameter(Mandatory = $false,ValueFromPipelineByPropertyName = $true)] - [Alias("PrimaryEmail","UserKey","Mail")] - [string] - $User = $Script:PSGSuite.AdminEmail, - [parameter(Mandatory = $true,ValueFromPipelineByPropertyName = $true)] - [Alias('MessageID')] + [parameter(Mandatory = $true,ValueFromPipelineByPropertyName = $true,ParameterSetName = "MessageId")] + [Alias('MessageId')] [String[]] $Id, + [parameter(Mandatory = $true, ParameterSetName = "Filter")] + [Alias('Query')] + [string] + $Filter, [parameter(Mandatory = $false)] [ValidateSet('Trash','Delete')] [String] - $Method = 'Trash' + $Method = 'Trash', + [parameter(Mandatory = $false,ValueFromPipelineByPropertyName = $true)] + [Alias("PrimaryEmail","UserKey","Mail")] + [string] + $User = $Script:PSGSuite.AdminEmail ) - Begin { + Process { if ($MyInvocation.InvocationName -eq 'Move-GSGmailMessageToTrash') { $Method = 'Trash' } @@ -59,11 +66,17 @@ function Remove-GSGmailMessage { ServiceType = 'Google.Apis.Gmail.v1.GmailService' User = $User } + $msgId = switch ($PSCmdlet.ParameterSetName) { + MessageId { + $Id + } + Filter { + (Get-GSGmailMessageList -Filter $Filter -User $User).Id + } + } $service = New-GoogleService @serviceParams - } - Process { try { - foreach ($mId in $Id) { + foreach ($mId in $msgId) { $request = switch ($Method) { Trash { $service.Users.Messages.Trash($User,$mId) @@ -93,4 +106,4 @@ function Remove-GSGmailMessage { } } } -} \ No newline at end of file +} diff --git a/PSGSuite/Public/Gmail/Update-GSGmailLabel.ps1 b/PSGSuite/Public/Gmail/Update-GSGmailLabel.ps1 new file mode 100644 index 00000000..81283873 --- /dev/null +++ b/PSGSuite/Public/Gmail/Update-GSGmailLabel.ps1 @@ -0,0 +1,191 @@ +function Update-GSGmailLabel { + <# + .SYNOPSIS + Updates Gmail label information for the specified labelid + + .DESCRIPTION + Updates Gmail label information for the specified labelid + + .PARAMETER LabelId + The unique Id of the label to update + + .PARAMETER LabelListVisibility + The visibility of the label in the label list in the Gmail web interface. + + Acceptable values are: + * "labelHide": Do not show the label in the label list. + * "labelShow": Show the label in the label list. (Default) + * "labelShowIfUnread": Show the label if there are any unread messages with that label. + + .PARAMETER MessageListVisibility + The visibility of messages with this label in the message list in the Gmail web interface. + + Acceptable values are: + * "hide": Do not show the label in the message list. + * "show": Show the label in the message list. (Default) + + .PARAMETER Name + The display name of the label + + .PARAMETER BackgroundColor + The background color of the label + + .PARAMETER TextColor + The text color of the label + + .PARAMETER User + The user to update label information for + + Defaults to the AdminEmail user + + .EXAMPLE + Update-GSGmailLabel -User user@domain.com -LabelId Label_79 -BackgroundColor Black -TextColor Bermuda + + Updates the specified Gmail label with new background and text colors + + .EXAMPLE + Get-GSGmailLabel | Where-Object {$_.LabelListVisibility -eq 'labelShowIfUnread'} | Update-GSGmailLabel -LabelListVisibility labelShow -BackgroundColor Bermuda -TextColor Tundora + + Updates all labels with LabelListVisibility of 'labelShowIfUnread' with new background and text colors and sets all of them to always show + #> + [cmdletbinding()] + Param + ( + [parameter(Mandatory = $true, Position = 0, ValueFromPipelineByPropertyName = $true)] + [Alias("Id")] + [string[]] + $LabelId, + [parameter(Mandatory = $false, Position = 1)] + [ValidateSet("labelHide","labelShow","labelShowIfUnread")] + [string] + $LabelListVisibility, + [parameter(Mandatory = $false, Position = 2)] + [ValidateSet("hide","show")] + [string] + $MessageListVisibility, + [parameter(Mandatory = $false, Position = 3)] + [string] + $Name, + [parameter(Mandatory = $false)] + [ValidateSet('Amethyst','BananaMania','Bermuda','BilobaFlower','Black','BlueRomance','BrandyPunch','BurntSienna','Cadillac','Camelot','CeruleanBlue','ChathamsBlue','Concrete','CornflowerBlue','CreamCan','Cupid','DeepBlush','Desert','DoveGray','DustyGray','Eucalyptus','Flesh','FringyFlower','Gallery','Goldenrod','Illusion','Jewel','Koromiko','LightCornflowerBlue','LightMoonRaker','LightMountainMeadow','LightShamrock','LuxorGold','MandysPink','MediumPurple','Meteorite','MoonRaker','MountainMeadow','Oasis','OceanGreen','OldGold','Perano','PersianPink','PigPink','Pueblo','RedOrange','RoyalBlue','RoyalPurple','Salem','Salomie','SeaPink','Shamrock','Silver','Tabasco','Tequila','Thunderbird','TropicalBlue','TulipTree','Tundora','VistaBlue','Watercourse','WaterLeaf','White','YellowOrange')] + [string] + $BackgroundColor, + [parameter(Mandatory = $false)] + [ValidateSet('Amethyst','BananaMania','Bermuda','BilobaFlower','Black','BlueRomance','BrandyPunch','BurntSienna','Cadillac','Camelot','CeruleanBlue','ChathamsBlue','Concrete','CornflowerBlue','CreamCan','Cupid','DeepBlush','Desert','DoveGray','DustyGray','Eucalyptus','Flesh','FringyFlower','Gallery','Goldenrod','Illusion','Jewel','Koromiko','LightCornflowerBlue','LightMoonRaker','LightMountainMeadow','LightShamrock','LuxorGold','MandysPink','MediumPurple','Meteorite','MoonRaker','MountainMeadow','Oasis','OceanGreen','OldGold','Perano','PersianPink','PigPink','Pueblo','RedOrange','RoyalBlue','RoyalPurple','Salem','Salomie','SeaPink','Shamrock','Silver','Tabasco','Tequila','Thunderbird','TropicalBlue','TulipTree','Tundora','VistaBlue','Watercourse','WaterLeaf','White','YellowOrange')] + [string] + $TextColor, + [parameter(Mandatory = $false, ValueFromPipelineByPropertyName = $true)] + [Alias("PrimaryEmail", "UserKey", "Mail")] + [ValidateNotNullOrEmpty()] + [string] + $User = $Script:PSGSuite.AdminEmail + ) + Begin { + $colorDict = @{ + Amethyst = '#8e63ce' + BananaMania = '#fce8b3' + Bermuda = '#68dfa9' + BilobaFlower = '#b694e8' + Black = '#000000' + BlueRomance = '#c6f3de' + BrandyPunch = '#cf8933' + BurntSienna = '#e66550' + Cadillac = '#b65775' + Camelot = '#83334c' + CeruleanBlue = '#285bac' + ChathamsBlue = '#1c4587' + Concrete = '#f3f3f3' + CornflowerBlue = '#4a86e8' + LightCornflowerBlue = '#6d9eeb' + CreamCan = '#f2c960' + Cupid = '#fbc8d9' + DeepBlush = '#e07798' + Desert = '#a46a21' + DoveGray = '#666666' + DustyGray = '#999999' + Eucalyptus = '#2a9c68' + Flesh = '#ffd6a2' + FringyFlower = '#b9e4d0' + Gallery = '#efefef' + Goldenrod = '#fad165' + Illusion = '#f7a7c0' + Jewel = '#1a764d' + Koromiko = '#ffbc6b' + LightMountainMeadow = '#16a766' + LightShamrock = '#43d692' + LuxorGold = '#aa8831' + MandysPink = '#f6c5be' + MediumPurple = '#a479e2' + Meteorite = '#41236d' + MoonRaker = '#d0bcf1' + LightMoonRaker = '#e4d7f5' + MountainMeadow = '#149e60' + Oasis = '#fef1d1' + OceanGreen = '#44b984' + OldGold = '#d5ae49' + Perano = '#a4c2f4' + PersianPink = '#f691b3' + PigPink = '#fcdee8' + Pueblo = '#822111' + RedOrange = '#fb4c2f' + RoyalBlue = '#3c78d8' + RoyalPurple = '#653e9b' + Salem = '#0b804b' + Salomie = '#fcda83' + SeaPink = '#efa093' + Shamrock = '#3dc789' + Silver = '#cccccc' + Tabasco = '#ac2b16' + Tequila = '#ffe6c7' + Thunderbird = '#cc3a21' + TropicalBlue = '#c9daf8' + TulipTree = '#eaa041' + Tundora = '#434343' + VistaBlue = '#89d3b2' + Watercourse = '#076239' + WaterLeaf = '#a0eac9' + White = '#ffffff' + YellowOrange = '#ffad47' + } + } + Process { + if ($User -ceq 'me') { + $User = $Script:PSGSuite.AdminEmail + } + elseif ($User -notlike "*@*.*") { + $User = "$($User)@$($Script:PSGSuite.Domain)" + } + $serviceParams = @{ + Scope = 'https://mail.google.com' + ServiceType = 'Google.Apis.Gmail.v1.GmailService' + User = $User + } + $service = New-GoogleService @serviceParams + $body = New-Object 'Google.Apis.Gmail.v1.Data.Label' + foreach ($prop in $PSBoundParameters.Keys | Where-Object {$body.PSObject.Properties.Name -contains $_}) { + $body.$prop = $PSBoundParameters[$prop] + } + if ($PSBoundParameters.Keys -contains 'BackgroundColor' -or $PSBoundParameters.Keys -contains 'TextColor') { + $color = New-Object 'Google.Apis.Gmail.v1.Data.LabelColor' + foreach ($prop in $PSBoundParameters.Keys | Where-Object {$color.PSObject.Properties.Name -contains $_}) { + $color.$prop = $colorDict[$PSBoundParameters[$prop]] + } + $body.Color = $color + } + foreach ($label in $LabelId) { + try { + Write-Verbose "Updating Label Id '$label' for user '$User'" + $request = $service.Users.Labels.Patch($body, $User, $label) + $request.Execute() | Add-Member -MemberType NoteProperty -Name 'User' -Value $User -PassThru + } + catch { + if ($ErrorActionPreference -eq 'Stop') { + $PSCmdlet.ThrowTerminatingError($_) + } + else { + Write-Error $_ + } + } + } + } +} diff --git a/PSGSuite/Public/Gmail/Update-GSGmailMessageLabel.ps1 b/PSGSuite/Public/Gmail/Update-GSGmailMessageLabel.ps1 new file mode 100644 index 00000000..e0d643d5 --- /dev/null +++ b/PSGSuite/Public/Gmail/Update-GSGmailMessageLabel.ps1 @@ -0,0 +1,133 @@ +function Update-GSGmailMessageLabel { + <# + .SYNOPSIS + Updates Gmail label information for the specified message + + .DESCRIPTION + Updates Gmail label information for the specified message + + .PARAMETER MessageId + The unique Id of the message to update. + + .PARAMETER Filter + The Gmail query to pull the list of messages to update instead of passing the MessageId directly. + + .PARAMETER AddLabel + The label(s) to add to the message. This supports either the unique LabelId or the Display Name for the label + + .PARAMETER RemoveLabel + The label(s) to remove from the message. This supports either the unique LabelId or the Display Name for the label + + .PARAMETER User + The user to update message labels for + + Defaults to the AdminEmail user + + .EXAMPLE + Set-GSGmailLabel -user user@domain.com -LabelId Label_798170282134616520 - + + Gets the Gmail labels of the AdminEmail user + #> + [cmdletbinding(DefaultParameterSetName = "MessageId")] + Param + ( + [parameter(Mandatory = $true, ValueFromPipelineByPropertyName = $true, ParameterSetName = "MessageId")] + [Alias("Id")] + [string[]] + $MessageId, + [parameter(Mandatory = $true, ParameterSetName = "Filter")] + [Alias('Query')] + [string] + $Filter, + [parameter(Mandatory = $false)] + [string[]] + $AddLabel, + [parameter(Mandatory = $false)] + [string[]] + $RemoveLabel, + [parameter(Mandatory = $false, ValueFromPipelineByPropertyName = $true)] + [Alias("PrimaryEmail", "UserKey", "Mail")] + [ValidateNotNullOrEmpty()] + [string] + $User = $Script:PSGSuite.AdminEmail + ) + Process { + if ($PSBoundParameters.Keys -notcontains 'AddLabel' -and $PSBoundParameters.Keys -notcontains 'RemoveLabel') { + throw "You must specify a value for either AddLabel or RemoveLabel!" + } + if ($User -ceq 'me') { + $User = $Script:PSGSuite.AdminEmail + } + elseif ($User -notlike "*@*.*") { + $User = "$($User)@$($Script:PSGSuite.Domain)" + } + $serviceParams = @{ + Scope = 'https://mail.google.com' + ServiceType = 'Google.Apis.Gmail.v1.GmailService' + User = $User + } + $msgId = switch ($PSCmdlet.ParameterSetName) { + MessageId { + $MessageId + } + Filter { + (Get-GSGmailMessageList -Filter $Filter -User $User).Id + } + } + $service = New-GoogleService @serviceParams + $userLabels = @{} + Get-GSGmailLabel -User $User -Verbose:$false | ForEach-Object { + $userLabels[$_.Name] = $_.Id + } + $body = New-Object 'Google.Apis.Gmail.v1.Data.ModifyMessageRequest' + if ($PSBoundParameters.Keys -contains 'AddLabel') { + $addLs = New-Object 'System.Collections.Generic.List[System.String]' + foreach ($label in $AddLabel) { + try { + $addLs.Add($userLabels[$label]) + } + catch { + if ($ErrorActionPreference -eq 'Stop') { + $PSCmdlet.ThrowTerminatingError($_) + } + else { + Write-Error $_ + } + } + } + $body.AddLabelIds = $addLs + } + if ($PSBoundParameters.Keys -contains 'RemoveLabel') { + $remLs = New-Object 'System.Collections.Generic.List[System.String]' + foreach ($label in $RemoveLabel) { + try { + $remLs.Add($userLabels[$label]) + } + catch { + if ($ErrorActionPreference -eq 'Stop') { + $PSCmdlet.ThrowTerminatingError($_) + } + else { + Write-Error $_ + } + } + } + $body.RemoveLabelIds = $remLs + } + foreach ($message in $msgId) { + try { + $request = $service.Users.Messages.Modify($body, $User, $message) + Write-Verbose "Updating Labels on Message '$message' for user '$User'" + $request.Execute() | Add-Member -MemberType NoteProperty -Name 'User' -Value $User -PassThru + } + catch { + if ($ErrorActionPreference -eq 'Stop') { + $PSCmdlet.ThrowTerminatingError($_) + } + else { + Write-Error $_ + } + } + } + } +} diff --git a/README.md b/README.md index e82e060b..d6c841bc 100644 --- a/README.md +++ b/README.md @@ -127,6 +127,15 @@ Update-GSSheetValue Export-GSSheet ### Most recent changes +#### 2.15.2 + +* [Pull Request #94](https://github.com/scrthq/PSGSuite/pull/94) **Thanks, [@dwrusse](https://github.com/dwrusse)!** + * Added `Update-GSGmailLabel` to enable updating of Gmail label properties + * Added `Update-GSGmailMessageLabel` enable updating of labels attached to Gmail messages +* [Issue #93](https://github.com/scrthq/PSGSuite/issues/93) + * Updated `Remove-GSGmailMessage` to include a `-Filter` parameter to allow removal of messages matching a filter in a single command + * Improved pipeline support for `Remove-GSGmailMessage` + #### 2.15.1 * [Issue #87](https://github.com/scrthq/PSGSuite/issues/87) @@ -137,10 +146,10 @@ Update-GSSheetValue Export-GSSheet #### 2.15.0 -- Updated Gmail Delegation functions to use the .NET SDK after Google announced delegation support for the Gmail API -- Cleaned up `Get-GSGmailDelegates` by removing the trailing `s` (now `Get-GSGmailDelegate`). Added the original function as an alias to the new function for backwards compatibility with scripts. -- Removed the `Raw` parameter from `Get-GSGmailDelegate` since it's no longer applicable. -- Enabled `Get-GSGmailDelegate` to perform both Get and List requests (previously only performed List requests) +* Updated Gmail Delegation functions to use the .NET SDK after Google announced delegation support for the Gmail API +* Cleaned up `Get-GSGmailDelegates` by removing the trailing `s` (now `Get-GSGmailDelegate`). Added the original function as an alias to the new function for backwards compatibility with scripts. +* Removed the `Raw` parameter from `Get-GSGmailDelegate` since it's no longer applicable. +* Enabled `Get-GSGmailDelegate` to perform both Get and List requests (previously only performed List requests) #### 2.14.1