Compare commits
14 commits
Author | SHA1 | Date | |
---|---|---|---|
1aa4455de0 | |||
c2d2780e4a | |||
f490e10f1f | |||
9c6ae12284 | |||
f75f0bfe83 | |||
5d978102c3 | |||
aecc01c3f0 | |||
22461f5c97 | |||
df27780c1e | |||
2fe25c4fc7 | |||
e87a386ddf | |||
4ddf5d9d8a | |||
dc11c497e7 | |||
3ad71d8654 |
6 changed files with 119 additions and 48 deletions
20
.forgejo/workflows/publish.yml
Normal file
20
.forgejo/workflows/publish.yml
Normal file
|
@ -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 }}
|
||||
|
84
README.md
84
README.md
|
@ -1,22 +1,21 @@
|
|||
<h1>Mail Format</h1>
|
||||
|
||||
`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, this script 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.
|
||||
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.
|
||||
|
||||
<!--toc:start-->
|
||||
|
||||
- [Features](#features)
|
||||
- [Installation](#installation)
|
||||
- [Usage](#usage)
|
||||
- [Output Example](#output-example)
|
||||
- [Markdown Safety](#markdown-safety)
|
||||
- [Aerc Integration](#aerc-integration)
|
||||
- [Contributing](#contributing)
|
||||
|
||||
<!--toc:end-->
|
||||
|
||||
|
@ -33,9 +32,27 @@ was written and tested against Python 3.13.3.
|
|||
- 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:
|
||||
|
||||
```sh
|
||||
uv tool install mailfmt
|
||||
```
|
||||
|
||||
Verify that the installation was successful:
|
||||
|
||||
```sh
|
||||
mailfmt --help
|
||||
```
|
||||
|
||||
## Usage
|
||||
|
||||
|
@ -63,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
|
||||
|
@ -87,8 +103,7 @@ Daniel
|
|||
|
||||
--
|
||||
Daniel
|
||||
sr.ht/~ficd
|
||||
daniel@ficd.ca
|
||||
daniel@ficd.sh
|
||||
```
|
||||
|
||||
After:
|
||||
|
@ -110,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
|
||||
|
@ -152,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.
|
||||
|
|
21
justfile
Normal file
21
justfile
Normal file
|
@ -0,0 +1,21 @@
|
|||
clean:
|
||||
#!/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
|
||||
publish:
|
||||
#!/bin/sh
|
||||
just clean
|
||||
uv build
|
||||
export UV_PUBLISH_TOKEN="$(pass show pypi)"
|
||||
uv publish
|
||||
|
28
mailfmt.py
28
mailfmt.py
|
@ -11,10 +11,11 @@
|
|||
# Author: Daniel Fichtinger
|
||||
# License: ISC
|
||||
|
||||
import textwrap
|
||||
import sys
|
||||
import re
|
||||
import argparse
|
||||
import re
|
||||
import sys
|
||||
import textwrap
|
||||
from importlib.metadata import version
|
||||
|
||||
|
||||
def main() -> None:
|
||||
|
@ -75,7 +76,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
|
||||
|
@ -84,14 +85,22 @@ 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.ficd.sh/ficd/mailfmt
|
||||
License : ISC
|
||||
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",
|
||||
|
@ -161,6 +170,9 @@ Contact: daniel@ficd.ca
|
|||
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
|
||||
|
|
|
@ -1,13 +1,19 @@
|
|||
[project]
|
||||
name = "mailfmt"
|
||||
version = "0.1.0"
|
||||
description = "Add your description here"
|
||||
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 = []
|
||||
license = "ISC"
|
||||
license-files = ["LICENSE"]
|
||||
keywords = ["email", "formatter", "cli"]
|
||||
|
||||
[project.urls]
|
||||
Repository = "https://git.ficd.sh/ficd/mailfmt"
|
||||
|
||||
[project.scripts]
|
||||
mailfmt = "mailfmt:main"
|
||||
|
|
2
uv.lock
generated
2
uv.lock
generated
|
@ -4,5 +4,5 @@ requires-python = ">=3.11"
|
|||
|
||||
[[package]]
|
||||
name = "mailfmt"
|
||||
version = "0.1.0"
|
||||
version = "1.0.3"
|
||||
source = { editable = "." }
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue