MailTidy enables the cleanup of an IMAP mail account by deleteting the accumulated dross while retaining relevant mails.
Project description
MailTidy
MailTidy enables the cleanup of an IMAP mail account by deleteting the accumulated dross while retaining relevant mails.
Much received mail, which while not spam, ceases to be revelant over time. Best practise is to delete these in a timely manner, but who does? Instead accounts become cluttered with irrelevant emails, many never read, until their volumes become too onerous to tidy manually.
Enter MailTidy, which creates a summary for each unique sender domain or each unique sender and allows an action to be performed against each summary. These actions can be filtered by age. For example, to delete mails received from the domain somewhere.com or the unique sender someone@somewhere.com older than 365 days the DELETE action is specified with an age of 365.
Installation
MailTidy can be installed from the PyPi repository or be built and installed from source.
Installation from the PyPi Repository
Run the command pip install mailtidy. This will install the latest version of MailTidy published to the PyPi repository into your active Python envirornment.
Installation from Source
- Python Poetry is used to build, install and publish MailTidy. If not already installed, follow these instructions - https://python-poetry.org/docs/#installation
- Clone the source code from the Git repository - https://github.com/sbrewin/mailtidy.git
- From the project's root directory execute
poetry installto build and install MailTidy into your active Python envvironemnt.
Configure the IMAP account
The account details are stored in the YAML formatted file connection_data.yml located in the directory $HOME/.mailtidy. The format of the file is:
imap_server: <imap server address>
port: <imap server port>
email: <email address>
password: <imap server password>
For example:
imap_server: imap.provider.com
port: 993
email: myaccount@myproveider.com
password: mysecret
IMPORTANT: Secure the credentials stored within
connection_data.ymlby restricting acesss to the owner.On *nix type systems, execute the command
chmod 600 ~/.mail_tidy/connection_data.yml.On Windows, right-click on the
connection_datafile and select> Properties > Securityto restrict access.
Workflow
The MailTidy workflow consists of the following steps:
-
Create summaries by executing
python3 -m mailtidy summariseThis creates a YAML formatted file containing entries for each sender in the configured IMAP account. By default summaries are created for each unique sender domain. Use the
-uoption to create a summary for each unique sender.By default, summaries are written to the file
summaries.ymlin the current directory. Use the-foption to specify an alternate location.Each summary is created with the default action of NONE and an age of 0. If applied, no changes will occur.
-
It can take some time to summarise accounts with a large number of mails. Once done it is recommended that the produced
summaries.ymlfile is copied to avoid the need to run a summary repeatedly while experimenting with the options. -
Having created a copy of
summaries.ymlfile edit the original to ammend the required Actions and ages. Initially, you may wish to process just a subset of the senders. To do simply leave the summaries for those you do not wish to process alone. -
Apply the Actions by executing
python3 -m mailtidy apply- Dry runs are supported and recommended prior to making destructive changes. Specify
-nor--dry-runon the command line.
- Dry runs are supported and recommended prior to making destructive changes. Specify
Summaries
A MailTidy summary contains:
- The mail address of the sender
- This may be the full email of the sender -
someone@somewhere.com- or the domain name -somewhere.com
- This may be the full email of the sender -
- The number of mails received from the sender
- The UTC first date and time a mail from the sender was received
- The UTC last date and time a mail from the sender was received
Additionally, the summary contains the following fields that describe the action to be applied
- The action to be taken, default =
'none' - The age in days below which the Action is performed, default =
0
MailTidy summaries are serialised in a YAML formatted file using the following format:
- !SenderSummary
action: !Action 'none'
age: 0
count: 68
first_datetime: 2023-03-18 19:03:03+01:00
from_: 'someone@somewhere.com'
last_datetime: 2023-03-18 19:03:03+01:00
The YAML file may use anchors (&) and aliases (*) to abbreviate these definitions. For example, the following defines the NONE action and then references its definition:
- !SenderSummary
action: &id001 !Action 'none'
age: 0
count: 68
first_datetime: 2023-03-18 19:03:03+01:00
from_: 'someone@somewhere.com'
last_datetime: 2023-03-18 19:03:03+01:00
- !SenderSummary
action: *id001
age: 0
count: 1
first_datetime: 2023-03-18 19:03:03+01:00
from_: 'someoneelse@elseswhere.com'
last_datetime: 2023-03-18 19:03:03+01:00
Supported Actions
MailTidy supports the following Actions, each of which is applied to mails from the sender younger than the specified age:
The below lists the supported Python Action enumeration, the action performed and their YAML equivalants...
- Action.NONE
- No processing is applied
!Action 'none'
- Action.DELETE
- Delete the selected mails
!Action 'delete'
- Action.ARCHIVE
- Move the selected mails to the
Archivefolder !Action 'archive'
- Move the selected mails to the
- Action.PRINT_ALL
- Print the entire content of the selected emails to
stdout !Action 'print_all'
- Print the entire content of the selected emails to
- Action.PRINT_HEADERS
- Print the headers of the selected emails to
stdout !Action 'print_headers'
- Print the headers of the selected emails to
Future Features
There are many features that might be added to MailTidy. Amongst these are:
- Filters on the flags described in https://www.rfc-editor.org/rfc/rfc3501.html#section-2.3.2mail, such as
seenandflaggedto include or exclude such mails from the summaries - A whitelist of domains or specific users to be excluded from the summaries
Ideas are welcome. Code contibutions particularly so 😏
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file mailtidy-1.0.2.tar.gz.
File metadata
- Download URL: mailtidy-1.0.2.tar.gz
- Upload date:
- Size: 10.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/2.1.3 CPython/3.13.5 Darwin/24.5.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
be19221cbe8396ade3932da249ad978146e9a795bac88b84ad7e4a9baefc3c33
|
|
| MD5 |
327e9656c632a187d52a851383b2a570
|
|
| BLAKE2b-256 |
469e9cba8706943bd88255f4fe2755f98ea15449a324f4cc8224b7e71ed747b2
|
File details
Details for the file mailtidy-1.0.2-py3-none-any.whl.
File metadata
- Download URL: mailtidy-1.0.2-py3-none-any.whl
- Upload date:
- Size: 12.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/2.1.3 CPython/3.13.5 Darwin/24.5.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9e68af606f65adcf5d622b8c4b1267dbf7af18206e6ba3b4861a9e88e4ecc819
|
|
| MD5 |
9e0a77af71a6ae96a694c6dccb521224
|
|
| BLAKE2b-256 |
c10eae45bdfa3a0e43d874abbd65ca63f09976aeacf3dc10b3f8ed4fd13c69b9
|