8000 GitHub - Pkfication/gmail-processor
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Pkfication/gmail-processor

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Gmail Rule-Based Email Processor

This project implements a rule-based email processing system that integrates with Gmail API to automate email management tasks.

Features

  • Gmail API integration using OAuth2 authentication
  • Email storage in SQLite database (stored locally in gmail_processor.db)
  • Rule-based email processing with configurable conditions and actions
  • Support for various email fields (From, Subject, Message, Received Date)
  • Multiple predicate types for different field types
  • Actions: Mark as read/unread, Move message

Prerequisites

  • Python 3.8+
  • Google Cloud Project with Gmail API enabled
  • OAuth 2.0 credentials

Setup

  1. Clone the repository:
git clone git@github.com:Pkfication/gmail-processor.git
cd gmail-rule-processor
  1. Create and activate virtual environment:
python -m venv venv
source venv/bin/activate  # On Windows: venv\Scripts\activate
  1. Install dependencies and the package in development mode:
pip install -r requirements.txt
  1. Set up Google Cloud Project:

    • Go to Google Cloud Console
    • Create a new project
    • Enable Gmail API
    • Create OAuth 2.0 credentials
    • Download credentials and save as credentials.json in the project root directory
  2. Set up environment variables: Create a .env file in the project root with the following variables:

GOOGLE_CREDENTIALS_FILE=credentials.json
  1. Initialize the database:
python -m scripts.init_db

Usage

  1. First-time authentication:
python -m scripts.auth
  1. Fetch emails:
python -m scripts.fetch_emails
  1. Process emails with rules:
python -m scripts.process_emails

Rule Configuration

Rules are defined in config/rules.json. Example:

{
  "rules": [
    {
      "name": "Newsletter Processing",
      "predicate": "all",
      "conditions": [
        {
          "field": "subject",
          "predicate": "contains",
          "value": "newsletter"
        },
        {
          "field": "from",
          "predicate": "contains",
          "value": "example.com"
        }
      ],
      "actions": [
        {
          "type": "mark_as_read"
        },
        {
          "type": "move_to",
          "value": "Newsletters"
        }
      ]
    }
  ]
}

Testing

Run tests using pytest:

python -m pytest tests/ -v

Project Structure

gmail-rule-processor/
├── config/
│   └── rules.json
├── scripts/
│   ├── auth.py
│   ├── fetch_emails.py
│   ├── init_db.py
│   └── process_emails.py
├── src/
│   ├── __init__.py
│   ├── database/
│   │   ├── __init__.py
│   │   ├── models.py
│   │   └── session.py
│   ├── gmail/
│   │   ├── __init__.py
│   │   ├── auth.py
│   │   └── client.py
│   └── rules/
│       ├── __init__.py
│       ├── engine.py
│       └── parser.py
├── tests/
│   ├── test_database.py
│   ├── test_gmail.py
│   └── test_rules.py
├── credentials.json    # Place your Google OAuth credentials here
├── gmail_processor.db
├── .env
├── requirements.txt
└── README.md

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

0