File mimer.lua
MIME Mail Emulator. Module to build on the fly a message from a header, a body (both in html or plain text format), a list of attachments urls
Functions
| Private.quoted_printable_encode (s) | Encodes the message for mail transfer. |
| Private.txt2mailnotencoded (s) | Converts a plain text string to a \r\n encoded message, ready to send as a RETR response. |
| callback_mangler (f) | Transforms a classical callback f(s,len) to a mimer compliant callback. |
| decodeQuotedPrintable (qp) | Decodes a quoted printable string (7-bit) into an 8-bit encoded string |
| decodeUTF8 (utf8) | Converts all UTF-8 character sets to unicode/ASCII characters to generate ISO-8859-1 email bodies etc. |
| encodeUTF8 (unicode) | Converts all unicode characters (>127) into UTF-8 character sets |
| html2txtmail (s, base_uri) | Tryes to convert an HTML document to a human readable plain text. |
| html2txtplain (s, base_uri) | Converts an HTML document to a plain text file, removing tags and unescaping &XXXX; sequences. |
| pipe_msg (headers, body, body_html, base_uri, attachments, browser, send_cb, inlineids, text_encoding) | Builds a MIME encoded message and pipes it to send_cb. |
| remove_lines_in_proper_mail_header (s, p) | Deletes some fields in a mail header. |
| remove_tags (s, p) | Removes unwanted tags from an html string. |
| txt2mail (s) | Converts a plain text string to a \r\n encoded message, ready to send as a RETR response. |
Functions
- Private.quoted_printable_encode (s)
-
Encodes the message for mail transfer. must be
Parameters
- s:
- Private.txt2mailnotencoded (s)
-
Converts a plain text string to a \r\n encoded message, ready to send as a RETR response.
Parameters
- s:
- callback_mangler (f)
-
Transforms a classical callback f(s,len) to a mimer compliant callback.
Parameters
- f: function a function that takes s,len and returns len,error.
Return value:
function a callback that returns non nil to stop (instead of 0,"" or nil,""). - decodeQuotedPrintable (qp)
-
Decodes a quoted printable string (7-bit) into an 8-bit encoded string
Parameters
- qp: quoted printable string
Return value:
a ASCII/ISO-8859-1 8-bit conform string - decodeUTF8 (utf8)
-
Converts all UTF-8 character sets to unicode/ASCII characters to generate ISO-8859-1 email bodies etc.
Parameters
- utf8: UTF-8 encoded string
Return value:
a ASCII/ISO-8859-1 8-bit conform string - encodeUTF8 (unicode)
-
Converts all unicode characters (>127) into UTF-8 character sets
Parameters
- unicode: ASCII or unicoded string
Return value:
a UTF-8 representation - html2txtmail (s, base_uri)
-
Tryes to convert an HTML document to a human readable plain text.
Parameters
- s:
- base_uri:
- html2txtplain (s, base_uri)
-
Converts an HTML document to a plain text file, removing tags and unescaping &XXXX; sequences.
Parameters
- s:
- base_uri:
- pipe_msg (headers, body, body_html, base_uri, attachments, browser, send_cb, inlineids, text_encoding)
-
Builds a MIME encoded message and pipes it to send_cb.
Parameters
- headers: string the mail headers, already mail encoded (\r\n) but without the blank line separator.
- body: string the plain text body, if null it is inferred from the html body that must be present in that case.
- body_html: string the html body, may be null.
- base_uri: string is used to mangle hrefs in the mail html body.
- attachments: table a table { ["filename"] = "http://url" }.
- browser: table used to fetch the attachments.
- send_cb: function the callback to send the message, may be called more then once and may return not nil to stop the ending process.
- inlineids: table a table { ["filename"] = "content-Ids" } which contains the ids for inline attachments (default {}).
- text_encoding: string default "iso-8859-1"
- remove_lines_in_proper_mail_header (s, p)
-
Deletes some fields in a mail header.
Parameters
- s: string a valid mail header.
- p: table a list of mail headers in this form {"content%-type","date"} (with - escaped with %).
Return value:
string the cleaned header. - remove_tags (s, p)
-
Removes unwanted tags from an html string.
Parameters
- s:
- p: table a list of tags in this form {"head","p"}.
Return value:
string the cleaned html. - txt2mail (s)
-
Converts a plain text string to a \r\n encoded message, ready to send as a RETR response.
Parameters
- s: