1. Calls to UrlFetchApp.fetchAll() will fail with an "Unexpected Error" exception about every 3 to 8 percent of calls. The way my code works is that I'll make one GET request to an AWS API Gateway endpoint to request a pre-signed S3 URL, and then I'll use the pre-signed S3 url to PUT a document. The unauthorized first request will fail sometimes, and issuing a PUT to the pre-signed S3 url will fail sometimes too. I have found no reason that these requests should fail, so instead of torturing myself by trying to figure out the root cause, I've decided to wrap both fetchAll() calls in a loop that retries the exact same request three times before giving up. If there was anything wrong with the request itself, one would expect a retry loop to be pointless, but it's significantly reduced the number of add-on failures.
2. If an email has invalid SPF alignment, then the add-on won't run at all. It's been three years and there's still no workaround for this. I have had to explain to dozens of people over the past three years that there's nothing I can do about it. https://issuetracker.google.com/issues/112064778 .
I feel like Google Apps Script - especially Gmail add-ons - are sorely neglected and are treated as an annoying legacy product that will probably be discontinued very soon with no replacement.
I also use Apps Script at home to send me email if the home network goes offline (a script at home updates a cell in a worksheet every 10 minutes, one on the cloud checks that it's been updated recently). It has saved my frozen goods at least once.
- For more real-time filtering you might also want to look into integrating with Google's Pub/Sub service (see Gmail.newWatchRequest() and Gmail.Users.watch()). It's kind of a pain to set up but it can help you avoid having to wait 10 minutes for everything to run, though you'll still want to have a polling mechanism as a fallback, and you might need to periodically call the watch methods to ensure you keep getting notifications pushed to you.
- If you need even better performance you can try manually batching up the HTTP requests via googleapis.com/batch (you can use ScriptApp.getOAuthToken() to get the auth token). This will let you factor out some of the server overhead across messages.
It doesn't look like it supports filtering on headers -- at least I don't see any calls to GmailMessage.getHeader(), and the only call to GmailMessage.getRawContent() appears to be in retrieving the ListID header (which Gmail's search natively supports). Looks like there's an open feature request for generalized header matching: https://github.com/ranmocy/gmail-automata/issues/36
I noticed that in the article I referenced (https://mjasion.pl/label-gitlab-notifications/) they also don't mention using getHeader and instead use getRawContent. It makes me wonder if the getHeader API was added more recently than this article and the project you mention.
I wrote a simple scripting utility to do similar labeling actions, bacause I came to gsuite with a large procmail configuration file previously. It was useful for a while, but gradually I stopped updating the filters:
https://github.com/skx/labeller
Nice to see there are other people doing similar things though, I'll definitely take a look at this more carefully over the next few days.
Next step in my things-to-try list is to just download the inbox via imap and sort it out locally.
Are you referring to actual Gmail filters, or Google Apps Scripts that attempt to mimic Gmail filters? I don't recall seeing the former be flaky, but the latter is another story.
The majority of the spam came in with emojis in the from or subject line, so this was immediately helpful for that, then I just add a rule whenever I notice certain phrases popping up more often.
I’d be delighted if someone can tell me I’m wrong, but it seems like Gmail filters don’t have built in options for stuff like emojis or regular expressions. Very disappointing that I have to brute force script my own filters.
That leads to polling, which ends up with a lackluster user experience. I don't want a random 30 second delay added to all my mail delivery.