email_client

EMAIL ORGANIZER

Features

  1. Download the emails from your gmail inbox.
  2. Filter the emails based on rules you define in rules.json file.
  3. Mark the filtered emails as READ/UNREAD.
  4. Move the messages/emails.
  5. If you are moving email to a label that doesn’t exist. Label will get created first. Then, email will be moved.

Folder Structure Details

Sample Rules JSON

[
    {
        "select": "all",
        "rules": [{
            "field": "subject",
            "value": "Assignment",
            "condition": "contains"
        }],
        "action": {"command": "mark", "value": "unread"}
    }
]

IMPORTANT NOTE

  1. Possible values of key field inside rules list - subject, mail_to, mail_from, email_received_date, body.
  2. Possible values for key condition - contains, does not contains, equal, does not equal when field is string type.
  3. Possible values for key condition when field is email_received_date - equal, does not equal, greater than, less than.

STEPS TO RUN THE PROJECT

Part 1

git clone git@github.com:mridubhatnagar/email_client.git

cd email_client
python3 -m venv ~/emailclient
source ~/emailclient/bin/activate
pip install -r requirements.txt
export ENV=local
python fetch_email.py init
python fetch_email.py 10

Part 2

[
    {
        "select": "all",
        "rules": [{
            "field": "subject",
            "value": "Assignment",
            "condition": "contains"
        }],
        "action": {"command": "mark", "value": "unread"}
    }
]
python process_email.py

STEPS TO RUN TEST CASES

  1. Export the correct enviornment
export ENV=test
  1. Run the below command. Go in the project repository.
pytest tests\<filename> -s