#email #smtp #mailer #message #sendmail

mime-msg-builder

Rust library for building MIME Messages inspired by the Emacs MML language

1 unstable release

0.1.0 Feb 7, 2023

#93 in Email

Download history 81/week @ 2023-02-02 141/week @ 2023-02-09 119/week @ 2023-02-16 39/week @ 2023-02-23 34/week @ 2023-03-02 54/week @ 2023-03-09 43/week @ 2023-03-16 29/week @ 2023-03-23 23/week @ 2023-03-30 49/week @ 2023-04-06 32/week @ 2023-04-13 63/week @ 2023-04-20 147/week @ 2023-04-27 62/week @ 2023-05-04 38/week @ 2023-05-11

312 downloads per month
Used in 3 crates (via himalaya-lib)

MIT license

77KB
2K SLoC

📫 MIME Message builder

mime-msg-builder is a Rust library for building MIME Messages.

The core feature of the library is the Rust implementation of the Emacs MML module:

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.

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

<#multipart type=alternative>
This is a plain text part.
<#part type=text/enriched>
<center>This is a centered enriched part</center>
<#/multipart>

compiles to:

Subject: MML simple
To: bob@localhost
From: alice@localhost
MIME-Version: 1.0
Date: Tue, 29 Nov 2022 13:07:01 +0000
Content-Type: multipart/alternative;
 boundary="4CV1Cnp7mXkDyvb55i77DcNSkKzB8HJzaIT84qZe"

--4CV1Cnp7mXkDyvb55i77DcNSkKzB8HJzaIT84qZe
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: 7bit

This is a plain text part.
--4CV1Cnp7mXkDyvb55i77DcNSkKzB8HJzaIT84qZe
Content-Type: text/enriched
Content-Transfer-Encoding: 7bit

<center>This is a centered enriched part</center>
--4CV1Cnp7mXkDyvb55i77DcNSkKzB8HJzaIT84qZe--

Definition

From the documentation:

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.

Examples

See ./examples:

cargo run --example

Features

  • Template builder
  • Multipart support <#multipart><#/multipart>
  • SinglePart support <#part><#/part>
  • Attachment support <#part filename=>
  • Part encryption using custom system commands (default: gpg --encrypt --armor --recipient <recipient> --quiet --output -)
  • Part signing using custom system commands (default: gpg --sign --armor --quiet --output -)

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

# starts a nix shell
$ nix-shell

# builds the lib
$ cargo build

Contributing

If you find a bug, feel free to open an issue at ~soywod/mime-msg-builder.

If you have a feature in mind, feel free to send a patchset at https://git.sr.ht/~soywod/mime-msg-builder/send-email or use the command git send-email.

You can also contact me directly on Matrix at @soywod:matrix.org.

Sponsoring

GitHub PayPal Ko-fi Buy Me a Coffee Liberapay

Dependencies

~8–14MB
~290K SLoC