diff --git a/doc/mime.html b/doc/mime.html index ae136fd..8cb3507 100644 --- a/doc/mime.html +++ b/doc/mime.html @@ -72,34 +72,6 @@ local mime = require("mime")

High-level filters

- - -

-mime.normalize([marker]) -

- -

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

- -

-Marker is the new marker. It defaults to CRLF, the canonic -end-of-line marker defined by the MIME standard. -

- -

-The function returns a filter that performs the conversion. -

- -

-Note: There is no perfect solution to this problem. Different end-of-line -markers are an evil that will probably plague developers forever. -This function, however, will work perfectly for text created with any of -the most common end-of-line markers, i.e. the Mac OS (CR), the Unix (LF), -or the DOS (CRLF) conventions. Even if the data has mixed end-of-line -markers, the function will still work well, although it doesn't -guarantee that the number of empty lines will be correct. -

@@ -159,6 +131,35 @@ base64 = ltn12.filter.chain( ) + + +

+mime.normalize([marker]) +

+ +

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

+ +

+Marker is the new marker. It defaults to CRLF, the canonic +end-of-line marker defined by the MIME standard. +

+ +

+The function returns a filter that performs the conversion. +

+ +

+Note: There is no perfect solution to this problem. Different end-of-line +markers are an evil that will probably plague developers forever. +This function, however, will work perfectly for text created with any of +the most common end-of-line markers, i.e. the Mac OS (CR), the Unix (LF), +or the DOS (CRLF) conventions. Even if the data has mixed end-of-line +markers, the function will still work well, although it doesn't +guarantee that the number of empty lines will be correct. +

+

@@ -466,7 +467,7 @@ marker.

Last modified by Diego Nehab on
-Thu Apr 20 00:25:44 EDT 2006 +Fri Mar 4 15:19:17 BRT 2016

