Help needed in script to identify emails with no labels in trash folder

96 views
Skip to first unread message

Steve Miller

unread,
Oct 15, 2023, 1:49:48 PM10/15/23
to Google Apps Script Community
I have a script that I've been using for a couple of years, that automatically deletes from my trash folder, any email that has the label "promotions", "updates" or "forums".  It works great and gets the job done.  The relevant line to identify the emails in question, is:

 var threadList=Gmail.Users.Threads.list('me', {q:'in:trash label:promotions OR label:updates OR label:forums',pageToken:pageToken});

I want to add to the choices, any email that contains NO label. I know how to do it from the program itself, but not in a script.

Can anyone assist? Thanks much.

Tanaike

unread,
Oct 15, 2023, 8:12:03 PM10/15/23
to Google Apps Script Community
Although I'm not sure whether I could correctly understand your question, is this thread useful? https://webapps.stackexchange.com/q/275

Steve Miller

unread,
Oct 16, 2023, 12:12:17 AM10/16/23
to Google Apps Script Community
Thanks. I was aware of has:nouserlabels to find emails with no labels, as I have used it to search in gmail occasionally, but didn't think it would work in a script.  Anyway, I threw it in my script along with the others, e.g label:promotions, label:updates and label:forums and it does work in the script to delete emails in the trash folder with no labels.  The only difference, and not sure why, the latter 3 take effect instantly re the deletions, the has:nouserlabels works but you don't see the effect until gmail is refreshed.  Anyway, thanks for the suggestion.
Reply all
Reply to author
Forward
0 new messages