Managing Deleting and Archiving Gmail with MUTT from Linux Bash Command Line Shell

Managing Deleting and Archiving Gmail with MUTT from Linux Bash Command Line Shell

I get alot of email in my gmail because I forward mail from many domains into my primary email account so I can check it from one location.

This works but over time my email box has grown to over 15gb of old emails that I never deleted and now it is costing me $$$ every month to have access to my email.

I have been doing some research into some linux command line tools to help automate the management of my email inboxes.

Some of the things I have learned so far is there is a cool command line tools called MUTT that can be used from the command line to read, send and delete email from any imap or pop3 email account including

It is a bit of a process to get a MUTT system installed and working but can be done.

This post will dive into how I did it.

So I wanted to install MUTT in a linux system.

First I tried to use the Windows BASH shell to install mutt but I seemed to run into issues with this system not working from my local macine because it was not connected to the open web and was just running as localhost and mutt could not see gmail correctly to allow it to log in right.

So I needed to set up MUTT on a public linux server somewhere.

I happened to have a CHUNKHOST vps running UBUNTU linux so I installed MUTT there.

>sudo apt-get install mutt

Once I got my mutt system set up I could use it to check my gmail account and delete emails from my inbox from the command line.

Then I needed to create a bash shell script that I could use to pass some command arguments to such as start date and end date of the sent date of each email.

I also wanted to be able to archive each email into a backup file that was stored off-line from gmail servers so I could use grep and regx to parse all the emails for stuff I wanted to look for such as email addresses and contacts and web site url's

Then I wanted to delete it permanently from my gmail box so I would not go over my storage quota of 15gb so I could unsubscribe from the paid tier.

This project has been taking me a few days of googling to find out how to do all of this and so far I have gotten MUTT installed and successfully checking my test gmail account while I worked out the bash shell script command syntax.

I will post updates to this post as I get my testing done and it worked.

So when I have solved this problem I will be able to issue a bash command in this format.
>purgegmail -startdate="mm/dd/yyyy" -enddate="mm/dd/yyyy" -archivefile="path/to/file/filename"

This will launch mutt then pass the -startdate, -enddate for mutt to tag that range of emails for delete and then copy each email to the -archivefile and then delete the emails from gmail.

The next step will be to create a bash command to parse through the archivefile and extract all the emails, deduplicate the list and put it in a format I can import into my MailPoet newsletter manager and manage my list that way.

Google links I found helpful to solve this project.