agentleFS
CarbeneAICarbeneAI/Forge/.claude/skills/EmailManager/SKILL.md

EmailManager

Skill9 starsChanged 6 months agoMITView on GitHub

Intelligent email management for Gmail accounts with spam filtering and Telegram notifications. USE WHEN user mentions email monitoring, check emails, email spam, email digest, email notifications, OR wants to manage Gmail accounts, filter spam, or get email alerts via Telegram.

  • Reads credentials

We split this skill into the rules it gives an agent

2 rules. About 0 are common, 2 are distinctive, and 0 are very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈2

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 0

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    Polling: Every 2 minutes via systemd service on your host machine

    line 27
  2. Distinctive:

    All data is gitignored. Tokens encrypted with AES-256-GCM.

    line 171

≈ “Common” is an estimate: at least 1 in 5 of the 308,232 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

EmailManager

Intelligent email management system for PAI that monitors Gmail accounts (personal + workspace), filters spam/phishing with 4-layer detection, and surfaces legitimate emails via Telegram notifications.

Agent: Philemon

Biblical character who received Paul's most important personal letter — a masterclass in diplomatic communication and message handling. Perfect for an email management agent.

Architecture

Gmail API (Personal) ─┐
                      ├→ EmailMonitor.ts → SpamFilter.ts → Telegram Notification
Gmail API (Workspace) ─┘
  • Auth: OAuth2 with encrypted refresh tokens
  • Polling: Every 2 minutes via systemd service on your host machine
  • Storage: JSON files in data/ (gitignored)
  • Notifications: Telegram (reuses existing PAI bot)

Quick Start

1. Setup OAuth (one-time per account)

# Personal Gmail
bun ~/.claude/skills/EmailManager/tools/OAuth2Setup.ts --account personal

# Workspace Gmail
bun ~/.claude/skills/EmailManager/tools/OAuth2Setup.ts --account workspace

2. Test Gmail Access

# List unread emails
bun ~/.claude/skills/EmailManager/tools/GmailClient.ts list --account personal --query "is:unread" --max 5

3. Test Spam Filter

# Analyze a specific message
bun ~/.claude/skills/EmailManager/tools/SpamFilter.ts analyze --account personal --message-id <id>

4. Run Monitor (manual)

# Dry run - no notifications
bun ~/.claude/skills/EmailManager/tools/EmailMonitor.ts --once --dry-run

# Single run with notifications
bun ~/.claude/skills/EmailManager/tools/EmailMonitor.ts --once

# Daemon mode
bun ~/.claude/skills/EmailManager/tools/EmailMonitor.ts --daemon

5. Service Management (Linux host)

~/.claude/skills/EmailManager/tools/manage.sh start
~/.claude/skills/EmailManager/tools/manage.sh status
~/.claude/skills/EmailManager/tools/manage.sh stop

Priority Gate System (Phase 4)

For high-volume inboxes (300+ emails/day), the Priority Gate drastically reduces Telegram noise by scoring emails on "decision required" probability.

Tier System

TierCriteriaAction
Tier 1 (Immediate)VIP sender OR (urgent category + decision score > 70)Telegram notification
Tier 2 (Daily Review)action_needed category OR decision score 40-70Daily digest only
Tier 3 (Auto-Archive)Everything elseSilent, no notification

Expected result for 300+ emails/day:

  • Tier 1: ~3-5 Telegram notifications/day
  • Tier 2: ~10-20 emails in daily digest
  • Tier 3: ~280+ auto-archived

Configuration

# Show current config
bun ~/.claude/skills/EmailManager/tools/PriorityGate.ts config

# Analyze specific email
bun ~/.claude/skills/EmailManager/tools/PriorityGate.ts tier --account personal --message-id <id>

Tuning

Edit data/email-config.json to adjust:

  • priorityGate.tier1Threshold (default: 70)
  • priorityGate.tier2Threshold (default: 40)
  • priorityGate.vipAlwaysTier1 (default: true)
  • priorityGate.urgentCategoriesForTier1 (default: ["urgent", "action_needed"])

Spam Filter - 4 Layers

LayerWeightChecks
Auth Headers0.4SPF, DKIM, DMARC pass/fail from Authentication-Results
Sender Reputation0.2Known vs unknown sender, domain analysis
Content Analysis0.2Suspicious URLs, urgency language, display name mismatch
AI Analysis0.2Claude Haiku spam probability scoring

Scoring: Weighted average 0-100

  • >80 = Spam (auto-filtered)
  • 50-80 = Suspicious (flagged, still delivered)
  • <50 = Legitimate (delivered normally)

Email Categories (Phase 2)

CategoryPriorityDescription
urgent100Time-sensitive, requires immediate attention
action_needed80Requires response or action
direct70Personal emails directly addressed to you
contact_form65Website contact form submissions
fyi40Informational only
receipt30Purchase/shipping confirmations
newsletter20Subscribed content, bulk mail

Categorization uses heuristics first (subject patterns, sender analysis), then Claude Haiku for ambiguous cases.

Daily Digest (Phase 2)

Daily summary sent to Telegram at 6 PM CST:

  • Total emails processed
  • Category breakdown
  • VIP emails highlighted
  • Urgent/action items listed
  • Spam blocked count
# Generate and send today's digest
bun ~/.claude/skills/EmailManager/tools/DailyDigest.ts --today --send-telegram

# Preview without sending
bun ~/.claude/skills/EmailManager/tools/DailyDigest.ts --today --dry-run

Cron: 0 0 * * * (midnight UTC = 6 PM CST, adjust for your timezone)

Data Directory

