Black Friday Hangover Cure

A search in Gmail for the phrase "Black Friday" yields the dreaded "1-50 of many". We can iron this out to ensure that Black Friday doesn't hang around ever again.

Black Friday Hangover Cure
Photo by Stephen Wagner / Unsplash

No one needs to keep Black Friday Emails

I write from the UK, where Black Friday has only become a thing in the last decade or so. Nonetheless, I don't exactly relish the avalanche of emails that I receive for the six weeks leading up to the period, and my credit card doesn't particularly enjoy the ones on the day either.

Amongst marketing clutter, Black Friday feels unusual just by the absolute volume of chat that brands dish out for what is often not that great a sale. If you had your eye on something, and it goes on sale, great. But more often than not, I'm inclined to agree with Patrick Grant of Community Clothing, as per below;

An image of Patrick Grant, the Founder of Community Clothing, with a speech bubble which says "Fuck Black Friday"
He's right, it is bullshit. via Instagram

So, we're now on the Tuesday after the Friday, and a quick search in my gmail for the phrase "Black Friday" yields the dreaded "1-50 of many", i.e. too many for us to count.

An image showing a screen of an email inbox searching for the phrase "Black Friday", with 1-50 of many as the result.
I laughed at the "exclude promotions" option.

We can iron this out once and for all with a pretty quick solution which will ensure that Black Friday doesn't hang around too long ever again. Unfortunately, Gmail's filters run the moment that an email hits your inbox, so great as a doorman, but not to give you the three days grace if you really do want that hair dryer. Instead, we're going to use a Google Apps Script, which is available for everyone with a Google Account (which is every Gmail user).

🗑️
This script sends things to the bin/trash. If you accidentally delete a receipt for a car you bought through a Black Friday deal, you should probably file that away first.

Google gets tired if you try to delete 5,000 emails at once. It imposes a limit of 100 threads per operation, so, we use a loop. Think of it like carrying shopping bags—you can't take them all in one trip.

  • Go to script.google.com.
  • Open a new project.
  • Paste this in:
function purgeBlackFriday() {
  var search = 'subject:"Black Friday" older_than:3d';
  
  // We process up to 500 emails per run (5 batches of 100)
  // so the script doesn't time out.
  for (var i = 0; i < 5; i++) {
    
    // Get a batch of 100 threads
    var threads = GmailApp.search(search, 0, 100);
    
    if (threads.length > 0) {
      GmailApp.moveThreadsToTrash(threads);
      // Brief pause to let Google catch its breath
      Utilities.sleep(1000); 
    } else {
      // No more emails found, stop the script
      break; 
    }
  }
}

A little code snippet to take out your Black Friday rubbish.

  1. Set a "Trigger" (the clock icon) to run this function once a day.
  2. I have the patience of a flea, so I always run it to check it works OK, or if there's any authentication to do.
⚠️
Google might ask for extra authentication for you to do this, and note that it doesn't know the developer. This makes sense - you're the developer, and this might be the first time you've ever done something like this.

Now, the script does the work. You get the sale emails for three days—just in case you actually do need 40% off an air fryer, a subscription, or a hair dryer—and then they vanish. No guilt, no manual archiving, just fresh air.

If you're a bit nervous about going straight into an Apps Script, test it by running this search on your own Gmail interface, and it will show you what the script will filter for;

subject:"Black Friday" older_than:3d

If you have an ancient mailbox that you've never cleared out (me), there might be a sizeable backlog to get through, in which case you can set the script to run hourly for the first day - this will get through 12k emails in 24 hours. After that, you can set it to monthly, weekly or daily to keep everything clear.

Items in the bin of most email inboxes are fully deleted after 30 days, recovering you an awful lot of space in your mailbox and a small amount of sanity too.