Skip to content

Commit

Permalink
feat: add assume_markdown config flag (#31)
Browse files Browse the repository at this point in the history
  • Loading branch information
Roguelazer authored May 18, 2024
1 parent 64c912c commit b553fe6
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 3 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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":
Expand All @@ -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+.
Expand Down
5 changes: 5 additions & 0 deletions man/muttdown.1
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 <Roguelazer@gmail.com>.
Expand Down
7 changes: 4 additions & 3 deletions muttdown/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
15 changes: 15 additions & 0 deletions tests/test_basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -310,3 +310,18 @@ def test_raw_unicode(basic_config):
converted = process_message(mail, basic_config)
assert converted["From"] == "Test <test@example.com>"
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"<p>This message has no <strong>sigil</strong></p>"

0 comments on commit b553fe6

Please sign in to comment.