All Projects → mattst88 → gmail-gitlab-filtering

mattst88 / gmail-gitlab-filtering

Licence: BSD-2-Clause license
Google Apps Script for Gmail to filter and sort email from GitLab

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to gmail-gitlab-filtering

Gmailctl
Declarative configuration for Gmail filters
Stars: ✭ 1,171 (+1294.05%)
Mutual labels:  gmail, labels, filters
Free Email Forwarding
The best free email forwarding for custom domains. Visit our website to get started (SMTP server)
Stars: ✭ 2,024 (+2309.52%)
Mutual labels:  email, gmail
Correo
💌 A menubar/taskbar Gmail App for Windows and macOS
Stars: ✭ 119 (+41.67%)
Mutual labels:  email, gmail
Wmail
The missing desktop client for Gmail & Google Inbox
Stars: ✭ 2,093 (+2391.67%)
Mutual labels:  email, gmail
Gatsby Mail
A Gatsby email *application*
Stars: ✭ 450 (+435.71%)
Mutual labels:  email, gmail
Imapcopy
Recursively copy all e-mail messages and folders from one IMAP account to another.
Stars: ✭ 52 (-38.1%)
Mutual labels:  email, gmail
Clojure Mail
A Clojure library for parsing, downloading and reading email from IMAP servers.
Stars: ✭ 172 (+104.76%)
Mutual labels:  email, gmail
gnome-email-notifications
Gnome Email Notifications
Stars: ✭ 65 (-22.62%)
Mutual labels:  email, gmail
Iky
OSINT Project
Stars: ✭ 203 (+141.67%)
Mutual labels:  gitlab, email
graphql-filter-java
This project is developed to help developers add filtering support to their graphql-java services
Stars: ✭ 52 (-38.1%)
Mutual labels:  filters, filtering
CubeMail
CubeMail is a webmail client built using React and Chakra UI, It runs in the browser and uses the Gmail's public Javascript API.
Stars: ✭ 25 (-70.24%)
Mutual labels:  gmail, gmail-api
Gmail Desktop
📮 Nifty Gmail desktop app for macOS, Linux & Windows
Stars: ✭ 317 (+277.38%)
Mutual labels:  email, gmail
Lieer
Fast email-fetching and sending and two-way tag synchronization between notmuch and GMail
Stars: ✭ 301 (+258.33%)
Mutual labels:  email, gmail
Waveboxapp
Wavebox Classic has been updated to Wavebox 10. Learn more Wavebox.io
Stars: ✭ 1,198 (+1326.19%)
Mutual labels:  email, gmail
Magento2 Gmail Smtp App
Configure Magento 2 to send email using Google App, Gmail, Amazon Simple Email Service (SES), Microsoft Office365 and many other SMTP (Simple Mail Transfer Protocol) servers
Stars: ✭ 281 (+234.52%)
Mutual labels:  email, gmail
React Letter
✉️ Display e-mails in your React.js projects. (Targets Gmail rendering.)
Stars: ✭ 164 (+95.24%)
Mutual labels:  email, gmail
elixir-gmail
A Gmail API client for Elixir
Stars: ✭ 46 (-45.24%)
Mutual labels:  gmail, gmail-api
emailpyspam
A python 3+ program to spam emails to a list of users repetitively
Stars: ✭ 63 (-25%)
Mutual labels:  email, gmail
Forwardemail.net
The best free email forwarding for custom domains (Web Server)
Stars: ✭ 211 (+151.19%)
Mutual labels:  email, gmail
email
Aplus Framework Email Library
Stars: ✭ 127 (+51.19%)
Mutual labels:  gitlab, email

gmail-gitlab-filtering

gmail-gitlab-filtering.gs is a Google Apps Script for Gmail to sort and filter email from GitLab.

BSD-2 license

The Problem

Receiving all messages from a mailing list and filtering by whether I am a direct recipient (in To: or Cc:) has been an effective strategy for me to both

  1. follow development at large
  2. not miss requests for my input

With mailing lists, I accomplish this with a combination of Gmail filters:

