summaryrefslogtreecommitdiff
path: root/lib/LuaTask.cc
diff options
context:
space:
mode:
Diffstat (limited to 'lib/LuaTask.cc')
-rw-r--r--lib/LuaTask.cc62
1 files changed, 61 insertions, 1 deletions
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 <LuaTask.h>
#include <LuaHandle.h>
@@ -25,6 +25,9 @@
#ifndef LUATASK_OMIT_HTTPCLIENT
#include <HttpClient.h>
#endif
+#ifndef LUATASK_OMIT_MAILCLIENT
+#include <MailClient.h>
+#endif
#ifndef LUATASK_OMIT_COMMAND
#include <CopyJob.h>
#endif
@@ -80,6 +83,25 @@ String LuaTask::GetName() {
return "LuaTask(" + cmd + ")";
}
+std::vector<String> LuaTask::array_to_vector(int index) throw (GeneralException) {
+ std::vector<String> 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<MailClient *>(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;