SMTPQ: don't multiplay the value for displaying it.
[citadel.git] / webcit / smtpqueue.c
1 /* 
2  * Display the outbound SMTP queue
3  */
4
5 #include "webcit.h"
6 HashList *QItemHandlers = NULL;
7
8 /*
9  * display one message in the queue
10  */
11 void display_queue_msg(long msgnum)
12 {
13         char buf[1024];
14         char keyword[32];
15         int in_body = 0;
16         int is_delivery_list = 0;
17         time_t submitted = 0;
18         time_t attempted = 0;
19         time_t last_attempt = 0;
20         int number_of_attempts = 0;
21         char sender[256];
22         char recipients[65536];
23         int recipients_len = 0;
24         char thisrecp[256];
25         char thisdsn[256];
26         char thismsg[512];
27         int thismsg_len;
28         long msgid = 0;
29         int len;
30
31         strcpy(sender, "");
32         strcpy(recipients, "");
33         recipients_len = 0;
34
35         serv_printf("MSG2 %ld", msgnum);
36         serv_getln(buf, sizeof buf);
37         if (buf[0] != '1') return;
38
39         while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
40
41                 if (!IsEmptyStr(buf)) {
42                         len = strlen(buf);
43                         if (buf[len - 1] == 13) {
44                                 buf[len - 1] = 0;
45                         }
46                 }
47
48                 if ( (IsEmptyStr(buf)) && (in_body == 0) ) {
49                         in_body = 1;
50                 }
51
52                 if ( (!in_body)
53                    && (!strncasecmp(buf, "Content-type: application/x-citadel-delivery-list", 49))
54                 ) {
55                         is_delivery_list = 1;
56                 }
57
58                 if ( (in_body) && (!is_delivery_list) ) {
59                         while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
60                                 /* Not a delivery list; flush and return quietly. */
61                         }
62                         return;
63                 }
64
65                 if ( (in_body) && (is_delivery_list) ) {
66                         extract_token(keyword, buf, 0, '|', sizeof keyword);
67
68                         if (!strcasecmp(keyword, "msgid")) {
69                                 msgid = extract_long(buf, 1);
70                         }
71
72                         if (!strcasecmp(keyword, "submitted")) {
73                                 submitted = extract_long(buf, 1);
74                         }
75
76                         if (!strcasecmp(keyword, "attempted")) {
77                                 attempted = extract_long(buf, 1);
78                                 ++number_of_attempts;
79                                 if (attempted > last_attempt) {
80                                         last_attempt = attempted;
81                                 }
82                         }
83
84                         if (!strcasecmp(keyword, "bounceto")) {
85                                 char *atsign;
86                                 extract_token(sender, buf, 1, '|', sizeof sender);
87
88                                 /* Strip off local hostname if it's our own */
89                                 atsign = strchr(sender, '@');
90                                 if (atsign != NULL) {
91                                         ++atsign;
92                                         if (!strcasecmp(atsign, ChrPtr(WC->serv_info->serv_nodename))) {
93                                                 --atsign;
94                                                 *atsign = 0;
95                                         }
96                                 }
97                         }
98
99                         if (!strcasecmp(keyword, "remote")) {
100                                 thismsg[0] = 0;
101
102                                 extract_token(thisrecp, buf, 1, '|', sizeof thisrecp);
103                                 extract_token(thisdsn, buf, 3, '|', sizeof thisdsn);
104
105                                 if (!IsEmptyStr(thisrecp)) {
106                                         stresc(thismsg, sizeof thismsg, thisrecp, 1, 1);
107                                         if (!IsEmptyStr(thisdsn)) {
108                                                 strcat(thismsg, "<br>&nbsp;&nbsp;<i>");
109                                                 stresc(&thismsg[strlen(thismsg)], sizeof thismsg,
110                                                         thisdsn, 1, 1);
111                                                 strcat(thismsg, "</i>");
112                                         }
113                                         thismsg_len = strlen(thismsg);
114
115                                         if ((recipients_len + thismsg_len + 100) < sizeof recipients) {
116                                                 if (!IsEmptyStr(recipients)) {
117                                                         strcpy(&recipients[recipients_len], "<br>");
118                                                         recipients_len += 6;
119                                                 }
120                                                 strcpy(&recipients[recipients_len], thismsg);
121                                                 recipients_len += thismsg_len;
122                                         }
123                                 }
124
125                         }
126
127                 }
128
129         }
130
131         wc_printf("<tr><td>");
132         wc_printf("%ld<br>", msgnum);
133         wc_printf(" <a href=\"javascript:DeleteSMTPqueueMsg(%ld,%ld);\">%s</a>", 
134                 msgnum, msgid, _("(Delete)")
135         );
136
137         wc_printf("</td><td>");
138         if (submitted > 0) {
139                 webcit_fmt_date(buf, 1024, submitted, 1);
140                 wc_printf("%s", buf);
141         }
142         else {
143                 wc_printf("&nbsp;");
144         }
145
146         wc_printf("</td><td>");
147         if (last_attempt > 0) {
148                 webcit_fmt_date(buf, 1024, last_attempt, 1);
149                 wc_printf("%s", buf);
150         }
151         else {
152                 wc_printf("&nbsp;");
153         }
154
155         wc_printf("</td><td>");
156         escputs(sender);
157
158         wc_printf("</td><td>");
159         wc_printf("%s", recipients);
160         wc_printf("</td></tr>\n");
161
162 }
163
164
165 void display_smtpqueue_inner_div(void) {
166         message_summary *Msg = NULL;
167         wcsession *WCC = WC;
168         int i;
169         int num_msgs;
170         StrBuf *Buf;
171         SharedMessageStatus Stat;
172
173         memset(&Stat, 0, sizeof(SharedMessageStatus));
174         /* Check to see if we can go to the __CitadelSMTPspoolout__ room.
175          * If not, we don't have access to the queue.
176          */
177         Buf = NewStrBufPlain(HKEY("__CitadelSMTPspoolout__"));
178         gotoroom(Buf);
179         FreeStrBuf(&Buf);
180         if (!strcasecmp(ChrPtr(WCC->CurRoom.name), "__CitadelSMTPspoolout__")) {
181
182                 Stat.maxload = 10000;
183                 Stat.lowest_found = (-1);
184                 Stat.highest_found = (-1);
185 //              num_msgs = load_msg_ptrs("MSGS ALL|0|1", "SUBJ|;QMSG", &Stat, NULL);
186                 num_msgs = load_msg_ptrs("MSGS ", NULL, &Stat, NULL);
187                 if (num_msgs > 0) {
188                         wc_printf("<table class=\"mailbox_summary\" rules=rows "
189                                 "cellpadding=2 style=\"width:100%%;\">"
190                         );
191
192                         wc_printf("<tr><td><b><i>");
193                         wc_printf(_("Message ID"));
194                         wc_printf("</i></b></td><td><b><i>");
195                         wc_printf(_("Date/time submitted"));
196                         wc_printf("</i></b></td><td><b><i>");
197                         wc_printf(_("Last attempt"));
198                         wc_printf("</i></b></td><td><b><i>");
199                         wc_printf(_("Sender"));
200                         wc_printf("</i></b></td><td><b><i>");
201                         wc_printf(_("Recipients"));
202                         wc_printf("</i></b></td></tr>\n");
203
204                         for (i=0; (i < num_msgs) && (i < Stat.maxload); ++i) {
205                                 Msg = GetMessagePtrAt(i, WCC->summ);
206                                 if (Msg != NULL) {
207                                         display_queue_msg(Msg->msgnum);
208                                 }
209                         }
210
211                         wc_printf("</table>");
212
213                 }
214                 else {
215                         wc_printf("<br><br><div align=\"center\">");
216                         wc_printf(_("The queue is empty."));
217                         wc_printf("</div><br><br>");
218                 }
219         }
220         else {
221                 wc_printf("<br><br><div align=\"center\">");
222                 wc_printf(_("You do not have permission to view this resource."));
223                 wc_printf("</div><br><br>");
224         }
225         output_headers(0, 0, 0, 0, 0, 0);
226         end_burst();
227 }
228
229 /*
230  * display the outbound SMTP queue
231  */
232 void display_smtpqueue(void)
233 {
234         output_headers(1, 1, 2, 0, 0, 0);
235
236         wc_printf("<div id=\"banner\">\n");
237         wc_printf("<h1>");
238         wc_printf(_("View the outbound SMTP queue"));
239         wc_printf("</h1>\n");
240         wc_printf("</div>\n");
241
242         wc_printf("<div id=\"content\" class=\"service\">\n");
243
244         wc_printf("<table class=\"smtpqueue_background\">"
245                 "<tr><td valign=top>\n");
246
247         wc_printf("<div id=\"smtpqueue_inner_div\">"
248                 "<div align=\"center\"><img src=\"static/webcit_icons/throbber.gif\"></div>"
249                 "</div>"
250                 "<div align=\"center\">"
251                 "<a href=\"javascript:RefreshSMTPqueueDisplay();\">%s</a>"
252                 "</div>"
253                 "</td></tr></table>\n", _("Refresh this page")
254         );
255
256         StrBufAppendPrintf(WC->trailing_javascript, "RefreshSMTPqueueDisplay();\n");
257
258         wDumpContent(1);
259
260 }
261
262
263
264
265
266
267
268
269
270
271 typedef struct _mailq_entry {
272         StrBuf *Recipient;
273         StrBuf *StatusMessage;
274         int Status;
275         /**<
276          * 0 = No delivery has yet been attempted
277          * 2 = Delivery was successful
278          * 3 = Transient error like connection problem. Try next remote if available.
279          * 4 = A transient error was experienced ... try again later
280          * 5 = Delivery to this address failed permanently.  The error message
281          *     should be placed in the fourth field so that a bounce message may
282          *     be generated.
283          */
284
285         int n;
286         int Active;
287 }MailQEntry;
288
289 typedef struct queueitem {
290         long MessageID;
291         long QueMsgID;
292         long Submitted;
293         int FailNow;
294         HashList *MailQEntries;
295 /* copy of the currently parsed item in the MailQEntries list;
296  * if null add a new one.
297  */
298         MailQEntry *Current;
299         time_t ReattemptWhen;
300         time_t Retry;
301
302         long ActiveDeliveries;
303         StrBuf *EnvelopeFrom;
304         StrBuf *BounceTo;
305         StrBuf *SenderRoom;
306         ParsedURL *URL;
307         ParsedURL *FallBackHost;
308 } OneQueItem;
309
310
311 typedef void (*QItemHandler)(OneQueItem *Item, StrBuf *Line, const char **Pos);
312
313 typedef struct __QItemHandlerStruct {
314         QItemHandler H;
315 } QItemHandlerStruct;
316
317 void RegisterQItemHandler(const char *Key, long Len, QItemHandler H)
318 {
319         QItemHandlerStruct *HS = (QItemHandlerStruct*)malloc(sizeof(QItemHandlerStruct));
320         HS->H = H;
321         Put(QItemHandlers, Key, Len, HS, NULL);
322 }
323
324 void FreeMailQEntry(void *qv)
325 {
326         MailQEntry *Q = qv;
327         FreeStrBuf(&Q->Recipient);
328         FreeStrBuf(&Q->StatusMessage);
329         free(Q);
330 }
331 void FreeQueItem(OneQueItem **Item)
332 {
333         DeleteHash(&(*Item)->MailQEntries);
334         FreeStrBuf(&(*Item)->EnvelopeFrom);
335         FreeStrBuf(&(*Item)->BounceTo);
336         FreeStrBuf(&(*Item)->SenderRoom);
337         FreeURL(&(*Item)->URL);
338         free(*Item);
339         Item = NULL;
340 }
341 void HFreeQueItem(void *Item)
342 {
343         FreeQueItem((OneQueItem**)&Item);
344 }
345
346
347 OneQueItem *DeserializeQueueItem(StrBuf *RawQItem, long QueMsgID)
348 {
349         OneQueItem *Item;
350         const char *pLine = NULL;
351         StrBuf *Line;
352         StrBuf *Token;
353         
354         Item = (OneQueItem*)malloc(sizeof(OneQueItem));
355         memset(Item, 0, sizeof(OneQueItem));
356         Item->Retry = 0;
357         Item->MessageID = -1;
358         Item->QueMsgID = QueMsgID;
359
360         Token = NewStrBuf();
361         Line = NewStrBufPlain(NULL, 128);
362         while (pLine != StrBufNOTNULL) {
363                 const char *pItemPart = NULL;
364                 void *vHandler;
365
366                 StrBufExtract_NextToken(Line, RawQItem, &pLine, '\n');
367                 if (StrLength(Line) == 0) continue;
368                 StrBufExtract_NextToken(Token, Line, &pItemPart, '|');
369                 if (GetHash(QItemHandlers, SKEY(Token), &vHandler))
370                 {
371                         QItemHandlerStruct *HS;
372                         HS = (QItemHandlerStruct*) vHandler;
373                         HS->H(Item, Line, &pItemPart);
374                 }
375         }
376         FreeStrBuf(&Line);
377         FreeStrBuf(&Token);
378 /*
379         Put(ActiveQItems,
380             LKEY(Item->MessageID),
381             Item,
382             HFreeQueItem);
383 */      
384
385         return Item;
386 }
387
388 void tmplput_MailQID(StrBuf *Target, WCTemplputParams *TP)
389 {
390         OneQueItem *Item = (OneQueItem*) CTX;
391         StrBufAppendPrintf(Target, "%ld", Item->QueMsgID);;
392 }
393 void tmplput_MailQPayloadID(StrBuf *Target, WCTemplputParams *TP)
394 {
395         OneQueItem *Item = (OneQueItem*) CTX;
396         StrBufAppendPrintf(Target, "%ld", Item->MessageID);
397 }
398 void tmplput_MailQBounceTo(StrBuf *Target, WCTemplputParams *TP)
399 {
400         OneQueItem *Item = (OneQueItem*) CTX;
401         StrBufAppendTemplate(Target, TP, Item->BounceTo, 0);
402 }
403 void tmplput_MailQAttempted(StrBuf *Target, WCTemplputParams *TP)
404 {
405         char datebuf[64];
406         OneQueItem *Item = (OneQueItem*) CTX;
407         webcit_fmt_date(datebuf, 64, Item->ReattemptWhen, DATEFMT_BRIEF);
408         StrBufAppendBufPlain(Target, datebuf, -1, 0);
409 }
410 void tmplput_MailQSubmitted(StrBuf *Target, WCTemplputParams *TP)
411 {
412         char datebuf[64];
413         OneQueItem *Item = (OneQueItem*) CTX;
414         webcit_fmt_date(datebuf, 64, Item->Submitted, DATEFMT_BRIEF);
415         StrBufAppendBufPlain(Target, datebuf, -1, 0);
416 }
417 void tmplput_MailQEnvelopeFrom(StrBuf *Target, WCTemplputParams *TP)
418 {
419         OneQueItem *Item = (OneQueItem*) CTX;
420         StrBufAppendTemplate(Target, TP, Item->EnvelopeFrom, 0);
421 }
422 void tmplput_MailQSourceRoom(StrBuf *Target, WCTemplputParams *TP)
423 {
424         OneQueItem *Item = (OneQueItem*) CTX;
425         StrBufAppendTemplate(Target, TP, Item->SenderRoom, 0);
426 }
427
428 int Conditional_MailQ_HaveSourceRoom(StrBuf *Target, WCTemplputParams *TP)
429 {
430         OneQueItem *Item = (OneQueItem*) CTX;
431         return StrLength(Item->SenderRoom) > 0;
432 }
433
434 void tmplput_MailQRetry(StrBuf *Target, WCTemplputParams *TP)
435 {
436         char datebuf[64];
437         OneQueItem *Item = (OneQueItem*) CTX;
438
439         if (Item->Retry == 0) {
440                 StrBufAppendBufPlain(Target, _("First Attempt pending"), -1, 0);
441         }
442         else {
443                 webcit_fmt_date(datebuf, sizeof(datebuf), Item->Retry, DATEFMT_BRIEF);
444                 StrBufAppendBufPlain(Target, datebuf, -1, 0);
445         }
446 }
447
448 void tmplput_MailQRCPT(StrBuf *Target, WCTemplputParams *TP)
449 {
450         MailQEntry *Entry = (MailQEntry*) CTX;
451         StrBufAppendTemplate(Target, TP, Entry->Recipient, 0);
452 }
453 void tmplput_MailQRCPTStatus(StrBuf *Target, WCTemplputParams *TP)
454 {
455         MailQEntry *Entry = (MailQEntry*) CTX;
456         StrBufAppendPrintf(Target, "%ld", Entry->Status);
457 }
458 void tmplput_MailQStatusMsg(StrBuf *Target, WCTemplputParams *TP)
459 {
460         MailQEntry *Entry = (MailQEntry*) CTX;
461         StrBufAppendTemplate(Target, TP, Entry->StatusMessage, 0);
462 }
463
464 HashList *iterate_get_Recipients(StrBuf *Target, WCTemplputParams *TP)
465 {
466         OneQueItem *Item = (OneQueItem*) CTX;
467         return Item->MailQEntries;
468 }
469
470
471 void NewMailQEntry(OneQueItem *Item)
472 {
473         Item->Current = (MailQEntry*) malloc(sizeof(MailQEntry));
474         memset(Item->Current, 0, sizeof(MailQEntry));
475
476         if (Item->MailQEntries == NULL)
477                 Item->MailQEntries = NewHash(1, Flathash);
478         Item->Current->StatusMessage = NewStrBuf();
479         Item->Current->n = GetCount(Item->MailQEntries);
480         Put(Item->MailQEntries,
481             IKEY(Item->Current->n),
482             Item->Current,
483             FreeMailQEntry);
484 }
485
486 void QItem_Handle_MsgID(OneQueItem *Item, StrBuf *Line, const char **Pos)
487 {
488         Item->MessageID = StrBufExtractNext_long(Line, Pos, '|');
489 }
490
491 void QItem_Handle_EnvelopeFrom(OneQueItem *Item, StrBuf *Line, const char **Pos)
492 {
493         if (Item->EnvelopeFrom == NULL)
494                 Item->EnvelopeFrom = NewStrBufPlain(NULL, StrLength(Line));
495         StrBufExtract_NextToken(Item->EnvelopeFrom, Line, Pos, '|');
496 }
497
498 void QItem_Handle_BounceTo(OneQueItem *Item, StrBuf *Line, const char **Pos)
499 {
500         if (Item->BounceTo == NULL)
501                 Item->BounceTo = NewStrBufPlain(NULL, StrLength(Line));
502         StrBufExtract_NextToken(Item->BounceTo, Line, Pos, '|');
503 }
504
505 void QItem_Handle_SenderRoom(OneQueItem *Item, StrBuf *Line, const char **Pos)
506 {
507         if (Item->SenderRoom == NULL)
508                 Item->SenderRoom = NewStrBufPlain(NULL, StrLength(Line));
509         StrBufExtract_NextToken(Item->SenderRoom, Line, Pos, '|');
510 }
511
512 void QItem_Handle_Recipient(OneQueItem *Item, StrBuf *Line, const char **Pos)
513 {
514         if (Item->Current == NULL)
515                 NewMailQEntry(Item);
516         if (Item->Current->Recipient == NULL)
517                 Item->Current->Recipient=NewStrBufPlain(NULL, StrLength(Line));
518         StrBufExtract_NextToken(Item->Current->Recipient, Line, Pos, '|');
519         Item->Current->Status = StrBufExtractNext_int(Line, Pos, '|');
520         StrBufExtract_NextToken(Item->Current->StatusMessage, Line, Pos, '|');
521         Item->Current = NULL; // TODO: is this always right?
522 }
523
524
525 void QItem_Handle_retry(OneQueItem *Item, StrBuf *Line, const char **Pos)
526 {
527         Item->Retry = StrBufExtractNext_int(Line, Pos, '|');
528 }
529
530
531 void QItem_Handle_Submitted(OneQueItem *Item, StrBuf *Line, const char **Pos)
532 {
533         Item->Submitted = atol(*Pos);
534
535 }
536
537 void QItem_Handle_Attempted(OneQueItem *Item, StrBuf *Line, const char **Pos)
538 {
539         Item->ReattemptWhen = StrBufExtractNext_int(Line, Pos, '|');
540 }
541
542
543
544
545
546
547
548
549 void render_QUEUE(wc_mime_attachment *Mime, StrBuf *RawData, StrBuf *FoundCharset)
550 {
551         WCTemplputParams SubTP;
552
553         memset(&SubTP, 0, sizeof(WCTemplputParams));
554         SubTP.Filter.ContextType = CTX_MAILQITEM;
555         SubTP.Context = DeserializeQueueItem(Mime->Data, Mime->msgnum);
556         DoTemplate(HKEY("view_mailq_message"),NULL, &SubTP);
557         FreeQueItem ((OneQueItem**)&SubTP.Context);
558 }
559
560 void
561 ServerShutdownModule_SMTP_QUEUE
562 (void)
563 {
564         DeleteHash(&QItemHandlers);
565 }
566 void
567 ServerStartModule_SMTP_QUEUE
568 (void)
569 {
570         QItemHandlers = NewHash(0, NULL);
571 }
572
573 int qview_PrintPageHeader(SharedMessageStatus *Stat, void **ViewSpecific)
574 {
575         if (!WC->is_aide)
576         {
577                 output_headers(1, 1, 1, 0, 0, 0);
578         }
579         else
580         {
581                 output_headers(1, 1, 2, 0, 0, 0);
582         }
583         return 0;
584 }
585
586 int qview_GetParamsGetServerCall(SharedMessageStatus *Stat,
587                                  void **ViewSpecific,
588                                  long oper,
589                                  char *cmd,
590                                  long len,
591                                  char *filter,
592                                  long flen)
593 {
594         if (!WC->is_aide)
595         {
596                 DoTemplate(HKEY("aide_required"), NULL, NULL);
597                 end_burst();
598
599                 return 300;
600         }
601         else {
602                 snprintf(cmd, len, "MSGS ALL|0|1");
603                 snprintf(filter, flen, "SUBJ|QMSG");
604                 DoTemplate(HKEY("view_mailq_header"), NULL, NULL);
605                 return 200;
606         }
607 }
608
609 /*
610  * Display task view
611  */
612 int qview_LoadMsgFromServer(SharedMessageStatus *Stat, 
613                             void **ViewSpecific, 
614                             message_summary* Msg, 
615                             int is_new, 
616                             int i)
617 {
618         wcsession *WCC = WC;
619         const StrBuf *Mime;
620
621         /* Not (yet?) needed here? calview *c = (calview *) *ViewSpecific; */
622         read_message(WCC->WBuf, HKEY("view_mailq_message_bearer"), Msg->msgnum, NULL, &Mime);
623
624         return 0;
625 }
626
627
628 int qview_RenderView_or_Tail(SharedMessageStatus *Stat, 
629                              void **ViewSpecific, 
630                              long oper)
631 {
632         wcsession *WCC = WC;
633         WCTemplputParams SubTP;
634
635         if (GetCount(WCC->summ) == 0)
636                 DoTemplate(HKEY("view_mailq_footer_empty"),NULL, &SubTP);
637         else
638                 DoTemplate(HKEY("view_mailq_footer"),NULL, &SubTP);
639         
640         return 0;
641 }
642 int qview_Cleanup(void **ViewSpecific)
643 {
644         wDumpContent(1);
645         return 0;
646 }
647
648 void 
649 InitModule_SMTP_QUEUE
650 (void)
651 {
652
653         RegisterQItemHandler(HKEY("msgid"),             QItem_Handle_MsgID);
654         RegisterQItemHandler(HKEY("envelope_from"),     QItem_Handle_EnvelopeFrom);
655         RegisterQItemHandler(HKEY("retry"),             QItem_Handle_retry);
656         RegisterQItemHandler(HKEY("attempted"),         QItem_Handle_Attempted);
657         RegisterQItemHandler(HKEY("remote"),            QItem_Handle_Recipient);
658         RegisterQItemHandler(HKEY("bounceto"),          QItem_Handle_BounceTo);
659         RegisterQItemHandler(HKEY("source_room"),       QItem_Handle_SenderRoom);
660         RegisterQItemHandler(HKEY("submitted"),         QItem_Handle_Submitted);
661
662         WebcitAddUrlHandler(HKEY("display_smtpqueue"), "", 0, display_smtpqueue, 0);
663         WebcitAddUrlHandler(HKEY("display_smtpqueue_inner_div"), "", 0, display_smtpqueue_inner_div, 0);
664         RegisterMimeRenderer(HKEY("application/x-citadel-delivery-list"), render_QUEUE, 1, 9000);
665
666
667         RegisterNamespace("MAILQ:ID", 0, 0, tmplput_MailQID, NULL, CTX_MAILQITEM);
668         RegisterNamespace("MAILQ:PAYLOAD:ID", 0, 0, tmplput_MailQPayloadID, NULL, CTX_MAILQITEM);
669         RegisterNamespace("MAILQ:BOUNCETO", 0, 1, tmplput_MailQBounceTo, NULL, CTX_MAILQITEM);
670         RegisterNamespace("MAILQ:ATTEMPTED", 0, 0, tmplput_MailQAttempted, NULL, CTX_MAILQITEM);
671         RegisterNamespace("MAILQ:SUBMITTED", 0, 0, tmplput_MailQSubmitted, NULL, CTX_MAILQITEM);
672         RegisterNamespace("MAILQ:ENVELOPEFROM", 0, 1, tmplput_MailQEnvelopeFrom, NULL, CTX_MAILQITEM);
673         RegisterNamespace("MAILQ:SRCROOM", 0, 1, tmplput_MailQSourceRoom, NULL, CTX_MAILQITEM);
674         RegisterConditional(HKEY("COND:MAILQ:HAVESRCROOM"), 0, Conditional_MailQ_HaveSourceRoom,  CTX_MAILQITEM);
675         RegisterNamespace("MAILQ:RETRY", 0, 0, tmplput_MailQRetry, NULL, CTX_MAILQITEM);
676
677         RegisterNamespace("MAILQ:RCPT:ADDR", 0, 1, tmplput_MailQRCPT, NULL, CTX_MAILQ_RCPT);
678         RegisterNamespace("MAILQ:RCPT:STATUS", 0, 0, tmplput_MailQRCPTStatus, NULL, CTX_MAILQ_RCPT);
679         RegisterNamespace("MAILQ:RCPT:STATUSMSG", 0, 1, tmplput_MailQStatusMsg, NULL, CTX_MAILQ_RCPT);
680
681         RegisterIterator("MAILQ:RCPT", 0, NULL, iterate_get_Recipients, 
682                          NULL, NULL, CTX_MAILQ_RCPT, CTX_MAILQITEM, IT_NOFLAG);
683
684
685         RegisterReadLoopHandlerset(
686                 VIEW_QUEUE,
687                 qview_GetParamsGetServerCall,
688                 qview_PrintPageHeader,
689                 NULL, /* TODO: is this right? */
690                 NULL,
691                 qview_LoadMsgFromServer,
692                 qview_RenderView_or_Tail,
693                 qview_Cleanup);
694
695 }