
Gmail Regex Rules Manager
A powerful Chrome extension that automatically manages your Gmail emails using regex-based rules. Set up custom patterns to automatically label, archive, mark as read, and perform other actions on incoming emails.
Features
⨠Regex Pattern Matching
Match emails by sender (From)
Match emails by recipient (To)
Match emails by subject
Match emails by body/snippet
Live Regex Helper - Test patterns in real-time as you type
šÆ Automated Actions
Add or remove labels
Mark as read/unread
Mark as important
Star emails
Archive emails
Move to trash
ā” Real-Time Monitoring
Automatically detects new emails in Gmail
Processes emails as they arrive
Configurable scan interval (1-60 minutes)
Works in the background with retry logic
šØ User-Friendly Interface
Easy rule creation and management
Drag & drop rule reordering to set priority
Test rules before applying
Enable/disable rules individually
Per-rule match statistics (count & last matched)
Visual feedback and status
š Performance & Observability
Stats tab with processing metrics
Configurable retention (5-500 entries)
Adjustable log levels (error/warn/info/debug)
Import/export rules for backup/sharing
Installation
š Important: This extension requires your own Google OAuth credentials to access Gmail. Follow the setup guide below.
Quick Setup
Get OAuth Credentials - Follow our detailed OAuth setup guide
Configure the extension - Use the helper script or edit manually
Load in Chrome - Install as an unpacked extension
Method 1: Using the Helper Script (Recommended)
Method 2: Manual Configuration
Download or clone this repository
Open
manifest.json in a text editorFind the
oauth2 section at the bottomReplace
YOUR_CLIENT_ID.apps.googleusercontent.com with your actual Client IDLoad Extension in Chrome
Open Chrome and go to
chrome://extensions/Enable Developer mode (toggle in top right)
Click Load unpacked
Select the extension folder
Click the extension icon and Sign In to authenticate
Need Help?
š Complete OAuth Setup Guide - Step-by-step instructions with troubleshooting
š Quick Start Guide - Get started in 5 minutes
ā Check the Troubleshooting Guide for common issues
Old Installation Section (For Reference)
Click to expand detailed manual setup
Step 1: Set up Google Cloud Project
Go to Google Cloud Console
Create a new project or select an existing one
Enable the Gmail API:
Navigate to "APIs & Services" > "Library"
Search for "Gmail API"
Click "Enable"
Create OAuth 2.0 credentials:
Go to "APIs & Services" > "Credentials"
Click "Create Credentials" > "OAuth client ID"
Select "Chrome Extension" as application type
Copy your Chrome Extension ID (you'll get this after loading the extension)
Add authorized redirect URIs:
https://<extension-id>.chromiumapp.org/Click "Create"
Copy the Client ID
Step 2: Configure the Extension
Download or clone this repository
Open
manifest.jsonReplace
YOUR_CLIENT_ID.apps.googleusercontent.com with your actual Client ID from Step 1Step 3: Load the Extension
Open Chrome and navigate to
chrome://extensions/Enable "Developer mode" (toggle in top-right corner)
Click "Load unpacked"
Select the
gmail-regex-manager folderNote the Extension ID shown on the extension card
Go back to Google Cloud Console and update your OAuth credentials with this Extension ID
Step 4: Authenticate
Click the extension icon in Chrome
Click "Sign In" button
Authorize the extension to access your Gmail
You're ready to create rules!
Usage
Creating a Rule
Click the extension icon
Go to the "Create Rule" tab
Give your rule a name (e.g., "Newsletter Filter")
Set up patterns:
From Pattern: Regex to match sender email
Subject Pattern: Regex to match subject line
Body Pattern: Regex to match email content
Live Regex Helper: Type sample values below each pattern to see live matches
Choose actions:
Add labels (comma-separated)
Mark as read
Archive
etc.
Click "Save Rule"
Live Regex Helper
The Create Rule tab includes a live testing panel:
Enter sample From, To, Subject, and Body values
As you type patterns, see instant feedback
ā Green = pattern matches sample
ā Red = pattern doesn't match
Yellow = regex syntax error
Empty pattern fields show as gray "ā"
This helps you validate patterns before saving the rule.
Rule Priority & Ordering
Rules are evaluated in the order shown on the Rules tab. Drag and drop rules using the ā° handle to reorder them. Higher priority rules run first. Reordering is saved automatically.
Per-Rule Statistics
Each rule card displays:
Matches: Total number of times the rule has matched
Last: Timestamp of the most recent match
Statistics help you understand which rules are actively processing emails.
Example Rules
Filter Newsletters
Urgent Emails
Invoice Tracker
GitHub Notifications
Regex Tips
. - matches any character.* - matches any characters (zero or more)^ - start of string$ - end of string| - OR operator\ - escape special characters[abc] - matches a, b, or c[a-z] - matches any lowercase letter\d - matches any digit\w - matches word charactersCase Insensitive: All patterns are automatically case-insensitive.
Testing Rules
Go to the "Test" tab
Enter sample email data (from, to, subject, body)
Click "Test Against All Rules"
See which rules would match your test email
Settings
The top of the popup includes configuration options:
Auto-process emails: Toggle to enable/disable automatic processing
Log Level: Choose verbosity (error, warn, info, debug)
Processing Interval: Set scan frequency in minutes (minimum 1 minute due to Chrome alarm API limits)
Lower values = more responsive but higher CPU/network usage
Default: 1 minute
Perf Retention: Maximum number of performance entries to store (5-500)
Default: 50 entries
Interval changes take effect immediately and reschedule the background alarm.
How It Works
Content Script: Monitors Gmail webpage for new emails using DOM observation
Background Service Worker: Processes emails and applies rules via Gmail API with exponential backoff retry logic
Storage: Rules and settings are stored locally using Chrome's storage API
Gmail API: Applies actions (labels, read status, etc.) to matched emails with automatic label creation
Performance Tracking: Records metrics for each processing run (configurable retention)
Logging: Structured logging with adjustable verbosity levels
Permissions
The extension requires the following permissions:
storage - Store rules and settings locallyidentity - Authenticate with Googlealarms - Periodic email checkingGmail API scopes:
gmail.modify - Modify emails (labels, read status, etc.)gmail.labels - Manage labelsTroubleshooting
Extension not processing emails
Make sure the extension is authenticated (click "Sign In")
Check that auto-process is enabled in the extension popup
Verify that Gmail is open in at least one tab
Rules not matching
Use the "Test" tab to verify your regex patterns
Check that patterns are properly escaped
Remember patterns are case-insensitive
Authentication fails
Verify Client ID is correctly configured in manifest.json
Make sure Gmail API is enabled in Google Cloud Console
Check that OAuth consent screen is properly configured
Labels not appearing
Labels are created automatically if they don't exist
Refresh Gmail to see newly created labels
Check browser console for any errors
File Structure
Privacy & Security
All rules are stored locally on your device
No data is sent to external servers (except Google APIs)
Extension only accesses Gmail when authenticated
You can revoke access anytime in your Google Account settings
Development
Local Testing
Make changes to the code
Go to
chrome://extensions/Click the refresh icon on the extension card
Test your changes
Debugging
Offline Rule Testing
Automated Tests
Jest tests live under
tests/unit/. Run (after installing dev dependencies locally):Tests cover:
Performance entry creation and storage
Gmail API retry logic with exponential backoff
Label creation and retrieval
Rule matching logic
CI runs tests automatically on push/PR via
.github/workflows/ci.yml.Import / Export Rules
Use the popup's Import/Export tab:
Export: Downloads
rules-export.json (current rules)Import: Select a JSON array of rules, they are validated and appended
Rule object shape:
Performance Metrics & Stats Tab
Processing performance entries are stored in
chrome.storage.local under perfStats (configurable retention: 5-500 entries, default 50). Each entry:You can inspect via the DevTools console in the service worker:
Stats Tab
Open the Stats tab in the popup to view a table of recent runs with:
Time of run
Emails scanned
Rules count
Match checks performed
Rule matches
Emails processed (actions applied)
Duration (ms)
Buttons:
Refresh: Reload data
Clear: Remove all stored performance entries
Summary line shows entry count, average duration, and total processed across runs.
Release Script
Use the release helper to bump version, update
manifest.json, update package.json, append a CHANGELOG entry, commit, and tag:Levels:
major | minor | patch.You can evaluate rules against sample emails outside Chrome using the Node test harness.
Sample data lives in
examples/:examples/rules-sample.jsonexamples/emails-sample.jsonRun harness (JSON output):
Compact summary:
Single inline email:
Version bump helper:
Add
--tag to auto commit & tag:Background script:
chrome://extensions/ > Click "service worker"Content script: Open Gmail, press F12, check Console
Popup: Right-click extension icon > "Inspect popup"
Limitations
Rules process emails visible in Gmail's current view
Body matching only works on email snippets (not full content)
Maximum 100 rules recommended for performance
Requires Gmail to be open in at least one browser tab
Future Enhancements
Import/export rules
Rule execution statistics (Stats tab)
Rule priority/ordering (drag & drop)
Live regex helper
Configurable processing interval
Retry logic with exponential backoff
Per-rule match statistics
Structured logging
Advanced regex builder UI
Email templates for responses
Scheduled rule execution (time-based)
Full email body search via API
Rule groups/folders
Conditional actions (if/then logic)
License
MIT License - Feel free to modify and distribute
Support
For issues, questions, or contributions, please visit the GitHub repository.
Note: This extension requires proper Google Cloud OAuth setup. Make sure to follow the installation instructions carefully.
1 like Ā· 7 views Ā· Feb 4, 2026
Developed a Chrome extension for Gmail email management using regex rules. Managed Regex Pattern Matching, Automated Actions, Real-Time Monitoring features.