use the same way to display all banners and services contents
[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         long msgid = 0;
29         int len;
30
31         strcpy(sender, "");
32         strcpy(recipients, "");
33
34         serv_printf("MSG2 %ld", msgnum);
35         serv_getln(buf, sizeof buf);
36         if (buf[0] != '1') return;
37
38         while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
39
40                 if (!IsEmptyStr(buf)) {
41                         len = strlen(buf);
42                         if (buf[len - 1] == 13) {
43                                 buf[len - 1] = 0;
44                         }
45                 }
46
47                 if ( (IsEmptyStr(buf) == 0) && (in_body == 0) ) {
48                         in_body = 1;
49                 }
50
51                 if ( (!in_body)
52                    && (!strncasecmp(buf, "Content-type: application/x-citadel-delivery-list", 49))
53                 ) {
54                         is_delivery_list = 1;
55                 }
56
57                 if ( (in_body) && (!is_delivery_list) ) {
58                         while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
59                                 /* Not a delivery list; flush and return quietly. */
60                         }
61                         return;
62                 }
63
64                 if ( (in_body) && (is_delivery_list) ) {
65                         extract_token(keyword, buf, 0, '|', sizeof keyword);
66
67                         if (!strcasecmp(keyword, "msgid")) {
68                                 msgid = extract_long(buf, 1);
69                         }
70
71                         if (!strcasecmp(keyword, "submitted")) {
72                                 submitted = extract_long(buf, 1);
73                         }
74
75                         if (!strcasecmp(keyword, "attempted")) {
76                                 attempted = extract_long(buf, 1);
77                                 ++number_of_attempts;
78                                 if (attempted > last_attempt) {
79                                         last_attempt = attempted;
80                                 }
81                         }
82
83                         if (!strcasecmp(keyword, "bounceto")) {
84                                 extract_token(sender, buf, 1, '|', sizeof sender);
85
86                                 /* Strip off local hostname if it's our own */
87                                 char *atsign;
88                                 atsign = strchr(sender, '@');
89                                 if (atsign != NULL) {
90                                         ++atsign;
91                                         if (!strcasecmp(atsign, serv_info.serv_nodename)) {
92                                                 --atsign;
93                                                 *atsign = 0;
94                                         }
95                                 }
96                         }
97
98                         if (!strcasecmp(keyword, "remote")) {
99                                 extract_token(thisrecp, buf, 1, '|', sizeof thisrecp);
100                                 extract_token(thisdsn, buf, 3, '|', sizeof thisdsn);
101
102                                 if (strlen(recipients) + strlen(thisrecp) + strlen(thisdsn) + 100
103                                    < sizeof recipients) {
104                                         if (!IsEmptyStr(recipients)) {
105                                                 strcat(recipients, "<br />");
106                                         }
107                                         stresc(&recipients[strlen(recipients)], thisrecp, 1, 1);
108                                         strcat(recipients, "<br />&nbsp;&nbsp;<i>");
109                                         stresc(&recipients[strlen(recipients)], thisdsn, 1, 1);
110                                         strcat(recipients, "</i>");
111                                 }
112
113                         }
114
115                 }
116
117         }
118
119         wprintf("<tr><td>");
120         wprintf("%ld<br />", msgnum);
121         wprintf(" <a href=\"javascript:DeleteQueueMsg(%ld,%ld);\">%s</a>", 
122                 msgnum, msgid, _("(Delete)")
123         );
124
125         wprintf("</td><td>");
126         if (submitted > 0) {
127                 fmt_date(buf, submitted, 1);
128                 wprintf("%s", buf);
129         }
130         else {
131                 wprintf("&nbsp;");
132         }
133
134         wprintf("</td><td>");
135         if (last_attempt > 0) {
136                 fmt_date(buf, last_attempt, 1);
137                 wprintf("%s", buf);
138         }
139         else {
140                 wprintf("&nbsp;");
141         }
142
143         wprintf("</td><td>");
144         escputs(sender);
145
146         wprintf("</td><td>");
147         wprintf("%s", recipients);
148         wprintf("</td></tr>\n");
149
150 }
151
152
153 void display_smtpqueue_inner_div(void) {
154         int i;
155         int num_msgs;
156
157         /* Check to see if we can go to the __CitadelSMTPspoolout__ room.
158          * If not, we don't have access to the queue.
159          */
160         gotoroom("__CitadelSMTPspoolout__");
161         if (!strcasecmp(WC->wc_roomname, "__CitadelSMTPspoolout__")) {
162
163                 num_msgs = load_msg_ptrs("MSGS ALL", 0);
164                 if (num_msgs > 0) {
165                         wprintf("<table class=\"mailbox_summary\" rules=rows "
166                                 "cellpadding=2 style=\"width:100%%;-moz-user-select:none;\">"
167                         );
168
169                         wprintf("<tr><td><b><i>");
170                         wprintf(_("Message ID"));
171                         wprintf("</i></b></td><td><b><i>");
172                         wprintf(_("Date/time submitted"));
173                         wprintf("</i></b></td><td><b><i>");
174                         wprintf(_("Last attempt"));
175                         wprintf("</i></b></td><td><b><i>");
176                         wprintf(_("Sender"));
177                         wprintf("</i></b></td><td><b><i>");
178                         wprintf(_("Recipients"));
179                         wprintf("</i></b></td></tr>\n");
180
181                         for (i=0; i<num_msgs; ++i) {
182                                 display_queue_msg(WC->msgarr[i]);
183                         }
184
185                         wprintf("</table>");
186
187                 }
188                 else {
189                         wprintf("<br /><br /><div align=\"center\">");
190                         wprintf(_("The queue is empty."));
191                         wprintf("</div><br /><br />");
192                 }
193         }
194         else {
195                 wprintf("<br /><br /><div align=\"center\">");
196                 wprintf(_("You do not have permission to view this resource."));
197                 wprintf("</div><br /><br />");
198         }
199
200 }
201
202 /**
203  * \brief display the outbound SMTP queue
204  */
205 void display_smtpqueue(void)
206 {
207         output_headers(1, 1, 2, 0, 0, 0);
208
209         wprintf("<script type=\"text/javascript\">                              \n"
210                 "function RefreshQueueDisplay() {                               \n"
211                 "       new Ajax.Updater('smtpqueue_inner_div',                 \n"
212                 "       'display_smtpqueue_inner_div', { method: 'get',         \n"
213                 "               parameters: Math.random() } );                  \n"
214                 "}                                                              \n"
215                 "                                                               \n"
216                 "function DeleteQueueMsg(msgnum1, msgnum2) {                                    \n"
217                 "       new Ajax.Request(                                                       \n"
218                 "               'ajax_servcmd', {                                               \n"
219                 "                       method: 'post',                                         \n"
220                 "                       parameters: 'g_cmd=DELE ' + msgnum1 + ',' + msgnum2,    \n"
221                 "                       onComplete: RefreshQueueDisplay()                       \n"
222                 "               }                                                               \n"
223                 "       );                                                                      \n"
224                 "}                                                                              \n"
225                 "                                                               \n"
226                 "</script>                                                      \n"
227         );
228
229         wprintf("<div id=\"banner\">\n");
230         wprintf("<h1>");
231         wprintf(_("View the outbound SMTP queue"));
232         wprintf("</h1>\n");
233         wprintf("</div>\n");
234
235         wprintf("<div id=\"content\" class=\"service\">\n");
236
237         wprintf("<div class=\"fix_scrollbar_bug\">"
238                 "<table class=\"smtpqueue_background\">"
239                 "<tr><td valign=top>\n");
240
241         wprintf("<div id=\"smtpqueue_inner_div\">");
242
243         display_smtpqueue_inner_div();
244
245         wprintf("</div>"
246                 "<div align=\"center\">"
247                 "<a href=\"javascript:RefreshQueueDisplay();\">%s</a>"
248                 "</div>"
249                 "</td></tr></table></div>\n", _("Refresh this page")
250         );
251         wDumpContent(1);
252
253 }
254
255
256
257
258 /*@}*/