From 93917d389efd6e39420ad5855db67930dc963de4 Mon Sep 17 00:00:00 2001 From: James Brown Date: Sat, 18 May 2024 16:11:50 -0700 Subject: [PATCH] feat: add assume_markdown config flag --- README.md | 3 +++ man/muttdown.1 | 5 +++++ muttdown/main.py | 7 ++++--- tests/test_basic.py | 15 +++++++++++++++ 4 files changed, 27 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 8d91a3f..98ecd68 100644 --- a/README.md +++ b/README.md @@ -46,6 +46,7 @@ Muttdown's configuration file is written using [YAML][]. Example: smtp_username: foo@bar.com smtp_password: foo css_file: ~/.muttdown.css + assume_markdown: false If you prefer not to put your password in plaintext in a configuration file, you can instead specify the `smtp_password_command` parameter to invoke a shell command to lookup your password. The command should output your password, followed by a newline, and no other text. On OS X, the following invocation will extract a generic "Password" entry with the application set to "mutt" and the title set to "foo@bar.com": @@ -58,6 +59,8 @@ The `css_file` should be regular CSS styling blocks; we use [pynliner][] to inli Muttdown can also send its mail using the native `sendmail` if you have that set up (instead of doing SMTP itself). To do so, just leave the smtp options in the config file blank, set the `sendmail` option to the fully-qualified path to your `sendmail` binary, and run muttdown with the `-s` flag +If `assume_markdown` is true, then all input is assumed to be Markdown by default and the `!m` sigil does nothing. + Installation ------------ Install muttdown with `pip install muttdown` or by downloading this package and running `python setup.py install`. You will need the [PyYAML][] and [Python-Markdown][] libraries, as specified in `requirements.txt`. This should work with Python 3.6+. diff --git a/man/muttdown.1 b/man/muttdown.1 index 8ac6b38..c6e37cb 100644 --- a/man/muttdown.1 +++ b/man/muttdown.1 @@ -83,6 +83,8 @@ smtp_username: foo@bar.com smtp_password: foo .br css_file: ~/.muttdown.css +.br +assume_markdown: false .P If you prefer not to put your password in plaintext in a configuration file, you can instead specify the \fBsmtp_password_command\fR parameter to invoke a shell @@ -106,6 +108,9 @@ have that set up (instead of doing SMTP itself). To do so, just leave the smtp options in the config file blank, set the \fBsendmail\fR option to the fully-qualified path to your \fBsendmail\fR binary, and run \fBmuttdown\fR with the \fB-s\fR flag +.P +If \fBassume_markdown\fR is true, then all input is assumed to be Markdown by +default and the \fB!m\fR sigil does nothing. .SH AUTHORS \fBmuttdown\fR was written by James Brown . diff --git a/muttdown/main.py b/muttdown/main.py index 578c6d3..bb047f9 100644 --- a/muttdown/main.py +++ b/muttdown/main.py @@ -42,9 +42,10 @@ def convert_one(part, config, charset): except UnicodeError: # this is because of message.py:278 and seems like a hack text = text.decode("raw-unicode-escape") - if not text.startswith("!m"): - return None - text = re.sub(r"\s*!m\s*", "", text, re.M) + if not config.assume_markdown: + if not text.startswith("!m"): + return None + text = re.sub(r"\s*!m\s*", "", text, re.M) if "\n-- \n" in text: pre_signature, signature = text.split("\n-- \n") md = markdown.markdown( diff --git a/tests/test_basic.py b/tests/test_basic.py index 0423683..45cfbea 100644 --- a/tests/test_basic.py +++ b/tests/test_basic.py @@ -310,3 +310,18 @@ def test_raw_unicode(basic_config): converted = process_message(mail, basic_config) assert converted["From"] == "Test " assert "Ø" in converted.get_payload() + + +def test_assume_markdown(basic_config): + msg = Message() + msg["Subject"] = "Test Message" + msg["From"] = "from@example.com" + msg["To"] = "to@example.com" + msg["Bcc"] = "bananas" + msg.set_payload("This message has no **sigil**") + + basic_config.merge_config({"assume_markdown": True}) + + converted = process_message(msg, basic_config) + html_part = converted.get_payload()[1].get_payload(decode=True) + assert html_part == b"

This message has no sigil

"