webmcp

diff framework/env/encode/mime/mail.lua @ 0:9fdfb27f8e67

Version 1.0.0
author jbe/bsw
date Sun Oct 25 12:00:00 2009 +0100 (2009-10-25)
parents
children b7596f5158d4
line diff
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/framework/env/encode/mime/mail.lua	Sun Oct 25 12:00:00 2009 +0100
     1.3 @@ -0,0 +1,66 @@
     1.4 +local un  = encode.mime.unstructured_header_line
     1.5 +local mbl = encode.mime.mailbox_list_header_line
     1.6 +
     1.7 +local function encode_container(parts, container)
     1.8 +  if container.multipart then
     1.9 +    local boundary
    1.10 +    boundary = "BOUNDARY--" .. multirand.string(
    1.11 +      24,
    1.12 +      "123456789BCDFGHJKLMNPQRSTVWXYZbcdfghjklmnpqrstvwxyz"
    1.13 +    )
    1.14 +    parts[#parts+1] = "Content-Type: "
    1.15 +    parts[#parts+1] = "multipart/"
    1.16 +    parts[#parts+1] = container.multipart
    1.17 +    parts[#parts+1] = "; boundary="
    1.18 +    parts[#parts+1] = boundary
    1.19 +    parts[#parts+1] = "\r\n\r\nMIME multipart\r\n"  -- last \r\n optional
    1.20 +    for idx, sub_container in ipairs(container) do
    1.21 +      parts[#parts+1] = "\r\n--"
    1.22 +      parts[#parts+1] = boundary
    1.23 +      parts[#parts+1] = "\r\n"
    1.24 +      encode_container(parts, sub_container)
    1.25 +    end
    1.26 +    parts[#parts+1] = "\r\n--"
    1.27 +    parts[#parts+1] = boundary
    1.28 +    parts[#parts+1] = "--\r\n"
    1.29 +  else
    1.30 +    parts[#parts+1] = "Content-Type: "
    1.31 +    parts[#parts+1] = container.content_type or "text/plain"
    1.32 +    parts[#parts+1] = "\r\n"
    1.33 +    if container.content_id then
    1.34 +      parts[#parts+1] = "Content-ID: <"
    1.35 +      parts[#parts+1] = container.content_id
    1.36 +      parts[#parts+1] = ">\r\n"
    1.37 +    end
    1.38 +    if container.attachment_filename then
    1.39 +      parts[#parts+1] = "Content-Disposition: attachment; filename="
    1.40 +      parts[#parts+1] = encode.mime.atom_token(
    1.41 +        container.attachment_filename
    1.42 +      )
    1.43 +      parts[#parts+1] = "\r\n"
    1.44 +    end
    1.45 +    if container.binary then
    1.46 +      parts[#parts+1] = "Content-Transfer-Encoding: base64\r\n\r\n"
    1.47 +      parts[#parts+1] = encode.mime.base64(container.content)
    1.48 +    else
    1.49 +      parts[#parts+1] =
    1.50 +        "Content-Transfer-Encoding: quoted-printable\r\n\r\n"
    1.51 +      parts[#parts+1] =
    1.52 +        encode.mime.quoted_printable_text_content(container.content)
    1.53 +    end
    1.54 +  end
    1.55 +end
    1.56 +
    1.57 +function encode.mime.mail(args)
    1.58 +  local parts = {}
    1.59 +  parts[#parts+1] = mbl("From",     args.from)
    1.60 +  parts[#parts+1] = mbl("Sender",   args.sender)
    1.61 +  parts[#parts+1] = mbl("Reply-To", args.reply_to)
    1.62 +  parts[#parts+1] = mbl("To",       args.to)
    1.63 +  parts[#parts+1] = mbl("Cc",       args.cc)
    1.64 +  parts[#parts+1] = mbl("Bcc",      args.bcc)
    1.65 +  parts[#parts+1] = un("Subject", args.subject)
    1.66 +  parts[#parts+1] = "MIME-Version: 1.0\r\n"
    1.67 +  encode_container(parts, args)
    1.68 +  return table.concat(parts)
    1.69 +end

Impressum / About Us