/*
- * $Id$
- *
* Display the outbound SMTP queue
*/
#include "webcit.h"
+HashList *QItemHandlers = NULL;
/*
* display one message in the queue
if (!IsEmptyStr(thisrecp)) {
stresc(thismsg, sizeof thismsg, thisrecp, 1, 1);
if (!IsEmptyStr(thisdsn)) {
- strcat(thismsg, "<br /> <i>");
+ strcat(thismsg, "<br> <i>");
stresc(&thismsg[strlen(thismsg)], sizeof thismsg,
thisdsn, 1, 1);
strcat(thismsg, "</i>");
if ((recipients_len + thismsg_len + 100) < sizeof recipients) {
if (!IsEmptyStr(recipients)) {
- strcpy(&recipients[recipients_len], "<br />");
+ strcpy(&recipients[recipients_len], "<br>");
recipients_len += 6;
}
strcpy(&recipients[recipients_len], thismsg);
}
- wprintf("<tr><td>");
- wprintf("%ld<br />", msgnum);
- wprintf(" <a href=\"javascript:DeleteQueueMsg(%ld,%ld);\">%s</a>",
+ wc_printf("<tr><td>");
+ wc_printf("%ld<br>", msgnum);
+ wc_printf(" <a href=\"javascript:DeleteSMTPqueueMsg(%ld,%ld);\">%s</a>",
msgnum, msgid, _("(Delete)")
);
- wprintf("</td><td>");
+ wc_printf("</td><td>");
if (submitted > 0) {
webcit_fmt_date(buf, 1024, submitted, 1);
- wprintf("%s", buf);
+ wc_printf("%s", buf);
}
else {
- wprintf(" ");
+ wc_printf(" ");
}
- wprintf("</td><td>");
+ wc_printf("</td><td>");
if (last_attempt > 0) {
webcit_fmt_date(buf, 1024, last_attempt, 1);
- wprintf("%s", buf);
+ wc_printf("%s", buf);
}
else {
- wprintf(" ");
+ wc_printf(" ");
}
- wprintf("</td><td>");
+ wc_printf("</td><td>");
escputs(sender);
- wprintf("</td><td>");
- wprintf("%s", recipients);
- wprintf("</td></tr>\n");
+ wc_printf("</td><td>");
+ wc_printf("%s", recipients);
+ wc_printf("</td></tr>\n");
}
Buf = NewStrBufPlain(HKEY("__CitadelSMTPspoolout__"));
gotoroom(Buf);
FreeStrBuf(&Buf);
- if (!strcasecmp(ChrPtr(WCC->wc_roomname), "__CitadelSMTPspoolout__")) {
+ if (!strcasecmp(ChrPtr(WCC->CurRoom.name), "__CitadelSMTPspoolout__")) {
- num_msgs = load_msg_ptrs("MSGS ALL", &Stat);
+ Stat.maxload = 10000;
+ Stat.lowest_found = (-1);
+ Stat.highest_found = (-1);
+// num_msgs = load_msg_ptrs("MSGS ALL|0|1", "SUBJ|;QMSG", &Stat, NULL);
+ num_msgs = load_msg_ptrs("MSGS ", NULL, &Stat, NULL);
if (num_msgs > 0) {
- wprintf("<table class=\"mailbox_summary\" rules=rows "
+ wc_printf("<table class=\"mailbox_summary\" rules=rows "
"cellpadding=2 style=\"width:100%%;\">"
);
- wprintf("<tr><td><b><i>");
- wprintf(_("Message ID"));
- wprintf("</i></b></td><td><b><i>");
- wprintf(_("Date/time submitted"));
- wprintf("</i></b></td><td><b><i>");
- wprintf(_("Last attempt"));
- wprintf("</i></b></td><td><b><i>");
- wprintf(_("Sender"));
- wprintf("</i></b></td><td><b><i>");
- wprintf(_("Recipients"));
- wprintf("</i></b></td></tr>\n");
-
- for (i=0; i<num_msgs; ++i) {
+ wc_printf("<tr><td><b><i>");
+ wc_printf(_("Message ID"));
+ wc_printf("</i></b></td><td><b><i>");
+ wc_printf(_("Date/time submitted"));
+ wc_printf("</i></b></td><td><b><i>");
+ wc_printf(_("Last attempt"));
+ wc_printf("</i></b></td><td><b><i>");
+ wc_printf(_("Sender"));
+ wc_printf("</i></b></td><td><b><i>");
+ wc_printf(_("Recipients"));
+ wc_printf("</i></b></td></tr>\n");
+
+ for (i=0; (i < num_msgs) && (i < Stat.maxload); ++i) {
Msg = GetMessagePtrAt(i, WCC->summ);
- if (Msg) {
- lprintf(9, "%d of %d: %ld\n", i, num_msgs, Msg->msgnum);
+ if (Msg != NULL) {
display_queue_msg(Msg->msgnum);
}
- else {
- lprintf(9, "%d of %d: is NULL!\n", i, num_msgs);
- }
}
- wprintf("</table>");
+ wc_printf("</table>");
}
else {
- wprintf("<br /><br /><div align=\"center\">");
- wprintf(_("The queue is empty."));
- wprintf("</div><br /><br />");
+ wc_printf("<br><br><div align=\"center\">");
+ wc_printf(_("The queue is empty."));
+ wc_printf("</div><br><br>");
}
}
else {
- wprintf("<br /><br /><div align=\"center\">");
- wprintf(_("You do not have permission to view this resource."));
- wprintf("</div><br /><br />");
+ wc_printf("<br><br><div align=\"center\">");
+ wc_printf(_("You do not have permission to view this resource."));
+ wc_printf("</div><br><br>");
}
output_headers(0, 0, 0, 0, 0, 0);
end_burst();
{
output_headers(1, 1, 2, 0, 0, 0);
- wprintf("<script type=\"text/javascript\"> \n"
- "function RefreshQueueDisplay() { \n"
- " new Ajax.Updater('smtpqueue_inner_div', \n"
- " 'display_smtpqueue_inner_div', { method: 'get', \n"
- " parameters: Math.random() } ); \n"
- "} \n"
- " \n"
- "function DeleteQueueMsg(msgnum1, msgnum2) { \n"
- " new Ajax.Request( \n"
- " 'ajax_servcmd', { \n"
- " method: 'post', \n"
- " parameters: 'g_cmd=DELE ' + msgnum1 + ',' + msgnum2, \n"
- " onComplete: RefreshQueueDisplay() \n"
- " } \n"
- " ); \n"
- "} \n"
- " \n"
- "</script> \n"
- );
-
- wprintf("<div id=\"banner\">\n");
- wprintf("<h1>");
- wprintf(_("View the outbound SMTP queue"));
- wprintf("</h1>\n");
- wprintf("</div>\n");
+ wc_printf("<div id=\"banner\">\n");
+ wc_printf("<h1>");
+ wc_printf(_("View the outbound SMTP queue"));
+ wc_printf("</h1>\n");
+ wc_printf("</div>\n");
- wprintf("<div id=\"content\" class=\"service\">\n");
+ wc_printf("<div id=\"content\" class=\"service\">\n");
- wprintf("<div class=\"fix_scrollbar_bug\">"
- "<table class=\"smtpqueue_background\">"
+ wc_printf("<table class=\"smtpqueue_background\">"
"<tr><td valign=top>\n");
- wprintf("<div id=\"smtpqueue_inner_div\">");
-
- display_smtpqueue_inner_div();
-
- wprintf("</div>"
+ wc_printf("<div id=\"smtpqueue_inner_div\">"
+ "<div align=\"center\"><img src=\"static/webcit_icons/throbber.gif\"></div>"
+ "</div>"
"<div align=\"center\">"
- "<a href=\"javascript:RefreshQueueDisplay();\">%s</a>"
+ "<a href=\"javascript:RefreshSMTPqueueDisplay();\">%s</a>"
"</div>"
- "</td></tr></table></div>\n", _("Refresh this page")
+ "</td></tr></table>\n", _("Refresh this page")
);
+
+ StrBufAppendPrintf(WC->trailing_javascript, "RefreshSMTPqueueDisplay();\n");
+
wDumpContent(1);
}
+
+
+
+
+
+
+
+
+
+typedef struct _mailq_entry {
+ StrBuf *Recipient;
+ StrBuf *StatusMessage;
+ int Status;
+ /**<
+ * 0 = No delivery has yet been attempted
+ * 2 = Delivery was successful
+ * 4 = A transient error was experienced ... try again later
+ * 5 = Delivery to this address failed permanently. The error message
+ * should be placed in the fourth field so that a bounce message may
+ * be generated.
+ */
+
+ int n;
+ int Active;
+}MailQEntry;
+
+typedef struct queueitem {
+ long MessageID;
+ long QueMsgID;
+ long Submitted;
+ int FailNow;
+ HashList *MailQEntries;
+/* copy of the currently parsed item in the MailQEntries list;
+ * if null add a new one.
+ */
+ MailQEntry *Current;
+ time_t ReattemptWhen;
+ time_t Retry;
+
+ long ActiveDeliveries;
+ StrBuf *EnvelopeFrom;
+ StrBuf *BounceTo;
+ ParsedURL *URL;
+ ParsedURL *FallBackHost;
+} OneQueItem;
+
+
+typedef void (*QItemHandler)(OneQueItem *Item, StrBuf *Line, const char **Pos);
+
+
+void FreeMailQEntry(void *qv)
+{
+ MailQEntry *Q = qv;
+ FreeStrBuf(&Q->Recipient);
+ FreeStrBuf(&Q->StatusMessage);
+ free(Q);
+}
+void FreeQueItem(OneQueItem **Item)
+{
+ DeleteHash(&(*Item)->MailQEntries);
+ FreeStrBuf(&(*Item)->EnvelopeFrom);
+ FreeStrBuf(&(*Item)->BounceTo);
+ FreeURL(&(*Item)->URL);
+ free(*Item);
+ Item = NULL;
+}
+void HFreeQueItem(void *Item)
+{
+ FreeQueItem((OneQueItem**)&Item);
+}
+
+
+OneQueItem *DeserializeQueueItem(StrBuf *RawQItem, long QueMsgID)
+{
+ OneQueItem *Item;
+ const char *pLine = NULL;
+ StrBuf *Line;
+ StrBuf *Token;
+
+ Item = (OneQueItem*)malloc(sizeof(OneQueItem));
+ memset(Item, 0, sizeof(OneQueItem));
+ Item->Retry = 0;
+ Item->MessageID = -1;
+ Item->QueMsgID = QueMsgID;
+
+ Token = NewStrBuf();
+ Line = NewStrBufPlain(NULL, 128);
+ while (pLine != StrBufNOTNULL) {
+ const char *pItemPart = NULL;
+ void *vHandler;
+
+ StrBufExtract_NextToken(Line, RawQItem, &pLine, '\n');
+ if (StrLength(Line) == 0) continue;
+ StrBufExtract_NextToken(Token, Line, &pItemPart, '|');
+ if (GetHash(QItemHandlers, SKEY(Token), &vHandler))
+ {
+ QItemHandler H;
+ H = (QItemHandler) vHandler;
+ H(Item, Line, &pItemPart);
+ }
+ }
+ FreeStrBuf(&Line);
+ FreeStrBuf(&Token);
+/*
+ Put(ActiveQItems,
+ LKEY(Item->MessageID),
+ Item,
+ HFreeQueItem);
+*/
+
+ return Item;
+}
+
+void tmplput_MailQID(StrBuf *Target, WCTemplputParams *TP)
+{
+ OneQueItem *Item = (OneQueItem*) CTX;
+ StrBufAppendPrintf(Target, "%ld", Item->QueMsgID);;
+}
+void tmplput_MailQPayloadID(StrBuf *Target, WCTemplputParams *TP)
+{
+ OneQueItem *Item = (OneQueItem*) CTX;
+ StrBufAppendPrintf(Target, "%ld", Item->MessageID);
+}
+void tmplput_MailQBounceTo(StrBuf *Target, WCTemplputParams *TP)
+{
+ OneQueItem *Item = (OneQueItem*) CTX;
+ StrBufAppendTemplate(Target, TP, Item->BounceTo, 0);
+}
+void tmplput_MailQAttempted(StrBuf *Target, WCTemplputParams *TP)
+{
+ char datebuf[64];
+ OneQueItem *Item = (OneQueItem*) CTX;
+ webcit_fmt_date(datebuf, 64, Item->ReattemptWhen, DATEFMT_BRIEF);
+ StrBufAppendBufPlain(Target, datebuf, -1, 0);
+}
+void tmplput_MailQSubmitted(StrBuf *Target, WCTemplputParams *TP)
+{
+ char datebuf[64];
+ OneQueItem *Item = (OneQueItem*) CTX;
+ webcit_fmt_date(datebuf, 64, Item->Submitted, DATEFMT_BRIEF);
+ StrBufAppendBufPlain(Target, datebuf, -1, 0);
+}
+void tmplput_MailQEnvelopeFrom(StrBuf *Target, WCTemplputParams *TP)
+{
+ OneQueItem *Item = (OneQueItem*) CTX;
+ StrBufAppendTemplate(Target, TP, Item->EnvelopeFrom, 0);
+}
+void tmplput_MailQRetry(StrBuf *Target, WCTemplputParams *TP)
+{
+ char datebuf[64];
+ OneQueItem *Item = (OneQueItem*) CTX;
+
+ if (Item->Retry == 0) {
+ StrBufAppendBufPlain(Target, _("First Attempt pending"), -1, 0);
+ }
+ else {
+ webcit_fmt_date(datebuf, sizeof(datebuf), Item->Retry, DATEFMT_BRIEF);
+ StrBufAppendBufPlain(Target, datebuf, -1, 0);
+ }
+}
+
+void tmplput_MailQRCPT(StrBuf *Target, WCTemplputParams *TP)
+{
+ MailQEntry *Entry = (MailQEntry*) CTX;
+ StrBufAppendTemplate(Target, TP, Entry->Recipient, 0);
+}
+void tmplput_MailQRCPTStatus(StrBuf *Target, WCTemplputParams *TP)
+{
+ MailQEntry *Entry = (MailQEntry*) CTX;
+ StrBufAppendPrintf(Target, "%ld", Entry->Status);
+}
+void tmplput_MailQStatusMsg(StrBuf *Target, WCTemplputParams *TP)
+{
+ MailQEntry *Entry = (MailQEntry*) CTX;
+ StrBufAppendTemplate(Target, TP, Entry->StatusMessage, 0);
+}
+
+HashList *iterate_get_Recipients(StrBuf *Target, WCTemplputParams *TP)
+{
+ OneQueItem *Item = (OneQueItem*) CTX;
+ return Item->MailQEntries;
+}
+
+
+void NewMailQEntry(OneQueItem *Item)
+{
+ Item->Current = (MailQEntry*) malloc(sizeof(MailQEntry));
+ memset(Item->Current, 0, sizeof(MailQEntry));
+
+ if (Item->MailQEntries == NULL)
+ Item->MailQEntries = NewHash(1, Flathash);
+ Item->Current->StatusMessage = NewStrBuf();
+ Item->Current->n = GetCount(Item->MailQEntries);
+ Put(Item->MailQEntries,
+ IKEY(Item->Current->n),
+ Item->Current,
+ FreeMailQEntry);
+}
+
+void QItem_Handle_MsgID(OneQueItem *Item, StrBuf *Line, const char **Pos)
+{
+ Item->MessageID = StrBufExtractNext_long(Line, Pos, '|');
+}
+
+void QItem_Handle_EnvelopeFrom(OneQueItem *Item, StrBuf *Line, const char **Pos)
+{
+ if (Item->EnvelopeFrom == NULL)
+ Item->EnvelopeFrom = NewStrBufPlain(NULL, StrLength(Line));
+ StrBufExtract_NextToken(Item->EnvelopeFrom, Line, Pos, '|');
+}
+
+void QItem_Handle_BounceTo(OneQueItem *Item, StrBuf *Line, const char **Pos)
+{
+ if (Item->BounceTo == NULL)
+ Item->BounceTo = NewStrBufPlain(NULL, StrLength(Line));
+ StrBufExtract_NextToken(Item->BounceTo, Line, Pos, '|');
+}
+
+void QItem_Handle_Recipient(OneQueItem *Item, StrBuf *Line, const char **Pos)
+{
+ if (Item->Current == NULL)
+ NewMailQEntry(Item);
+ if (Item->Current->Recipient == NULL)
+ Item->Current->Recipient=NewStrBufPlain(NULL, StrLength(Line));
+ StrBufExtract_NextToken(Item->Current->Recipient, Line, Pos, '|');
+ Item->Current->Status = StrBufExtractNext_int(Line, Pos, '|');
+ StrBufExtract_NextToken(Item->Current->StatusMessage, Line, Pos, '|');
+ Item->Current = NULL; // TODO: is this always right?
+}
+
+
+void QItem_Handle_retry(OneQueItem *Item, StrBuf *Line, const char **Pos)
+{
+ Item->Retry =
+ StrBufExtractNext_int(Line, Pos, '|');
+ Item->Retry *= 2;
+}
+
+
+void QItem_Handle_Submitted(OneQueItem *Item, StrBuf *Line, const char **Pos)
+{
+ Item->Submitted = atol(*Pos);
+
+}
+
+void QItem_Handle_Attempted(OneQueItem *Item, StrBuf *Line, const char **Pos)
+{
+ Item->ReattemptWhen = StrBufExtractNext_int(Line, Pos, '|');
+}
+
+
+
+
+
+
+
+
+void render_QUEUE(wc_mime_attachment *Mime, StrBuf *RawData, StrBuf *FoundCharset)
+{
+ WCTemplputParams SubTP;
+
+ memset(&SubTP, 0, sizeof(WCTemplputParams));
+ SubTP.Filter.ContextType = CTX_MAILQITEM;
+ SubTP.Context = DeserializeQueueItem(Mime->Data, Mime->msgnum);
+ DoTemplate(HKEY("view_mailq_message"),NULL, &SubTP);
+ FreeQueItem ((OneQueItem**)&SubTP.Context);
+}
+
+void
+ServerShutdownModule_SMTP_QUEUE
+(void)
+{
+ DeleteHash(&QItemHandlers);
+}
+void
+ServerStartModule_SMTP_QUEUE
+(void)
+{
+ QItemHandlers = NewHash(0, NULL);
+}
+
+int qview_PrintPageHeader(SharedMessageStatus *Stat, void **ViewSpecific)
+{
+ if (!WC->is_aide)
+ {
+ output_headers(1, 1, 1, 0, 0, 0);
+ }
+ else
+ {
+ output_headers(1, 1, 2, 0, 0, 0);
+ }
+ return 0;
+}
+
+int qview_GetParamsGetServerCall(SharedMessageStatus *Stat,
+ void **ViewSpecific,
+ long oper,
+ char *cmd,
+ long len,
+ char *filter,
+ long flen)
+{
+ if (!WC->is_aide)
+ {
+ DoTemplate(HKEY("aide_required"), NULL, NULL);
+ end_burst();
+
+ return 300;
+ }
+ else {
+ snprintf(cmd, len, "MSGS ALL|0|1");
+ snprintf(filter, flen, "SUBJ|QMSG");
+ DoTemplate(HKEY("view_mailq_header"), NULL, NULL);
+ return 200;
+ }
+}
+
+/*
+ * Display task view
+ */
+int qview_LoadMsgFromServer(SharedMessageStatus *Stat,
+ void **ViewSpecific,
+ message_summary* Msg,
+ int is_new,
+ int i)
+{
+ wcsession *WCC = WC;
+ const StrBuf *Mime;
+
+ /* Not (yet?) needed here? calview *c = (calview *) *ViewSpecific; */
+ read_message(WCC->WBuf, HKEY("view_mailq_message_bearer"), Msg->msgnum, NULL, &Mime);
+
+ return 0;
+}
+
+
+int qview_RenderView_or_Tail(SharedMessageStatus *Stat,
+ void **ViewSpecific,
+ long oper)
+{
+ wcsession *WCC = WC;
+ WCTemplputParams SubTP;
+
+ if (GetCount(WCC->summ) == 0)
+ DoTemplate(HKEY("view_mailq_footer_empty"),NULL, &SubTP);
+ else
+ DoTemplate(HKEY("view_mailq_footer"),NULL, &SubTP);
+
+ return 0;
+}
+int qview_Cleanup(void **ViewSpecific)
+{
+ wDumpContent(1);
+ return 0;
+}
+
void
InitModule_SMTP_QUEUE
(void)
{
- WebcitAddUrlHandler(HKEY("display_smtpqueue"), display_smtpqueue, 0);
- WebcitAddUrlHandler(HKEY("display_smtpqueue_inner_div"), display_smtpqueue_inner_div, 0);
+
+ Put(QItemHandlers, HKEY("msgid"), QItem_Handle_MsgID, reference_free_handler);
+ Put(QItemHandlers, HKEY("envelope_from"), QItem_Handle_EnvelopeFrom, reference_free_handler);
+ Put(QItemHandlers, HKEY("retry"), QItem_Handle_retry, reference_free_handler);
+ Put(QItemHandlers, HKEY("attempted"), QItem_Handle_Attempted, reference_free_handler);
+ Put(QItemHandlers, HKEY("remote"), QItem_Handle_Recipient, reference_free_handler);
+ Put(QItemHandlers, HKEY("bounceto"), QItem_Handle_BounceTo, reference_free_handler);
+ Put(QItemHandlers, HKEY("submitted"), QItem_Handle_Submitted, reference_free_handler);
+
+ WebcitAddUrlHandler(HKEY("display_smtpqueue"), "", 0, display_smtpqueue, 0);
+ WebcitAddUrlHandler(HKEY("display_smtpqueue_inner_div"), "", 0, display_smtpqueue_inner_div, 0);
+ RegisterMimeRenderer(HKEY("application/x-citadel-delivery-list"), render_QUEUE, 1, 9000);
+
+
+ RegisterNamespace("MAILQ:ID", 0, 0, tmplput_MailQID, NULL, CTX_MAILQITEM);
+ RegisterNamespace("MAILQ:PAYLOAD:ID", 0, 0, tmplput_MailQPayloadID, NULL, CTX_MAILQITEM);
+ RegisterNamespace("MAILQ:BOUNCETO", 0, 1, tmplput_MailQBounceTo, NULL, CTX_MAILQITEM);
+ RegisterNamespace("MAILQ:ATTEMPTED", 0, 0, tmplput_MailQAttempted, NULL, CTX_MAILQITEM);
+ RegisterNamespace("MAILQ:SUBMITTED", 0, 0, tmplput_MailQSubmitted, NULL, CTX_MAILQITEM);
+ RegisterNamespace("MAILQ:ENVELOPEFROM", 0, 1, tmplput_MailQEnvelopeFrom, NULL, CTX_MAILQITEM);
+ RegisterNamespace("MAILQ:RETRY", 0, 0, tmplput_MailQRetry, NULL, CTX_MAILQITEM);
+
+ RegisterNamespace("MAILQ:RCPT:ADDR", 0, 1, tmplput_MailQRCPT, NULL, CTX_MAILQ_RCPT);
+ RegisterNamespace("MAILQ:RCPT:STATUS", 0, 0, tmplput_MailQRCPTStatus, NULL, CTX_MAILQ_RCPT);
+ RegisterNamespace("MAILQ:RCPT:STATUSMSG", 0, 1, tmplput_MailQStatusMsg, NULL, CTX_MAILQ_RCPT);
+
+ RegisterIterator("MAILQ:RCPT", 0, NULL, iterate_get_Recipients,
+ NULL, NULL, CTX_MAILQ_RCPT, CTX_MAILQITEM, IT_NOFLAG);
+
+
+ RegisterReadLoopHandlerset(
+ VIEW_QUEUE,
+ qview_GetParamsGetServerCall,
+ qview_PrintPageHeader,
+ NULL, /* TODO: is this right? */
+ NULL,
+ qview_LoadMsgFromServer,
+ qview_RenderView_or_Tail,
+ qview_Cleanup);
+
}