mirror of
https://github.com/lunarmodules/luasocket.git
synced 2024-12-25 12:08:21 +01:00
smtp.c was eatten by mime.c
This commit is contained in:
parent
94b97bdc00
commit
613534c795
2
TODO
2
TODO
@ -1,6 +1,8 @@
|
||||
|
||||
ajeitar os README.*
|
||||
ajeitar as referencias a RFCS e LTNS em todos os arquivos.
|
||||
|
||||
smtp.o goes to mime.dll
|
||||
make sure sockets are closed when exceptions are raised
|
||||
|
||||
check garbage collection in test*.lua
|
||||
|
@ -230,6 +230,35 @@ print((mime.b64("diego:password")))
|
||||
--> ZGllZ286cGFzc3dvcmQ=
|
||||
</pre>
|
||||
|
||||
<!-- dot +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
|
||||
<p class=name id="dot">
|
||||
A, B = mime.<b>dot(</b>C [, D]<b>)</b>
|
||||
</p>
|
||||
|
||||
<p class=description>
|
||||
Low-level filter to perform Base64 encoding.
|
||||
</p>
|
||||
|
||||
<p class=description>
|
||||
<tt>A</tt> is the encoded version of the largest prefix of
|
||||
<tt>C..D</tt>
|
||||
that can be encoded unambiguously. <tt>B</tt> has the remaining bytes of
|
||||
<tt>C..D</tt>, <em>before</em> encoding.
|
||||
If <tt>D</tt> is <tt><b>nil</b></tt>, <tt>A</tt> is padded with
|
||||
the encoding of the remaining bytes of <tt>C</tt>.
|
||||
</p>
|
||||
|
||||
<p class=note>
|
||||
Note: The simplest use of this function is to encode a string into it's
|
||||
Base64 transfer content encoding. Notice the extra parenthesis around the
|
||||
call to <tt>mime.b64</tt>, to discard the second return value.
|
||||
</p>
|
||||
|
||||
<pre class=example>
|
||||
print((mime.b64("diego:password")))
|
||||
--> ZGllZ286cGFzc3dvcmQ=
|
||||
</pre>
|
||||
|
||||
<!-- eol ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
|
||||
|
||||
<p class=name id="eol">
|
||||
|
@ -1,3 +1,9 @@
|
||||
-----------------------------------------------------------------------------
|
||||
-- Little program to adjust end of line markers.
|
||||
-- LuaSocket sample files
|
||||
-- Author: Diego Nehab
|
||||
-- RCS ID: $Id$
|
||||
-----------------------------------------------------------------------------
|
||||
local mime = require("mime")
|
||||
local ltn12 = require("ltn12")
|
||||
local marker = '\n'
|
||||
|
@ -12,11 +12,6 @@ local socket = require("socket")
|
||||
local ltn12 = require("ltn12")
|
||||
local url = require("url")
|
||||
|
||||
-----------------------------------------------------------------------------
|
||||
-- Setup namespace
|
||||
-----------------------------------------------------------------------------
|
||||
_LOADED["tftp"] = getfenv(1)
|
||||
|
||||
-----------------------------------------------------------------------------
|
||||
-- Program constants
|
||||
-----------------------------------------------------------------------------
|
||||
|
@ -13,11 +13,6 @@ local ltn12 = require("ltn12")
|
||||
local url = require("url")
|
||||
local tp = require("tp")
|
||||
|
||||
-----------------------------------------------------------------------------
|
||||
-- Setup namespace
|
||||
-----------------------------------------------------------------------------
|
||||
_LOADED["ftp"] = getfenv(1)
|
||||
|
||||
-----------------------------------------------------------------------------
|
||||
-- Program constants
|
||||
-----------------------------------------------------------------------------
|
||||
|
@ -13,11 +13,6 @@ local ltn12 = require("ltn12")
|
||||
local mime = require("mime")
|
||||
local url = require("url")
|
||||
|
||||
-----------------------------------------------------------------------------
|
||||
-- Setup namespace
|
||||
-------------------------------------------------------------------------------
|
||||
_LOADED["http"] = getfenv(1)
|
||||
|
||||
-----------------------------------------------------------------------------
|
||||
-- Program constants
|
||||
-----------------------------------------------------------------------------
|
||||
|
@ -5,11 +5,6 @@
|
||||
-- RCS ID: $Id$
|
||||
-----------------------------------------------------------------------------
|
||||
|
||||
-----------------------------------------------------------------------------
|
||||
-- Setup namespace
|
||||
-----------------------------------------------------------------------------
|
||||
_LOADED["ltn12"] = getfenv(1)
|
||||
|
||||
filter = {}
|
||||
source = {}
|
||||
sink = {}
|
||||
|
48
src/mime.c
48
src/mime.c
@ -28,7 +28,9 @@ static int mime_global_qp(lua_State *L);
|
||||
static int mime_global_unqp(lua_State *L);
|
||||
static int mime_global_qpwrp(lua_State *L);
|
||||
static int mime_global_eol(lua_State *L);
|
||||
static int mime_global_dot(lua_State *L);
|
||||
|
||||
static size_t dot(int c, size_t state, luaL_Buffer *buffer);
|
||||
static void b64setup(UC *b64unbase);
|
||||
static size_t b64encode(UC c, UC *input, size_t size, luaL_Buffer *buffer);
|
||||
static size_t b64pad(const UC *input, size_t size, luaL_Buffer *buffer);
|
||||
@ -43,6 +45,7 @@ static size_t qppad(UC *input, size_t size, luaL_Buffer *buffer);
|
||||
|
||||
/* code support functions */
|
||||
static luaL_reg func[] = {
|
||||
{ "dot", mime_global_dot },
|
||||
{ "b64", mime_global_b64 },
|
||||
{ "eol", mime_global_eol },
|
||||
{ "qp", mime_global_qp },
|
||||
@ -659,3 +662,48 @@ static int mime_global_eol(lua_State *L)
|
||||
lua_pushnumber(L, ctx);
|
||||
return 2;
|
||||
}
|
||||
|
||||
/*-------------------------------------------------------------------------*\
|
||||
* Takes one byte and stuff it if needed.
|
||||
\*-------------------------------------------------------------------------*/
|
||||
static size_t dot(int c, size_t state, luaL_Buffer *buffer)
|
||||
{
|
||||
luaL_putchar(buffer, c);
|
||||
switch (c) {
|
||||
case '\r':
|
||||
return 1;
|
||||
case '\n':
|
||||
return (state == 1)? 2: 0;
|
||||
case '.':
|
||||
if (state == 2)
|
||||
luaL_putchar(buffer, '.');
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
/*-------------------------------------------------------------------------*\
|
||||
* Incrementally applies smtp stuffing to a string
|
||||
* A, n = dot(l, D)
|
||||
\*-------------------------------------------------------------------------*/
|
||||
static int mime_global_dot(lua_State *L)
|
||||
{
|
||||
size_t isize = 0, state = (size_t) luaL_checknumber(L, 1);
|
||||
const char *input = luaL_optlstring(L, 2, NULL, &isize);
|
||||
const char *last = input + isize;
|
||||
luaL_Buffer buffer;
|
||||
/* end-of-input blackhole */
|
||||
if (!input) {
|
||||
lua_pushnil(L);
|
||||
lua_pushnumber(L, 2);
|
||||
return 2;
|
||||
}
|
||||
/* process all input */
|
||||
luaL_buffinit(L, &buffer);
|
||||
while (input < last)
|
||||
state = dot(*input++, state, &buffer);
|
||||
luaL_pushresult(&buffer);
|
||||
lua_pushnumber(L, state);
|
||||
return 2;
|
||||
}
|
||||
|
||||
|
10
src/mime.lua
10
src/mime.lua
@ -11,11 +11,6 @@
|
||||
local mime = requirelib("mime", "luaopen_mime", getfenv(1))
|
||||
local ltn12 = require("ltn12")
|
||||
|
||||
-----------------------------------------------------------------------------
|
||||
-- Setup namespace
|
||||
-----------------------------------------------------------------------------
|
||||
_LOADED["mime"] = mime
|
||||
|
||||
-- encode, decode and wrap algorithm tables
|
||||
encodet = {}
|
||||
decodet = {}
|
||||
@ -73,3 +68,8 @@ wrap = choose(wrapt)
|
||||
function normalize(marker)
|
||||
return ltn12.filter.cycle(eol, 0, marker)
|
||||
end
|
||||
|
||||
-- high level stuffing filter
|
||||
function stuff()
|
||||
return ltn12.filter.cycle(dot, 2)
|
||||
end
|
||||
|
13
src/smtp.lua
13
src/smtp.lua
@ -8,17 +8,11 @@
|
||||
-----------------------------------------------------------------------------
|
||||
-- Load required modules
|
||||
-----------------------------------------------------------------------------
|
||||
local smtp = requirelib("smtp", "luaopen_smtp", getfenv(1))
|
||||
local socket = require("socket")
|
||||
local ltn12 = require("ltn12")
|
||||
local mime = require("mime")
|
||||
local tp = require("tp")
|
||||
|
||||
-----------------------------------------------------------------------------
|
||||
-- Setup namespace
|
||||
-----------------------------------------------------------------------------
|
||||
_LOADED["smtp"] = smtp
|
||||
|
||||
-- timeout for connection
|
||||
TIMEOUT = 60
|
||||
-- default server used to send e-mails
|
||||
@ -31,11 +25,6 @@ DOMAIN = os.getenv("SERVER_NAME") or "localhost"
|
||||
-- default time zone (means we don't know)
|
||||
ZONE = "-0000"
|
||||
|
||||
-- high level stuffing filter
|
||||
function stuff()
|
||||
return ltn12.filter.cycle(dot, 2)
|
||||
end
|
||||
|
||||
---------------------------------------------------------------------------
|
||||
-- Low level SMTP API
|
||||
-----------------------------------------------------------------------------
|
||||
@ -110,7 +99,7 @@ function metat.__index:send(mailt)
|
||||
else
|
||||
self:rcpt(mailt.rcpt)
|
||||
end
|
||||
self:data(ltn12.source.chain(mailt.source, stuff()), mailt.step)
|
||||
self:data(ltn12.source.chain(mailt.source, mime.stuff()), mailt.step)
|
||||
end
|
||||
|
||||
function open(server, port)
|
||||
|
@ -11,11 +11,6 @@
|
||||
local socket = require("socket")
|
||||
local ltn12 = require("ltn12")
|
||||
|
||||
-----------------------------------------------------------------------------
|
||||
-- Setup namespace
|
||||
-----------------------------------------------------------------------------
|
||||
_LOADED["tp"] = getfenv(1)
|
||||
|
||||
-----------------------------------------------------------------------------
|
||||
-- Program constants
|
||||
-----------------------------------------------------------------------------
|
||||
|
@ -5,11 +5,6 @@
|
||||
-- RCS ID: $Id$
|
||||
-----------------------------------------------------------------------------
|
||||
|
||||
-----------------------------------------------------------------------------
|
||||
-- Setup namespace
|
||||
-----------------------------------------------------------------------------
|
||||
_LOADED["url"] = getfenv(1)
|
||||
|
||||
-----------------------------------------------------------------------------
|
||||
-- Encodes a string into its escaped hexadecimal representation
|
||||
-- Input
|
||||
|
@ -390,7 +390,7 @@ local r, c, h = http.request {
|
||||
method = "HEAD",
|
||||
url = "http://www.cs.princeton.edu/~diego/"
|
||||
}
|
||||
assert(r and h and c == 200)
|
||||
assert(r and h and (c == 200), c)
|
||||
print("ok")
|
||||
|
||||
------------------------------------------------------------------------
|
||||
|
Loading…
Reference in New Issue
Block a user