How to delete all messages under a label

364 views
Skip to first unread message

Johnnie W Adams

unread,
Feb 20, 2023, 4:43:07 PM2/20/23
to google-ap...@googlegroups.com
Hi, folks,

     I've got a user who'd like to delete all the mail under a very heavily nested set of lables. I naïvely tried this search:

gam user me trash messages query label:Foo*


     to try to trash all messages under Foo, including Foo/Bar, but it unsurprisingly did not work. Can this be done in a single line? Or do I have to do a little Linux magic (which I like doing)?

Thanks,

     John A
--
John Adams
Senior Linux/Middleware Administrator  | Information Technology Services
+1-501-916-3010 | jxa...@ualr.edu | http://ualr.edu/itservices
UA Little Rock

Reminder:  IT Services will never ask for your password over the phone or in an email. Always be suspicious of requests for personal information that come via email, even from known contacts.  For more information or to report suspicious email, visit IT Security.

Ross Scroggs

unread,
Feb 20, 2023, 5:31:02 PM2/20/23
to google-ap...@googlegroups.com
John,


gam user me trash messages labelmatchpattern Foo

Ross
----
Ross Scroggs



--
You received this message because you are subscribed to the Google Groups "GAM for Google Workspace" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-apps-man...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/google-apps-manager/CAGfWJCOntHP5m_KPPb%2BF-ueqH%3DsWjBZw1XHupHYs71cGEuQrQQ%40mail.gmail.com.

Gordon Suchomski

unread,
Dec 9, 2024, 2:58:51 PM12/9/24
to GAM for Google Workspace
Hello,

for some reason the labelmatchpattern work for show messages but it did not work for trash messages

DUS-Ramp PST % gam user f.s@d trash messages labelmatchpattern OutlookDatendatei
Command: /Users/g/bin/gamadv-xtd3/gam user f.s@d trash messages labelmatchpattern OutlookDatendatei >>><<<

ERROR: Missing argument: Expected <query|matchlabel|ids>
Help: Syntax in file /Users/gordon/bin/gamadv-xtd3/GamCommands.txt
Help: Documentation is at https://github.com/taers232c/GAMADV-XTD3/wiki

Cheers and thanks,
Gordon

Sitz: Schönefeld | Amtsgericht Cottbus | HRB 17486 | Geschäftsleitung: Dieter R. Streuli, Gordon Suchomski

Diese Nachricht wird Ihnen von einer deutschen Firma gesendet. Die Nachricht und ihr Inhalt sind vertraulich und können rechtlich geschützte Informationen enthalten. Wenn Sie nicht die angeschriebene Person sind, haben Sie kein Recht, diese Mitteilung oder ihren Inhalt zu lesen, auszudrucken, aufzubewahren, zu kopieren oder zu verbreiten. Wir bitten Sie, uns umgehend per E-Mail zu informieren, die E-Mail-Dateien zu löschen und sämtliche Ausdrucke zu vernichten. Wenn Sie uns E-Mails senden, werden wir zur Erleichterung der Kommunikation Ihren Namen und Ihre Adresse speichern und davon ausgehen, dass wir ermächtigt sind, mit Ihnen per E-Mail zu kommunizieren. Falls Sie damit nicht einverstanden sind, bitten wir Sie, uns dies unverzüglich mitzuteilen und wir werden Ihre Informationen löschen.


This message is sent to you by a German company. The message and its content are confidential and may contain legally protected information. If you are not the person contacted, you have no right to read, print, retain, copy or distribute this message or its contents. We ask you to inform us immediately by e-mail, to delete the e-mail files and to destroy all printouts. If you send us e-mails, we will store your name and address to facilitate communication and assume that we are authorized to communicate with you by e-mail. If you do not agree, please let us know and we will delete your information.


Ross Scroggs

unread,
Dec 9, 2024, 3:37:54 PM12/9/24
to google-ap...@googlegroups.com

Gordon Suchomski

unread,
Dec 9, 2024, 10:42:34 PM12/9/24
to GAM for Google Workspace
Maybe this will be helpful for someone.
This script deletes all messages and labels matching a grep pattern:
user="$1"
labelpattern="$2"
doit="$3"
deleteLabels="$4"

if [ -z "$user" ] || [ -z "$labelpattern" ]; then
echo "Usage: $0 <user> <labelpattern> [doit] [deleteLabels]"
echo "Example: $0 test...@your.domain rootLabelName doit deleteLabels"
echo "If 'doit' is not specified, the script will only show affected labels/messages."
echo "If 'deleteLabels' is specified, the labels themselves will also be deleted."
exit 1
fi

gam user "$user" show labels useronly display fullname | grep "$labelpattern" | \
while read -r label; do
echo "$label"
# Nachrichten löschen (mit oder ohne doit)
if [ "$doit" = "doit" ]; then
gam user "$user" delete messages matchlabel "$label" max_to_process 0 doit
else
gam user "$user" delete messages matchlabel "$label" max_to_process 0
fi

# Labels löschen falls verlangt
if [ "$deleteLabels" = "deleteLabels" ]; then
gam user "$user" delete label "$label"
fi
done

Reply all
Reply to author
Forward
0 new messages