* typedef wcsession, so we don't always need to say gcc again its a struct.
[citadel.git] / webcit / smtpqueue.c
index 664e5eff6f087736512a0cde2f5e6f7ecfc930cc..ca17b24e1fcb6dfb2a265b531edd6de07ec7e0c5 100644 (file)
@@ -1,15 +1,13 @@
 /* 
  * $Id$
+ *
+ * Display the outbound SMTP queue
  */
-/**
- * \defgroup SMTPqueue Display the outbound SMTP queue
- * \ingroup CitadelConfig
- */
-/*@{*/
+
 #include "webcit.h"
 
-/**
- * \brief display one message in the queue
+/*
+ * display one message in the queue
  */
 void display_queue_msg(long msgnum)
 {
@@ -23,13 +21,17 @@ void display_queue_msg(long msgnum)
        int number_of_attempts = 0;
        char sender[256];
        char recipients[65536];
+       int recipients_len = 0;
        char thisrecp[256];
        char thisdsn[256];
+       char thismsg[512];
+       int thismsg_len;
        long msgid = 0;
        int len;
 
        strcpy(sender, "");
        strcpy(recipients, "");
+       recipients_len = 0;
 
        serv_printf("MSG2 %ld", msgnum);
        serv_getln(buf, sizeof buf);
@@ -44,7 +46,7 @@ void display_queue_msg(long msgnum)
                        }
                }
 
-               if ( (IsEmptyStr(buf) == 0) && (in_body == 0) ) {
+               if ( (IsEmptyStr(buf)) && (in_body == 0) ) {
                        in_body = 1;
                }
 
@@ -96,38 +98,29 @@ void display_queue_msg(long msgnum)
                        }
 
                        if (!strcasecmp(keyword, "remote")) {
-                               int RcptLen;
-                               int TRcptLen;
-                               int TDsn;
-                               int NLen;
+                               thismsg[0] = 0;
+
                                extract_token(thisrecp, buf, 1, '|', sizeof thisrecp);
                                extract_token(thisdsn, buf, 3, '|', sizeof thisdsn);
-                               RcptLen = strlen(recipients);
-                               TRcptLen = strlen(thisrecp);
-                               TDsn = strlen(thisdsn);
-                               if ( RcptLen + TRcptLen + TDsn + 100
-                                  < sizeof recipients) {
-                                       if (!IsEmptyStr(recipients)) {
-                                               // copy the \0 to be sure..
-                                               memcpy (&recipients[RcptLen], "<br />\0",  7);
-                                               RcptLen += 6;
+
+                               if (!IsEmptyStr(thisrecp)) {
+                                       stresc(thismsg, sizeof thismsg, thisrecp, 1, 1);
+                                       if (!IsEmptyStr(thisdsn)) {
+                                               strcat(thismsg, "<br />&nbsp;&nbsp;<i>");
+                                               stresc(&thismsg[strlen(thismsg)], sizeof thismsg,
+                                                       thisdsn, 1, 1);
+                                               strcat(thismsg, "</i>");
+                                       }
+                                       thismsg_len = strlen(thismsg);
+
+                                       if ((recipients_len + thismsg_len + 100) < sizeof recipients) {
+                                               if (!IsEmptyStr(recipients)) {
+                                                       strcpy(&recipients[recipients_len], "<br />");
+                                                       recipients_len += 6;
+                                               }
+                                               strcpy(&recipients[recipients_len], thismsg);
+                                               recipients_len += thismsg_len;
                                        }
-                                       NLen = stresc(&recipients[RcptLen], 
-                                                     sizeof recipients - RcptLen, 
-                                                     thisrecp, 1, 1);
-                                       if (NLen != -1)
-                                       {
-                                               RcptLen += NLen;
-                                               NLen = sizeof "<br />&nbsp;&nbsp;<i>";
-                                               memcpy(recipients, "<br />&nbsp;&nbsp;<i>", 
-                                                      NLen);
-                                               RcptLen += NLen - 1;
-                                               NLen = stresc(&recipients[RcptLen], 
-                                                             sizeof recipients - RcptLen, 
-                                                             thisdsn, 1, 1);
-                                               if (NLen != -1)
-                                                       memcpy (recipients, "</i>\0", 5);
-                                       } /// else bail out?
                                }
 
                        }
@@ -144,7 +137,7 @@ void display_queue_msg(long msgnum)
 
        wprintf("</td><td>");
        if (submitted > 0) {
-               fmt_date(buf, submitted, 1);
+               webcit_fmt_date(buf, submitted, 1);
                wprintf("%s", buf);
        }
        else {
@@ -153,7 +146,7 @@ void display_queue_msg(long msgnum)
 
        wprintf("</td><td>");
        if (last_attempt > 0) {
-               fmt_date(buf, last_attempt, 1);
+               webcit_fmt_date(buf, last_attempt, 1);
                wprintf("%s", buf);
        }
        else {
@@ -171,6 +164,8 @@ void display_queue_msg(long msgnum)
 
 
 void display_smtpqueue_inner_div(void) {
+       message_summary *Msg;
+       wcsession *WCC = WC;
        int i;
        int num_msgs;
 
@@ -178,12 +173,12 @@ void display_smtpqueue_inner_div(void) {
         * If not, we don't have access to the queue.
         */
        gotoroom("__CitadelSMTPspoolout__");
-       if (!strcasecmp(WC->wc_roomname, "__CitadelSMTPspoolout__")) {
+       if (!strcasecmp(WCC->wc_roomname, "__CitadelSMTPspoolout__")) {
 
                num_msgs = load_msg_ptrs("MSGS ALL", 0);
                if (num_msgs > 0) {
                         wprintf("<table class=\"mailbox_summary\" rules=rows "
-                               "cellpadding=2 style=\"width:100%%;-moz-user-select:none;\">"
+                               "cellpadding=2 style=\"width:100%%;\">"
                        );
 
                        wprintf("<tr><td><b><i>");
@@ -199,7 +194,9 @@ void display_smtpqueue_inner_div(void) {
                        wprintf("</i></b></td></tr>\n");
 
                        for (i=0; i<num_msgs; ++i) {
-                               display_queue_msg(WC->msgarr[i]);
+                               Msg = GetMessagePtrAt(i, WCC->summ);
+
+                               display_queue_msg((Msg==NULL)? 0 : Msg->msgnum);
                        }
 
                        wprintf("</table>");
@@ -272,7 +269,12 @@ void display_smtpqueue(void)
 
 }
 
-
-
+void 
+InitModule_SMTP_QUEUE
+(void)
+{
+       WebcitAddUrlHandler(HKEY("display_smtpqueue"), display_smtpqueue, 0);
+       WebcitAddUrlHandler(HKEY("display_smtpqueue_inner_div"), display_smtpqueue_inner_div, 0);
+}
 
 /*@}*/