This has been a continuous project since 2018. Starting off as something to do while killing time in study hall in High School while also solving a problem I didn’t expect to be having at the time. That problem being the number of emails I receive from different places. With versions of this project having sorted over 16,396 emails at the time of writing this. All in the name of having a reasonably empty Inbox. Making use of Google’s App Scripts.

First Phase

When I initially started this project it was mildly dumb how it was set up but it functioned. With many of the original ideas from it carrying into the current version of the project I’m using today. Such as how it sorts emails based on either the first 30 characters of the subject line or my the address the email was sent from into different labels. Then removing them from the inbox.

What was mildly stupid about how it was implemented was how the information on how things should be sorted was sorted. Which was directly embedded into the source code in 2D arrays.

var labels = ["Label 1","Label 2","Label 1/Sub-label 1"];
var filters = [
                ["example@gmail.com", "Email Sorter"],
                ["example2@gmail.com"],
                ["example3@gmail.com"]
            ];

Example of how the information was embedded.

And while this worked it was not easily expandable. Requiring the editing of source code to add new filters. Labels also had to be manually added to the list as well. Which was also a problem.

Second Phase

But that’s how I used the project for a month or two. Until I came to some senses about how stupid this was. So to solve the problem I began making use of the fact that Google App Scripts can access Google Sheets. So I began to use a Google Spreadsheet as a database of sorts.

Image of old stats “Dashboard”

This is also about the time I added some statistics tracking for the program. With it then recording how many emails had been sorted every day of the week. As well as a running total of how many emails where sorted as well as the number of labels it sorted into and the number of “filters” it used. With each “filter” being either a unique email address or subject line.

This version of the project still had it’s issues. Such as still requiring the manual entry of labels that I had created on my Gmail account. That though was minor compared to the larger issue of how slow it was. Which was mostly from my own bumbling around.

Being inexperienced with the spreadsheets API and never having had an issue with run time in the past I would access the spreadsheet repeatedly for every email that it was filtering. Rebuilding the array of filtering values every time. And the time it took to access the spreadsheet was not insignificant. That coupled with the fact that Google App Scripts can only run for 5 minutes before being shut down in the free tier and the program would effectively crash if I had received to many emails sense the last sorting operation. And with how I had it set up it wouldn’t actually sort the emails until it had determined where everything was to go. So if it did crash nothing got sorted. Making it so that ones I received to many emails it wouldn’t recover without outside assistance.

Third Phase

So after nursing those issues along for over a year I decided to actually rewrite the program. With the first thing being to be fixed being the number of times it accessed the spreadsheet. With it now only accessing the spreadsheet once for every time the entire project is run.

I also implemented a time checker within the program that would ensure that if it was approaching a 5 minute run time that it would stop sorting and finalize all changes before the time was up. While also triggering the program to run again within 15 minutes of it closing to ensure that their isn’t more email to be sorted. This though has rarely triggered since I reduced the number of times it tries to access the spreadsheet.

Example of email sorting interface

It was also during this rewrite that I implemented some convenience features. Such as an interface that allows emails currently in my inbox to be listed as well as where they would be sorted. I can then change where these emails will be sorted to from this interface through a dropdown menu of labels that I have created within my Gmail account. Which automatically update when I add new labels. Eliminating the need to manually add labels to a list.

Example of weekly report output

I also improved some features that I had always had within the program. Such as the weekly emailed report on how it’s been preforming. With it now presenting more information than it had in previous versions.

Future Phases

But that doesn’t make it’s current implementation perfect. It still uses spreadsheets for interfaces and dashboards. Which while they function can easily be broken if the wrong cell is modified. And no matter how long I’ve used it for spreadsheets are not the best thing to use to store data.

One example of that being how currently it is possible for the program to reach a point where it can run out of cells to store statistics that it records. Which it which came close to doing requiring the manual moving of that data elsewhere. And while it took well over two years to happen it’s not exactly the most elegant solution.

So now that I’ve had a few classes on Databases as well as having now worked with Firebase a fair bit I intend to eventually convert this project from using Google Sheets to Firebase for it’s data storage needs. Though that’s subject to change. I also want to eventually give it a proper interface. And not just use the spreadsheet as the solution to everything.

Either way I intend on it continuing to be a learning experience and a useful tool to keeping my email organized. Heck. Maybe I’ll make it a proper extension if I find the time. Who knows what the future may hold.