Hacker Timesnew | past | comments | ask | show | jobs | submitlogin
Show HN: Gmail CLI Utils (bulk delete mail by query, get/create filters) (github.com/abhishekkr)
192 points by abionic on April 26, 2020 | hide | past | favorite | 39 comments


Related: would this tool let me analyze my gmail for cleanup? That is, identify which senders/domains send me the most email by number or size. Some way to automatically download large attachments and then deletes those. I know there are 3rd party apps that do this, but I don’t like giving access to random 3rd party apps.


I know this isn't exactly what you are looking for, but I run this search once every few months: [has:attachment larger:5M]

That finds everything bigger than 5 megabytes. You can't sort by size, but at least you can find big stuff. If that search has too many results, just keep upping the number until you find the few really big messages.


suggestion by @jedberg would work good for a search based on attachment size

your suggestion on "auto analysis for cleanup" is good, I'll add it to my ToDo list


Thanks. Yes I know that search option, but sometimes 1 mb x 100 is sitting there while I take trouble locating a single 5 mb message.


This looks useful!

For "Declarative configuration for Gmail filters", see also https://github.com/mbrt/gmailctl


This is nice. A couple of days back I was thinking of a utility where labels are created automatically. It uses meta information like:

  * How many emails I get from a sender

  * From mails' subject 

  * Which similar mails I open or not.


Hijacking this comment, but it seems likely to attract the right sort of crowd..

Can anyone recommend a Mac/web Gmail UI with exceptionally fast hotkey interactions? The Gmail web interface has slowed to the point of un-usability for me now.

Command line (Alpine, etc) would be fine, but my Gmail account is secured by work and has the required access control settings disabled.


Use the plain HTML interface (no JS) and it's very fast. The option to disable it is at the bottom. You can of course enable it any time.


Neomutt! If you want something nice and easy to get you up and running: https://github.com/LukeSmithxyz/mutt-wizard


FWIW, I tried Superhuman for a month and it was exellent. Extremely fast and responsive shortcuts.

30 USD/month was a bit more than I can justify so I cancelled but I still wish I hadn't.

Not sure what you meant by 'secured by work' - you can still authorize 3rd party apps can't you? Is it even possible to block that?


That's an avenue I'm pursuing - have joined the waiting list and am waiting for someone to get back to me after a brief email interaction over the weekend.

Secured by work was a reference to one possible suggestion of using Alpine or similar, which requires app-specific passwords. And yes, it seems it is possible to block that!


I’m working on a native Mac email client for Gmail that uses the Gmail API and support Gmail-specific features like labels and categorized inboxes. If you’re able enable access for 3rd party apps, and interested in beta testing this, would love to have you sign up at https://mimestream.com


I know this is an odd question but...

Have you tried deleting a very large number of messages? I am talking about > 100,000. I once needed to clean up > million messages and it was rather challenging even utilizing Google's scripting. Batching ( within Google's recommended parameters ) would periodically fail. Triggers would not run. etc.


I've had the same issue spanning years. I didn't bother going further than the web UI. I would delete 100k+ messages, it would hang, and when it returned it would only have deleted like 70k.


This hack might work.

1. Move all the messages to a folder.

2. Then delete that folder.


You can just Create a filter to delete such messages and check apply to all existing conversations.


Having gone through this recently you'll see a spinner/progress indicator. Then a short time later it'll terminate and half your messages will still be present.

I took several days deleting a few hundred thousand messages, "Select all", "delete". Each time it would remove 1000-10,000 messages and leave the rest. Was a real pain.


After a lot of trial and error I have been successful at doing a limit fetch and limit delete with a limit of 9000 in 5 minute intervals using scripting API with a registering a timed trigger.

1. Get current time, increase the time by 5 minutes and find the 5 minute mark after that.

2. Register itself to run the time determined in (1).

3. Fetch a batch of 9000 ids matching the filter.

4. Delete the batch

This script would comfortably run for days cleaning out the inbox until it would hit some weird message that looked nearly identical to the messages around it and bomb(!?). Running it by hand would bomb at which point script won't be able to continue to execute. Deleting a message by hand would work. Running the script again after the manual deletion would work.


My first thought after "how hard can it be? Since all the messages are from the monitoring systems I can just assign the labels based on the 'from' address and..." was to use that exact approach. It have never seen that many timeouts in my life.


yes I did

although I tried deleting for one or two years at a time


This is sweet. If you're interested, I'd be happy to help out with your todo to integrate with a local database. Getting the rate-limiting and retries right can be a little tricky but it's been on my list to add Gmail support to AspenDB https://github.com/aspen-cloud/aspen-cli.


any help is welcome, thanks


Related: I recently used mbsync and notmuch to clean-up my Outlook/Live/Office email account. A one-liner to get email count per domain:

    notmuch address '*' | sed "s/^.*@//" | sed "s/>\$//" | sort | uniq > domains.txt
To "delete" emails (move them to the deleted folder):

    notmuch search --output=files --format=text0 '(tag:whatever and not folder:Deleted' | xargs -0 --no-run-if-empty mv -t ~/.mail/live/Deleted/new/
Useful alternative to this for non-Gmail. The Outlook interface couldn't delete more than a few hundred mails.


See also my little hack, a sort of procmail for gmail, with a small scripting language:

https://github.com/skx/labeller/

Adding/Removing labels based upon arbitrary expressions/headers/values, etc.


Maybe this will help me get to a zero inbox finally. 65k emails 99% of which are junk.


You could try email bankruptcy.

Just mark everything as read. If it's important, they'll send it again. I cheat by marking everything more than 30 days old as read.

I do that once a year in February. I mark everything from the previous year as read on Feb 1. Sometimes I do it again in July/August.


Same, I go even more ruthless. Any unread email over a week old gets marked read, any read email over a week old gets archived. All Updates, Social, Promotion emails get marked read on arrival. All Primary inbox emails get intercepted on arrival and batched back into inbox on a schedule (usually twice a day).

I sit at zero most of the time, and ive only ever missed emails a bare handful of times, so seems to work.


How do you batch the incoming emails into a few drops a day?


I use a simple Apps Script. A filter adds a "New Messages" label to incoming "category:primary" and skips inbox, then the script on timer triggers remove the label and put them back in inbox

https://github.com/MichaelYock/GmailScripts/blob/master/Gmai...

Come to think of it, i was going to make a GUI for this now that gmail add-on Cards have a Home Card option


Sounds like you could benefit from enabling the category tabs feature in gmail, at least it will separate few categories for you


You could do that to an extent with filters. Just make sure to check apply to all existing conversations.


I did something similar - in fact looking at the add filter, very similar, where I add a label to certain mails by query and then delete - but the weirdest part was i could not auto-create one new filter - i have to re-create them all (so if I want to add a 21st filter with 20 still there my create filter routine needs to apply 21 filters. I just have it trying to reduce the spam and should spend some time trying to add new filters - one day.

But this is cool and love to know if there is a "add one" feature i missed.


I am using google-api-client, which has a "create" for single GMail Filter

available here: https://developers.google.com/gmail/api/v1/reference/users/s...


thanks i will have a look


Creating this was on my to-do list this week. Ya beat me to it!


:)


How might I use this to delete emails with big attachments? Can I filter and delete by message size?

I'm cheap. :-)


Use a filter like "has:attachment larger:10mb in:all". For each 100 deleted emails you get 1GB of free space back.


I will be going to work tomorrow and baking this into our email test suite.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: