SMTP-Queue-View: templatize
authorWilfried Goesgens <dothebart@citadel.org>
Sat, 18 Feb 2012 17:35:59 +0000 (18:35 +0100)
committerWilfried Goesgens <dothebart@citadel.org>
Sat, 18 Feb 2012 17:35:59 +0000 (18:35 +0100)
register a view for the mailq. its not supporting a separate js for reloading, since the original didn't also.

webcit/smtpqueue.c
webcit/static/styles/webcit.css
webcit/static/t/aide/global_config.html
webcit/static/t/view_mailq/footer.html [new file with mode: 0644]
webcit/static/t/view_mailq/footer_empty.html [new file with mode: 0644]
webcit/static/t/view_mailq/header.html [new file with mode: 0644]
webcit/static/t/view_mailq/message.html [new file with mode: 0644]
webcit/static/t/view_mailq/message_bearer.html [new file with mode: 0644]
webcit/static/t/view_mailq/recipient.html [new file with mode: 0644]
webcit/subst.c
webcit/subst.h

index 4cb1ce74ba284977ab3ae0e1c90c1a81ccc24a28..4a30afa45b80dd334864420fed0b3a03b3e9e7ad 100644 (file)
@@ -3,6 +3,7 @@
  */
 
 #include "webcit.h"
+HashList *QItemHandlers = NULL;
 
 /*
  * display one message in the queue
@@ -181,7 +182,8 @@ void display_smtpqueue_inner_div(void) {
                Stat.maxload = 10000;
                Stat.lowest_found = (-1);
                Stat.highest_found = (-1);
-               num_msgs = load_msg_ptrs("MSGS ALL", &Stat, NULL);
+//             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) {
                         wc_printf("<table class=\"mailbox_summary\" rules=rows "
                                "cellpadding=2 style=\"width:100%%;\">"
@@ -257,10 +259,404 @@ void display_smtpqueue(void)
 
 }
 
+
+
+
+
+
+
+
+
+
+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)
 {
+
+       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);
+
 }
index 278b42e531726065f92bd9e4f225905dccc89ecf..884b0d0ae1928f2e461e5480cdd189fa71b7dedc 100644 (file)
@@ -738,6 +738,14 @@ ul.adminitems li {
 
 ul.adminitems li span {        display: block }
 
+/* Mailq */
+table.mailstatus {background-color: lightgray }
+td.mailstatus_0 {background-color: gray }
+td.mailstatus_1 {background-color: gray }
+td.mailstatus_2 {background-color: green }
+td.mailstatus_3 {background-color: orange }
+td.mailstatus_4 {background-color: yellow }
+td.mailstatus_5 {background-color: red }
 
 /* Room list - Tree Node */
 
index fb11d1a0d410c6fceee871bab87a4d865ffa5235..891c7ec2dccccff600f780395c140e16da2f8231 100644 (file)
@@ -2,5 +2,5 @@
 <li><a href="do_template?template=aide_display_sitewide_config"><?_("Edit site-wide configuration")></a></li>
 <li><a href="do_template?template=aide_display_inetconf"><?_("Domain names and Internet mail configuration")></a></li>
 <li><a href="do_template?template=aide_display_ignetconf"><?_("Configure replication with other Citadel servers")></a></li>
-<li><a href="display_smtpqueue"><?_("View the outbound SMTP queue")></a></li>
+<li><a href="dotgoto?room=__CitadelSMTPspoolout__&view=11"><?_("View the outbound SMTP queue")></a></li>
 </ul>
