Skip to content
business-ai Running · 6 min read

Gmail Inbox from 105 to 18 Threads Without Deleting Anything: Numbered Labels and a 14-Day Rule

How I took a Workspace Gmail inbox from 105 threads to 18 without deleting a single mail: numbered labels, a fixed sorting order and the Gmail API.

My work inbox had 105 threads in it. Not catastrophic, but enough that I stopped trusting it. Invoices forwarded for accounting, app notifications, DMARC reports, client threads from three weeks ago that were long done, and somewhere in there the few things I actually had to do. The inbox was doing three jobs at once: to-do list, archive and notification feed. It was bad at all of them.

So I sat down and fixed it. 105 threads down to 18. Nothing deleted. Every mail is still there, archived and labeled.

TL;DR: Gmail sorts labels alphabetically, so prefix them with numbers (01 To-Do … 11 Newsletter) to get the order you want. Rename parents and their sublabels. Then work the inbox in a fixed order: accounting, automated mail, real people by project, then archive everything older than 14 days that isn't a to-do. Going forward the inbox only holds the last 14 days plus 01 To-Do. I scripted the bulk work against the Gmail API, but every step works by hand too.

The label structure

01 ⚡ To-Do
02 ⏳ Waiting for reply
03 Accounting
03 Accounting/Invoices
04 Projects
04 Projects/<one sublabel per client>
05 Internal
06 Events
07 Private
08 Accounts
09 Security
10 Notifications
11 Newsletter

Why numbers: Gmail shows user labels sorted by name. Without prefixes my sidebar was Accounts, Accounting, Events, Internal, Newsletter, … in whatever order the alphabet felt like. With a two-digit prefix, the stuff I touch daily sits on top and the noise sits at the bottom. Two digits, not one, or 10 lands between 1 and 2.

The two emoji on 01 and 02 aren't decoration. Those are the only two labels that mean "this needs me", and the emoji make them findable at a glance in a long sidebar and in the label chips on each mail. Everything below 02 is storage, so it stays plain.

Most of these labels already existed, just without numbers and in a random order. One client got a new sublabel under 04 Projects because they didn't have one yet.

Step 1: rename the labels (and drag the sublabels along)

Here is the generic shape of it in Python with the official client library:

# service = googleapiclient.discovery.build("gmail", "v1", credentials=creds)

renames = {
    "To-Do": "01 ⚡ To-Do",
    "Waiting for reply": "02 ⏳ Waiting for reply",
    "Accounting": "03 Accounting",
    "Projects": "04 Projects",
    # ...
    "Newsletter": "11 Newsletter",
}

labels = service.users().labels().list(userId="me").execute()["labels"]

for lbl in labels:
    if lbl["type"] != "user":
        continue
    name = lbl["name"]
    parent, _, child = name.partition("/")
    if parent not in renames:
        continue
    new = renames[parent] + ("/" + child if child else "")
    service.users().labels().patch(
        userId="me", id=lbl["id"], body={"name": new}
    ).execute()
    print(f"{name} -> {new}")

Gotcha: sublabels are just names with a slash

Gmail doesn't have real folders. A sublabel is a label whose name happens to be Parent/Child. In the web UI, renaming a parent renames the children with it. Through the API, each label is its own object with its own ID, and the / is just a character in the name. Rename Accounting to 03 Accounting and Accounting/Invoices is still called Accounting/Invoices. It now hangs as a lonely orphan with a parent that doesn't exist anymore.

That's why the loop above splits on the first / and rebuilds the full name. Rename the parent, then every label whose name starts with Parent/.

Gotcha: your filters don't care about the name

I was worried the existing filters (the ones that auto-label mail from certain senders) would break after renaming. They don't. Filters reference labels by ID, not by name, so a rename is invisible to them. Same for anything else that uses the label ID. If you have an external script that looks labels up by name, that one you'll need to update.

Step 2: work the inbox in a fixed order

The order matters. Clear the easy, bulk stuff first, so the human mail you have to actually read gets smaller and smaller.

1. Accounting. Forwarded invoices and statements that my receipt pipeline had already processed (I wrote about matching receipts with deterministic parsing), plus old invoices from suppliers. Label 03 Accounting or 03 Accounting/Invoices, archive.

