diff options
author | Caleb Maclennan <caleb@alerque.com> | 2023-11-10 09:12:04 +0300 |
---|---|---|
committer | Caleb Maclennan <caleb@alerque.com> | 2023-11-10 09:12:04 +0300 |
commit | 5c4fc93d5f4137bf4c22ddf1a048c907a4a26727 (patch) | |
tree | a9a68e1f6a9c3bfe2b64fa1c3a4098865b7d3b5d /docs/mime.html | |
parent | ccef3bc4e2aa6ee5b997a80aabb58f4ff0b0e98f (diff) | |
parent | 43a97b7f0053313b43906371dbdc226271e6c8ab (diff) | |
download | luasocket-hjelmeland-patch-1.tar.gz luasocket-hjelmeland-patch-1.tar.bz2 luasocket-hjelmeland-patch-1.zip |
Merge branch 'master' into hjelmeland-patch-1hjelmeland-patch-1
Diffstat (limited to 'docs/mime.html')
-rw-r--r-- | docs/mime.html | 477 |
1 files changed, 477 insertions, 0 deletions
diff --git a/docs/mime.html b/docs/mime.html new file mode 100644 index 0000000..ff4d8e8 --- /dev/null +++ b/docs/mime.html | |||
@@ -0,0 +1,477 @@ | |||
1 | <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" | ||
2 | "http://www.w3.org/TR/html4/strict.dtd"> | ||
3 | <html> | ||
4 | |||
5 | <head> | ||
6 | <meta name="description" content="LuaSocket: MIME support"> | ||
7 | <meta name="keywords" content="Lua, LuaSocket, MIME, Library, Support"> | ||
8 | <title>LuaSocket: MIME module</title> | ||
9 | <link rel="stylesheet" href="reference.css" type="text/css"> | ||
10 | </head> | ||
11 | |||
12 | <body> | ||
13 | |||
14 | <!-- header +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ --> | ||
15 | |||
16 | <div class="header"> | ||
17 | <hr> | ||
18 | <center> | ||
19 | <table summary="LuaSocket logo"> | ||
20 | <tr><td align="center"><a href="http://www.lua.org"> | ||
21 | <img width="128" height="128" border="0" alt="LuaSocket" src="luasocket.png"> | ||
22 | </a></td></tr> | ||
23 | <tr><td align="center" valign="top">Network support for the Lua language | ||
24 | </td></tr> | ||
25 | </table> | ||
26 | <p class="bar"> | ||
27 | <a href="index.html">home</a> · | ||
28 | <a href="index.html#download">download</a> · | ||
29 | <a href="installation.html">installation</a> · | ||
30 | <a href="introduction.html">introduction</a> · | ||
31 | <a href="reference.html">reference</a> | ||
32 | </p> | ||
33 | </center> | ||
34 | <hr> | ||
35 | </div> | ||
36 | |||
37 | <!-- mime +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ --> | ||
38 | |||
39 | <h2 id="mime">MIME</h2> | ||
40 | |||
41 | <p> | ||
42 | The <tt>mime</tt> namespace offers filters that apply and remove common | ||
43 | content transfer encodings, such as Base64 and Quoted-Printable. | ||
44 | It also provides functions to break text into lines and change | ||
45 | the end-of-line convention. | ||
46 | MIME is described mainly in | ||
47 | <a href="http://www.ietf.org/rfc/rfc2045.txt">RFC 2045</a>, | ||
48 | <a href="http://www.ietf.org/rfc/rfc2046.txt">2046</a>, | ||
49 | <a href="http://www.ietf.org/rfc/rfc2047.txt">2047</a>, | ||
50 | <a href="http://www.ietf.org/rfc/rfc2047.txt">2048</a>, and | ||
51 | <a href="http://www.ietf.org/rfc/rfc2048.txt">2049</a>. | ||
52 | </p> | ||
53 | |||
54 | <p> | ||
55 | All functionality provided by the MIME module | ||
56 | follows the ideas presented in | ||
57 | <a href="http://lua-users.org/wiki/FiltersSourcesAndSinks"> | ||
58 | LTN012, Filters sources and sinks</a>. | ||
59 | </p> | ||
60 | |||
61 | <p> | ||
62 | To obtain the <tt>mime</tt> namespace, run: | ||
63 | </p> | ||
64 | |||
65 | <pre class="example"> | ||
66 | -- loads the MIME module and everything it requires | ||
67 | local mime = require("mime") | ||
68 | </pre> | ||
69 | |||
70 | |||
71 | <!-- High-level +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ --> | ||
72 | |||
73 | <h3 id="high">High-level filters</h3> | ||
74 | |||
75 | |||
76 | <!-- decode +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ --> | ||
77 | |||
78 | <p class="name" id="decode"> | ||
79 | mime.<b>decode(</b>"base64"<b>)</b><br> | ||
80 | mime.<b>decode(</b>"quoted-printable"<b>)</b> | ||
81 | </p> | ||
82 | |||
83 | <p class="description"> | ||
84 | Returns a filter that decodes data from a given transfer content | ||
85 | encoding. | ||
86 | </p> | ||
87 | |||
88 | <!-- encode +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ --> | ||
89 | |||
90 | <p class="name" id="encode"> | ||
91 | mime.<b>encode(</b>"base64"<b>)</b><br> | ||
92 | mime.<b>encode(</b>"quoted-printable" [, mode]<b>)</b> | ||
93 | </p> | ||
94 | |||
95 | <p class="description"> | ||
96 | Returns a filter that encodes data according to a given transfer content | ||
97 | encoding. | ||
98 | </p> | ||
99 | |||
100 | <p class="parameters"> | ||
101 | In the Quoted-Printable case, the user can specify whether the data is | ||
102 | textual or binary, by passing the <tt>mode</tt> strings "<tt>text</tt>" or | ||
103 | "<tt>binary</tt>". <tt>Mode</tt> defaults to "<tt>text</tt>". | ||
104 | </p> | ||
105 | |||
106 | <p class="note"> | ||
107 | Although both transfer content encodings specify a limit for the line | ||
108 | length, the encoding filters do <em>not</em> break text into lines (for | ||
109 | added flexibility). | ||
110 | Below is a filter that converts binary data to the Base64 transfer content | ||
111 | encoding and breaks it into lines of the correct size. | ||
112 | </p> | ||
113 | |||
114 | <pre class="example"> | ||
115 | base64 = ltn12.filter.chain( | ||
116 | mime.encode("base64"), | ||
117 | mime.wrap("base64") | ||
118 | ) | ||
119 | </pre> | ||
120 | |||
121 | <p class="note"> | ||
122 | Note: Text data <em>has</em> to be converted to canonic form | ||
123 | <em>before</em> being encoded. | ||
124 | </p> | ||
125 | |||
126 | <pre class="example"> | ||
127 | base64 = ltn12.filter.chain( | ||
128 | mime.normalize(), | ||
129 | mime.encode("base64"), | ||
130 | mime.wrap("base64") | ||
131 | ) | ||
132 | </pre> | ||
133 | |||
134 | <!-- normalize ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ --> | ||
135 | |||
136 | <p class="name" id="normalize"> | ||
137 | mime.<b>normalize(</b>[marker]<b>)</b> | ||
138 | </p> | ||
139 | |||
140 | <p class="description"> | ||
141 | Converts most common end-of-line markers to a specific given marker. | ||
142 | </p> | ||
143 | |||
144 | <p class="parameters"> | ||
145 | <tt>Marker</tt> is the new marker. It defaults to CRLF, the canonic | ||
146 | end-of-line marker defined by the MIME standard. | ||
147 | </p> | ||
148 | |||
149 | <p class="return"> | ||
150 | The function returns a filter that performs the conversion. | ||
151 | </p> | ||
152 | |||
153 | <p class="note"> | ||
154 | Note: There is no perfect solution to this problem. Different end-of-line | ||
155 | markers are an evil that will probably plague developers forever. | ||
156 | This function, however, will work perfectly for text created with any of | ||
157 | the most common end-of-line markers, i.e. the Mac OS (CR), the Unix (LF), | ||
158 | or the DOS (CRLF) conventions. Even if the data has mixed end-of-line | ||
159 | markers, the function will still work well, although it doesn't | ||
160 | guarantee that the number of empty lines will be correct. | ||
161 | </p> | ||
162 | |||
163 | <!-- stuff +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ --> | ||
164 | |||
165 | <p class="name" id="stuff"> | ||
166 | mime.<b>stuff()</b><br> | ||
167 | </p> | ||
168 | |||
169 | <p class="description"> | ||
170 | Creates and returns a filter that performs stuffing of SMTP messages. | ||
171 | </p> | ||
172 | |||
173 | <p class="note"> | ||
174 | Note: The <a href="smtp.html#send"><tt>smtp.send</tt></a> function | ||
175 | uses this filter automatically. You don't need to chain it with your | ||
176 | source, or apply it to your message body. | ||
177 | </p> | ||
178 | |||
179 | <!-- wrap +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ --> | ||
180 | |||
181 | <p class="name" id="wrap"> | ||
182 | mime.<b>wrap(</b>"text" [, length]<b>)</b><br> | ||
183 | mime.<b>wrap(</b>"base64"<b>)</b><br> | ||
184 | mime.<b>wrap(</b>"quoted-printable"<b>)</b> | ||
185 | </p> | ||
186 | |||
187 | <p class="description"> | ||
188 | Returns a filter that breaks data into lines. | ||
189 | </p> | ||
190 | |||
191 | <p class="parameters"> | ||
192 | The "<tt>text</tt>" line-wrap filter simply breaks text into lines by | ||
193 | inserting CRLF end-of-line markers at appropriate positions. | ||
194 | <tt>Length</tt> defaults 76. | ||
195 | The "<tt>base64</tt>" line-wrap filter works just like the default | ||
196 | "<tt>text</tt>" line-wrap filter with default length. | ||
197 | The function can also wrap "<tt>quoted-printable</tt>" lines, taking care | ||
198 | not to break lines in the middle of an escaped character. In that case, the | ||
199 | line length is fixed at 76. | ||
200 | </p> | ||
201 | |||
202 | <p class="note"> | ||
203 | For example, to create an encoding filter for the Quoted-Printable transfer content encoding of text data, do the following: | ||
204 | </p> | ||
205 | |||
206 | <pre class="example"> | ||
207 | qp = ltn12.filter.chain( | ||
208 | mime.normalize(), | ||
209 | mime.encode("quoted-printable"), | ||
210 | mime.wrap("quoted-printable") | ||
211 | ) | ||
212 | </pre> | ||
213 | |||
214 | <p class="note"> | ||
215 | Note: To break into lines with a different end-of-line convention, apply | ||
216 | a normalization filter after the line break filter. | ||
217 | </p> | ||
218 | |||
219 | <!-- Low-level ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ --> | ||
220 | |||
221 | <h3 id="low">Low-level filters</h3> | ||
222 | |||
223 | <!-- b64 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ --> | ||
224 | |||
225 | <p class="name" id="b64"> | ||
226 | A, B = mime.<b>b64(</b>C [, D]<b>)</b> | ||
227 | </p> | ||
228 | |||
229 | <p class="description"> | ||
230 | Low-level filter to perform Base64 encoding. | ||
231 | </p> | ||
232 | |||
233 | <p class="description"> | ||
234 | <tt>A</tt> is the encoded version of the largest prefix of | ||
235 | <tt>C..D</tt> | ||
236 | that can be encoded unambiguously. <tt>B</tt> has the remaining bytes of | ||
237 | <tt>C..D</tt>, <em>before</em> encoding. | ||
238 | If <tt>D</tt> is <tt><b>nil</b></tt>, <tt>A</tt> is padded with | ||
239 | the encoding of the remaining bytes of <tt>C</tt>. | ||
240 | </p> | ||
241 | |||
242 | <p class="note"> | ||
243 | Note: The simplest use of this function is to encode a string into it's | ||
244 | Base64 transfer content encoding. Notice the extra parenthesis around the | ||
245 | call to <tt>mime.b64</tt>, to discard the second return value. | ||
246 | </p> | ||
247 | |||
248 | <pre class="example"> | ||
249 | print((mime.b64("diego:password"))) | ||
250 | --> ZGllZ286cGFzc3dvcmQ= | ||
251 | </pre> | ||
252 | |||
253 | <!-- dot +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ --> | ||
254 | <p class="name" id="dot"> | ||
255 | A, n = mime.<b>dot(</b>m [, B]<b>)</b> | ||
256 | </p> | ||
257 | |||
258 | <p class="description"> | ||
259 | Low-level filter to perform SMTP stuffing and enable transmission of | ||
260 | messages containing the sequence "CRLF.CRLF". | ||
261 | </p> | ||
262 | |||
263 | <p class="parameters"> | ||
264 | <tt>A</tt> is the stuffed version of <tt>B</tt>. '<tt>n</tt>' gives the | ||
265 | number of characters from the sequence CRLF seen in the end of <tt>B</tt>. | ||
266 | '<tt>m</tt>' should tell the same, but for the previous chunk. | ||
267 | </p> | ||
268 | |||
269 | <p class="note">Note: The message body is defined to begin with | ||
270 | an implicit CRLF. Therefore, to stuff a message correctly, the | ||
271 | first <tt>m</tt> should have the value 2. | ||
272 | </p> | ||
273 | |||
274 | <pre class="example"> | ||
275 | print((string.gsub(mime.dot(2, ".\r\nStuffing the message.\r\n.\r\n."), "\r\n", "\\n"))) | ||
276 | --> ..\nStuffing the message.\n..\n.. | ||
277 | </pre> | ||
278 | |||
279 | <p class="note"> | ||
280 | Note: The <a href="smtp.html#send"><tt>smtp.send</tt></a> function | ||
281 | uses this filter automatically. You don't need to | ||
282 | apply it again. | ||
283 | </p> | ||
284 | |||
285 | <!-- eol ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ --> | ||
286 | |||
287 | <p class="name" id="eol"> | ||
288 | A, B = mime.<b>eol(</b>C [, D, marker]<b>)</b> | ||
289 | </p> | ||
290 | |||
291 | <p class="description"> | ||
292 | Low-level filter to perform end-of-line marker translation. | ||
293 | For each chunk, the function needs to know if the last character of the | ||
294 | previous chunk could be part of an end-of-line marker or not. This is the | ||
295 | context the function receives besides the chunk. An updated version of | ||
296 | the context is returned after each new chunk. | ||
297 | </p> | ||
298 | |||
299 | <p class="parameters"> | ||
300 | <tt>A</tt> is the translated version of <tt>D</tt>. <tt>C</tt> is the | ||
301 | ASCII value of the last character of the previous chunk, if it was a | ||
302 | candidate for line break, or 0 otherwise. | ||
303 | <tt>B</tt> is the same as <tt>C</tt>, but for the current | ||
304 | chunk. <tt>Marker</tt> gives the new end-of-line marker and defaults to CRLF. | ||
305 | </p> | ||
306 | |||
307 | <pre class="example"> | ||
308 | -- translates the end-of-line marker to UNIX | ||
309 | unix = mime.eol(0, dos, "\n") | ||
310 | </pre> | ||
311 | |||
312 | <!-- qp ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ --> | ||
313 | |||
314 | <p class="name" id="qp"> | ||
315 | A, B = mime.<b>qp(</b>C [, D, marker]<b>)</b> | ||
316 | </p> | ||
317 | |||
318 | <p class="description"> | ||
319 | Low-level filter to perform Quoted-Printable encoding. | ||
320 | </p> | ||
321 | |||
322 | <p class="parameters"> | ||
323 | <tt>A</tt> is the encoded version of the largest prefix of | ||
324 | <tt>C..D</tt> | ||
325 | that can be encoded unambiguously. <tt>B</tt> has the remaining bytes of | ||
326 | <tt>C..D</tt>, <em>before</em> encoding. | ||
327 | If <tt>D</tt> is <tt><b>nil</b></tt>, <tt>A</tt> is padded with | ||
328 | the encoding of the remaining bytes of <tt>C</tt>. | ||
329 | Throughout encoding, occurrences of CRLF are replaced by the | ||
330 | <tt>marker</tt>, which itself defaults to CRLF. | ||
331 | </p> | ||
332 | |||
333 | <p class="note"> | ||
334 | Note: The simplest use of this function is to encode a string into it's | ||
335 | Quoted-Printable transfer content encoding. | ||
336 | Notice the extra parenthesis around the call to <tt>mime.qp</tt>, to discard the second return value. | ||
337 | </p> | ||
338 | |||
339 | <pre class="example"> | ||
340 | print((mime.qp("ma��"))) | ||
341 | --> ma=E7=E3= | ||
342 | </pre> | ||
343 | |||
344 | <!-- qpwrp ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ --> | ||
345 | |||
346 | <p class="name" id="qpwrp"> | ||
347 | A, m = mime.<b>qpwrp(</b>n [, B, length]<b>)</b> | ||
348 | </p> | ||
349 | |||
350 | <p class="description"> | ||
351 | Low-level filter to break Quoted-Printable text into lines. | ||
352 | </p> | ||
353 | |||
354 | <p class="parameters"> | ||
355 | <tt>A</tt> is a copy of <tt>B</tt>, broken into lines of at most | ||
356 | <tt>length</tt> bytes (defaults to 76). | ||
357 | '<tt>n</tt>' should tell how many bytes are left for the first | ||
358 | line of <tt>B</tt> and '<tt>m</tt>' returns the number of bytes | ||
359 | left in the last line of <tt>A</tt>. | ||
360 | </p> | ||
361 | |||
362 | <p class="note"> | ||
363 | Note: Besides breaking text into lines, this function makes sure the line | ||
364 | breaks don't fall in the middle of an escaped character combination. Also, | ||
365 | this function only breaks lines that are bigger than <tt>length</tt> bytes. | ||
366 | </p> | ||
367 | |||
368 | <!-- unb64 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ --> | ||
369 | |||
370 | <p class="name" id="unb64"> | ||
371 | A, B = mime.<b>unb64(</b>C [, D]<b>)</b> | ||
372 | </p> | ||
373 | |||
374 | <p class="description"> | ||
375 | Low-level filter to perform Base64 decoding. | ||
376 | </p> | ||
377 | |||
378 | <p class="parameters"> | ||
379 | <tt>A</tt> is the decoded version of the largest prefix of | ||
380 | <tt>C..D</tt> | ||
381 | that can be decoded unambiguously. <tt>B</tt> has the remaining bytes of | ||
382 | <tt>C..D</tt>, <em>before</em> decoding. | ||
383 | If <tt>D</tt> is <tt><b>nil</b></tt>, <tt>A</tt> is the empty string | ||
384 | and <tt>B</tt> returns whatever couldn't be decoded. | ||
385 | </p> | ||
386 | |||
387 | <p class="note"> | ||
388 | Note: The simplest use of this function is to decode a string from it's | ||
389 | Base64 transfer content encoding. | ||
390 | Notice the extra parenthesis around the call to <tt>mime.unqp</tt>, to discard the second return value. | ||
391 | </p> | ||
392 | |||
393 | <pre class="example"> | ||
394 | print((mime.unb64("ZGllZ286cGFzc3dvcmQ="))) | ||
395 | --> diego:password | ||
396 | </pre> | ||
397 | |||
398 | <!-- unqp +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ --> | ||
399 | |||
400 | <p class="name" id="unqp"> | ||
401 | A, B = mime.<b>unqp(</b>C [, D]<b>)</b> | ||
402 | </p> | ||
403 | |||
404 | <p class="description"> | ||
405 | Low-level filter to remove the Quoted-Printable transfer content encoding | ||
406 | from data. | ||
407 | </p> | ||
408 | |||
409 | <p class="parameters"> | ||
410 | <tt>A</tt> is the decoded version of the largest prefix of | ||
411 | <tt>C..D</tt> | ||
412 | that can be decoded unambiguously. <tt>B</tt> has the remaining bytes of | ||
413 | <tt>C..D</tt>, <em>before</em> decoding. | ||
414 | If <tt>D</tt> is <tt><b>nil</b></tt>, <tt>A</tt> is augmented with | ||
415 | the encoding of the remaining bytes of <tt>C</tt>. | ||
416 | </p> | ||
417 | |||
418 | <p class="note"> | ||
419 | Note: The simplest use of this function is to decode a string from it's | ||
420 | Quoted-Printable transfer content encoding. | ||
421 | Notice the extra parenthesis around the call to <tt>mime.unqp</tt>, to discard the second return value. | ||
422 | </p> | ||
423 | |||
424 | <pre class="example"> | ||
425 | print((mime.qp("ma=E7=E3="))) | ||
426 | --> ma�� | ||
427 | </pre> | ||
428 | |||
429 | <!-- wrp ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ --> | ||
430 | |||
431 | <p class="name" id="wrp"> | ||
432 | A, m = mime.<b>wrp(</b>n [, B, length]<b>)</b> | ||
433 | </p> | ||
434 | |||
435 | <p class="description"> | ||
436 | Low-level filter to break text into lines with CRLF marker. | ||
437 | Text is assumed to be in the <a href="#normalize"><tt>normalize</tt></a> form. | ||
438 | </p> | ||
439 | |||
440 | <p class="parameters"> | ||
441 | <tt>A</tt> is a copy of <tt>B</tt>, broken into lines of at most | ||
442 | <tt>length</tt> bytes (defaults to 76). | ||
443 | '<tt>n</tt>' should tell how many bytes are left for the first | ||
444 | line of <tt>B</tt> and '<tt>m</tt>' returns the number of bytes | ||
445 | left in the last line of <tt>A</tt>. | ||
446 | </p> | ||
447 | |||
448 | <p class="note"> | ||
449 | Note: This function only breaks lines that are bigger than | ||
450 | <tt>length</tt> bytes. The resulting line length does not include the CRLF | ||
451 | marker. | ||
452 | </p> | ||
453 | |||
454 | |||
455 | <!-- footer +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ --> | ||
456 | |||
457 | <div class="footer"> | ||
458 | <hr> | ||
459 | <center> | ||
460 | <p class="bar"> | ||
461 | <a href="index.html">home</a> · | ||
462 | <a href="index.html#down">download</a> · | ||
463 | <a href="installation.html">installation</a> · | ||
464 | <a href="introduction.html">introduction</a> · | ||
465 | <a href="reference.html">reference</a> | ||
466 | </p> | ||
467 | <p> | ||
468 | <small> | ||
469 | Last modified by Diego Nehab on <br> | ||
470 | Fri Mar 4 15:19:17 BRT 2016 | ||
471 | </small> | ||
472 | </p> | ||
473 | </center> | ||
474 | </div> | ||
475 | |||
476 | </body> | ||
477 | </html> | ||