Git Product home page Git Product logo

pyle-of-mail's Introduction

GitHub Available on docker Docker Pulls GitHub top language

pyle-of-mail

A Python script that sorts all read emails from your mailbox.

How it works

With the information provided in the config.py file, this script will connect to your IMAP server of choice, and then start filtering the mailboxes you tell it to.

How does it log in to the imap server?

In the config file, there are 3 variables of interest:

  • imap_server: the address of the imap server.
    For example, if you're using gmail, it will be imap.gmail.com.
    Personally, my main email address is a Yahoo address, so for that, it would be imap.mail.yahoo.com
  • username: the email address for the given IMAP server
  • password: the password, or access token used to authenticate
    For gmail, you need to enable insecure app access.
    For Yahoo, you can generate a dedicated access token for this app.

How does it filter my emails?

Glad you asked!
So here's the basic logic behind. The script firstly gets a list of all UNREAD emails from the given mailbox, and then iterates through it.
In the config file, there is a dictionary, filters that basically explains what should happen. The structure of the dictionary is: { 'keyword': 'destination/mailbox' }. The keyword is NOT case sensitive, and it will look for it in the sender address.
For example, the following rules should handle all emails from amazon, regardless if they come from [email protected] or [email protected] or whatever else. As long as it has amazon in the address somewhere, it will get filtered.

filters = {
    'amazon'; 'Shopping/Amazon'
}

For each email in the list, it checks it against all filters from the config file, until it finds a match or it runs out of options.

As such, your inbox will eventually just be a place for unread emails, that require your attention. After they have been read, they will automatically get placed into the appropriate directory.

How often does it filter my emails?

As often as you want!
In the config file, there is the sleep_time variable, along with some sample values, if you want the script to run multiple times a day, daily or even weekly.

How does it know which mailboxes to filter?

Again, the config file holds all the secrets. There is an array, called mailboxes. You simply populate it with the names of all mailboxes you want filtered, and it will go ham at them, one at a time.

What if it moved an email that it shouldn't have, or I can't find something?

Log files are here to save us!
Every email that gets moved around, is also logged. The script logs to a file, at the path given in the config (logfile=/var/log/pyle-of-mail.log by default) and to stdout.
Anything that moves or breathes, gets logged, so you should be able to find anything.

How to deploy

You can either clone the source code and run it manually whenever you feel like it, but I think the true power of this comes when you deploy it in a Docker Container and allow it to run periodically.

You can find a sample docker-compose.yml file in this repo that uses the image pushed to DockerHub. If you so desire, you can also build your own docker image with the provided Dockerfile and run that one.

Feedback, suggestions and help

For feedback, suggestions, bug reports etc., feel free to e-mail me at '[email protected]'.


a project by Mircea-Pavel Anton (Mike Anthony)

pyle-of-mail's People

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.