"SfR Fresh" - the SfR Freeware/Shareware Archive 
As a special service "SfR Fresh" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting with prefixed line numbers.
Alternatively you can here view or download the uninterpreted source code file.
That can be also achieved for any archive member file by clicking within an archive contents listing on the first character of the file(path) respectively on the according byte size field.
1 #include <stdio.h>
2
3 #include <lua.h>
4 #include <lauxlib.h>
5 #include <lualib.h>
6
7 #include "imapfilter.h"
8
9
10 static int ifcore_noop(lua_State *lua);
11 static int ifcore_login(lua_State *lua);
12 static int ifcore_logout(lua_State *lua);
13 static int ifcore_status(lua_State *lua);
14 static int ifcore_select(lua_State *lua);
15 static int ifcore_close(lua_State *lua);
16 static int ifcore_expunge(lua_State *lua);
17 static int ifcore_search(lua_State *lua);
18 static int ifcore_list(lua_State *lua);
19 static int ifcore_lsub(lua_State *lua);
20 static int ifcore_fetchfast(lua_State *lua);
21 static int ifcore_fetchflags(lua_State *lua);
22 static int ifcore_fetchdate(lua_State *lua);
23 static int ifcore_fetchsize(lua_State *lua);
24 static int ifcore_fetchheader(lua_State *lua);
25 static int ifcore_fetchtext(lua_State *lua);
26 static int ifcore_fetchfields(lua_State *lua);
27 static int ifcore_store(lua_State *lua);
28 static int ifcore_copy(lua_State *lua);
29 static int ifcore_append(lua_State *lua);
30 static int ifcore_create(lua_State *lua);
31 static int ifcore_delete(lua_State *lua);
32 static int ifcore_rename(lua_State *lua);
33 static int ifcore_subscribe(lua_State *lua);
34 static int ifcore_unsubscribe(lua_State *lua);
35
36
37 /* Lua imapfilter core library functions. */
38 static const luaL_reg ifcorelib[] = {
39 { "noop", ifcore_noop },
40 { "logout", ifcore_logout },
41 { "login", ifcore_login },
42 { "select", ifcore_select },
43 { "create", ifcore_create },
44 { "delete", ifcore_delete },
45 { "rename", ifcore_rename },
46 { "subscribe", ifcore_subscribe },
47 { "unsubscribe", ifcore_unsubscribe },
48 { "list", ifcore_list },
49 { "lsub", ifcore_lsub },
50 { "status", ifcore_status },
51 { "append", ifcore_append },
52 { "close", ifcore_close },
53 { "expunge", ifcore_expunge },
54 { "search", ifcore_search },
55 { "fetchfast", ifcore_fetchfast },
56 { "fetchflags", ifcore_fetchflags },
57 { "fetchdate", ifcore_fetchdate },
58 { "fetchsize", ifcore_fetchsize },
59
60 /*
61 * RFC 822: message == header + body
62 * RFC 3501: body == header + text
63 *
64 * RFC 3501 notation is used internally, and RFC 822 notation is used
65 * for the interface available to the user.
66 */
67 { "fetchheader", ifcore_fetchheader },
68 { "fetchbody", ifcore_fetchtext },
69
70 { "fetchfields", ifcore_fetchfields },
71 { "store", ifcore_store },
72 { "copy", ifcore_copy },
73 { NULL, NULL }
74 };
75
76
77 #define DISCOVER_PORT(P, S) ((P) ? (P) : (!(S) ? "143" : "993"))
78
79
80 /*
81 * Core function to reset any inactivity autologout timer on the server.
82 */
83 static int
84 ifcore_noop(lua_State *lua)
85 {
86 const char *s, *u, *p;
87 int r;
88
89 if (lua_gettop(lua) != 1)
90 luaL_error(lua, "wrong number of arguments");
91
92 luaL_checktype(lua, 1, LUA_TTABLE);
93
94 if (!(s = get_table_string("server")))
95 luaL_error(lua, "no mail server specified");
96 if (!(u = get_table_string("username")))
97 luaL_error(lua, "no username specified");
98 p = DISCOVER_PORT(get_table_string("port"), get_table_string("ssl"));
99
100 r = request_noop(s, p, u);
101
102 lua_pop(lua, 1);
103
104 lua_pushboolean(lua, (r == STATUS_RESPONSE_OK));
105
106 return 1;
107 }
108
109
110 /*
111 * Core function to login to the server.
112 */
113 static int
114 ifcore_login(lua_State *lua)
115 {
116 const char *s, *u, *w, *p;
117 int r;
118
119 if (lua_gettop(lua) != 1)
120 luaL_error(lua, "wrong number of arguments");
121
122 luaL_checktype(lua, 1, LUA_TTABLE);
123
124 if (!(s = get_table_string("server")))
125 luaL_error(lua, "no mail server specified");
126 if (!(u = get_table_string("username")))
127 luaL_error(lua, "no username specified");
128 if (!(w = get_table_string("password")))
129 luaL_error(lua, "no password specified");
130 p = DISCOVER_PORT(get_table_string("port"), get_table_string("ssl"));
131
132 r = request_login(s, p, get_table_string("ssl"), u, w);
133
134 lua_pop(lua, 1);
135
136 lua_pushboolean(lua, (r == STATUS_RESPONSE_OK ||
137 r == STATUS_RESPONSE_PREAUTH));
138
139 return 1;
140 }
141
142
143 /*
144 * Core function to logout from the server.
145 */
146 static int
147 ifcore_logout(lua_State *lua)
148 {
149 const char *s, *u, *p;
150 int r;
151
152 if (lua_gettop(lua) != 1)
153 luaL_error(lua, "wrong number of arguments");
154
155 luaL_checktype(lua, 1, LUA_TTABLE);
156
157 if (!(s = get_table_string("server")))
158 luaL_error(lua, "no mail server specified");
159 if (!(u = get_table_string("username")))
160 luaL_error(lua, "no username specified");
161 p = DISCOVER_PORT(get_table_string("port"), get_table_string("ssl"));
162
163 r = request_logout(s, p, u);
164
165 lua_pop(lua, 1);
166
167 lua_pushboolean(lua, (r == STATUS_RESPONSE_OK));
168
169 return 1;
170 }
171
172
173 /*
174 * Core function to get the status of a mailbox.
175 */
176 static int
177 ifcore_status(lua_State *lua)
178 {
179 const char *s, *u, *p;
180 int r;
181 unsigned int exists, recent, unseen;
182
183 exists = recent = unseen = 0;
184
185 if (lua_gettop(lua) != 2)
186 luaL_error(lua, "wrong number of arguments");
187
188 luaL_checktype(lua, 1, LUA_TTABLE);
189 luaL_checktype(lua, 2, LUA_TSTRING);
190
191 lua_pushvalue(lua, 1);
192 if (!(s = get_table_string("server")))
193 luaL_error(lua, "no mail server specified");
194 if (!(u = get_table_string("username")))
195 luaL_error(lua, "no username specified");
196 p = DISCOVER_PORT(get_table_string("port"), get_table_string("ssl"));
197 lua_pop(lua, 1);
198
199 r = request_status(s, p, u, lua_tostring(lua, 2), &exists, &recent,
200 &unseen);
201
202 lua_pop(lua, 2);
203
204 lua_pushboolean(lua, (r == STATUS_RESPONSE_OK));
205 lua_pushnumber(lua, (lua_Number) (exists));
206 lua_pushnumber(lua, (lua_Number) (recent));
207 lua_pushnumber(lua, (lua_Number) (unseen));
208
209 return 4;
210 }
211
212
213 /*
214 * Core function to select a mailbox.
215 */
216 static int
217 ifcore_select(lua_State *lua)
218 {
219 const char *s, *u, *p;
220 int r;
221
222 if (lua_gettop(lua) != 2)
223 luaL_error(lua, "wrong number of arguments");
224
225 luaL_checktype(lua, 1, LUA_TTABLE);
226 luaL_checktype(lua, 2, LUA_TSTRING);
227
228 lua_pushvalue(lua, 1);
229 if (!(s = get_table_string("server")))
230 luaL_error(lua, "no mail server specified");
231 if (!(u = get_table_string("username")))
232 luaL_error(lua, "no username specified");
233 p = DISCOVER_PORT(get_table_string("port"), get_table_string("ssl"));
234 lua_pop(lua, 1);
235
236 r = request_select(s, p, u, lua_tostring(lua, 2));
237
238 lua_pop(lua, 2);
239
240 lua_pushboolean(lua, (r == STATUS_RESPONSE_OK));
241
242 return 1;
243 }
244
245
246 /*
247 * Core function to close a mailbox.
248 */
249 static int
250 ifcore_close(lua_State *lua)
251 {
252 const char *s, *u, *p;
253 int r;
254
255 if (lua_gettop(lua) != 1)
256 luaL_error(lua, "wrong number of arguments");
257
258 luaL_checktype(lua, 1, LUA_TTABLE);
259
260 if (!(s = get_table_string("server")))
261 luaL_error(lua, "no mail server specified");
262 if (!(u = get_table_string("username")))
263 luaL_error(lua, "no username specified");
264 p = DISCOVER_PORT(get_table_string("port"), get_table_string("ssl"));
265
266 r = request_close(s, p, u);
267
268 lua_pop(lua, 1);
269
270 lua_pushboolean(lua, (r == STATUS_RESPONSE_OK));
271
272 return 1;
273 }
274
275
276 /*
277 * Core function to expunge a mailbox.
278 */
279 static int
280 ifcore_expunge(lua_State *lua)
281 {
282 const char *s, *u, *p;
283 int r;
284
285 if (lua_gettop(lua) != 1)
286 luaL_error(lua, "wrong number of arguments");
287
288 luaL_checktype(lua, 1, LUA_TTABLE);
289
290 if (!(s = get_table_string("server")))
291 luaL_error(lua, "no mail server specified");
292 if (!(u = get_table_string("username")))
293 luaL_error(lua, "no username specified");
294 p = DISCOVER_PORT(get_table_string("port"), get_table_string("ssl"));
295
296 r = request_expunge(s, p, u);
297
298 lua_pop(lua, 1);
299
300 lua_pushboolean(lua, (r == STATUS_RESPONSE_OK));
301
302 return 1;
303 }
304
305
306 /*
307 * Core function to list available mailboxes.
308 */
309 static int
310 ifcore_list(lua_State *lua)
311 {
312 const char *s, *u, *p;
313 int r;
314 char *mboxs, *folders;
315
316 mboxs = folders = NULL;
317
318 if (lua_gettop(lua) != 3)
319 luaL_error(lua, "wrong number of arguments");
320
321 luaL_checktype(lua, 1, LUA_TTABLE);
322 luaL_checktype(lua, 2, LUA_TSTRING);
323 luaL_checktype(lua, 3, LUA_TSTRING);
324
325 lua_pushvalue(lua, 1);
326 if (!(s = get_table_string("server")))
327 luaL_error(lua, "no mail server specified");
328 if (!(u = get_table_string("username")))
329 luaL_error(lua, "no username specified");
330 p = DISCOVER_PORT(get_table_string("port"), get_table_string("ssl"));
331 lua_pop(lua, 1);
332
333 r = request_list(s, p, u, lua_tostring(lua, 2), lua_tostring(lua, 3),
334 &mboxs, &folders);
335
336 lua_pop(lua, 3);
337
338 lua_pushboolean(lua, (r == STATUS_RESPONSE_OK));
339
340 if (!mboxs && !folders)
341 return 1;
342
343 lua_pushstring(lua, mboxs);
344 lua_pushstring(lua, folders);
345
346 xfree(mboxs);
347 xfree(folders);
348
349 return 3;
350 }
351
352
353 /*
354 * Core function to list subscribed mailboxes.
355 */
356 static int
357 ifcore_lsub(lua_State *lua)
358 {
359 const char *s, *u, *p;
360 int r;
361 char *mboxs, *folders;
362
363 mboxs = folders = NULL;
364
365 if (lua_gettop(lua) != 3)
366 luaL_error(lua, "wrong number of arguments");
367
368 luaL_checktype(lua, 1, LUA_TTABLE);
369 luaL_checktype(lua, 2, LUA_TSTRING);
370 luaL_checktype(lua, 3, LUA_TSTRING);
371
372 lua_pushvalue(lua, 1);
373 if (!(s = get_table_string("server")))
374 luaL_error(lua, "no mail server specified");
375 if (!(u = get_table_string("username")))
376 luaL_error(lua, "no username specified");
377 p = DISCOVER_PORT(get_table_string("port"), get_table_string("ssl"));
378 lua_pop(lua, 1);
379
380 r = request_lsub(s, p, u, lua_tostring(lua, 2), lua_tostring(lua, 3),
381 &mboxs, &folders);
382
383 lua_pop(lua, 3);
384
385 lua_pushboolean(lua, (r == STATUS_RESPONSE_OK));
386
387 if (!mboxs)
388 return 1;
389
390 lua_pushstring(lua, mboxs);
391 lua_pushstring(lua, folders);
392
393 xfree(mboxs);
394
395 return 3;
396 }
397
398
399 /*
400 * Core function to search the messages of a mailbox.
401 */
402 static int
403 ifcore_search(lua_State *lua)
404 {
405 const char *s, *u, *p;
406 int r;
407 char *mesgs;
408
409 mesgs = NULL;
410
411 if (lua_gettop(lua) != 3)
412 luaL_error(lua, "wrong number of arguments");
413
414 luaL_checktype(lua, 1, LUA_TTABLE);
415 luaL_checktype(lua, 2, LUA_TSTRING);
416 luaL_checktype(lua, 3, LUA_TSTRING);
417
418 lua_pushvalue(lua, 1);
419 if (!(s = get_table_string("server")))
420 luaL_error(lua, "no mail server specified");
421 if (!(u = get_table_string("username")))
422 luaL_error(lua, "no username specified");
423 p = DISCOVER_PORT(get_table_string("port"), get_table_string("ssl"));
424 lua_pop(lua, 1);
425
426 r = request_search(s, p, u, lua_tostring(lua, 2), lua_tostring(lua, 3),
427 &mesgs);
428
429 lua_pop(lua, 3);
430
431 lua_pushboolean(lua, (r == STATUS_RESPONSE_OK));
432
433 if (!mesgs)
434 return 1;
435
436 lua_pushstring(lua, mesgs);
437
438 xfree(mesgs);
439
440 return 2;
441 }
442
443
444 /*
445 * Core function to fetch message information (flags, date, size).
446 */
447 static int
448 ifcore_fetchfast(lua_State *lua)
449 {
450 const char *s, *u, *p;
451 int r;
452 char *flags, *date, *size;
453
454 flags = date = size = NULL;
455
456 if (lua_gettop(lua) != 2)
457 luaL_error(lua, "wrong number of arguments");
458
459 luaL_checktype(lua, 1, LUA_TTABLE);
460 luaL_checktype(lua, 2, LUA_TSTRING);
461
462 lua_pushvalue(lua, 1);
463 if (!(s = get_table_string("server")))
464 luaL_error(lua, "no mail server specified");
465 if (!(u = get_table_string("username")))
466 luaL_error(lua, "no username specified");
467 p = DISCOVER_PORT(get_table_string("port"), get_table_string("ssl"));
468 lua_pop(lua, 1);
469
470 r = request_fetchfast(s, p, u, lua_tostring(lua, 2), &flags, &date,
471 &size);
472
473 lua_pop(lua, 2);
474
475 lua_pushboolean(lua, (r == STATUS_RESPONSE_OK));
476
477 if (!flags || !date || !size)
478 return 1;
479
480 lua_pushstring(lua, flags);
481 lua_pushstring(lua, date);
482 lua_pushstring(lua, size);
483
484 xfree(flags);
485 xfree(date);
486 xfree(size);
487
488 return 4;
489 }
490
491
492 /*
493 * Core function to fetch message flags.
494 */
495 static int
496 ifcore_fetchflags(lua_State *lua)
497 {
498 const char *s, *u, *p;
499 int r;
500 char *flags;
501
502 flags = NULL;
503
504 if (lua_gettop(lua) != 2)
505 luaL_error(lua, "wrong number of arguments");
506
507 luaL_checktype(lua, 1, LUA_TTABLE);
508 luaL_checktype(lua, 2, LUA_TSTRING);
509
510 lua_pushvalue(lua, 1);
511 if (!(s = get_table_string("server")))
512 luaL_error(lua, "no mail server specified");
513 if (!(u = get_table_string("username")))
514 luaL_error(lua, "no username specified");
515 p = DISCOVER_PORT(get_table_string("port"), get_table_string("ssl"));
516 lua_pop(lua, 1);
517
518 r = request_fetchflags(s, p, u, lua_tostring(lua, 2), &flags);
519
520 lua_pop(lua, 2);
521
522 lua_pushboolean(lua, (r == STATUS_RESPONSE_OK));
523
524 if (!flags)
525 return 1;
526
527 lua_pushstring(lua, flags);
528
529 xfree(flags);
530
531 return 2;
532 }
533
534
535 /*
536 * Core function to fetch message date.
537 */
538 static int
539 ifcore_fetchdate(lua_State *lua)
540 {
541 const char *s, *u, *p;
542 int r;
543 char *date;
544
545 date = NULL;
546
547 if (lua_gettop(lua) != 2)
548 luaL_error(lua, "wrong number of arguments");
549
550 luaL_checktype(lua, 1, LUA_TTABLE);
551 luaL_checktype(lua, 2, LUA_TSTRING);
552
553 lua_pushvalue(lua, 1);
554 if (!(s = get_table_string("server")))
555 luaL_error(lua, "no mail server specified");
556 if (!(u = get_table_string("username")))
557 luaL_error(lua, "no username specified");
558 p = DISCOVER_PORT(get_table_string("port"), get_table_string("ssl"));
559 lua_pop(lua, 1);
560
561 r = request_fetchdate(s, p, u, lua_tostring(lua, 2), &date);
562
563 lua_pop(lua, 2);
564
565 lua_pushboolean(lua, (r == STATUS_RESPONSE_OK));
566
567 if (!date)
568 return 1;
569
570 lua_pushstring(lua, date);
571
572 xfree(date);
573
574 return 2;
575 }
576
577
578 /*
579 * Core function to fetch message size.
580 */
581 static int
582 ifcore_fetchsize(lua_State *lua)
583 {
584 const char *s, *u, *p;
585 int r;
586 char *size;
587
588 size = NULL;
589
590 if (lua_gettop(lua) != 2)
591 luaL_error(lua, "wrong number of arguments");
592
593 luaL_checktype(lua, 1, LUA_TTABLE);
594 luaL_checktype(lua, 2, LUA_TSTRING);
595
596 lua_pushvalue(lua, 1);
597 if (!(s = get_table_string("server")))
598 luaL_error(lua, "no mail server specified");
599 if (!(u = get_table_string("username")))
600 luaL_error(lua, "no username specified");
601 p = DISCOVER_PORT(get_table_string("port"), get_table_string("ssl"));
602 lua_pop(lua, 1);
603
604 r = request_fetchsize(s, p, u, lua_tostring(lua, 2), &size);
605
606 lua_pop(lua, 2);
607
608 lua_pushboolean(lua, (r == STATUS_RESPONSE_OK));
609
610 if (!size)
611 return 1;
612
613 lua_pushstring(lua, size);
614
615 xfree(size);
616
617 return 2;
618 }
619
620
621 /*
622 * Core function to fetch message header.
623 */
624 static int
625 ifcore_fetchheader(lua_State *lua)
626 {
627 const char *s, *u, *p;
628 int r;
629 char *header;
630 size_t len;
631
632 header = NULL;
633 len = 0;
634
635 if (lua_gettop(lua) != 2)
636 luaL_error(lua, "wrong number of arguments");
637
638 luaL_checktype(lua, 1, LUA_TTABLE);
639 luaL_checktype(lua, 2, LUA_TSTRING);
640
641 lua_pushvalue(lua, 1);
642 if (!(s = get_table_string("server")))
643 luaL_error(lua, "no mail server specified");
644 if (!(u = get_table_string("username")))
645 luaL_error(lua, "no username specified");
646 p = DISCOVER_PORT(get_table_string("port"), get_table_string("ssl"));
647 lua_pop(lua, 1);
648
649 r = request_fetchheader(s, p, u, lua_tostring(lua, 2), &header, &len);
650
651 lua_pop(lua, 2);
652
653 lua_pushboolean(lua, (r == STATUS_RESPONSE_OK));
654
655 if (!header)
656 return 1;
657
658 lua_pushlstring(lua, header, len);
659
660 return 2;
661 }
662
663
664 /*
665 * Core function to fetch message text.
666 */
667 static int
668 ifcore_fetchtext(lua_State *lua)
669 {
670 const char *s, *u, *p;
671 int r;
672 char *text;
673 size_t len;
674
675 text = NULL;
676 len = 0;
677
678 if (lua_gettop(lua) != 2)
679 luaL_error(lua, "wrong number of arguments");
680
681 luaL_checktype(lua, 1, LUA_TTABLE);
682 luaL_checktype(lua, 2, LUA_TSTRING);
683
684 lua_pushvalue(lua, 1);
685 if (!(s = get_table_string("server")))
686 luaL_error(lua, "no mail server specified");
687 if (!(u = get_table_string("username")))
688 luaL_error(lua, "no username specified");
689 p = DISCOVER_PORT(get_table_string("port"), get_table_string("ssl"));
690 lua_pop(lua, 1);
691
692 r = request_fetchtext(s, p, u, lua_tostring(lua, 2), &text, &len);
693
694 lua_pop(lua, 2);
695
696 lua_pushboolean(lua, (r == STATUS_RESPONSE_OK));
697
698 if (!text)
699 return 1;
700
701 lua_pushlstring(lua, text, len);
702
703 return 2;
704 }
705
706
707 /*
708 * Core function to fetch message specific header fields.
709 */
710 static int
711 ifcore_fetchfields(lua_State *lua)
712 {
713 const char *s, *u, *p;
714 int r;
715 char *fields;
716 size_t len;
717
718 fields = NULL;
719 len = 0;
720
721 if (lua_gettop(lua) != 3)
722 luaL_error(lua, "wrong number of arguments");
723
724 luaL_checktype(lua, 1, LUA_TTABLE);
725 luaL_checktype(lua, 2, LUA_TSTRING);
726 luaL_checktype(lua, 3, LUA_TSTRING);
727
728 lua_pushvalue(lua, 1);
729 if (!(s = get_table_string("server")))
730 luaL_error(lua, "no mail server specified");
731 if (!(u = get_table_string("username")))
732 luaL_error(lua, "no username specified");
733 p = DISCOVER_PORT(get_table_string("port"), get_table_string("ssl"));
734 lua_pop(lua, 1);
735
736 r = request_fetchfields(s, p, u, lua_tostring(lua, 2),
737 lua_tostring(lua, 3), &fields, &len);
738
739 lua_pop(lua, 3);
740
741 lua_pushboolean(lua, (r == STATUS_RESPONSE_OK));
742
743 if (!fields)
744 return 1;
745
746 lua_pushlstring(lua, fields, len);
747
748 return 2;
749 }
750
751
752 /*
753 * Core function to change message flags.
754 */
755 static int
756 ifcore_store(lua_State *lua)
757 {
758 const char *s, *u, *p;
759 int r;
760
761 if (lua_gettop(lua) != 4)
762 luaL_error(lua, "wrong number of arguments");
763
764 luaL_checktype(lua, 1, LUA_TTABLE);
765 luaL_checktype(lua, 2, LUA_TSTRING);
766 luaL_checktype(lua, 3, LUA_TSTRING);
767 luaL_checktype(lua, 4, LUA_TSTRING);
768
769 lua_pushvalue(lua, 1);
770 if (!(s = get_table_string("server")))
771 luaL_error(lua, "no mail server specified");
772 if (!(u = get_table_string("username")))
773 luaL_error(lua, "no username specified");
774 p = DISCOVER_PORT(get_table_string("port"), get_table_string("ssl"));
775 lua_pop(lua, 1);
776
777 r = request_store(s, p, u, lua_tostring(lua, 2), lua_tostring(lua, 3),
778 lua_tostring(lua, 4));
779
780 lua_pop(lua, 4);
781
782 lua_pushboolean(lua, (r == STATUS_RESPONSE_OK));
783
784 return 1;
785 }
786
787
788 /*
789 * Core function to copy messages between mailboxes.
790 */
791 static int
792 ifcore_copy(lua_State *lua)
793 {
794 const char *s, *u, *p;
795 int r;
796
797 if (lua_gettop(lua) != 3)
798 luaL_error(lua, "wrong number of arguments");
799
800 luaL_checktype(lua, 1, LUA_TTABLE);
801 luaL_checktype(lua, 2, LUA_TSTRING);
802 luaL_checktype(lua, 3, LUA_TSTRING);
803
804 lua_pushvalue(lua, 1);
805 if (!(s = get_table_string("server")))
806 luaL_error(lua, "no mail server specified");
807 if (!(u = get_table_string("username")))
808 luaL_error(lua, "no username specified");
809 p = DISCOVER_PORT(get_table_string("port"), get_table_string("ssl"));
810 lua_pop(lua, 1);
811
812 r = request_copy(s, p, u, lua_tostring(lua, 2), lua_tostring(lua, 3));
813
814 lua_pop(lua, 3);
815
816 lua_pushboolean(lua, (r == STATUS_RESPONSE_OK));
817
818 return 1;
819 }
820
821
822 /*
823 * Core function to append messages to a mailbox.
824 */
825 static int
826 ifcore_append(lua_State *lua)
827 {
828 const char *s, *u, *p;
829 int r;
830
831 switch (lua_gettop(lua)) {
832 case 5:
833 luaL_checktype(lua, 5, LUA_TSTRING);
834 /* FALLTHROUGH */
835 case 4:
836 luaL_checktype(lua, 4, LUA_TSTRING);
837 /* FALLTHROUGH */
838 case 3:
839 luaL_checktype(lua, 3, LUA_TSTRING);
840 luaL_checktype(lua, 2, LUA_TSTRING);
841 luaL_checktype(lua, 1, LUA_TTABLE);
842 break;
843 default:
844 luaL_error(lua, "wrong number of arguments");
845 break;
846 }
847
848 lua_pushvalue(lua, 1);
849 if (!(s = get_table_string("server")))
850 luaL_error(lua, "no mail server specified");
851 if (!(u = get_table_string("username")))
852 luaL_error(lua, "no username specified");
853 p = DISCOVER_PORT(get_table_string("port"), get_table_string("ssl"));
854 lua_pop(lua, 1);
855
856 r = request_append(s, p, u, lua_tostring(lua, 2), lua_tostring(lua, 3),
857 lua_strlen(lua, 3), lua_tostring(lua, 4), lua_tostring(lua, 5));
858
859 lua_pop(lua, lua_gettop(lua));
860
861 lua_pushboolean(lua, (r == STATUS_RESPONSE_OK));
862
863 return 1;
864 }
865
866
867 /*
868 * Core function to create a mailbox.
869 */
870 static int
871 ifcore_create(lua_State *lua)
872 {
873 const char *s, *u, *p;
874 int r;
875
876 if (lua_gettop(lua) != 2)
877 luaL_error