Added a new screen to view the outbound SMTP queue.
[citadel.git] / webcit / smtpqueue.c
1 /* 
2  * $Id: $
3  */
4 /**
5  * \defgroup SMTPqueue Display the outbound SMTP queue
6  * \ingroup CitadelConfig
7  */
8 /*@{*/
9 #include "webcit.h"
10
11 /**
12  * \brief display one message in the queue
13  */
14 void display_queue_msg(long msgnum)
15 {
16         char buf[1024];
17         char keyword[32];
18         int in_body = 0;
19         int is_delivery_list = 0;
20         time_t submitted = 0;
21         time_t attempted = 0;
22         time_t last_attempt = 0;
23         int number_of_attempts = 0;
24         char sender[256];
25         char recipients[65536];
26         char thisrecp[256];
27         char thisdsn[256];
28
29         strcpy(sender, "");
30         strcpy(recipients, "");
31
32         serv_printf("MSG2 %ld", msgnum);
33         serv_getln(buf, sizeof buf);
34         if (buf[0] != '1') return;
35
36         while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
37
38                 if (strlen(buf) > 0) {
39                         if (buf[strlen(buf)-1] == 13) {
40                                 buf[strlen(buf)-1] = 0;
41                         }
42                 }
43
44                 if ( (strlen(buf) == 0) && (in_body == 0) ) {
45                         in_body = 1;
46                 }
47
48                 if ( (!in_body)
49                    && (!strncasecmp(buf, "Content-type: application/x-citadel-delivery-list", 49))
50                 ) {
51                         is_delivery_list = 1;
52                 }
53
54                 if ( (in_body) && (!is_delivery_list) ) {
55                         while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
56                                 /* Not a delivery list; flush and return quietly. */
57                         }
58                         return;
59                 }
60
61                 if ( (in_body) && (is_delivery_list) ) {
62                         extract_token(keyword, buf, 0, '|', sizeof keyword);
63
64                         if (!strcasecmp(keyword, "submitted")) {
65                                 submitted = extract_long(buf, 1);
66                         }
67
68                         if (!strcasecmp(keyword, "attempted")) {
69                                 attempted = extract_long(buf, 1);
70                                 ++number_of_attempts;
71                                 if (attempted > last_attempt) {
72                                         last_attempt = attempted;
73                                 }
74                         }
75
76                         if (!strcasecmp(keyword, "bounceto")) {
77                                 extract_token(sender, buf, 1, '|', sizeof sender);
78                         }
79
80                         if (!strcasecmp(keyword, "remote")) {
81                                 extract_token(thisrecp, buf, 1, '|', sizeof thisrecp);
82                                 extract_token(thisdsn, buf, 3, '|', sizeof thisdsn);
83
84                                 if (strlen(recipients) + strlen(thisrecp) + strlen(thisdsn) + 100
85                                    < sizeof recipients) {
86                                         if (strlen(recipients) > 0) {
87                                                 strcat(recipients, "<br />");
88                                         }
89                                         stresc(&recipients[strlen(recipients)], thisrecp, 1, 1);
90                                         strcat(recipients, "<br />&nbsp;&nbsp;<i>");
91                                         stresc(&recipients[strlen(recipients)], thisdsn, 1, 1);
92                                         strcat(recipients, "</i>");
93                                 }
94
95                         }
96
97                 }
98
99         }
100
101         wprintf("<tr><td>");
102         wprintf("%ld", msgnum);
103
104         wprintf("</td><td>");
105         if (submitted > 0) {
106                 fmt_date(buf, submitted, 1);
107                 wprintf("%s", buf);
108         }
109         else {
110                 wprintf("&nbsp;");
111         }
112
113         wprintf("</td><td>");
114         if (last_attempt > 0) {
115                 fmt_date(buf, last_attempt, 1);
116                 wprintf("%s", buf);
117         }
118         else {
119                 wprintf("&nbsp;");
120         }
121
122         wprintf("</td><td>");
123         escputs(sender);
124
125         wprintf("</td><td>");
126         wprintf("%s", recipients);
127         wprintf("</td></tr>\n");
128
129 }
130
131
132 /**
133  * \brief display the outbound SMTP queue
134  */
135 void display_smtpqueue(void)
136 {
137         int i;
138         int num_msgs;
139
140         output_headers(1, 1, 2, 0, 0, 0);
141         wprintf("<div id=\"banner\">\n");
142         wprintf("<TABLE WIDTH=100%% BORDER=0 BGCOLOR=\"#444455\"><TR><TD>");
143         wprintf("<SPAN CLASS=\"titlebar\">");
144         wprintf(_("View the outbound SMTP queue"));
145         wprintf("</SPAN>\n");
146         wprintf("</TD></TR></TABLE>\n");
147         wprintf("</div>\n<div id=\"content\">\n");
148
149         wprintf("<div class=\"fix_scrollbar_bug\">"
150                 "<table border=0 width=100%% bgcolor=\"#FFFFFF\">"
151                 "<tr><td valign=top>\n");
152
153
154         /* Check to see if we can go to the __CitadelSMTPspoolout__ room.
155          * If not, we don't have access to the queue.
156          */
157         gotoroom("__CitadelSMTPspoolout__");
158         if (!strcasecmp(WC->wc_roomname, "__CitadelSMTPspoolout__")) {
159
160                 num_msgs = load_msg_ptrs("MSGS ALL", 0);
161                 if (num_msgs > 0) {
162                         wprintf("<table class=\"mailbox_summary\" rules=rows "
163                                 "cellpadding=2 style=\"width:100%%;-moz-user-select:none;\">"
164                         );
165
166                         wprintf("<tr><td><b><i>");
167                         wprintf(_("Message ID"));
168                         wprintf("</i></b></td><td><b><i>");
169                         wprintf(_("Date/time submitted"));
170                         wprintf("</i></b></td><td><b><i>");
171                         wprintf(_("Last attempt"));
172                         wprintf("</i></b></td><td><b><i>");
173                         wprintf(_("Sender"));
174                         wprintf("</i></b></td><td><b><i>");
175                         wprintf(_("Recipients"));
176                         wprintf("</i></b></td></tr>\n");
177
178                         for (i=0; i<num_msgs; ++i) {
179                                 display_queue_msg(WC->msgarr[i]);
180                         }
181
182                         wprintf("</table>");
183
184                 }
185                 else {
186                         wprintf("<br /><br /><div align=\"center\">");
187                         wprintf(_("The queue is empty."));
188                         wprintf("</div><br /><br />");
189                 }
190         }
191         else {
192                 wprintf("<br /><br /><div align=\"center\">");
193                 wprintf(_("You do not have permission to view this resource."));
194                 wprintf("</div><br /><br />");
195         }
196
197         wprintf("</td></tr></table></div>\n");
198         wDumpContent(1);
199
200 }
201
202
203
204
205 /*@}*/