This Google Apps Script moves your low priority (promotional, social, political, etc.) emails in Gmail to a custom label and sends you a daily synopsis of received emails for review. Basically, this is `unroll.me` without any third-party access or [creepy data brokering](https://archive.is/30hj9).
Configure the script easily by setting global constants for your spreadsheet ID, sheet name, Gmail label, and email digest time range.
- **Performance Enhancements:**
The script now uses JavaScript Sets and batch updates (instead of multiple `appendRow` calls) to handle larger datasets more efficiently. My personal instance of this script filters messages from almost 1300 email addresses.
- **Automatic Deduplication:**
A new `dedupeEmails` function is included to automatically remove duplicate email addresses from your spreadsheet. You can schedule this to run periodically.
- **Improved Unsubscribe Link Extraction & HTML Template:**
The unsubscribe link extraction has been refined, and the HTML template now uses centralized CSS.
- **Modern Code Practices:**
The script has been updated with ES6 syntax (`const`, `let`, for‑of loops) for improved clarity and maintainability.
- Copy the updated code into the project's `Code.gs` file.
- Replace the placeholder `SHEET_ID` (currently set to `'sheetID'`) with the actual ID of the spreadsheet (the string between `spreadsheets/d/` and `/edit` in your sheet's URL).
- Update `SHEET_NAME` if your target sheet name differs from the default ("Sheet1").
Column A of your spreadsheet will be populated with the email addresses of low priority senders.
The script’s `addEmail` function should prevent duplicate entries, but the `dedupeEmails` function will periodically clean up any accidental duplicates.
To stop an email from being flagged as low priority, remove its corresponding email address from your spreadsheet and (for safety) remove the label from any related messages in Gmail.
The updated script handles thousands of entries efficiently. For extremely large datasets, consider archiving older data or scheduling deduplication more frequently.