2. Automated mail. App notifications, DMARC aggregate reports, workspace security warnings, subscription notices, shipping updates. Label 10 Notifications or 09 Security, archive. If you get DMARC reports and never read them, here's what's actually in them. They still don't belong in your inbox.

3. Real people, by project. Whatever is left is mail from humans. Each thread gets its client's sublabel under 04 Projects, or 05 Internal, or 08 Accounts. The biggest client alone accounted for 32 threads in this round. Threads where I'd sent something and was waiting for an answer went to 02 ⏳ Waiting for reply. That ended up being 4.

4. The 14-day cut. Everything older than 14 days that isn't marked to-do leaves the inbox.

The search queries

Gmail search operators do most of the work. These are the kinds of queries I used:

in:inbox older_than:14d -label:"01 ⚡ To-Do"
in:inbox from:noreply OR from:no-reply OR from:notifications
in:inbox subject:"Report domain"
in:inbox has:attachment subject:(invoice OR receipt)
label:"04 Projects/client-a" in:inbox
in:inbox -has:userlabels

The last one is the useful control query: anything in the inbox that has no label yet is the stuff you haven't sorted.

Label names with spaces need quotes in the search box.

Step 3: archive in bulk

Archiving in Gmail means one thing: remove the INBOX label. The mail stays in All Mail and in every other label. Via the API, batchModify does that for up to 1000 message IDs per call:

def search_ids(service, q):
    ids, token = [], None
    while True:
        res = service.users().messages().list(
            userId="me", q=q, pageToken=token, maxResults=500
        ).execute()
        ids += [m["id"] for m in res.get("messages", [])]
        token = res.get("nextPageToken")
        if not token:
            return ids

def label_and_archive(service, q, add_label_id=None):
    ids = search_ids(service, q)
    for i in range(0, len(ids), 1000):
        body = {"ids": ids[i:i + 1000], "removeLabelIds": ["INBOX"]}
        if add_label_id:
            body["addLabelIds"] = [add_label_id]
        service.users().messages().batchModify(userId="me", body=body).execute()
    return len(ids)

label_and_archive(service, 'in:inbox older_than:14d -label:"01 ⚡ To-Do"')

Note messages().list works on messages, not threads. A thread stays in the inbox as long as any of its messages has INBOX, so you want all of them. Searching messages with in:inbox gives you exactly those. The scope you need for this is gmail.modify, not full mail access. gmail.modify can move mail to trash but can't permanently delete it, which is a reasonable safety margin when the goal is "nothing deleted".

Doing it by hand in the web UI: run the search, select all, "Select all conversations that match this search", then archive. Same effect.

Gotcha: the label says 0, the mails are there

After renaming, a few sublabels showed 0 mails in the sidebar. Including the busiest client label and the invoices label. My first thought was that the rename had somehow detached the mails. It hadn't. A search on the label showed them all: 177 in the one client label, 230 in invoices. The counts in the UI were just stale after the rename.

So if you see a 0 after renaming: search before you panic. label:"03 Accounting/Invoices" tells you the truth.

The result

Before: 105 threads (155 messages) in the inbox. After: 18 threads (34 messages). What's left:

  • Fresh client threads from the last couple of days that are genuinely in progress.
  • A file transfer link that expires soon.
  • Three things marked 01 ⚡ To-Do: a payment reminder, a "storage full" warning with a deadline, and an app store account asking for a status update.

That's an inbox I can actually read in a minute. Everything else is one click away in its label.

The rule going forward

Inbox = last 14 days + To-Do. That's it. Anything older that isn't flagged gets archived. Anything that needs me gets 01 ⚡ To-Do and stays until it's done. Anything I'm waiting on goes to 02 ⏳ Waiting for reply so I can check that one label once a week instead of scanning the whole inbox for "did they ever answer?".

Rerunning the 14-day query once in a while is all the maintenance it needs. Before I run it, I look at what's in 01, so nothing there goes stale.

Nothing about this is clever. Numbers in front of label names, a fixed order and a 14-day cut. The win is that the inbox has one job again.

If you're moving mail around between systems in the first place, I've also written about exporting an M365 mailbox from OST to PST and migrating mailboxes with imapsync.


Related posts