diff --git a/webcit/static/t/view_mailq/footer.html b/webcit/static/t/view_mailq/footer.html
new file mode 100644 (file)
index 0000000..2880a2b
--- /dev/null
@@ -0,0 +1,7 @@
+</table>
+
+<?!("COND:AIDE", 1)>
+<br><br><div align="center">
+<?_("You do not have permission to view this resource.")>
+</div><br><br>
+<?!("X", 1)>
diff --git a/webcit/static/t/view_mailq/footer_empty.html b/webcit/static/t/view_mailq/footer_empty.html
new file mode 100644 (file)
index 0000000..6121b3b
--- /dev/null
@@ -0,0 +1,11 @@
+</table>
+
+<br><br><div align="center">
+<?_("The queue is empty.")>
+</div><br><br>
+
+<?!("COND:AIDE", 1)>
+<br><br><div align="center">
+<?_("You do not have permission to view this resource.")>
+</div><br><br>
+<?!("X", 1)>
diff --git a/webcit/static/t/view_mailq/header.html b/webcit/static/t/view_mailq/header.html
new file mode 100644 (file)
index 0000000..919a4f3
--- /dev/null
@@ -0,0 +1,31 @@
+<div id="banner">
+<h1>
+<?_("View the outbound SMTP queue")>
+</h1>
+</div>
+
+<div id="content" class="service">
+<!--
+<table class="smtpqueue_background">
+<tr><td valign=top>
+<div id="smtpqueue_inner_div">
+<div align="center"><img src="static/webcit_icons/throbber.gif"></div>"
+</div>
+<div align="center">
+<a href="javascript:RefreshSMTPqueueDisplay();"><?_("Refresh this page")></a>
+</div>
+</td></tr></table>
+-->
+<table class="mailbox_summary" rules=rows cellpadding=2 style="width:100%%;">
+<tr><td><b><i>
+<?_("Message ID")>
+</i></b></td><td><b><i>
+<?_("Date/time submitted")>
+</i></b></td><td><b><i>
+<?_("Last attempt")>
+</i></b></td><td><b><i>
+<?_("Sender")>
+</i></b></td><td><b><i>
+<?_("Recipients")>
+</i></b></td></tr>
+
diff --git a/webcit/static/t/view_mailq/message.html b/webcit/static/t/view_mailq/message.html
new file mode 100644 (file)
index 0000000..a6e972f
--- /dev/null
@@ -0,0 +1,11 @@
+<tr>
+<td><a href="javascript:DeleteSMTPqueueMsg(<?MAILQ:PAYLOAD:ID>,<?MAILQ:ID>);"><?_("(Delete)")></a><br>
+<?MAILQ:ID></td>
+<td><?MAILQ:SUBMITTED></td>
+<td><?MAILQ:RETRY></td>
+<td><?MAILQ:BOUNCETO()><br><?MAILQ:ENVELOPEFROM()></td>
+
+<td><table class="mailstatus">
+<?ITERATE("MAILQ:RCPT", ="view_mailq_recipient")>
+</table></td>
+</tr>
diff --git a/webcit/static/t/view_mailq/message_bearer.html b/webcit/static/t/view_mailq/message_bearer.html
new file mode 100644 (file)
index 0000000..939ded0
--- /dev/null
@@ -0,0 +1,2 @@
+<?--("this page was intentionaly left blank")>
+
diff --git a/webcit/static/t/view_mailq/recipient.html b/webcit/static/t/view_mailq/recipient.html
new file mode 100644 (file)
index 0000000..62dd821
--- /dev/null
@@ -0,0 +1,4 @@
+<tr >
+<td class="mailstatus_<?MAILQ:RCPT:STATUS()>"><?MAILQ:RCPT:ADDR()></td>
+<td class="mailstatus_<?MAILQ:RCPT:STATUS()>"><?MAILQ:RCPT:STATUSMSG()><td>
+</tr>
index f1a01cf55807ce286e726afdbe55b60223d5e3bd..6e5ab6fc690248e63532ddf0408ae3c8bfff4cac 100644 (file)
@@ -111,6 +111,8 @@ const char *CtxNames[]  = {
        "Context VCARD",
        "Context SIEVE List",
        "Context SIEVE Script",
+       "Context MailQ-Item",
+       "Context MailQ-Recipient",
        "Context UNKNOWN"
 };
 
index e04489c5deac8186afeeedee0f397ec7351de778..3bf4917490473e9e0316606013f4118ad1fc35ec 100644 (file)
@@ -62,8 +62,10 @@ enum {
 #define CTX_VCARD 21
 #define CTX_SIEVELIST 22
 #define CTX_SIEVESCRIPT 23
+#define CTX_MAILQITEM 24
+#define CTX_MAILQ_RCPT 25
 
-#define CTX_UNKNOWN 24
+#define CTX_UNKNOWN 25
 
 
 /**