This Python module provides a convenient tool for creating a bunch of handy Gmail Filters. Run.py is the main Operation Center, which is the only file you need to run.
NOTE: You must complete your GMail API OAuth2 Setup (To obtain your credentials.json file, which must be moved to your cloned directory)
A useful guide for that can be found here
The project consists of several Python scripts designed to automate specific tasks related to managing email data. Each script serves a distinct purpose:
- email_fix.py: Reads the metadata of your top n chunk of emails [default: 40,000],and indexes all unique email addresses. [This operation takes a considerable amount of time.]
- tag_all_emails.py: Allows you to manually tag each unique email address for proper categorization [and sub-categorization].
- generate_filter_xmls.py: Generates an XML file that can be imported in Gmail to apply filters based on the criteria that you set.
Option 1: Follow this guide until the end of step 3
Option 2: TBA
- Click the Settings Icon on the top-right of the screen
- Select "See all Settings"
- Select "Filters and blocked Addresses"
- Then, at the bottom of the page, Select All, and Export.
-
Clone the Repository: Clone this repository to your local machine using:
git clone https://github.com/danyshs/Gmail_Sorting.git
-
Navigate to the Directory: Enter the directory where the scripts are located:
cd Gmail_Sorting
-
Run the Script: Execute the main script
run.py
. This script guides you through the process of selecting and running the desired automation script:python run.py
Follow the prompts to choose which task you want to execute.
- Upon running
run.py
, you will see a list of available scripts along with their descriptions. - Enter the number corresponding to the script you wish to run.
-
email_fix.py: Reads the metadata of your top n chunk of emails, lists unique email addresses sorted alphabetically and by frequency, stores it in a text file) [Takes a long while]
-
tag_all_emails.py: Allows you to manually tag each unique email address for proper categorization [and sub-categorization]. Requires the output file of #1
-
generate_filter_xmls.py: Generates an XML file that can be imported in Gmail to apply filters based on the criteria that you set. Requires the output file of #2
These have been separated into 3 separate files for the user's ease.
-
#1 takes a while and can be set to run at a time one isn't using the machine
-
#2 can be done in small bursts to fully categorize emails within categories you have, and you can keep creating new categories as you go
-
#3 is instant, and adds to your existing
mailFilters.xml
file
- Python 3.x
- Google OAuth2 Setup (To obtain both a credentials.json file, which must be moved to your cloned directory)
Contributions are welcome! If you find any issues or have suggestions for improvements, please feel free to open an issue or a pull request.
This project is (to be) licensed under the MIT License (when possible). Feel free to use it as you see fit.
- This script runner was developed to ease the automation of emails into folders within Gmail.
- Inspired by the need for efficient handling of large datasets in email processing workflows.