Matches: to:([email protected])
Do this: Apply label "mattst88"
Matches: list:mesa-dev.lists.freedesktop.org
Do this: Apply label "mesa-dev"
Matches: -{to:[email protected]}
Do this: Skip Inbox

Thus, mail from mailing lists is labeled appropriately and doesn't clutter my inbox. Any messages with me in To: or Cc: cause the thread to be labeled with a personal mattst88 label and appear in the inbox.

I have not been able to replicate this with GitLab and Gmail, given the limitations of each.

Emails from GitLab contain many headers that can be used to filter the message. Of the headers GitLab uses, Gmail's filtering system can only filter on List-Id.

GitLab can be configured to email updates under different circumstances: any activity, only for threads you've participated in, only for comments that mention you, etc.

This leaves me with a choice of receiving notifications only for threads I'm involved in or for all threads but without the ability to easily find requests directed to me.

The Solution

Google Apps Script provides a method of automating many operations on a Gmail account (sending email, searching, labeling, etc.) via the GmailApp class. The gmail-gitlab-filtering.gs script is run every 10 minutes via a trigger on script.google.com and performs filtering and labeling based on the X-GitLab headers.

This allows me to appropriately label notifications that are directed to me, as well as dynamically create labels for notifications received from new projects.

How

Email from GitLab is labeled using Gmail's default filtering with a top-level label and skips the inbox. In my case, all mail from [email protected] is given the freedesktop label:

Matches: from:([email protected])
Do this: Skip Inbox, Apply label "freedesktop"

Threads with this label are considered unprocessed.

The gmail-gitlab-filtering.gs script searches for threads with that label, and inspects the headers of each message using the GmailMessage.getHeader() function.

The script records the value of all X-GitLab-Project-Path headers and whether any message in the thread contained a X-GitLab-NotificationReason header.

Threads containing a X-GitLab-NotificationReason header retain the personal label and are moved to the inbox. Threads without X-GitLab-NotificationReason header remain archived and the personal label is removed. All threads are labeled with ${unprocessedLabel}/${X-GitLab-Project-Path}, and the label is dynamically created if needed. The unprocessed label is always removed as the final step, in case the script's runtime exceeds the allowed timelimit (see below).

For example, if I were to receive a notification of a merge request in the mesa/shader-db project that mentioned me, the script would move the thread to the inbox, leave the mattst88 label intact, label the mail freedesktop/mesa/shader-db (creating the label if needed), and remove the freedesktop label.

Implementation notes and limitations

None of the limitations cause problems for my usage. I receive a few hundred GitLab notifications per day.

Google Apps Scripts are subject to quotas.

While developing this script, I hit two quotas:

  • Script runtime: 6 min / execution
  • Email read/write (excluding send): 20,000 / day

To fit into the 6 minutes / execution limit, the script operates on a maximum of 240 threads per execution. See the maxThreads variable. I arrived at the 240 number empirically; it's not definitive.

I reached the 20,000 / day email read/write quota during development and expect to never reach it again now that the script functions.

To improve efficiency (and perhaps avoid hitting quotas), the script creates lists of GmailThreads so they can be passed in batches to GmailApp.moveThreadsToInbox, GmailLabel.addToThreads, and GmailLabel.removeFromThreads †. It's unclear to me which functions use quota and how much they use.

† These functions accept only 100 threads per call, so the script calls them multiple times on .slice()s of the lists.

Google Apps Scripts don't support async/await

I initially though I would be able to improve performance of the script by using async/await. While the V8 Runtime recognizes the keywords it does not make use of them. An upstream bug is filed here.

I found an interesting work-around: Async.gs. It works by scheduling a script execution in the future. I did not experiment with it.

Setup

  1. Create a project on script.google.com
  2. Paste gmail-gitlab-filtering.gs into the default Code.gs file
  3. Modify as needed for your particular filtering rules
  4. Set up a trigger to run the script periodically. I followed the instructions from Marcin Jasion's How to label GitLab notification in Gmail by headers? article.

I'm not a JavaScript developer

I muddled through writing the script with the help of the Apps Script documentation and the Mozilla Web Docs JavaScript Reference. Improvements to the code are welcome.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].