diff options
Diffstat (limited to 'lib/LuaSmtp.cc')
-rw-r--r-- | lib/LuaSmtp.cc | 166 |
1 files changed, 166 insertions, 0 deletions
diff --git a/lib/LuaSmtp.cc b/lib/LuaSmtp.cc new file mode 100644 index 0000000..8652ece --- /dev/null +++ b/lib/LuaSmtp.cc @@ -0,0 +1,166 @@ +/* + * Baltisot + * Copyright (C) 1999-2008 Nicolas "Pixel" Noble + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#include "MailServer.h" +#include "LuaSmtp.h" +#include "LuaHandle.h" +#include "LuaTask.h" + +class LuaMailHandler : public MailHandler { + public: + LuaMailHandler(Lua * _L); + virtual ~LuaMailHandler(); + virtual bool doProcessMail(Handle * in, const String & from, std::vector<String> tos); + private: + Lua * L; + static int max_id; + int id; +}; + +LuaLuaMailHandler::LuaLuaMailHandler(LuaMailHandler * _mh) : mh(_mh) { } + +enum LuaMailHandler_methods_t { + LUAMAILHANDLER_ONTOP = 0, +}; + +enum LuaMailHandler_functions_t { + LUAMAILHANDLER_NEWMAILHANDLER = 0, +// LUAMAILHANDLER_IMAILHANDLER, +// LUAMAILHANDLER_NMAILHANDLER, +}; + +struct lua_functypes_t LuaMailHandler_methods[] = { + { LUAMAILHANDLER_ONTOP, "OnTop", 0, 0, { } }, + { -1, 0, 0, 0, 0 }, +}; + +struct lua_functypes_t LuaMailHandler_functions[] = { + { LUAMAILHANDLER_NEWMAILHANDLER, "MailHandler", 1, 1, { BLUA_FUNCTION } }, +// { LUAMAILHANDLER_IMAILHANDLER, "iMailHandler", 0, 0, { } }, +// { LUAMAILHANDLER_NMAILHANDLER, "nMailHandler", 2, 2, { BLUA_USERDATA, BLUA_STRING | BLUA_NIL } }, + { -1, 0, 0, 0, 0 }, +}; + +class sLua_LuaMailHandler : public Base { + public: + DECLARE_METHOD(LuaMailHandler, LUAMAILHANDLER_ONTOP); + + DECLARE_FUNCTION(LuaMailHandler, LUAMAILHANDLER_NEWMAILHANDLER); +// DECLARE_FUNCTION(LuaMailHandler, LUAMAILHANDLER_IMAILHANDLER); +// DECLARE_FUNCTION(LuaMailHandler, LUAMAILHANDLER_NMAILHANDLER); + + private: + static int LuaMailHandler_proceed(Lua * L, int n, LuaMailHandler * obj, int caller); + static int LuaMailHandler_proceed_statics(Lua * L, int n, int caller); +}; + +void LuaLuaMailHandler::pushmembers(Lua * L) { + pushme(L, mh, "LuaMailHandler"); + + PUSH_METHOD(LuaMailHandler, LUAMAILHANDLER_ONTOP); +} + +void LuaLuaMailHandler::pushstatics(Lua * L) throw (GeneralException) { + CHECK_METHODS(LuaMailHandler); + CHECK_FUNCTIONS(LuaMailHandler); + + PUSH_FUNCTION(LuaMailHandler, LUAMAILHANDLER_NEWMAILHANDLER); +// PUSH_FUNCTION(LuaMailHandler, LUAMAILHANDLER_IMAILHANDLER); +// PUSH_FUNCTION(LuaMailHandler, LUAMAILHANDLER_NMAILHANDLER); +} + +#define MAILHANDLER_REGISTRY "MAILHANDLERS_KEYS" + +LuaMailHandler::LuaMailHandler(Lua * _L) : MailHandler(), L(_L->Father()) { + id = max_id++; /***FIXME***/ + + L->push(MAILHANDLER_REGISTRY); + L->gettable(LUA_REGISTRYINDEX); + L->push((lua_Number) id); + L->copy(2); + L->settable(); + L->pop(); +} + +LuaMailHandler::~LuaMailHandler() { + L->push(MAILHANDLER_REGISTRY); + L->gettable(LUA_REGISTRYINDEX); + L->push((lua_Number) id); + L->push(); + L->settable(); + L->pop(); +} + +bool LuaMailHandler::doProcessMail(Handle * in, const String & from, std::vector<String> tos) { + return true; +} + +int LuaMailHandler::max_id = 1; + +int sLua_LuaMailHandler::LuaMailHandler_proceed(Lua * L, int n, LuaMailHandler * obj, int caller) { + int r = 0; + + switch (caller) { + case LUAMAILHANDLER_ONTOP: + obj->OnTop(); + break; + } + + return r; +} + +int sLua_LuaMailHandler::LuaMailHandler_proceed_statics(Lua * L, int n, int caller) { + int r = 0; +// MailHandler ** p; + + switch (caller) { + case LUAMAILHANDLER_NEWMAILHANDLER: + { + LuaLuaMailHandler lld(new LuaMailHandler(L)); + lld.pushdestruct(L); + r = 1; + } + break; +/* + case LUAMAILHANDLER_IMAILHANDLER: + L->getglobal("nMailHandler"); + p = (MailHandler **) L->newuser(sizeof(MailHandler *)); + *p = 0; + L->push(); + r = 3; + break; + case LUAMAILHANDLER_NMAILHANDLER: + p = (MailHandler **) L->touserdata(1); + if (*p) { + *p = (*p)->Next(); + } else { + *p = MailHandler::First(); + } + if (*p) { + L->push((*p)->GetPattern()); + } else { + L->push(); + } + r = 1; + break; +*/ + } + + return r; +} |