diff --git a/doc/reference.html b/doc/reference.html index 878e7d2..287dc19 100644 --- a/doc/reference.html +++ b/doc/reference.html @@ -187,6 +187,7 @@ Support, Manual"> getpeername, getsockname, getstats, +gettimeout, listen, receive, send, @@ -207,6 +208,7 @@ Support, Manual"> getoption, getpeername, getsockname, +gettimeout, receive, receivefrom, send, diff --git a/doc/smtp.html b/doc/smtp.html index bbbff80..600ec37 100644 --- a/doc/smtp.html +++ b/doc/smtp.html @@ -114,6 +114,124 @@ the SMTP module:
  • ZONE: default time zone. + + +

    +smtp.message(mesgt) +

    + +

    +Returns a simple +LTN12 source that sends an SMTP message body, possibly multipart (arbitrarily deep). +

    + +

    +The only parameter of the function is a table describing the message. +Mesgt has the following form (notice the recursive structure): +

    + +
    + + +
    +mesgt = {
    +  headers = header-table,
    +  body = LTN12 source or string or +multipart-mesgt
    +}

    +multipart-mesgt = {
    +  [preamble = string,]
    +  [1] = mesgt,
    +  [2] = mesgt,
    +  ...
    +  [n] = mesgt,
    +  [epilogue = string,]
    +}
    +
    +
    + +

    +For a simple message, all that is needed is a set of headers +and the body. The message body can be given as a string +or as a simple +LTN12 +source. For multipart messages, the body is a table that +recursively defines each part as an independent message, plus an optional +preamble and epilogue. +

    + +

    +The function returns a simple +LTN12 +source that produces the +message contents as defined by mesgt, chunk by chunk. +Hopefully, the following +example will make things clear. When in doubt, refer to the appropriate RFC +as listed in the introduction.

    + +
    +-- load the smtp support and its friends
    +local smtp = require("socket.smtp")
    +local mime = require("mime")
    +local ltn12 = require("ltn12")
    +
    +-- creates a source to send a message with two parts. The first part is 
    +-- plain text, the second part is a PNG image, encoded as base64.
    +source = smtp.message{
    +  headers = {
    +     -- Remember that headers are *ignored* by smtp.send. 
    +     from = "Sicrano de Oliveira <sicrano@example.com>",
    +     to = "Fulano da Silva <fulano@example.com>",
    +     subject = "Here is a message with attachments"
    +  },
    +  body = {
    +    preamble = "If your client doesn't understand attachments, \r\n" ..
    +               "it will still display the preamble and the epilogue.\r\n" ..
    +               "Preamble will probably appear even in a MIME enabled client.",
    +    -- first part: no headers means plain text, us-ascii.
    +    -- The mime.eol low-level filter normalizes end-of-line markers.
    +    [1] = { 
    +      body = mime.eol(0, [[
    +        Lines in a message body should always end with CRLF. 
    +        The smtp module will *NOT* perform translation. However, the 
    +        send function *DOES* perform SMTP stuffing, whereas the message
    +        function does *NOT*.
    +      ]])
    +    },
    +    -- second part: headers describe content to be a png image, 
    +    -- sent under the base64 transfer content encoding.
    +    -- notice that nothing happens until the message is actually sent. 
    +    -- small chunks are loaded into memory right before transmission and 
    +    -- translation happens on the fly.
    +    [2] = { 
    +      headers = {
    +        ["content-type"] = 'image/png; name="image.png"',
    +        ["content-disposition"] = 'attachment; filename="image.png"',
    +        ["content-description"] = 'a beautiful image',
    +        ["content-transfer-encoding"] = "BASE64"
    +      },
    +      body = ltn12.source.chain(
    +        ltn12.source.file(io.open("image.png", "rb")),
    +        ltn12.filter.chain(
    +          mime.encode("base64"),
    +          mime.wrap()
    +        )
    +      )
    +    },
    +    epilogue = "This might also show up, but after the attachments"
    +  }
    +}
    +
    +-- finally send it
    +r, e = smtp.send{
    +    from = "<sicrano@example.com>",
    +    rcpt = "<fulano@example.com>",
    +    source = source,
    +}
    +
    + +

    @@ -275,123 +393,6 @@ r, e = smtp.send{ } - - -

    -smtp.message(mesgt) -

    - -

    -Returns a simple -LTN12 source that sends an SMTP message body, possibly multipart (arbitrarily deep). -

    - -

    -The only parameter of the function is a table describing the message. -Mesgt has the following form (notice the recursive structure): -

    - -
    - - -
    -mesgt = {
    -  headers = header-table,
    -  body = LTN12 source or string or -multipart-mesgt
    -}

    -multipart-mesgt = {
    -  [preamble = string,]
    -  [1] = mesgt,
    -  [2] = mesgt,
    -  ...
    -  [n] = mesgt,
    -  [epilogue = string,]
    -}
    -
    -
    - -

    -For a simple message, all that is needed is a set of headers -and the body. The message body can be given as a string -or as a simple -LTN12 -source. For multipart messages, the body is a table that -recursively defines each part as an independent message, plus an optional -preamble and epilogue. -

    - -

    -The function returns a simple -LTN12 -source that produces the -message contents as defined by mesgt, chunk by chunk. -Hopefully, the following -example will make things clear. When in doubt, refer to the appropriate RFC -as listed in the introduction.

    - -
    --- load the smtp support and its friends
    -local smtp = require("socket.smtp")
    -local mime = require("mime")
    -local ltn12 = require("ltn12")
    -
    --- creates a source to send a message with two parts. The first part is 
    --- plain text, the second part is a PNG image, encoded as base64.
    -source = smtp.message{
    -  headers = {
    -     -- Remember that headers are *ignored* by smtp.send. 
    -     from = "Sicrano de Oliveira <sicrano@example.com>",
    -     to = "Fulano da Silva <fulano@example.com>",
    -     subject = "Here is a message with attachments"
    -  },
    -  body = {
    -    preamble = "If your client doesn't understand attachments, \r\n" ..
    -               "it will still display the preamble and the epilogue.\r\n" ..
    -               "Preamble will probably appear even in a MIME enabled client.",
    -    -- first part: no headers means plain text, us-ascii.
    -    -- The mime.eol low-level filter normalizes end-of-line markers.
    -    [1] = { 
    -      body = mime.eol(0, [[
    -        Lines in a message body should always end with CRLF. 
    -        The smtp module will *NOT* perform translation. However, the 
    -        send function *DOES* perform SMTP stuffing, whereas the message
    -        function does *NOT*.
    -      ]])
    -    },
    -    -- second part: headers describe content to be a png image, 
    -    -- sent under the base64 transfer content encoding.
    -    -- notice that nothing happens until the message is actually sent. 
    -    -- small chunks are loaded into memory right before transmission and 
    -    -- translation happens on the fly.
    -    [2] = { 
    -      headers = {
    -        ["content-type"] = 'image/png; name="image.png"',
    -        ["content-disposition"] = 'attachment; filename="image.png"',
    -        ["content-description"] = 'a beautiful image',
    -        ["content-transfer-encoding"] = "BASE64"
    -      },
    -      body = ltn12.source.chain(
    -        ltn12.source.file(io.open("image.png", "rb")),
    -        ltn12.filter.chain(
    -          mime.encode("base64"),
    -          mime.wrap()
    -        )
    -      )
    -    },
    -    epilogue = "This might also show up, but after the attachments"
    -  }
    -}
    -
    --- finally send it
    -r, e = smtp.send{
    -    from = "<sicrano@example.com>",
    -    rcpt = "<fulano@example.com>",
    -    source = source,
    -}
    -
    -