0 " ˆl–Ãa¾”*j"Tâ€jãnÜdJbÑ¿Ä ƒh¹ÇÆ 1  Á 0ÀÇÆCˆl–äY>”ªe¶… @;pÜţŠ„ BiÏ_‡I|¥‰ÓMa–Ãa¾”*j"Tâ€nã/ÜmÅ1hßÉ7¦ LuaSocket: MIME module

LuaSocket
Network support for the Lua language

home · download · installation · introduction · reference


MIME

The mime namespace offers filters that apply and remove common content transfer encodings, such as Base64 and Quoted-Printable. It also provides functions to break text into lines and change the end-of-line convention. MIME is described mainly in RFC 2045, 2046, 2047, 2048, and 2049.

All functionality provided by the MIME module follows the ideas presented in LTN012, Filters sources and sinks.

To obtain the mime namespace, run:

-- loads the MIME module and everything it requires
local mime = require("mime")

High-level filters

mime.decode("base64")
mime.decode("quoted-printable")

Returns a filter that decodes data from a given transfer content encoding.

mime.encode("base64")
mime.encode("quoted-printable" [, mode])

Returns a filter that encodes data according to a given transfer content encoding.

In the Quoted-Printable case, the user can specify whether the data is textual or binary, by passing the mode strings "text" or "binary". Mode defaults to "text".

Although both transfer content encodings specify a limit for the line length, the encoding filters do not break text into lines (for added flexibility). Below is a filter that converts binary data to the Base64 transfer content encoding and breaks it into lines of the correct size.

base64 = ltn12.filter.chain(
  mime.encode("base64"),
  mime.wrap("base64")
)

Note: Text data has to be converted to canonic form before being encoded.

base64 = ltn12.filter.chain(
  mime.normalize(),
  mime.encode("base64"),
  mime.wrap("base64")
)

mime.normalize([marker])

Converts most common end-of-line markers to a specific given marker. </