|
| 1 | +# Gmail Inbox Monitor |
| 2 | + |
| 3 | +A simple Python application that monitors your Gmail inbox for unread emails and displays them in the terminal. The app refreshes every 5 seconds to show new unread emails and can analyze emails for spam using Google's Gemini AI. |
| 4 | + |
| 5 | +## Prerequisites |
| 6 | + |
| 7 | +- Python 3.6+ |
| 8 | +- Gmail account |
| 9 | +- Google Cloud project with Gmail API enabled |
| 10 | +- (Optional) Google Gemini API key for spam detection |
| 11 | + |
| 12 | +## Setup |
| 13 | + |
| 14 | +1. Clone this repository |
| 15 | +2. Install dependencies: |
| 16 | + ``` |
| 17 | + pip install -r requirements.txt |
| 18 | + ``` |
| 19 | +3. Set up Google API credentials: |
| 20 | + - Go to [Google Cloud Console](https://console.cloud.google.com/) |
| 21 | + - Create a new project (or select an existing one) |
| 22 | + - Enable the Gmail API |
| 23 | + - Create OAuth credentials (Desktop application) |
| 24 | + - Download the credentials JSON file and save it as `credentials.json` in the project directory |
| 25 | + |
| 26 | +4. (Optional) Set up Google Gemini for spam detection: |
| 27 | + - Go to [Google AI Studio](https://makersuite.google.com/app/apikey) |
| 28 | + - Create a new API key |
| 29 | + - Run the setup command: |
| 30 | + ``` |
| 31 | + python gmail_monitor.py --setup-gemini |
| 32 | + ``` |
| 33 | + - Follow the prompts to enter your API key |
| 34 | +
|
| 35 | +## Usage |
| 36 | +
|
| 37 | +1. Run the authentication module to set up your credentials: |
| 38 | + ``` |
| 39 | + python auth.py |
| 40 | + ``` |
| 41 | + - This will open a browser window where you need to log in with your Google account and grant permissions |
| 42 | + - After successful authentication, a `token.json` file will be created |
| 43 | +
|
| 44 | +2. Run the main script to monitor your inbox: |
| 45 | + ``` |
| 46 | + python gmail_monitor.py |
| 47 | + ``` |
| 48 | + |
| 49 | +3. Press Ctrl+C to stop the application |
| 50 | +
|
| 51 | +## Spam Detection and Response |
| 52 | +
|
| 53 | +When spam detection is enabled: |
| 54 | +
|
| 55 | +- Each email is analyzed by Google's Gemini AI |
| 56 | +- If an email is identified as legitimate, a standard auto-reply is sent with the spam analysis result |
| 57 | +- If an email is identified as spam, the system generates a clever time-wasting reply |
| 58 | + - The reply is designed to bait spammers by showing interest without revealing any valuable information |
| 59 | + - It asks questions that require lengthy responses and maintains a naive but interested tone |
| 60 | + - This helps waste spammers' time and resources while keeping you safe |
| 61 | +
|
| 62 | +### Conversation Tracking |
| 63 | +
|
| 64 | +The system tracks spam email threads persistently: |
| 65 | +
|
| 66 | +- Once an email is identified as spam, the entire conversation thread is marked for special handling |
| 67 | +- All future replies in that thread will automatically receive AI-generated responses |
| 68 | +- The system uses different prompts for initial spam emails versus follow-up messages |
| 69 | +- Thread information is stored between sessions in `spam_threads.json` |
| 70 | +
|
| 71 | +To set up or reconfigure spam detection: |
| 72 | +``` |
| 73 | +python gmail_monitor.py --setup-gemini |
| 74 | +``` |
| 75 | +
|
| 76 | +## Sign Out / Switch Accounts |
| 77 | +
|
| 78 | +You can sign out (remove saved credentials) in two ways: |
| 79 | +
|
| 80 | +1. Using the main script: |
| 81 | + ``` |
| 82 | + python gmail_monitor.py --signout |
| 83 | + ``` |
| 84 | +
|
| 85 | +2. Using the auth module directly: |
| 86 | + ``` |
| 87 | + python auth.py --signout |
| 88 | + ``` |
| 89 | +
|
| 90 | +After signing out, you'll need to re-authenticate the next time you run the application, allowing you to use a different Google account. |
| 91 | +
|
| 92 | +## Customization |
| 93 | +
|
| 94 | +You can modify the following aspects of the application: |
| 95 | +- Change the refresh interval (default: 5 seconds) |
| 96 | +- Adjust email display format |
| 97 | +- Add filters for specific senders or subjects |
| 98 | +- Modify the spam detection prompt in `gemini_spam_detector.py` |
| 99 | +- Customize the spam-baiting reply generation by editing the prompt in the `generate_email_reply` function |
0 commit comments