mailsort 0.0.1__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,218 @@
1
+ # Byte-compiled / optimized / DLL files
2
+ __pycache__/
3
+ *.py[codz]
4
+ *$py.class
5
+
6
+ # C extensions
7
+ *.so
8
+
9
+ # Distribution / packaging
10
+ .Python
11
+ build/
12
+ develop-eggs/
13
+ dist/
14
+ downloads/
15
+ eggs/
16
+ .eggs/
17
+ lib/
18
+ lib64/
19
+ parts/
20
+ sdist/
21
+ var/
22
+ wheels/
23
+ share/python-wheels/
24
+ *.egg-info/
25
+ .installed.cfg
26
+ *.egg
27
+ MANIFEST
28
+
29
+ # PyInstaller
30
+ # Usually these files are written by a python script from a template
31
+ # before PyInstaller builds the exe, so as to inject date/other infos into it.
32
+ *.manifest
33
+ *.spec
34
+
35
+ # Installer logs
36
+ pip-log.txt
37
+ pip-delete-this-directory.txt
38
+
39
+ # Unit test / coverage reports
40
+ htmlcov/
41
+ .tox/
42
+ .nox/
43
+ .coverage
44
+ .coverage.*
45
+ .cache
46
+ nosetests.xml
47
+ coverage.xml
48
+ *.cover
49
+ *.py.cover
50
+ .hypothesis/
51
+ .pytest_cache/
52
+ cover/
53
+
54
+ # Translations
55
+ *.mo
56
+ *.pot
57
+
58
+ # Django stuff:
59
+ *.log
60
+ local_settings.py
61
+ db.sqlite3
62
+ db.sqlite3-journal
63
+
64
+ # Flask stuff:
65
+ instance/
66
+ .webassets-cache
67
+
68
+ # Scrapy stuff:
69
+ .scrapy
70
+
71
+ # Sphinx documentation
72
+ docs/_build/
73
+
74
+ # PyBuilder
75
+ .pybuilder/
76
+ target/
77
+
78
+ # Jupyter Notebook
79
+ .ipynb_checkpoints
80
+
81
+ # IPython
82
+ profile_default/
83
+ ipython_config.py
84
+
85
+ # pyenv
86
+ # For a library or package, you might want to ignore these files since the code is
87
+ # intended to run in multiple environments; otherwise, check them in:
88
+ # .python-version
89
+
90
+ # pipenv
91
+ # According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
92
+ # However, in case of collaboration, if having platform-specific dependencies or dependencies
93
+ # having no cross-platform support, pipenv may install dependencies that don't work, or not
94
+ # install all needed dependencies.
95
+ # Pipfile.lock
96
+
97
+ # UV
98
+ # Similar to Pipfile.lock, it is generally recommended to include uv.lock in version control.
99
+ # This is especially recommended for binary packages to ensure reproducibility, and is more
100
+ # commonly ignored for libraries.
101
+ # uv.lock
102
+
103
+ # poetry
104
+ # Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
105
+ # This is especially recommended for binary packages to ensure reproducibility, and is more
106
+ # commonly ignored for libraries.
107
+ # https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
108
+ # poetry.lock
109
+ # poetry.toml
110
+
111
+ # pdm
112
+ # Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
113
+ # pdm recommends including project-wide configuration in pdm.toml, but excluding .pdm-python.
114
+ # https://pdm-project.org/en/latest/usage/project/#working-with-version-control
115
+ # pdm.lock
116
+ # pdm.toml
117
+ .pdm-python
118
+ .pdm-build/
119
+
120
+ # pixi
121
+ # Similar to Pipfile.lock, it is generally recommended to include pixi.lock in version control.
122
+ # pixi.lock
123
+ # Pixi creates a virtual environment in the .pixi directory, just like venv module creates one
124
+ # in the .venv directory. It is recommended not to include this directory in version control.
125
+ .pixi
126
+
127
+ # PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
128
+ __pypackages__/
129
+
130
+ # Celery stuff
131
+ celerybeat-schedule
132
+ celerybeat.pid
133
+
134
+ # Redis
135
+ *.rdb
136
+ *.aof
137
+ *.pid
138
+
139
+ # RabbitMQ
140
+ mnesia/
141
+ rabbitmq/
142
+ rabbitmq-data/
143
+
144
+ # ActiveMQ
145
+ activemq-data/
146
+
147
+ # SageMath parsed files
148
+ *.sage.py
149
+
150
+ # Environments
151
+ .env
152
+ .envrc
153
+ .venv
154
+ env/
155
+ venv/
156
+ ENV/
157
+ env.bak/
158
+ venv.bak/
159
+
160
+ # Spyder project settings
161
+ .spyderproject
162
+ .spyproject
163
+
164
+ # Rope project settings
165
+ .ropeproject
166
+
167
+ # mkdocs documentation
168
+ /site
169
+
170
+ # mypy
171
+ .mypy_cache/
172
+ .dmypy.json
173
+ dmypy.json
174
+
175
+ # Pyre type checker
176
+ .pyre/
177
+
178
+ # pytype static type analyzer
179
+ .pytype/
180
+
181
+ # Cython debug symbols
182
+ cython_debug/
183
+
184
+ # PyCharm
185
+ # JetBrains specific template is maintained in a separate JetBrains.gitignore that can
186
+ # be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
187
+ # and can be added to the global gitignore or merged into this file. For a more nuclear
188
+ # option (not recommended) you can uncomment the following to ignore the entire idea folder.
189
+ # .idea/
190
+
191
+ # Abstra
192
+ # Abstra is an AI-powered process automation framework.
193
+ # Ignore directories containing user credentials, local state, and settings.
194
+ # Learn more at https://abstra.io/docs
195
+ .abstra/
196
+
197
+ # Visual Studio Code
198
+ # Visual Studio Code specific template is maintained in a separate VisualStudioCode.gitignore
199
+ # that can be found at https://github.com/github/gitignore/blob/main/Global/VisualStudioCode.gitignore
200
+ # and can be added to the global gitignore or merged into this file. However, if you prefer,
201
+ # you could uncomment the following to ignore the entire vscode folder
202
+ # .vscode/
203
+ # Temporary file for partial code execution
204
+ tempCodeRunnerFile.py
205
+
206
+ # Ruff stuff:
207
+ .ruff_cache/
208
+
209
+ # PyPI configuration file
210
+ .pypirc
211
+
212
+ # Marimo
213
+ marimo/_static/
214
+ marimo/_lsp/
215
+ __marimo__/
216
+
217
+ # Streamlit
218
+ .streamlit/secrets.toml
mailsort-0.0.1/LICENSE ADDED
@@ -0,0 +1,29 @@
1
+ BSD 3-Clause License
2
+
3
+ Copyright (c) 2022, Jan Janssen
4
+ All rights reserved.
5
+
6
+ Redistribution and use in source and binary forms, with or without
7
+ modification, are permitted provided that the following conditions are met:
8
+
9
+ * Redistributions of source code must retain the above copyright notice, this
10
+ list of conditions and the following disclaimer.
11
+
12
+ * Redistributions in binary form must reproduce the above copyright notice,
13
+ this list of conditions and the following disclaimer in the documentation
14
+ and/or other materials provided with the distribution.
15
+
16
+ * Neither the name of the copyright holder nor the names of its
17
+ contributors may be used to endorse or promote products derived from
18
+ this software without specific prior written permission.
19
+
20
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
23
+ DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
24
+ FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25
+ DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
26
+ SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
27
+ CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
28
+ OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29
+ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
@@ -0,0 +1,66 @@
1
+ Metadata-Version: 2.5
2
+ Name: mailsort
3
+ Version: 0.0.1
4
+ Summary: Assign labels to emails on any IMAP mail server based on their similarity to other emails assigned to the same label.
5
+ Project-URL: Homepage, https://github.com/jan-janssen/mailsort
6
+ Author-email: Jan Janssen <jan.janssen@outlook.com>
7
+ License-Expression: BSD-3-Clause
8
+ License-File: LICENSE
9
+ Classifier: Development Status :: 4 - Beta
10
+ Classifier: Intended Audience :: Science/Research
11
+ Classifier: License :: OSI Approved :: BSD License
12
+ Classifier: Operating System :: OS Independent
13
+ Classifier: Programming Language :: Python :: 3.11
14
+ Classifier: Programming Language :: Python :: 3.12
15
+ Classifier: Programming Language :: Python :: 3.13
16
+ Classifier: Programming Language :: Python :: 3.14
17
+ Requires-Python: >=3.10
18
+ Requires-Dist: numpy>=2.5.1
19
+ Requires-Dist: pandas>=3.0.5
20
+ Requires-Dist: scikit-learn>=1.9.0
21
+ Requires-Dist: sqlalchemy>=2.0.52
22
+ Requires-Dist: tqdm>=4.70.1
23
+ Description-Content-Type: text/markdown
24
+
25
+ # mailsort
26
+ [![Python package](https://github.com/jan-janssen/mailsort/actions/workflows/unittest.yml/badge.svg?branch=main)](https://github.com/jan-janssen/mailsort/actions/workflows/unittest.yml)
27
+ [![codecov](https://codecov.io/github/jan-janssen/mailsort/graph/badge.svg)](https://codecov.io/github/jan-janssen/mailsort)
28
+ [![Code style: black](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/psf/black)
29
+
30
+ Assign labels to emails on any IMAP mail server based on their similarity to other emails already
31
+ assigned to the same label.
32
+
33
+ `mailsort` connects to a mail account over plain IMAP, trains a machine learning model on the labels
34
+ (IMAP folders) you have already assigned, and uses that model to suggest or apply labels to new
35
+ messages. It has no dependency on Google APIs - for Gmail-specific features (OAuth, the Gmail label
36
+ API, the sorting daemon and web UI) see [gmailsorter](https://github.com/jan-janssen/gmailsorter),
37
+ which depends on `mailsort` for the shared IMAP and machine learning core.
38
+
39
+ ## Installation
40
+ ```
41
+ pip install mailsort
42
+ ```
43
+
44
+ ## Command line interface
45
+ ```
46
+ mailsort --host imap.example.com --username user@example.com -u
47
+ mailsort --host imap.example.com --username user@example.com -l "some_label"
48
+ ```
49
+ The IMAP password is read from the `IMAP_PASSWORD` environment variable (configurable with
50
+ `--password-env`).
51
+
52
+ ## Python interface
53
+ ```python
54
+ from mailsort import Imap
55
+
56
+ imap = Imap(
57
+ host="imap.example.com",
58
+ port=993,
59
+ username="user@example.com",
60
+ password="...",
61
+ connection_str="sqlite:///email.db",
62
+ )
63
+ imap.update_database(quick=False)
64
+ imap.fit_machine_learning_model_to_database()
65
+ imap.filter_messages_from_server(label="some_label", recommendation_ratio=0.9)
66
+ ```
@@ -0,0 +1,42 @@
1
+ # mailsort
2
+ [![Python package](https://github.com/jan-janssen/mailsort/actions/workflows/unittest.yml/badge.svg?branch=main)](https://github.com/jan-janssen/mailsort/actions/workflows/unittest.yml)
3
+ [![codecov](https://codecov.io/github/jan-janssen/mailsort/graph/badge.svg)](https://codecov.io/github/jan-janssen/mailsort)
4
+ [![Code style: black](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/psf/black)
5
+
6
+ Assign labels to emails on any IMAP mail server based on their similarity to other emails already
7
+ assigned to the same label.
8
+
9
+ `mailsort` connects to a mail account over plain IMAP, trains a machine learning model on the labels
10
+ (IMAP folders) you have already assigned, and uses that model to suggest or apply labels to new
11
+ messages. It has no dependency on Google APIs - for Gmail-specific features (OAuth, the Gmail label
12
+ API, the sorting daemon and web UI) see [gmailsorter](https://github.com/jan-janssen/gmailsorter),
13
+ which depends on `mailsort` for the shared IMAP and machine learning core.
14
+
15
+ ## Installation
16
+ ```
17
+ pip install mailsort
18
+ ```
19
+
20
+ ## Command line interface
21
+ ```
22
+ mailsort --host imap.example.com --username user@example.com -u
23
+ mailsort --host imap.example.com --username user@example.com -l "some_label"
24
+ ```
25
+ The IMAP password is read from the `IMAP_PASSWORD` environment variable (configurable with
26
+ `--password-env`).
27
+
28
+ ## Python interface
29
+ ```python
30
+ from mailsort import Imap
31
+
32
+ imap = Imap(
33
+ host="imap.example.com",
34
+ port=993,
35
+ username="user@example.com",
36
+ password="...",
37
+ connection_str="sqlite:///email.db",
38
+ )
39
+ imap.update_database(quick=False)
40
+ imap.fit_machine_learning_model_to_database()
41
+ imap.filter_messages_from_server(label="some_label", recommendation_ratio=0.9)
42
+ ```
@@ -0,0 +1,94 @@
1
+ [build-system]
2
+ requires = ["hatchling", "hatch-vcs"]
3
+ build-backend = "hatchling.build"
4
+
5
+ [project]
6
+ name = "mailsort"
7
+ dynamic = ["version"]
8
+ description = "Assign labels to emails on any IMAP mail server based on their similarity to other emails assigned to the same label."
9
+ readme = "README.md"
10
+ license = "BSD-3-Clause"
11
+ authors = [
12
+ { name = "Jan Janssen", email = "jan.janssen@outlook.com" },
13
+ ]
14
+ requires-python = ">=3.10"
15
+ classifiers = [
16
+ "Development Status :: 4 - Beta",
17
+ "Intended Audience :: Science/Research",
18
+ "License :: OSI Approved :: BSD License",
19
+ "Operating System :: OS Independent",
20
+ "Programming Language :: Python :: 3.11",
21
+ "Programming Language :: Python :: 3.12",
22
+ "Programming Language :: Python :: 3.13",
23
+ "Programming Language :: Python :: 3.14",
24
+ ]
25
+ dependencies = [
26
+ "numpy>=2.5.1",
27
+ "tqdm>=4.70.1",
28
+ "pandas>=3.0.5",
29
+ "scikit-learn>=1.9.0",
30
+ "sqlalchemy>=2.0.52",
31
+ ]
32
+
33
+ [project.urls]
34
+ Homepage = "https://github.com/jan-janssen/mailsort"
35
+
36
+ [project.scripts]
37
+ mailsort = "mailsort.__main__:command_line_parser"
38
+
39
+ [tool.ruff.lint]
40
+ select = [
41
+ # pycodestyle
42
+ "E",
43
+ # Pyflakes
44
+ "F",
45
+ # pyupgrade
46
+ "UP",
47
+ # flake8-bugbear
48
+ "B",
49
+ # flake8-simplify
50
+ "SIM",
51
+ # isort
52
+ "I",
53
+ # flake8-comprehensions
54
+ "C4",
55
+ # eradicate
56
+ "ERA",
57
+ # pylint
58
+ "PL",
59
+ ]
60
+ ignore = [
61
+ # ignore line-length violations
62
+ "E501",
63
+ # Too many arguments in function definition
64
+ "PLR0913",
65
+ # Too many not-keyword-only arguments,
66
+ "PLR0917",
67
+ ]
68
+
69
+ [tool.hatch.build]
70
+ include = [
71
+ "src/mailsort"
72
+ ]
73
+
74
+ [tool.hatch.build.hooks.vcs]
75
+ version-file = "src/mailsort/_version.py"
76
+
77
+ [tool.hatch.build.targets.sdist]
78
+ include = [
79
+ "src/mailsort",
80
+ "LICENSE"
81
+ ]
82
+
83
+ [tool.hatch.build.targets.wheel]
84
+ packages = [
85
+ "src/mailsort"
86
+ ]
87
+
88
+ [tool.hatch.version]
89
+ source = "vcs"
90
+ path = "src/mailsort/_version.py"
91
+
92
+ [tool.coverage.run]
93
+ source = ["mailsort"]
94
+ command_line = "-m unittest discover tests"
@@ -0,0 +1,6 @@
1
+ from mailsort.local import Imap
2
+
3
+ from . import _version
4
+
5
+ __version__: str = _version.__version__
6
+ __all__ = ["Imap"]
@@ -0,0 +1,99 @@
1
+ import argparse
2
+ import os
3
+
4
+ from mailsort import Imap
5
+
6
+
7
+ def command_line_parser():
8
+ """
9
+ Main function primarily used for the command line interface of the IMAP backend
10
+ """
11
+ parser = argparse.ArgumentParser(prog="mailsort")
12
+ parser.add_argument(
13
+ "--host",
14
+ help="IMAP server hostname e.g. imap.example.com .",
15
+ )
16
+ parser.add_argument(
17
+ "--port",
18
+ type=int,
19
+ default=993,
20
+ help="IMAP server port - default: 993 .",
21
+ )
22
+ parser.add_argument(
23
+ "--username",
24
+ help="IMAP account username.",
25
+ )
26
+ parser.add_argument(
27
+ "--password-env",
28
+ default="IMAP_PASSWORD",
29
+ help=(
30
+ "Name of the environment variable holding the IMAP account password - "
31
+ "default: IMAP_PASSWORD ."
32
+ ),
33
+ )
34
+ parser.add_argument(
35
+ "--no-ssl",
36
+ action="store_true",
37
+ help="Connect without SSL (IMAP4 instead of IMAP4_SSL).",
38
+ )
39
+ parser.add_argument(
40
+ "-d",
41
+ "--database",
42
+ help="Connection string to connect to database e.g. sqlite:///email.db .",
43
+ )
44
+ parser.add_argument(
45
+ "-u",
46
+ "--update",
47
+ action="store_true",
48
+ help="Update local database and retrain machine learning model.",
49
+ )
50
+ parser.add_argument(
51
+ "-i",
52
+ "--identification",
53
+ help="User ID of the database user e.g. 1 .",
54
+ )
55
+ parser.add_argument(
56
+ "-l",
57
+ "--label",
58
+ help="Email label (IMAP folder) to be filtered with machine learning.",
59
+ )
60
+ args = parser.parse_args()
61
+ db_user_id = int(args.identification) if args.identification else 1
62
+ password = os.environ.get(args.password_env)
63
+ if not args.host or not args.username:
64
+ print("Please provide --host and --username.")
65
+ elif not password:
66
+ print(
67
+ f"Please set the {args.password_env} environment variable to your IMAP password."
68
+ )
69
+ else:
70
+ database = args.database or "sqlite:///email.db"
71
+ imap = Imap(
72
+ host=args.host,
73
+ port=args.port,
74
+ username=args.username,
75
+ password=password,
76
+ connection_str=database,
77
+ db_user_id=db_user_id,
78
+ use_ssl=not args.no_ssl,
79
+ email_download_format="metadata",
80
+ )
81
+ if args.update:
82
+ imap.update_database(quick=False)
83
+ imap.fit_machine_learning_model_to_database(
84
+ n_estimators=100,
85
+ max_features=400,
86
+ random_state=42,
87
+ bootstrap=True,
88
+ include_deleted=False,
89
+ )
90
+ elif args.label:
91
+ imap.filter_messages_from_server(
92
+ label=args.label, recommendation_ratio=0.9, label_prefix="labels_"
93
+ )
94
+ else:
95
+ parser.print_help()
96
+
97
+
98
+ if __name__ == "__main__":
99
+ command_line_parser()
@@ -0,0 +1,24 @@
1
+ # file generated by vcs-versioning
2
+ # don't change, don't track in version control
3
+ from __future__ import annotations
4
+
5
+ __all__ = [
6
+ "__version__",
7
+ "__version_tuple__",
8
+ "version",
9
+ "version_tuple",
10
+ "__commit_id__",
11
+ "commit_id",
12
+ ]
13
+
14
+ version: str
15
+ __version__: str
16
+ __version_tuple__: tuple[int | str, ...]
17
+ version_tuple: tuple[int | str, ...]
18
+ commit_id: str | None
19
+ __commit_id__: str | None
20
+
21
+ __version__ = version = '0.0.1'
22
+ __version_tuple__ = version_tuple = (0, 0, 1)
23
+
24
+ __commit_id__ = commit_id = None
@@ -0,0 +1,3 @@
1
+ from mailsort.base.database import get_email_database
2
+
3
+ __all__ = ["get_email_database"]