#mime #message #emacs #mml #plain-text

mml-lib

Rust implementation of the Emacs MIME message Meta Language (MML)

26 releases (13 stable)

1.0.12 Apr 9, 2024
1.0.8 Mar 14, 2024
1.0.6 Dec 31, 2023
1.0.1 Oct 9, 2023
0.5.1 Sep 26, 2023

#20 in Email

Download history 78/week @ 2024-01-01 65/week @ 2024-01-08 11/week @ 2024-01-15 27/week @ 2024-01-22 25/week @ 2024-01-29 26/week @ 2024-02-05 300/week @ 2024-02-12 95/week @ 2024-02-19 97/week @ 2024-02-26 47/week @ 2024-03-04 287/week @ 2024-03-11 137/week @ 2024-03-18 1/week @ 2024-03-25 374/week @ 2024-04-01 558/week @ 2024-04-08 273/week @ 2024-04-15

1,219 downloads per month
Used in 6 crates (4 directly)

MIT and maybe LGPL-2.1

155KB
3.5K SLoC

📫 MIME Meta Language

Rust implementation of the Emacs MIME message Meta Language, as known as MML.

This library exposes a MML to MIME message compiler and a MIME to MML message interpreter. See the API documentation for more information.

For example:

From: alice@localhost
To: bob@localhost
Subject: MML examples

This is a plain text part.

<#part type=text/html>
<h1>This is a HTML part.</h1>
<#/part>

<#part description="This is an attachment." filename=./examples/attachment.png><#/part>

compiles to:

MIME-Version: 1.0
From: <alice@localhost>
To: <bob@localhost>
Subject: MML examples
Message-ID: <17886a741feef4a2.f9706245cd3a3f97.3b41d60ef9e2fbfb@soywod>
Date: Tue, 26 Sep 2023 09:58:26 +0000
Content-Type: multipart/mixed; 
	boundary="17886a741fef2cb2_97a7dbff4c84bbac_3b41d60ef9e2fbfb"


--17886a741fef2cb2_97a7dbff4c84bbac_3b41d60ef9e2fbfb
Content-Type: text/plain; charset="utf-8"
Content-Transfer-Encoding: 7bit

This is a plain text part.


--17886a741fef2cb2_97a7dbff4c84bbac_3b41d60ef9e2fbfb
Content-Type: text/html; charset="utf-8"
Content-Transfer-Encoding: 7bit

<h1>This is a HTML part.</h1>

Content-Type: application/octet-stream
Content-Disposition: attachment; filename="attachment.png"
Content-Transfer-Encoding: base64

iVBORw0KGgo…

--17886a741fef2cb2_97a7dbff4c84bbac_3b41d60ef9e2fbfb--

Definition

From the Emacs documentation:

Creating a MIME message is boring and non-trivial. Therefore, a library called mml has been defined that parses a language called MML (MIME Meta Language) and generates MIME messages.

The MML language is very simple. It looks a bit like an SGML application, but it’s not.

The main concept of MML is the part. Each part can be of a different type or use a different charset. The way to delineate a part is with a ‘<#part ...>’ tag. Multipart parts can be introduced with the ‘<#multipart ...>’ tag. Parts are ended by the ‘<#/part>’ or ‘<#/multipart>’ tags. Parts started with the ‘<#part ...>’ tags are also closed by the next open tag.

[…]

Each tag can contain zero or more parameters on the form ‘parameter=value’. The values may be enclosed in quotation marks, but that’s not necessary unless the value contains white space. So ‘filename=/home/user/#hello$^yes’ is perfectly valid.

Features

  • MML to MIME messages compilation using MmlCompilerBuilder (cargo feature compiler required, enabled by default)
  • MIME to MML messages interpretation using the MimeInterpreterBuilder (cargo feature interpreter required, activated by default)
  • Multiple parts support <#multipart><#/multipart>
  • Inline part support <#part text=mime/type><#/part>
  • Attachment support <#part disposition=attachment filename=/path/to/attachment.ext><#/part>
  • Comment support <#!part>This will not be compiled<#!/part>
  • PGP support:
    • Shell commands (cargo feature pgp-commands required)
    • GPG bindings (cargo feature pgp-gpg and gpgme lib required)
    • Native Rust implementation (cargo feature pgp-native required)

Examples

See ./examples:

cargo run --example

Development

The development environment is managed by Nix. Running nix-shell will spawn a shell with everything you need to get started with the lib: cargo, cargo-watch, rust-bin, rust-analyzer

# Start a Nix shell
$ nix-shell

# then build the lib
$ cargo build -p mml-lib

Contributing

A bug tracker is available on SourceHut. [send an email]

A mailing list is available on SourceHut. [send an email] [subscribe] [unsubscribe]

If you want to report a bug, please send an email at ~soywod/pimalaya@todo.sr.ht.

If you want to propose a feature or fix a bug, please send a patch at ~soywod/pimalaya@lists.sr.ht. The simplest way to send a patch is to use git send-email, follow this guide to configure git properly.

If you just want to discuss about the project, feel free to join the Matrix workspace #pimalaya or contact me directly @soywod. You can also use the mailing list.

Sponsoring

nlnet

Special thanks to the NLnet foundation and the European Commission that helped the project to receive financial support from:

If you appreciate the project, feel free to donate using one of the following providers:

GitHub PayPal Ko-fi Buy Me a Coffee Liberapay

Dependencies

~1–17MB
~227K SLoC