data/
├── oauth-tokens.json          # Encrypted OAuth refresh tokens
├── email-state.json           # Last processed message IDs
├── inbox/YYYY-MM/             # Processed email metadata
├── spam-log/YYYY-MM-DD.jsonl  # Spam filter decisions
└── digests/YYYY-MM-DD.md      # Daily digests (Phase 2)

All data is gitignored. Tokens encrypted with AES-256-GCM.

Environment Variables

Required in ~/.claude/.env:

GMAIL_CLIENT_ID=xxxx.apps.googleusercontent.com
GMAIL_CLIENT_SECRET=GOCSPX-xxxx
GMAIL_REDIRECT_URI=http://localhost:8888/oauth2callback
EMAIL_ENCRYPTION_KEY=<32-byte-hex>
GMAIL_PERSONAL_EMAIL=your@gmail.com
GMAIL_WORKSPACE_EMAIL=your@workspace.com

Telegram Notifications

Legitimate emails trigger Telegram notifications with:

  • Sender name and email
  • Subject line
  • Category (if categorized)
  • 200-char preview
  • Direct Gmail link

Response & Scheduling (Phase 3)

Draft Email Replies

# Draft a reply with intent
bun ~/.claude/skills/EmailManager/tools/ResponseDrafter.ts draft --account personal --message-id <id> --intent "politely decline"

# Draft with specific tone
bun ~/.claude/skills/EmailManager/tools/ResponseDrafter.ts draft --account personal --message-id <id> --tone friendly

# Send a drafted reply (requires user approval)
bun ~/.claude/skills/EmailManager/tools/ResponseDrafter.ts send --account personal --message-id <id> --draft "Your draft text..."

# Get quick reply suggestions
bun ~/.claude/skills/EmailManager/tools/ResponseDrafter.ts quick --account personal --message-id <id>

Calendar Management

# List upcoming events
bun ~/.claude/skills/EmailManager/tools/CalendarClient.ts list --account personal --days 7

# Find available slots
bun ~/.claude/skills/EmailManager/tools/CalendarClient.ts available --account personal --start "2026-02-10" --end "2026-02-14" --duration 30

# Create a meeting
bun ~/.claude/skills/EmailManager/tools/CalendarClient.ts create --account personal --title "Meeting" --start "2026-02-10T10:00:00" --duration 60

# Check free/busy
bun ~/.claude/skills/EmailManager/tools/CalendarClient.ts freebusy --account personal --start "2026-02-10T09:00:00" --end "2026-02-10T17:00:00"

Meeting Scheduling

# Parse meeting request from email
bun ~/.claude/skills/EmailManager/tools/MeetingScheduler.ts parse --account personal --message-id <id>

# Full workflow: parse, find slots, prepare response
bun ~/.claude/skills/EmailManager/tools/MeetingScheduler.ts process --account personal --message-id <id>

# Schedule from a slot
bun ~/.claude/skills/EmailManager/tools/MeetingScheduler.ts schedule --account personal --message-id <id> --slot 0 --send-invite

OAuth Scope Upgrade (Required for Phase 3)

Phase 3 requires additional scopes. Re-run OAuth setup for each account:

bun ~/.claude/skills/EmailManager/tools/OAuth2Setup.ts --account personal
bun ~/.claude/skills/EmailManager/tools/OAuth2Setup.ts --account workspace

New scopes added:

  • gmail.modify - Modify message labels
  • gmail.send - Send emails
  • calendar.readonly - Read calendar events
  • calendar.events - Create/modify calendar events

Phases

PhaseStatusFeatures
1. FoundationCompleteOAuth, Gmail API, SpamFilter, Monitor, Telegram buttons
2. Smart InboxCompleteEmailCategorizer, DailyDigest, priority scoring
3. RespondCompleteResponseDrafter, CalendarClient, MeetingScheduler
4. Priority GateCompleteDecision scoring, 3-tier system, reduced Telegram noise

Workflows

WorkflowFilePurpose
Monitorworkflows/Monitor.mdEmail monitoring workflow
Respondworkflows/Respond.mdResponse drafting workflow
Scheduleworkflows/Schedule.mdMeeting scheduling workflow

Tools

ToolPurpose
OAuth2Setup.tsOne-time OAuth browser flow (Phase 3 scopes)
GmailClient.tsGmail API wrapper (list, get, send, labels)
SpamFilter.ts4-layer spam detection
EmailCategorizer.tsSmart categorization (urgent, action_needed, fyi, etc.)
EmailMonitor.tsPolling daemon with spam + category + priority gate
DailyDigest.tsEnd-of-day summary with Tier 2 emails to Telegram
EmailConfig.tsTune thresholds and lists
PriorityGate.tsDecision scoring, tier determination for high-volume inboxes
ResponseDrafter.tsDraft replies with Claude Sonnet
CalendarClient.tsGoogle Calendar API (events, freebusy, available)
MeetingScheduler.tsParse meeting requests, suggest times, schedule
manage.shService start/stop/restart

Service Deployment

Runs as systemd service (example for Linux host):

# Install service
sudo cp ~/.claude/skills/EmailManager/linux-service/emailmanager.service /etc/systemd/system/
sudo systemctl daemon-reload
sudo systemctl enable emailmanager
sudo systemctl start emailmanager

Security

  • OAuth tokens encrypted with AES-256-GCM
  • Email bodies never logged (200 char preview max)
  • data/ directory gitignored
  • Response drafts require user approval before sending
  • File permissions: chmod 600 data/oauth-tokens.json

OAuth Scopes by Phase

PhaseScopes
1-2gmail.readonly, userinfo.email
3+ gmail.modify, gmail.send, calendar.readonly, calendar.events

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

Reviews can't be read right now.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.