magic.lambda.mime - Creating and parsing MIME messages from Hyperlambda

magic.lambda.mime gives you the ability to parse and create MIME messages from Hyperlambda. This project contains the following slots.

How to use [mime.parse]

Below is an example of how parsing a MIME message might look like using [mime.parse].

// Actual message
.msg:"Content-Type: multipart/mixed; boundary=\"=-3O9TzEjuVDwt7d5uGDkV/Q==\"\n\n--=-3O9TzEjuVDwt7d5uGDkV/Q==\nContent-Type: text/plain\nContent-Disposition: attachment;\n\n# Your dynamic files folder\n\nSome file\n\n--=-3O9TzEjuVDwt7d5uGDkV/Q==\nContent-Type: text/plain\n\nBar\n--=-3O9TzEjuVDwt7d5uGDkV/Q==--\n"

// Parsing the above message

After evaluating the above, you’ll end up with something resembling the following.

      content:"# Your dynamic files folder\n\nSome file\n"

Notice how the slot creates a tree structure, perfectly resembling your original MIME message. It will also take care of MIME headers for you, adding these into a [headers] collection, on a per MIME entity basis, depending upon whether or not your message actually contains headers or not.

How to use [mime.create]

The [mime.create] slot is logically the exact opposite of the [mime.parse] slot, and can take (almost) the exact same input as its sibling produces as output. Below is an example.


      content:this is the body text

      content:this is another body text

Which of course wil result in something resembling the following after evaluation.

mime.create:"Content-Type: multipart/mixed; boundary=\"=-7+NI+p6PuOyQUzW5ihnXvw==\"\n\n--=-7+NI+p6PuOyQUzW5ihnXvw==\nContent-Type: text/plain\n\nthis is the body text\n--=-7+NI+p6PuOyQUzW5ihnXvw==\nContent-Type: text/plain\n\nthis is another body text\n--=-7+NI+p6PuOyQUzW5ihnXvw==--\n"

Notice - If you set its [structured] argument to boolean true, the slot will return the MIME envelope headers for the outermost MIME entity “detached” from the rest of the message. This is useful when you for some reasons don’t want the headers for the outermost entity to be a part of the actual message, such as for instance when creating multipart/form-data types of messages you need to transmit to some HTTP endpoint. If you do this, the return after executing the slot will resemble the following.

   Content-Type:"multipart/mixed; boundary=\"=-EbMBZ3eHrSrMqtB2KHSv+A==\""
   content:"--=-EbMBZ3eHrSrMqtB2KHSv+A==\nContent-Type: text/plain\n\nthis is the body text\n--=-EbMBZ3eHrSrMqtB2KHSv+A==\nContent-Type: text/plain\n\nthis is another body text\n--=-EbMBZ3eHrSrMqtB2KHSv+A==--\n"

Project website for magic.lambda.mime

The source code for this repository can be found at, and you can provide feedback, provide bug reports, etc at the same place.

The projects is copyright of Aista, Ltd 2021 - 2023