Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Gmail search syntax for Remove-GSGmailMessage #93

Closed
jboiselle opened this issue Oct 8, 2018 · 3 comments
Closed

Gmail search syntax for Remove-GSGmailMessage #93

jboiselle opened this issue Oct 8, 2018 · 3 comments
Assignees

Comments

@jboiselle
Copy link

jboiselle commented Oct 8, 2018

Hi Nate,

I'm looking for some additional functionality that is closely related to the Remove-GSGmailMessage cmdlet. Specifically, feature parity with the Gmail search syntax functionality that a similar command in GAM currently has. I'd like to request one (or both) of the following features:

  1. The ability to use Remove-GSGmailMessage with the Gmail search syntax. For example, if I wanted to delete all messages from a particular sender (from:example@domain.com).

  2. A new cmdlet with the ability to modify labels on a particular email (also using the Gmail search syntax). For example, if I wanted to mark all messages from a particular Gmail search syntax query as spam or trash.

You can read the documentation for the GAM commands here:
https://github.com/jay0lee/GAM/wiki/ExamplesEmailSettings#modifying-user-emails

The reason I'm looking for this functionality is that I often use these commands to combat spam or phishing. Attackers will often send several emails with different message IDs. The search syntax would allow far greater flexibility in targeting these emails. I still find myself using GAM for removing emails specifically for the ability to use Gmail search syntax.

Thoughts?

Thanks,
Josh

@scrthq
Copy link
Member

scrthq commented Oct 8, 2018

Hey Josh - Definitely good ideas! I use PSGSuite myself for almost the same purpose (among many other), so I completely get the goal here!

For item 1 - I'll check out expanding the functionality so it's wrapped into a single command, but you can currently use the pipeline though to do it in a short one-liner (see below). Would it be worth adding in an additional MaxThreshold parameter in case you're not doing something as precise as searching by MessageId and want to ensure you don't accidentally delete more than expected?

Also worth noting that the pipeline support doesn't play too nice with passing the same username from one Gmail command to the next -- working on fixing that as well

# Trash everything not sent directly to the user
Get-GSGmailMessageList -User "tom@domain.com" -Filter "to:-me" | Remove-GSGmailMessage -User "tom@domain.com" -Confirm:$false

image


For item 2 - Definitely need to expand on label management! I'll work on this as I can, pull requests also very much accepted! 😄

@scrthq
Copy link
Member

scrthq commented Oct 9, 2018

Alright, everything all fixed up and about to deploy in v2.15.2!

  • Added in Update-GSGmailMessageLabel with help from @dwrusse and included -Filter parameter
  • Updated Remove-GSGmailMessage with the same -Filter parameter
  • Fixed the pipeline support so that -User isn't needed to pass through the pipeline so the pipeline works exactly as expected and pulls the User from the objects passed into it

Demo with WhatIf + Verbose showing new Remove-GSGmailMessage functionality:

image

scrthq added a commit that referenced this issue Oct 9, 2018
## 2.15.2

* [Pull Request #94](#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](#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`
@scrthq scrthq self-assigned this Oct 9, 2018
@scrthq
Copy link
Member

scrthq commented Oct 9, 2018

v2.15.2 has been deployed! Update and check it out, cheers!

@scrthq scrthq closed this as completed Oct 9, 2018
scrthq added a commit that referenced this issue Oct 10, 2018
scrthq added a commit that referenced this issue Oct 10, 2018
## 2.15.3

* [Issue #87](#87)
  * Fixed `Add-GSCourseParticipant` error: `"Cannot convert the "student@uni.edu" value of type "System.String" to type "Google.Apis.Classroom.v1.Data.Student"."`
  * Set `$request.Fields = "*"` for `Get-GSCourseParticipant` and `Get-GSClassroomUserProfile` to return all available fields for the `Profile`, including `EmailAddress`
* [Issue #93](#93)
  * Added: `MaxToModify` parameter to `Remove-GSGmailMessage` and `Update-GSGmailMessageLabels` in the `Filter` parameter set to prevent removing/updating more messages than expected when using a filter to gather the list of messages to update.
* Added: `Id` alias for `User` parameter on `Get-GSUser` for better pipeline support
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants