Gmail Automata is to do a better job replacing existing Gmail filters.
The idea is to archive all incoming emails by default and attach it to the "unprocessed" label. Then a background script which is included in this spreadsheet will run automatically every 5 minutes (or according to the "configs"). When the script runs, it fetches all emails with the "unprocessed" label, apply actions to those emails according to the "rules. Finally, move them to the "processed" label and remove them from the "unprocessed" one.
During the process, it goes through all unprocessed email threads. For each email in the thread, check all rules in the order specified by the "stage". If a rule's "condition" matches that email, the associated actions will be applied to the thread. If any rule matches, the processing of the email will stop after all rules with the same stage are applied. If no rule matches the thread, it will treat it as an error in case it's a new type of email. You could add a rule to match all emails at the end if you don't like this behavior.
If any error happens to the processing, the email thread will be moved to inbox with label "error" by default, so you won't miss it because of this script. Also, the script executor will send you an email about the failure, so you could check what's the reason behind it.
Clone this spreadsheet: File -> Make a copy. You need your own version to process your emails on your behalf. You need to grant permissions for your new spreadsheet to continue.
Notice: If you can't see "Gmail Automata" in the spreadsheet menu, you may need to manually add the trigger:
Review sheets "configs" and "rules". Replace "ranmocy@gmail.com" with your email address in those sheets.
In Gmail, create label "0unprocessed"
If you want to test before automation, go to step 5; Otherwise, go to step 7.
Add some (<=50) emails to "0unprocessed" label. Click menu "Gmail Automata" -> "Process now" to trigger one time processing. Notice that if you add too many threads, each execution would only process the first 50 threads. Also if a thread is too old (twice the processing interval, 10 minutes by default), only the latest email would be processed.
Check emails result with label "0processed" and update rules and go back to step 5 until you are satisfied.
In Gmail's settings, empty your current filters (better to export them first as a backup!) and add following ones (Remember to replace email with yours! Also replace "urgent" to a tag you wish to bypass the script to reduce the latency):
Matches: from:(-apps-scripts-notifications@google.com) -in:chats to:(-YOUR_EMAIL+urgent@gmail.com) -{label:mute}
Do this: Skip Inbox
Matches: from:(YOUR_EMAIL@gmail.com) to:(YOUR_EMAIL@gmail.com)
Do this: Apply label "0unprocessed"
Matches: from:(-YOUR_EMAIL@gmail.com,-apps-scripts-notifications@google.com) to:(-YOUR_EMAIL+urgent@gmail.com) -in:chats -{label:mute}
Do this: Apply label "0unprocessed"
[Optional] In Gmail settings -> "Inbox", switch "Inbox type" to "Important first"
Click menu "Gmail Automata" -> "Start auto processing" to setup auto triggering
You are good to go! Enjoy!
Check notes of headers of "configs" and "rules" for detailed explaination on each columns.
See section Deploy below.
Click menu "Gmail Automata" -> "Stop auto processing" to remove auto triggering.
npm install -g yarn
git clone https://github.com/ranmocy/gmail-automata.git
cd gmail-automata
yarn install
cp .clasp.template.json .clasp.json
.yarn claspLogin
and authorize the app in the browser.yarn deploy
.