# Gmail Invoice Extractor This application automatically scans Gmail for emails containing PDF attachments, checks if they contain your company's VAT number, and saves them to a designated folder. ## Features - 🔍 Scans Gmail for emails with PDF attachments - 📄 Extracts text from PDF files using OCR - 💾 Automatically saves valid invoices to a local folder - 📝 Comprehensive logging - 🐳 Docker support ## Setup ### 1. Gmail API Setup 1. Go to the [Google Cloud Console](https://console.cloud.google.com/) 2. Create a new project or select an existing one 3. Enable the Gmail API 4. Create credentials (OAuth 2.0 Client ID) 5. Download the credentials file and save it as `credentials.json` in this directory ### 2. Configuration 1. Update the VAT number patterns in `config.yaml` to match your company's VAT numbers 2. Modify the Gmail search query if needed (default: emails with PDF attachments) ### 3. Running the Application #### Option A: Direct Python execution ```bash pip install -r requirements.txt python main.py ``` #### Option B: Using Docker ```bash docker build -t gmail-invoice-extractor . docker run -v $(pwd)/invoices:/app/invoices -v $(pwd)/credentials.json:/app/credentials.json gmail-invoice-extractor ``` ## First Run On the first run, the application will: 1. Open a browser window for Gmail authentication 2. Ask you to authorize the application 3. Save the authentication token for future runs ## Configuration Edit `config.yaml` to customize: - VAT number patterns for your company - Gmail search query - Maximum messages to process - Save folder location - Logging level ## Logs The application creates detailed logs in `invoice_extractor.log` and displays them in the console. ## Security Notes - Keep your `credentials.json` and `token.json` files secure - Never commit these files to version control - The application only requests read-only access to Gmail ## Troubleshooting - **Authentication issues**: Delete `token.json` and run again to re-authenticate - **No PDFs found**: Check your Gmail search query in `config.yaml` - **VAT numbers not detected**: Verify your VAT number patterns in `config.yaml`