From 0cad9c91c3825821f664abbe5167a3b3e801f443 Mon Sep 17 00:00:00 2001 From: Daniel Fichtinger Date: Wed, 4 Jun 2025 12:34:00 -0400 Subject: [PATCH 01/15] packaged for pypi --- .gitignore | 177 ++++++++++++++++++++++++++++++++++++++++++ .python-version | 1 + install.sh | 5 -- mailfmt => mailfmt.py | 123 +++++++++++++++-------------- pyproject.toml | 17 ++++ uninstall.sh | 4 - uv.lock | 8 ++ 7 files changed, 264 insertions(+), 71 deletions(-) create mode 100644 .gitignore create mode 100644 .python-version delete mode 100755 install.sh rename mailfmt => mailfmt.py (71%) create mode 100644 pyproject.toml delete mode 100755 uninstall.sh create mode 100644 uv.lock diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..729a846 --- /dev/null +++ b/.gitignore @@ -0,0 +1,177 @@ +typings/ + +# Byte-compiled / optimized / DLL files +__pycache__/ +*.py[cod] +*$py.class + +# C extensions +*.so + +# Distribution / packaging +.Python +build/ +develop-eggs/ +dist/ +downloads/ +eggs/ +.eggs/ +lib/ +lib64/ +parts/ +sdist/ +var/ +wheels/ +share/python-wheels/ +*.egg-info/ +.installed.cfg +*.egg +MANIFEST + +# PyInstaller +# Usually these files are written by a python script from a template +# before PyInstaller builds the exe, so as to inject date/other infos into it. +*.manifest +*.spec + +# Installer logs +pip-log.txt +pip-delete-this-directory.txt + +# Unit test / coverage reports +htmlcov/ +.tox/ +.nox/ +.coverage +.coverage.* +.cache +nosetests.xml +coverage.xml +*.cover +*.py,cover +.hypothesis/ +.pytest_cache/ +cover/ + +# Translations +*.mo +*.pot + +# Django stuff: +*.log +local_settings.py +db.sqlite3 +db.sqlite3-journal + +# Flask stuff: +instance/ +.webassets-cache + +# Scrapy stuff: +.scrapy + +# Sphinx documentation +docs/_build/ + +# PyBuilder +.pybuilder/ +target/ + +# Jupyter Notebook +.ipynb_checkpoints + +# IPython +profile_default/ +ipython_config.py + +# pyenv +# For a library or package, you might want to ignore these files since the code is +# intended to run in multiple environments; otherwise, check them in: +# .python-version + +# pipenv +# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control. +# However, in case of collaboration, if having platform-specific dependencies or dependencies +# having no cross-platform support, pipenv may install dependencies that don't work, or not +# install all needed dependencies. +#Pipfile.lock + +# UV +# Similar to Pipfile.lock, it is generally recommended to include uv.lock in version control. +# This is especially recommended for binary packages to ensure reproducibility, and is more +# commonly ignored for libraries. +#uv.lock + +# poetry +# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control. +# This is especially recommended for binary packages to ensure reproducibility, and is more +# commonly ignored for libraries. +# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control +#poetry.lock + +# pdm +# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control. +#pdm.lock +# pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it +# in version control. +# https://pdm.fming.dev/latest/usage/project/#working-with-version-control +.pdm.toml +.pdm-python +.pdm-build/ + +# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm +__pypackages__/ + +# Celery stuff +celerybeat-schedule +celerybeat.pid + +# SageMath parsed files +*.sage.py + +# Environments +.env +.venv +env/ +venv/ +ENV/ +env.bak/ +venv.bak/ + +# Spyder project settings +.spyderproject +.spyproject + +# Rope project settings +.ropeproject + +# mkdocs documentation +/site + +# mypy +.mypy_cache/ +.dmypy.json +dmypy.json + +# Pyre type checker +.pyre/ + +# pytype static type analyzer +.pytype/ + +# Cython debug symbols +cython_debug/ + +# PyCharm +# JetBrains specific template is maintained in a separate JetBrains.gitignore that can +# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore +# and can be added to the global gitignore or merged into this file. For a more nuclear +# option (not recommended) you can uncomment the following to ignore the entire idea folder. +#.idea/ + +# Ruff stuff: +.ruff_cache/ + +# PyPI configuration file +.pypirc + diff --git a/.python-version b/.python-version new file mode 100644 index 0000000..2c07333 --- /dev/null +++ b/.python-version @@ -0,0 +1 @@ +3.11 diff --git a/install.sh b/install.sh deleted file mode 100755 index f72f4c4..0000000 --- a/install.sh +++ /dev/null @@ -1,5 +0,0 @@ -#!/bin/sh - -SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)" -sudo cp "$SCRIPT_DIR/mailfmt" /usr/bin/mailfmt -echo "mailfmt has been installed to /usr/bin/mailfmt." diff --git a/mailfmt b/mailfmt.py similarity index 71% rename from mailfmt rename to mailfmt.py index a12e4c7..e8d1f7a 100755 --- a/mailfmt +++ b/mailfmt.py @@ -16,78 +16,73 @@ import sys import re import argparse -paragraph: list[str] = [] -skipping = False -squash = True -prev_is_parbreak = False -out_stream = sys.stdout -reflow = True -width = 74 -break_long_words = False -replace_whitespace = True -markdown_safe = False -in_signoff = False -in_signature = False +def main() -> None: + paragraph: list[str] = [] + skipping = False + squash = True + prev_is_parbreak = False + out_stream = sys.stdout + reflow = True + width = 74 + break_long_words = False + replace_whitespace = True + markdown_safe = False + in_signoff = False + in_signature = False -def pprint(string: str): - if markdown_safe and (in_signoff or in_signature) and string: - string += " \\" - if not squash: - print(string, file=out_stream) - else: - parbreak = not string - global prev_is_parbreak - if skipping or not (parbreak and prev_is_parbreak): + def pprint(string: str): + if markdown_safe and (in_signoff or in_signature) and string: + string += " \\" + if not squash: print(string, file=out_stream) - prev_is_parbreak = parbreak - - -def wrap(text: str): - return textwrap.wrap( - text, - width=width, - break_long_words=break_long_words, - replace_whitespace=replace_whitespace, - ) - - -def flush_paragraph(): - if paragraph: - if reflow: - joined = " ".join(paragraph) - wrapped = wrap(joined) - pprint("\n".join(wrapped)) else: - for line in paragraph: - for wrapped_line in wrap(line): - pprint(wrapped_line) - paragraph.clear() + parbreak = not string + nonlocal prev_is_parbreak + if skipping or not (parbreak and prev_is_parbreak): + print(string, file=out_stream) + prev_is_parbreak = parbreak + def wrap(text: str): + return textwrap.wrap( + text, + width=width, + break_long_words=break_long_words, + replace_whitespace=replace_whitespace, + ) -signoff_cache: str = "" + def flush_paragraph(): + if paragraph: + if reflow: + joined = " ".join(paragraph) + wrapped = wrap(joined) + pprint("\n".join(wrapped)) + else: + for line in paragraph: + for wrapped_line in wrap(line): + pprint(wrapped_line) + paragraph.clear() + signoff_cache: str = "" -def check_signoff(line: str) -> bool: - if not line: - return False - words = line.split() - n = len(words) - # first potential signoff line - if not signoff_cache and 1 <= n <= 5 and line[-1] == ",": - return True - # second potential line - elif signoff_cache and 1 <= n <= 5 and line[-1].isalpha(): - for w in words: - if not w[0].isupper(): - return False - return True - else: - return False + def check_signoff(line: str) -> bool: + if not line: + return False + words = line.split() + n = len(words) + # first potential signoff line + if not signoff_cache and 1 <= n <= 5 and line[-1] == ",": + return True + # second potential line + elif signoff_cache and 1 <= n <= 5 and line[-1].isalpha(): + for w in words: + if not w[0].isupper(): + return False + return True + else: + return False - -if __name__ == "__main__": parser = argparse.ArgumentParser( description='Formatter for plain text email.\n"--no-*" options are NOT passed by default.', epilog=""" @@ -228,4 +223,8 @@ Contact: daniel@ficd.ca if out_stream is not None: out_stream.close() + +if __name__ == "__main__": + main() + # pyright: basic diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 0000000..d8dedf2 --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,17 @@ +[project] +name = "mailfmt" +version = "0.1.0" +description = "Add your description here" +readme = "README.md" +authors = [ + { name = "Daniel Fichtinger", email = "daniel@ficd.ca" } +] +requires-python = ">=3.11" +dependencies = [] + +[project.scripts] +mailfmt = "mailfmt:main" + +[build-system] +requires = ["hatchling"] +build-backend = "hatchling.build" diff --git a/uninstall.sh b/uninstall.sh deleted file mode 100755 index e995aa0..0000000 --- a/uninstall.sh +++ /dev/null @@ -1,4 +0,0 @@ -#!/bin/sh - -sudo rm /usr/bin/mailfmt -echo "mailfmt has been uninstalled." diff --git a/uv.lock b/uv.lock new file mode 100644 index 0000000..6688ee9 --- /dev/null +++ b/uv.lock @@ -0,0 +1,8 @@ +version = 1 +revision = 2 +requires-python = ">=3.11" + +[[package]] +name = "mailfmt" +version = "0.1.0" +source = { editable = "." } From 3ad71d86543bcd393bfeb213bb33c0393e5716b8 Mon Sep 17 00:00:00 2001 From: Daniel Fichtinger Date: Wed, 4 Jun 2025 12:34:00 -0400 Subject: [PATCH 02/15] packaged for pypi --- .gitignore | 177 ++++++++++++++++++++++++++++++++++++++++++ .python-version | 1 + install.sh | 5 -- mailfmt => mailfmt.py | 123 +++++++++++++++-------------- pyproject.toml | 17 ++++ uninstall.sh | 4 - uv.lock | 8 ++ 7 files changed, 264 insertions(+), 71 deletions(-) create mode 100644 .gitignore create mode 100644 .python-version delete mode 100755 install.sh rename mailfmt => mailfmt.py (71%) create mode 100644 pyproject.toml delete mode 100755 uninstall.sh create mode 100644 uv.lock diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..729a846 --- /dev/null +++ b/.gitignore @@ -0,0 +1,177 @@ +typings/ + +# Byte-compiled / optimized / DLL files +__pycache__/ +*.py[cod] +*$py.class + +# C extensions +*.so + +# Distribution / packaging +.Python +build/ +develop-eggs/ +dist/ +downloads/ +eggs/ +.eggs/ +lib/ +lib64/ +parts/ +sdist/ +var/ +wheels/ +share/python-wheels/ +*.egg-info/ +.installed.cfg +*.egg +MANIFEST + +# PyInstaller +# Usually these files are written by a python script from a template +# before PyInstaller builds the exe, so as to inject date/other infos into it. +*.manifest +*.spec + +# Installer logs +pip-log.txt +pip-delete-this-directory.txt + +# Unit test / coverage reports +htmlcov/ +.tox/ +.nox/ +.coverage +.coverage.* +.cache +nosetests.xml +coverage.xml +*.cover +*.py,cover +.hypothesis/ +.pytest_cache/ +cover/ + +# Translations +*.mo +*.pot + +# Django stuff: +*.log +local_settings.py +db.sqlite3 +db.sqlite3-journal + +# Flask stuff: +instance/ +.webassets-cache + +# Scrapy stuff: +.scrapy + +# Sphinx documentation +docs/_build/ + +# PyBuilder +.pybuilder/ +target/ + +# Jupyter Notebook +.ipynb_checkpoints + +# IPython +profile_default/ +ipython_config.py + +# pyenv +# For a library or package, you might want to ignore these files since the code is +# intended to run in multiple environments; otherwise, check them in: +# .python-version + +# pipenv +# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control. +# However, in case of collaboration, if having platform-specific dependencies or dependencies +# having no cross-platform support, pipenv may install dependencies that don't work, or not +# install all needed dependencies. +#Pipfile.lock + +# UV +# Similar to Pipfile.lock, it is generally recommended to include uv.lock in version control. +# This is especially recommended for binary packages to ensure reproducibility, and is more +# commonly ignored for libraries. +#uv.lock + +# poetry +# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control. +# This is especially recommended for binary packages to ensure reproducibility, and is more +# commonly ignored for libraries. +# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control +#poetry.lock + +# pdm +# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control. +#pdm.lock +# pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it +# in version control. +# https://pdm.fming.dev/latest/usage/project/#working-with-version-control +.pdm.toml +.pdm-python +.pdm-build/ + +# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm +__pypackages__/ + +# Celery stuff +celerybeat-schedule +celerybeat.pid + +# SageMath parsed files +*.sage.py + +# Environments +.env +.venv +env/ +venv/ +ENV/ +env.bak/ +venv.bak/ + +# Spyder project settings +.spyderproject +.spyproject + +# Rope project settings +.ropeproject + +# mkdocs documentation +/site + +# mypy +.mypy_cache/ +.dmypy.json +dmypy.json + +# Pyre type checker +.pyre/ + +# pytype static type analyzer +.pytype/ + +# Cython debug symbols +cython_debug/ + +# PyCharm +# JetBrains specific template is maintained in a separate JetBrains.gitignore that can +# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore +# and can be added to the global gitignore or merged into this file. For a more nuclear +# option (not recommended) you can uncomment the following to ignore the entire idea folder. +#.idea/ + +# Ruff stuff: +.ruff_cache/ + +# PyPI configuration file +.pypirc + diff --git a/.python-version b/.python-version new file mode 100644 index 0000000..2c07333 --- /dev/null +++ b/.python-version @@ -0,0 +1 @@ +3.11 diff --git a/install.sh b/install.sh deleted file mode 100755 index f72f4c4..0000000 --- a/install.sh +++ /dev/null @@ -1,5 +0,0 @@ -#!/bin/sh - -SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)" -sudo cp "$SCRIPT_DIR/mailfmt" /usr/bin/mailfmt -echo "mailfmt has been installed to /usr/bin/mailfmt." diff --git a/mailfmt b/mailfmt.py similarity index 71% rename from mailfmt rename to mailfmt.py index a12e4c7..e8d1f7a 100755 --- a/mailfmt +++ b/mailfmt.py @@ -16,78 +16,73 @@ import sys import re import argparse -paragraph: list[str] = [] -skipping = False -squash = True -prev_is_parbreak = False -out_stream = sys.stdout -reflow = True -width = 74 -break_long_words = False -replace_whitespace = True -markdown_safe = False -in_signoff = False -in_signature = False +def main() -> None: + paragraph: list[str] = [] + skipping = False + squash = True + prev_is_parbreak = False + out_stream = sys.stdout + reflow = True + width = 74 + break_long_words = False + replace_whitespace = True + markdown_safe = False + in_signoff = False + in_signature = False -def pprint(string: str): - if markdown_safe and (in_signoff or in_signature) and string: - string += " \\" - if not squash: - print(string, file=out_stream) - else: - parbreak = not string - global prev_is_parbreak - if skipping or not (parbreak and prev_is_parbreak): + def pprint(string: str): + if markdown_safe and (in_signoff or in_signature) and string: + string += " \\" + if not squash: print(string, file=out_stream) - prev_is_parbreak = parbreak - - -def wrap(text: str): - return textwrap.wrap( - text, - width=width, - break_long_words=break_long_words, - replace_whitespace=replace_whitespace, - ) - - -def flush_paragraph(): - if paragraph: - if reflow: - joined = " ".join(paragraph) - wrapped = wrap(joined) - pprint("\n".join(wrapped)) else: - for line in paragraph: - for wrapped_line in wrap(line): - pprint(wrapped_line) - paragraph.clear() + parbreak = not string + nonlocal prev_is_parbreak + if skipping or not (parbreak and prev_is_parbreak): + print(string, file=out_stream) + prev_is_parbreak = parbreak + def wrap(text: str): + return textwrap.wrap( + text, + width=width, + break_long_words=break_long_words, + replace_whitespace=replace_whitespace, + ) -signoff_cache: str = "" + def flush_paragraph(): + if paragraph: + if reflow: + joined = " ".join(paragraph) + wrapped = wrap(joined) + pprint("\n".join(wrapped)) + else: + for line in paragraph: + for wrapped_line in wrap(line): + pprint(wrapped_line) + paragraph.clear() + signoff_cache: str = "" -def check_signoff(line: str) -> bool: - if not line: - return False - words = line.split() - n = len(words) - # first potential signoff line - if not signoff_cache and 1 <= n <= 5 and line[-1] == ",": - return True - # second potential line - elif signoff_cache and 1 <= n <= 5 and line[-1].isalpha(): - for w in words: - if not w[0].isupper(): - return False - return True - else: - return False + def check_signoff(line: str) -> bool: + if not line: + return False + words = line.split() + n = len(words) + # first potential signoff line + if not signoff_cache and 1 <= n <= 5 and line[-1] == ",": + return True + # second potential line + elif signoff_cache and 1 <= n <= 5 and line[-1].isalpha(): + for w in words: + if not w[0].isupper(): + return False + return True + else: + return False - -if __name__ == "__main__": parser = argparse.ArgumentParser( description='Formatter for plain text email.\n"--no-*" options are NOT passed by default.', epilog=""" @@ -228,4 +223,8 @@ Contact: daniel@ficd.ca if out_stream is not None: out_stream.close() + +if __name__ == "__main__": + main() + # pyright: basic diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 0000000..e73335a --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,17 @@ +[project] +name = "mailfmt" +version = "0.1.0" +description = "Plain text email formatter" +readme = "README.md" +authors = [ + { name = "Daniel Fichtinger", email = "daniel@ficd.ca" } +] +requires-python = ">=3.11" +dependencies = [] + +[project.scripts] +mailfmt = "mailfmt:main" + +[build-system] +requires = ["hatchling"] +build-backend = "hatchling.build" diff --git a/uninstall.sh b/uninstall.sh deleted file mode 100755 index e995aa0..0000000 --- a/uninstall.sh +++ /dev/null @@ -1,4 +0,0 @@ -#!/bin/sh - -sudo rm /usr/bin/mailfmt -echo "mailfmt has been uninstalled." diff --git a/uv.lock b/uv.lock new file mode 100644 index 0000000..6688ee9 --- /dev/null +++ b/uv.lock @@ -0,0 +1,8 @@ +version = 1 +revision = 2 +requires-python = ">=3.11" + +[[package]] +name = "mailfmt" +version = "0.1.0" +source = { editable = "." } From dc11c497e7ba1967f537ff4defd90c3fa15180c0 Mon Sep 17 00:00:00 2001 From: Daniel Fichtinger Date: Wed, 4 Jun 2025 13:27:19 -0400 Subject: [PATCH 03/15] updated docs and metadata --- README.md | 28 +++++++++++++++++++++++++--- pyproject.toml | 9 ++++++++- 2 files changed, 33 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index e09b662..fb5594a 100644 --- a/README.md +++ b/README.md @@ -4,14 +4,14 @@ consistent paragraph spacing while preserving markdown syntax, email headers, sign-offs, and signature blocks. -By default, this script accepts its input on `stdin` and prints to `stdout`. +By default, the command accepts its input on `stdin` and prints to `stdout`. This makes it well suited for use as a formatter with a text editor like Kakoune -or Helix. It has no dependencies besides the standard Python interpreter, and -was written and tested against Python 3.13.3. +or Helix. - [Features](#features) +- [Installation](#installation) - [Usage](#usage) - [Output Example](#output-example) - [Markdown Safety](#markdown-safety) @@ -37,6 +37,28 @@ was written and tested against Python 3.13.3. - Use case: piping the output to `pandoc` to write a `text/html` message. See [Markdown Safety](#markdown-safety). +## Installation + +`mailfmt` is intended for use as a standaole tool. The package is available on +PyPI as `mailfmt`. I recommend using [uv](https://github.com/astral-sh/uv) or +`pipx` to install it so the `mailfmt` command is available on your path: + +```sh +uv tool install mailfmt +``` + +Verify that the installation was successful: + +```sh +mailfmt --help +``` + +The tool doesn't currently have any dependencies. Therefore, you can just +download and execute the +[mailfmt](https://git.sr.ht/~ficd/mailfmt/tree/main/item/mailfmt.py) script +directly. However, dependencies may be introduced later, so I recommend +installing with a Python package manager. + ## Usage ``` diff --git a/pyproject.toml b/pyproject.toml index e73335a..16b6704 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [project] name = "mailfmt" -version = "0.1.0" +version = "1.0.0" description = "Plain text email formatter" readme = "README.md" authors = [ @@ -8,6 +8,13 @@ authors = [ ] requires-python = ">=3.11" dependencies = [] +license = "ISC" +license-files = ["LICENSE"] +keywords = ["email", "formatter"] + +[project.urls] +Repository = "https://git.sr.ht/~ficd/mailfmt" +Homepage = "https://sr.ht/~ficd/mailfmt" [project.scripts] mailfmt = "mailfmt:main" From 4ddf5d9d8a93f8b15f296e2b9a7d18da321c0aa3 Mon Sep 17 00:00:00 2001 From: Daniel Fichtinger Date: Sat, 21 Jun 2025 14:20:30 -0400 Subject: [PATCH 04/15] Added justfile with clean recipe --- justfile | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 justfile diff --git a/justfile b/justfile new file mode 100644 index 0000000..ca4213b --- /dev/null +++ b/justfile @@ -0,0 +1,2 @@ +clean: + rm -r dist/ __pycache__/ From e87a386ddf5b0abb696a01559d56296417ff9742 Mon Sep 17 00:00:00 2001 From: Daniel Fichtinger Date: Sat, 21 Jun 2025 14:24:28 -0400 Subject: [PATCH 05/15] update self-reference in lockfile --- uv.lock | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/uv.lock b/uv.lock index 6688ee9..91a774e 100644 --- a/uv.lock +++ b/uv.lock @@ -4,5 +4,5 @@ requires-python = ">=3.11" [[package]] name = "mailfmt" -version = "0.1.0" +version = "1.0.0" source = { editable = "." } From 2fe25c4fc7a0f7b32ed4a4291f63dccf77c6a6b2 Mon Sep 17 00:00:00 2001 From: Daniel Fichtinger Date: Sat, 21 Jun 2025 14:24:36 -0400 Subject: [PATCH 06/15] update clean recipe --- justfile | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/justfile b/justfile index ca4213b..37656df 100644 --- a/justfile +++ b/justfile @@ -1,2 +1,14 @@ clean: - rm -r dist/ __pycache__/ + #!/bin/sh + if [ ! -d "dist" ] && [ ! -d "__pycache__" ]; then + echo "Nothing to clean." + exit 0 + fi + if [ -d "dist" ]; then + echo "Removing dist/" + rm -r dist/ + fi + if [ -d "__pycache__" ]; then + echo "Removing __pycache__/" + rm -r "__pycache__" + fi From df27780c1e959a75830dc76020ab7eae419308cf Mon Sep 17 00:00:00 2001 From: Daniel Fichtinger Date: Sat, 21 Jun 2025 14:27:03 -0400 Subject: [PATCH 07/15] add publish recipe --- justfile | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/justfile b/justfile index 37656df..ca07235 100644 --- a/justfile +++ b/justfile @@ -12,3 +12,10 @@ clean: echo "Removing __pycache__/" rm -r "__pycache__" fi +publish: + #!/bin/sh + just clean + uv build + UV_PUBLISH_TOKEN="$(pass show pypi)" + uv publish + From 22461f5c973e2c2693e70174c0ed94d0761974b9 Mon Sep 17 00:00:00 2001 From: Daniel Fichtinger Date: Sat, 21 Jun 2025 14:29:30 -0400 Subject: [PATCH 08/15] updated help menu --- mailfmt.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/mailfmt.py b/mailfmt.py index e8d1f7a..dba3722 100755 --- a/mailfmt.py +++ b/mailfmt.py @@ -84,11 +84,12 @@ def main() -> None: return False parser = argparse.ArgumentParser( - description='Formatter for plain text email.\n"--no-*" options are NOT passed by default.', + description="Heuristic formatter for plain text email. Preserves markup, signoffs, and signature blocks.", epilog=""" -Author : Daniel Fichtinger -License: ISC -Contact: daniel@ficd.ca +Author : Daniel Fichtinger +Repository: https://git.sr.ht/~ficd/mailfmt +License : ISC +Contact : daniel@ficd.ca """, formatter_class=argparse.RawDescriptionHelpFormatter, ) From aecc01c3f07d3be48961e372031c1b8db17b1dde Mon Sep 17 00:00:00 2001 From: Daniel Fichtinger Date: Sat, 21 Jun 2025 14:30:39 -0400 Subject: [PATCH 09/15] Updated metadata --- pyproject.toml | 7 +++---- uv.lock | 2 +- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 16b6704..ee637a7 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,7 +1,7 @@ [project] name = "mailfmt" -version = "1.0.0" -description = "Plain text email formatter" +version = "1.0.1" +description = "Heuristic plain text email formatter." readme = "README.md" authors = [ { name = "Daniel Fichtinger", email = "daniel@ficd.ca" } @@ -10,11 +10,10 @@ requires-python = ">=3.11" dependencies = [] license = "ISC" license-files = ["LICENSE"] -keywords = ["email", "formatter"] +keywords = ["email", "formatter", "cli"] [project.urls] Repository = "https://git.sr.ht/~ficd/mailfmt" -Homepage = "https://sr.ht/~ficd/mailfmt" [project.scripts] mailfmt = "mailfmt:main" diff --git a/uv.lock b/uv.lock index 91a774e..927ca8f 100644 --- a/uv.lock +++ b/uv.lock @@ -4,5 +4,5 @@ requires-python = ">=3.11" [[package]] name = "mailfmt" -version = "1.0.0" +version = "1.0.1" source = { editable = "." } From 5d978102c3072fb34524b55b73a3b78ce5e2c34c Mon Sep 17 00:00:00 2001 From: Daniel Fichtinger Date: Sat, 21 Jun 2025 14:32:35 -0400 Subject: [PATCH 10/15] fixed publish recipe --- justfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/justfile b/justfile index ca07235..b0828ed 100644 --- a/justfile +++ b/justfile @@ -16,6 +16,6 @@ publish: #!/bin/sh just clean uv build - UV_PUBLISH_TOKEN="$(pass show pypi)" + export UV_PUBLISH_TOKEN="$(pass show pypi)" uv publish From f75f0bfe837745d97cd67c3e68671d5c824254b7 Mon Sep 17 00:00:00 2001 From: Daniel Fichtinger Date: Fri, 27 Jun 2025 21:05:08 -0400 Subject: [PATCH 11/15] fixed issue with signoff detection --- mailfmt.py | 2 +- pyproject.toml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/mailfmt.py b/mailfmt.py index dba3722..fb34d8a 100755 --- a/mailfmt.py +++ b/mailfmt.py @@ -75,7 +75,7 @@ def main() -> None: if not signoff_cache and 1 <= n <= 5 and line[-1] == ",": return True # second potential line - elif signoff_cache and 1 <= n <= 5 and line[-1].isalpha(): + elif signoff_cache and 1 <= n <= 5: for w in words: if not w[0].isupper(): return False diff --git a/pyproject.toml b/pyproject.toml index ee637a7..fcf662c 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [project] name = "mailfmt" -version = "1.0.1" +version = "1.0.2" description = "Heuristic plain text email formatter." readme = "README.md" authors = [ From 9c6ae12284c62c7525ecf737b2cabe6cc30913bf Mon Sep 17 00:00:00 2001 From: Daniel Fichtinger Date: Sun, 13 Jul 2025 02:51:22 -0400 Subject: [PATCH 12/15] updated metadata --- README.md | 78 ++++++++++++++++++++++---------------------------- pyproject.toml | 4 +-- 2 files changed, 36 insertions(+), 46 deletions(-) diff --git a/README.md b/README.md index fb5594a..ff2c780 100644 --- a/README.md +++ b/README.md @@ -1,12 +1,12 @@

