From f470cc086bf9edb3348a66e95b6c97fa10629054 Mon Sep 17 00:00:00 2001 From: pixel Date: Fri, 12 Oct 2007 15:18:26 +0000 Subject: Adding MailClient to LuaTask. --- lib/LuaTask.cc | 62 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 61 insertions(+), 1 deletion(-) diff --git a/lib/LuaTask.cc b/lib/LuaTask.cc index fdb723d..d25efda 100644 --- a/lib/LuaTask.cc +++ b/lib/LuaTask.cc @@ -17,7 +17,7 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -/* $Id: LuaTask.cc,v 1.16 2007-07-27 10:05:52 pixel Exp $ */ +/* $Id: LuaTask.cc,v 1.17 2007-10-12 15:18:26 pixel Exp $ */ #include #include @@ -25,6 +25,9 @@ #ifndef LUATASK_OMIT_HTTPCLIENT #include #endif +#ifndef LUATASK_OMIT_MAILCLIENT +#include +#endif #ifndef LUATASK_OMIT_COMMAND #include #endif @@ -80,6 +83,25 @@ String LuaTask::GetName() { return "LuaTask(" + cmd + ")"; } +std::vector LuaTask::array_to_vector(int index) throw (GeneralException) { + std::vector r; + + if (L->isnil(index)) + return r; + + if (!L->istable(index)) { + throw GeneralException("Argument isn't a table."); + } + + L->push(); + while(L->next(index) != 0) { + r.push_back(L->tostring(-1)); + L->pop(); + } + + return r; +} + int LuaTask::Do() throw (GeneralException) { bool yielded; switch (current) { @@ -100,6 +122,15 @@ int LuaTask::Do() throw (GeneralException) { } #endif +#ifndef LUATASK_OMIT_MAILCLIENT + if (task == "MailClient") { + L->push(dynamic_cast(c)->GetStatus()); + nargs = 1; + delete b; + b = 0; + } +#endif + #ifndef LUATASK_OMIT_COMMAND if (task == "Command") { delete p; @@ -165,6 +196,35 @@ int LuaTask::Do() throw (GeneralException) { WaitFor(c); Suspend(TASK_ON_HOLD); #endif +#ifndef LUATASK_OMIT_MAILCLIENT + } else if (task == "MailClient") { + String smtp, subject, from, body; + MailClient::strings_t headers, tos, ccs, bccs, fakes; + + if (L->gettop() != 9) { + L->error("Incorrect parameters to MailClient."); + return TASK_DONE; + } + smtp = L->tostring(1); + subject = L->tostring(2); + from = L->tostring(3); + try { + headers = array_to_vector(4); + tos = array_to_vector(5); + ccs = array_to_vector(6); + bccs = array_to_vector(7); + fakes = array_to_vector(8); + } catch (GeneralException e) { + L->error("Incorrect parameters to MailClient."); + } + body = L->tostring(9); + + b = new Buffer(true); + (*b) << body; + c = new MailClient(smtp, subject, from, headers, tos, ccs, bccs, fakes, b); + WaitFor(c); + Suspend(TASK_ON_HOLD); +#endif #ifndef LUATASK_OMIT_COMMAND } else if (task == "Command") { pid_t pid; -- cgit v1.2.3