Mail Format

`mailfmt` is a simple plain text email formatter. It's designed to ensure -consistent paragraph spacing while preserving markdown syntax, email headers, -sign-offs, and signature blocks. +consistent paragraph spacing while preserving markdown syntax, email +headers, sign-offs, and signature blocks. -By default, the command accepts its input on `stdin` and prints to `stdout`. -This makes it well suited for use as a formatter with a text editor like Kakoune -or Helix. +By default, the command accepts its input on `stdin` and prints to +`stdout`. This makes it well suited for use as a formatter with a text +editor like Kakoune or Helix. @@ -16,7 +16,6 @@ or Helix. - [Output Example](#output-example) - [Markdown Safety](#markdown-safety) - [Aerc Integration](#aerc-integration) -- [Contributing](#contributing) @@ -33,15 +32,17 @@ or Helix. - Markdown-style code blocks. - Usenet-style signature block at EOF. - Sign-offs. -- If specified, output can be made safe for passing to a Markdown renderer. - - Use case: piping the output to `pandoc` to write a `text/html` message. See - [Markdown Safety](#markdown-safety). +- If specified, output can be made safe for passing to a Markdown + renderer. + - Use case: piping the output to `pandoc` to write a `text/html` + message. See [Markdown Safety](#markdown-safety). ## Installation -`mailfmt` is intended for use as a standaole tool. The package is available on -PyPI as `mailfmt`. I recommend using [uv](https://github.com/astral-sh/uv) or -`pipx` to install it so the `mailfmt` command is available on your path: +`mailfmt` is intended for use as a standaole tool. The package is +available on PyPI as `mailfmt`. I recommend using +[uv](https://github.com/astral-sh/uv) or `pipx` to install it so the +`mailfmt` command is available on your path: ```sh uv tool install mailfmt @@ -53,12 +54,6 @@ Verify that the installation was successful: mailfmt --help ``` -The tool doesn't currently have any dependencies. Therefore, you can just -download and execute the -[mailfmt](https://git.sr.ht/~ficd/mailfmt/tree/main/item/mailfmt.py) script -directly. However, dependencies may be introduced later, so I recommend -installing with a Python package manager. - ## Usage ``` @@ -85,8 +80,7 @@ options: -o, --output OUTPUT Output file. (default: STDOUT) Author : Daniel Fichtinger -License: ISC -Contact: daniel@ficd.ca +Contact: daniel@ficd.sh ``` ## Output Example @@ -109,8 +103,7 @@ Daniel -- Daniel -sr.ht/~ficd -daniel@ficd.ca +daniel@ficd.sh ``` After: @@ -132,23 +125,24 @@ Daniel -- Daniel -sr.ht/~ficd -daniel@ficd.ca +daniel@ficd.sh ``` ## Markdown Safety -In some cases, you may want to generate an HTML email. Ideally, you'd want the -HTML to be generated directly from the plain text message, and for _both_ -versions to be legible and have the same semantics. +In some cases, you may want to generate an HTML email. Ideally, you'd want +the HTML to be generated directly from the plain text message, and for +_both_ versions to be legible and have the same semantics. -Although `mailfmt` was written with Markdown markup in mind, its intended output -is still the `text/plain` format. If you pass its output directly to a Markdown -renderer, line breaks in sign-offs and the signature block won't be preserved. +Although `mailfmt` was written with Markdown markup in mind, its intended +output is still the `text/plain` format. If you pass its output directly +to a Markdown renderer, line breaks in sign-offs and the signature block +won't be preserved. -If you invoke `mailfmt --markdown-safe`, then `\` characters will be appended to -mark line breaks that would otherwise be squashed, making the output suitable -for conversion into HTML. Here's an example of one such pipeline: +If you invoke `mailfmt --markdown-safe`, then `\` characters will be +appended to mark line breaks that would otherwise be squashed, making the +output suitable for conversion into HTML. Here's an example of one such +pipeline: ```bash cat message.txt | mailfmt --markdown-safe | pandoc -f markdown -t html @@ -174,24 +168,20 @@ Daniel \ -- \ Daniel \ -sr.ht/~ficd \ -daniel@ficd.ca \ +daniel@ficd.sh \ ``` ## Aerc Integration -For integration with `aerc`, consider adding the following to your `aerc.conf`: +For integration with `aerc`, consider adding the following to your +`aerc.conf`: ```ini [multipart-converters] text/html=mailfmt --markdown-safe | pandoc -f markdown -t html --standalone ``` -When you're done writing your email, you can call the `:multipart text/html` -command to generate a `multipart/alternative` message which includes _both_ your -original `text/plain` _and_ the newly generated `text/html` content. - -## Contributing - -Please send patches, requests, and concerns to my -[public inbox](https://lists.sr.ht/~ficd/public-inbox). +When you're done writing your email, you can call the +`:multipart text/html` command to generate a `multipart/alternative` +message which includes _both_ your original `text/plain` _and_ the newly +generated `text/html` content. diff --git a/pyproject.toml b/pyproject.toml index fcf662c..583a3bc 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [project] name = "mailfmt" -version = "1.0.2" +version = "1.0.3" description = "Heuristic plain text email formatter." readme = "README.md" authors = [ @@ -13,7 +13,7 @@ license-files = ["LICENSE"] keywords = ["email", "formatter", "cli"] [project.urls] -Repository = "https://git.sr.ht/~ficd/mailfmt" +Repository = "https://git.ficd.sh/ficd/mailfmt" [project.scripts] mailfmt = "mailfmt:main" From f490e10f1f14f4b0d641f9067a7f18c7069c5f8c Mon Sep 17 00:00:00 2001 From: Daniel Fichtinger Date: Thu, 17 Jul 2025 22:13:55 -0400 Subject: [PATCH 13/15] updated repo link in help text --- mailfmt.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/mailfmt.py b/mailfmt.py index fb34d8a..1af4272 100755 --- a/mailfmt.py +++ b/mailfmt.py @@ -11,10 +11,10 @@ # Author: Daniel Fichtinger # License: ISC -import textwrap -import sys -import re import argparse +import re +import sys +import textwrap def main() -> None: @@ -87,9 +87,9 @@ def main() -> None: description="Heuristic formatter for plain text email. Preserves markup, signoffs, and signature blocks.", epilog=""" Author : Daniel Fichtinger -Repository: https://git.sr.ht/~ficd/mailfmt +Repository: https://git.ficd.sh/ficd/mailfmt License : ISC -Contact : daniel@ficd.ca +Contact : daniel@ficd.sh """, formatter_class=argparse.RawDescriptionHelpFormatter, ) From c2d2780e4ab6afb6ed4b8304d3e41961f87ea6cf Mon Sep 17 00:00:00 2001 From: Daniel Fichtinger Date: Thu, 17 Jul 2025 22:19:09 -0400 Subject: [PATCH 14/15] added --version flag --- mailfmt.py | 11 +++++++++++ pyproject.toml | 4 ++-- uv.lock | 2 +- 3 files changed, 14 insertions(+), 3 deletions(-) diff --git a/mailfmt.py b/mailfmt.py index 1af4272..995e9aa 100755 --- a/mailfmt.py +++ b/mailfmt.py @@ -15,6 +15,7 @@ import argparse import re import sys import textwrap +from importlib.metadata import version def main() -> None: @@ -93,6 +94,13 @@ Contact : daniel@ficd.sh """, formatter_class=argparse.RawDescriptionHelpFormatter, ) + parser.add_argument( + "-v", + "--version", + required=False, + help="Print version info and exit.", + action="store_true", + ) parser.add_argument( "-w", "--width", @@ -162,6 +170,9 @@ Contact : daniel@ficd.sh help="Output file. (default: %(default)s)", ) args = parser.parse_args() + if args.version: + print(version("mailfmt")) + exit(0) width = args.width should_check_signoff = args.no_signoff should_check_signature = args.no_signature diff --git a/pyproject.toml b/pyproject.toml index 583a3bc..5694f65 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,10 +1,10 @@ [project] name = "mailfmt" -version = "1.0.3" +version = "1.0.4" description = "Heuristic plain text email formatter." readme = "README.md" authors = [ - { name = "Daniel Fichtinger", email = "daniel@ficd.ca" } + { name = "Daniel Fichtinger", email = "daniel@ficd.sh" } ] requires-python = ">=3.11" dependencies = [] diff --git a/uv.lock b/uv.lock index 927ca8f..029043b 100644 --- a/uv.lock +++ b/uv.lock @@ -4,5 +4,5 @@ requires-python = ">=3.11" [[package]] name = "mailfmt" -version = "1.0.1" +version = "1.0.3" source = { editable = "." } From 1aa4455de0c2b6e40365da2b6ce41feed84839c9 Mon Sep 17 00:00:00 2001 From: Daniel Fichtinger Date: Thu, 17 Jul 2025 22:20:09 -0400 Subject: [PATCH 15/15] added publish workflow --- .forgejo/workflows/publish.yml | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 .forgejo/workflows/publish.yml diff --git a/.forgejo/workflows/publish.yml b/.forgejo/workflows/publish.yml new file mode 100644 index 0000000..fde3206 --- /dev/null +++ b/.forgejo/workflows/publish.yml @@ -0,0 +1,20 @@ +on: + push: + tags: + - 'v*' +jobs: + publish: + runs-on: based-alpine + steps: + - uses: actions/checkout@v4 + - name: setup cache + id: uv-cache + uses: https://git.ficd.sh/ficd/uv-cache@v1 + - name: build + run: | + uv sync + uv build + - name: publish + run: | + uv publish --token ${{ secrets.PYPI_TOKEN }} +